dotfiles

My personal shell configs and stuff
git clone git://git.alex.balgavy.eu/dotfiles.git
Log | Files | Refs | Submodules | README | LICENSE

commit 115f368191c407250f538175d55255c9570d897e
parent 799ac36353163409bc8cf012dce381d3717c644a
Author: Alex Balgavy <alex@balgavy.eu>
Date:   Thu,  3 Mar 2022 23:09:25 +0100

emacs: get rid of add-hook lambdas

They provide no information. It's better to have namespaced defuns
with proper docstrings.

Diffstat:
Memacs/config.org | 111+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--------------------
1 file changed, 83 insertions(+), 28 deletions(-)

diff --git a/emacs/config.org b/emacs/config.org @@ -193,6 +193,8 @@ Furthermore, tags were getting cut off, so I manually set the best column to dis (defun za/settings-org-mode () "My settings for org mode" (org-bullets-mode 1) + (za/toggle-wrap t) + (org-indent-mode) (setq org-tags-column (- 10 (window-total-width))) ;; Realign tags (org-set-tags-command '(4))) @@ -482,6 +484,13 @@ Relative line numbers: (global-display-line-numbers-mode) #+end_src +Function to hide them: + +#+begin_src emacs-lisp + (defun za/hide-line-numbers () + "Hide line numbers" + (display-line-numbers-mode 0)) +#+end_src Don't display them in specific modes. For each of the modes in 'mode-hooks', add a function to hide line numbers when the mode activates (which triggers the 'mode'-hook). @@ -490,7 +499,7 @@ activates (which triggers the 'mode'-hook). (let ((mode-hooks '(doc-view-mode-hook vterm-mode-hook mpc-status-mode-hook mpc-tagbrowser-mode-hook))) (mapc (lambda (mode-name) - (add-hook mode-name (lambda () (display-line-numbers-mode 0)))) + (add-hook mode-name #'za/hide-line-numbers)) mode-hooks)) #+end_src *** Modeline @@ -631,14 +640,9 @@ But I want to automatically strip trailing whitespace. Luckily there's already a function for that, I just need to call it in a hook: #+begin_src emacs-lisp - (add-hook 'before-save-hook 'delete-trailing-whitespace) + (add-hook 'before-save-hook #'delete-trailing-whitespace) #+end_src ** Formatting & indentation -Disable fill mode in Markdown - -#+begin_src emacs-lisp - (add-hook 'markdown-mode-hook (lambda () (auto-fill-mode 0) (flyspell-mode 1))) -#+end_src Show a tab as 8 spaces: @@ -727,11 +731,13 @@ And a keybinding to toggle wrapping: I want to wrap text at window boundary for some modes: #+begin_src emacs-lisp - (add-hook 'org-mode-hook (lambda () - (za/toggle-wrap t) - (org-indent-mode))) - (add-hook 'markdown-mode-hook (lambda () (za/toggle-wrap t))) - (add-hook 'help-mode-hook (lambda () (za/toggle-wrap t))) + (defun za/settings-help-mode () + "Help mode settings" + (za/toggle-wrap t)) +#+end_src + +#+begin_src emacs-lisp + (add-hook 'help-mode-hook #'za/settings-help-mode) #+end_src ** Pulse line @@ -766,7 +772,7 @@ And set the pulse color: (custom-set-faces '(pulse-highlight-start-face ((t (:background "CadetBlue2"))))) #+end_src -** Pager mode +** Pager toggle keybinding M-x view-mode enables pager behavior. I want read-only files to automatically use pager mode: @@ -836,9 +842,14 @@ SemanticDB is written into ~/.emacs.d/semanticdb/. Enable semantic mode for major modes: #+begin_src emacs-lisp + (defun za/settings-c-mode () + "C mode settings" + (semantic-mode 1)) +#+end_src +#+begin_src emacs-lisp (let ((mode-hooks [c-mode-common-hook])) (mapc (lambda (mode-name) - (add-hook mode-name (lambda () (semantic-mode 1)))) + (add-hook mode-name #'za/settings-c-mode)) mode-hooks)) #+end_src @@ -1232,17 +1243,37 @@ macOS doesn't have dbus. So I use terminal-notifier for functions like org-notif "-group" "org.gnu.Emacs" "-sender" "org.gnu.Emacs")))) #+end_src + +* Markdown +Markdown mode settings. + +#+begin_src emacs-lisp + (defun za/settings-markdown-mode () + "My settings for markdown mode" + (auto-fill-mode 0) + (flyspell-mode 1) + (za/toggle-wrap t)) + + (add-hook 'markdown-mode-hook #'za-settings-markdown-mode) +#+end_src + * Bib(la)tex #+begin_src emacs-lisp - (add-hook 'bibtex-mode-hook (lambda () (bibtex-set-dialect "biblatex"))) + (defun za/settings-bibtex-mode () + "My settings for bibtex mode" + (bibtex-set-dialect "biblatex")) +#+end_src + +#+begin_src emacs-lisp + (add-hook 'bibtex-mode-hook #'za/settings-bibtex-mode) #+end_src * Python In Python, I want to enable flycheck and semantic mode: #+begin_src emacs-lisp - (add-hook 'python-mode-hook 'flycheck-mode) - (add-hook 'python-mode-hook 'semantic-mode) + (add-hook 'python-mode-hook #'flycheck-mode) + (add-hook 'python-mode-hook #'semantic-mode) #+end_src * Misc settings @@ -1375,7 +1406,13 @@ Set tags: Run notmuch-hook script on hello refresh, to move messages to folders according to their tags: #+begin_src emacs-lisp - (add-hook 'notmuch-hello-refresh-hook (lambda () (start-process "notmuch-hook" nil "notmuch-hook" "tags2folders"))) + (defun za/notmuch-hook-tags2folders () + "Run notmuch-hook to organise email in folders based on tags." + (start-process "notmuch-hook" nil "notmuch-hook" "tags2folders")) +#+end_src + +#+begin_src emacs-lisp + (add-hook 'notmuch-hello-refresh-hook #'za/notmuch-hook/tags2folders) #+end_src Sort with newest first: @@ -1391,18 +1428,36 @@ Set the windows I want to show: (setq mpc-browser-tags '(AlbumArtist Album Genre Playlist)) #+end_src +Define some functions: + +#+begin_src emacs-lisp + (defun za/mpc-seek-forward-20-seconds () + "Seek forward 20 seconds" + (interactive) + (mpc-seek-current "+20")) + + (defun za/mpc-seek-backward-20-seconds () + "Seek backward 20 seconds" + (interactive) + (mpc-seek-current "-20")) +#+end_src + Define some keybindings: #+begin_src emacs-lisp - (add-hook 'mpc-mode-hook - (lambda () - (define-key mpc-mode-map "a" #'mpc-playlist-add) - (define-key mpc-mode-map "P" #'mpc-playlist) - (define-key mpc-mode-map "x" #'mpc-playlist-delete) - (define-key mpc-mode-map "p" #'mpc-toggle-play) - (define-key mpc-mode-map "t" #'mpc-select-toggle) - (define-key mpc-mode-map "f" (lambda () "Seek forward 20 seconds" (interactive) (mpc-seek-current "+20"))) - (define-key mpc-mode-map "b" (lambda () "Seek backward 20 seconds" (interactive) (mpc-seek-current "-20"))))) + (defun za/mpc-mode-settings () + "MPC mode settings" + (define-key mpc-mode-map "a" #'mpc-playlist-add) + (define-key mpc-mode-map "P" #'mpc-playlist) + (define-key mpc-mode-map "x" #'mpc-playlist-delete) + (define-key mpc-mode-map "p" #'mpc-toggle-play) + (define-key mpc-mode-map "t" #'mpc-select-toggle) + (define-key mpc-mode-map "f" #'za/mpc-seek-forward-20-seconds) + (define-key mpc-mode-map "b" #'za/mpc-seek-backward-20-seconds)) +#+end_src + +#+begin_src emacs-lisp + (add-hook 'mpc-mode-hook #'za/mpc-mode-settings) #+end_src Unfortunately the lambda keybindings don't show up documented properly, but oh well. That's a minor problem. @@ -1433,7 +1488,7 @@ Set up listing display: By default, hide details (show again by pressing oparen): #+begin_src emacs-lisp - (add-hook 'dired-mode-hook 'dired-hide-details-mode) + (add-hook 'dired-mode-hook #'dired-hide-details-mode) #+end_src If I have another dired window open, use that as target: