emacs: Fix olivetti mode issue, add a manual toggle check
This commit is contained in:
parent
d199950bc3
commit
d4879ef719
@ -348,33 +348,50 @@ Use Dashboard.el. First load `all-the-icons` for nicer rendering
|
|||||||
#+begin_src emacs-lisp
|
#+begin_src emacs-lisp
|
||||||
(require 'olivetti)
|
(require 'olivetti)
|
||||||
|
|
||||||
(setq olivetti-minimum-body-width 160)
|
(setq olivetti-minimum-body-width 140)
|
||||||
|
|
||||||
(global-set-key (kbd "C-x x o") 'olivetti-mode)
|
(defvar-local joe/olivetti-manually-toggled nil
|
||||||
|
"Non-nil if olivetti-mode was manually toggled via keybinding.")
|
||||||
|
|
||||||
|
(defun joe/olivetti-manual-toggle ()
|
||||||
|
"Toggle olivetti-mode and mark buffer as manually toggled."
|
||||||
|
(interactive)
|
||||||
|
(setq joe/olivetti-manually-toggled t)
|
||||||
|
(olivetti-mode 'toggle)
|
||||||
|
(message "Olivetti mode %s" (if olivetti-mode "enabled" "disabled")))
|
||||||
|
|
||||||
|
(global-set-key (kbd "C-x x o") #'joe/olivetti-manual-toggle)
|
||||||
|
|
||||||
(defun joe/toggle-olivetti-based-on-neighbors ()
|
(defun joe/toggle-olivetti-based-on-neighbors ()
|
||||||
(when (derived-mode-p 'org-mode 'prog-mode)
|
(when (and (derived-mode-p 'org-mode 'prog-mode)
|
||||||
|
(not joe/olivetti-manually-toggled))
|
||||||
(if (or (window-in-direction 'left)
|
(if (or (window-in-direction 'left)
|
||||||
(window-in-direction 'right))
|
(window-in-direction 'right))
|
||||||
(olivetti-mode -1)
|
(olivetti-mode -1)
|
||||||
(olivetti-mode 1))))
|
(olivetti-mode 1))))
|
||||||
|
|
||||||
|
|
||||||
(add-hook 'window-configuration-change-hook #'joe/toggle-olivetti-based-on-neighbors)
|
(add-hook 'window-configuration-change-hook #'joe/toggle-olivetti-based-on-neighbors)
|
||||||
|
|
||||||
(defun joe/olivetti-minibuffer ()
|
(defun joe/olivetti-minibuffer ()
|
||||||
(setq-local olivetti-minimum-body-width 180)
|
(setq-local olivetti-minimum-body-width 180)
|
||||||
(olivetti-mode 1))
|
(olivetti-mode 1))
|
||||||
|
|
||||||
(add-hook 'minibuffer-setup-hook #'joe/olivetti-minibuffer)
|
;; (add-hook 'minibuffer-setup-hook #'joe/olivetti-minibuffer)
|
||||||
|
|
||||||
;; (remove-hook 'window-configuration-change-hook #'joe/toggle-olivetti-based-on-neighbors)
|
;; (remove-hook 'window-configuration-change-hook #'joe/toggle-olivetti-based-on-neighbors)
|
||||||
#+end_src
|
#+end_src
|
||||||
|
|
||||||
Remove this hook from Olivetti so that lines can truncate [[https://github.com/rnkn/olivetti/issues/76][Github issue]]
|
Remove this hook from Olivetti so that lines can truncate [[https://github.com/rnkn/olivetti/issues/76][Github issue]], but keep visual-line-mode for org-mode
|
||||||
|
|
||||||
#+begin_src emacs-lisp
|
#+begin_src emacs-lisp
|
||||||
(remove-hook 'olivetti-mode-on-hook 'visual-line-mode)
|
(remove-hook 'olivetti-mode-on-hook 'visual-line-mode)
|
||||||
|
|
||||||
|
(defun joe/restore-visual-line-mode-for-org ()
|
||||||
|
"Re-enable visual-line-mode when olivetti-mode turns off in org buffers."
|
||||||
|
(when (derived-mode-p 'org-mode)
|
||||||
|
(visual-line-mode 1)))
|
||||||
|
|
||||||
|
(add-hook 'olivetti-mode-off-hook #'joe/restore-visual-line-mode-for-org)
|
||||||
#+end_src
|
#+end_src
|
||||||
*** Themes
|
*** Themes
|
||||||
|
|
||||||
@ -459,7 +476,7 @@ Setup other stuff
|
|||||||
;; (right-divider-width . 5)
|
;; (right-divider-width . 5)
|
||||||
;; (tab-bar-lines . 0)
|
;; (tab-bar-lines . 0)
|
||||||
;; (internal-border-width . 12)))
|
;; (internal-border-width . 12)))
|
||||||
(add-hook 'text-mode-hook (lambda () (setq fill-column 80) (turn-on-auto-fill)))
|
(add-hook 'text-mode-hook (lambda () (setq fill-column 120) (turn-on-auto-fill)))
|
||||||
|
|
||||||
;; (setq display-line-numbers 'relative)
|
;; (setq display-line-numbers 'relative)
|
||||||
(make-variable-buffer-local 'global-hl-line-mode)
|
(make-variable-buffer-local 'global-hl-line-mode)
|
||||||
@ -516,8 +533,8 @@ Setup other stuff
|
|||||||
|
|
||||||
|
|
||||||
;; TODO Likely not needed anymore
|
;; TODO Likely not needed anymore
|
||||||
(dolist (mode '(dired-mode-hook lsp-help-mode-hook fundamental-mode-hook))
|
;; (dolist (mode '(dired-mode-hook lsp-help-mode-hook fundamental-mode-hook))
|
||||||
(add-hook mode (lambda () (setq truncate-lines t))))
|
;; (add-hook mode (lambda () (setq truncate-lines t))))
|
||||||
#+end_src
|
#+end_src
|
||||||
|
|
||||||
Ligatures... are they that useful?
|
Ligatures... are they that useful?
|
||||||
@ -624,7 +641,8 @@ Emacs is an great operating system, if only it had a good text editor...
|
|||||||
(global-set-key (kbd "M-o") #'joe/insert-line-below)
|
(global-set-key (kbd "M-o") #'joe/insert-line-below)
|
||||||
(global-set-key (kbd "M-O") #'joe/insert-line-above)
|
(global-set-key (kbd "M-O") #'joe/insert-line-above)
|
||||||
|
|
||||||
(setq-default truncate-lines t)
|
;; (setq-default truncate-lines nil)
|
||||||
|
(setq-default truncate-partial-width-windows nil)
|
||||||
|
|
||||||
(defun joe/backward-kill-word-or-kill-region ()
|
(defun joe/backward-kill-word-or-kill-region ()
|
||||||
(interactive)
|
(interactive)
|
||||||
@ -806,7 +824,6 @@ Fill region is great, except when you don't need it...
|
|||||||
(kbd "SPC sv") 'vterm-other-window
|
(kbd "SPC sv") 'vterm-other-window
|
||||||
(kbd "SPC mm") 'mu4e
|
(kbd "SPC mm") 'mu4e
|
||||||
(kbd "SPC cl") 'consult-line
|
(kbd "SPC cl") 'consult-line
|
||||||
(kbd "SPC ci") 'consult-imenu
|
|
||||||
(kbd "SPC cy") 'consult-yank-from-kill-ring
|
(kbd "SPC cy") 'consult-yank-from-kill-ring
|
||||||
(kbd "SPC cg") 'consult-ripgrep
|
(kbd "SPC cg") 'consult-ripgrep
|
||||||
(kbd "SPC cF") 'consult-find
|
(kbd "SPC cF") 'consult-find
|
||||||
@ -849,9 +866,10 @@ Fill region is great, except when you don't need it...
|
|||||||
(setq evil-goggles-async-duration 0.55)
|
(setq evil-goggles-async-duration 0.55)
|
||||||
|
|
||||||
;; Recenter lines after mark jump
|
;; Recenter lines after mark jump
|
||||||
(defun joe/recenter-after-goto-mark ()
|
;; (defun joe/recenter-after-goto-mark ()
|
||||||
(recenter))
|
;; (interactive)
|
||||||
(advice-add 'evil-goto-mark :after #'joe/recenter-after-goto-mark)
|
;; (recenter))
|
||||||
|
;; (advice-add 'evil-goto-mark :after #'joe/recenter-after-goto-mark)
|
||||||
#+end_src
|
#+end_src
|
||||||
*** COMMENT easy-kill
|
*** COMMENT easy-kill
|
||||||
#+begin_src emacs-lisp
|
#+begin_src emacs-lisp
|
||||||
@ -1952,7 +1970,7 @@ close and remove the hook
|
|||||||
(with-current-buffer vterm-buf
|
(with-current-buffer vterm-buf
|
||||||
(setq mode-line-format nil)
|
(setq mode-line-format nil)
|
||||||
(setq popper-popup-status 'raised)
|
(setq popper-popup-status 'raised)
|
||||||
(olivetti-mode)
|
;; (olivetti-mode)
|
||||||
(add-hook 'delete-frame-functions #'joe/kill-vterm-scratch)
|
(add-hook 'delete-frame-functions #'joe/kill-vterm-scratch)
|
||||||
(add-hook 'kill-buffer-hook #'joe/kill-frame))))
|
(add-hook 'kill-buffer-hook #'joe/kill-frame))))
|
||||||
#+end_src
|
#+end_src
|
||||||
@ -2096,8 +2114,6 @@ These help speed eglot up apparently [[https://www.reddit.com/r/emacs/comments/1
|
|||||||
(flymake-mode -1))
|
(flymake-mode -1))
|
||||||
(add-hook 'lsp-mode-hook #'joe/lsp-mode-hook)
|
(add-hook 'lsp-mode-hook #'joe/lsp-mode-hook)
|
||||||
|
|
||||||
(define-key global-map (kbd "C-c l l") #'lsp)
|
|
||||||
|
|
||||||
;; (setq lsp-ui-doc-position 'at-point)
|
;; (setq lsp-ui-doc-position 'at-point)
|
||||||
;; (setq lsp-ui-doc-show-with-mouse nil)
|
;; (setq lsp-ui-doc-show-with-mouse nil)
|
||||||
|
|
||||||
@ -2118,9 +2134,8 @@ These help speed eglot up apparently [[https://www.reddit.com/r/emacs/comments/1
|
|||||||
|
|
||||||
#+end_src
|
#+end_src
|
||||||
|
|
||||||
Omnisharp is very slow to start, so I want to start it manually, but not if the
|
Some servers/projects start up really slow, so let's start LSP manually. This function allows buffers to attach only to
|
||||||
buffer already belongs to the current lsp workspace. This function checks if a
|
existing LSP sessions that were manually started.
|
||||||
newly opened buffer belongs to an LSP session and if it does, start lsp
|
|
||||||
|
|
||||||
#+begin_src emacs-lisp
|
#+begin_src emacs-lisp
|
||||||
(defun lsp-mode-server-exists-p+ (mode &optional all-workspaces)
|
(defun lsp-mode-server-exists-p+ (mode &optional all-workspaces)
|
||||||
@ -2139,6 +2154,26 @@ newly opened buffer belongs to an LSP session and if it does, start lsp
|
|||||||
;; (setq treesit-load-name-override-list '((csharp "libtree-sitter-c-sharp.so")))
|
;; (setq treesit-load-name-override-list '((csharp "libtree-sitter-c-sharp.so")))
|
||||||
#+end_src
|
#+end_src
|
||||||
|
|
||||||
|
Likewise, because opening buffers doesn't start LSP, there could be a lot of already opened buffers before we decide to
|
||||||
|
start it, so go through all existing buffers that match the mode and belong to the project.
|
||||||
|
|
||||||
|
#+begin_src emacs-lisp
|
||||||
|
(defun joe/lsp-activate-for-project-buffers ()
|
||||||
|
(interactive)
|
||||||
|
(lsp)
|
||||||
|
(let ((root (lsp-workspace-root))
|
||||||
|
(mode major-mode))
|
||||||
|
(dolist (buf (buffer-list))
|
||||||
|
(with-current-buffer buf
|
||||||
|
(when (and (eq major-mode mode)
|
||||||
|
(buffer-file-name)
|
||||||
|
(not lsp-mode)
|
||||||
|
(equal (lsp-workspace-root) root))
|
||||||
|
(lsp))))))
|
||||||
|
|
||||||
|
(define-key global-map (kbd "C-c l l") #'joe/lsp-activate-for-project-buffers)
|
||||||
|
#+end_src
|
||||||
|
|
||||||
#+end_src
|
#+end_src
|
||||||
*** Flycheck
|
*** Flycheck
|
||||||
|
|
||||||
@ -2245,6 +2280,8 @@ newly opened buffer belongs to an LSP session and if it does, start lsp
|
|||||||
(evil-define-key 'visual joe/evil-space-mode-map (kbd "SPC a r") #'gptel-rewrite)
|
(evil-define-key 'visual joe/evil-space-mode-map (kbd "SPC a r") #'gptel-rewrite)
|
||||||
(evil-define-key 'visual joe/evil-space-mode-map (kbd "SPC a RET") #'gptel-ask)
|
(evil-define-key 'visual joe/evil-space-mode-map (kbd "SPC a RET") #'gptel-ask)
|
||||||
(evil-define-key 'visual joe/evil-space-mode-map (kbd "SPC a c") #'gptel-add)
|
(evil-define-key 'visual joe/evil-space-mode-map (kbd "SPC a c") #'gptel-add)
|
||||||
|
(setq gptel-model 'claude-sonnet-4-6)
|
||||||
|
(setq gptel-backend (gptel-get-backend "Claude"))
|
||||||
#+end_src
|
#+end_src
|
||||||
|
|
||||||
gptel-context-remove-all without confirmation
|
gptel-context-remove-all without confirmation
|
||||||
@ -2648,8 +2685,7 @@ Org mode buffers have associated files.
|
|||||||
(org-fancy-priorities-mode)
|
(org-fancy-priorities-mode)
|
||||||
(visual-line-mode)
|
(visual-line-mode)
|
||||||
(org-bullets-mode)
|
(org-bullets-mode)
|
||||||
(org-indent-mode)
|
(org-indent-mode))
|
||||||
(olivetti-mode))
|
|
||||||
(add-hook 'org-mode-hook 'joe/org-hook)
|
(add-hook 'org-mode-hook 'joe/org-hook)
|
||||||
|
|
||||||
#+end_src
|
#+end_src
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user