From e1897c2e95fff9267df4bd93e4bf924740e2556a Mon Sep 17 00:00:00 2001 From: Howard Abrams Date: Sun, 30 Jun 2024 11:52:46 -0700 Subject: [PATCH] Toggle menu and line numbers easily Toggling between relative, absolute and off for line numbers. --- ha-config.org | 23 +++++++++++++++++------ ha-general.org | 19 +++---------------- 2 files changed, 20 insertions(+), 22 deletions(-) diff --git a/ha-config.org b/ha-config.org index e3cd43a..6ac62b4 100644 --- a/ha-config.org +++ b/ha-config.org @@ -30,12 +30,6 @@ I begin configuration of Emacs that isn’t /package-specific/. For instance, I (setq confirm-kill-emacs 'yes-or-no-p) #+end_src -Emacs has some new code to display line-numbers: -#+begin_src emacs-lisp - (setq display-line-numbers t - display-line-numbers-type 'visual) -#+end_src - I like the rendering of curved quotes using [[help:text-quoting-style][text-quoting-style]], because it improves the readability of documentation strings in the =∗Help∗= buffer and whatnot. #+begin_src emacs-lisp (setq text-quoting-style 'curve @@ -50,6 +44,23 @@ Changes and settings I like introduced that were introduced in Emacs 28: completions-detailed t) #+end_src +Emacs has some new code to display line-numbers, and the =visual= value works well with my Org files, allowing a jump to a line via ~6 j~: +#+begin_src emacs-lisp + (setq display-line-numbers-type 'visual) +#+end_src + +But sometimes we want to jump to /absolute/ line numbers, so I have a toggling function: +#+begin_src emacs-lisp + (defun ha-toggle-relative-line-numbers () + (interactive) + (cond + ((null display-line-numbers) (display-line-numbers-mode)) + ((or (eq display-line-numbers 'relative) + (eq display-line-numbers 'visual)) + (setq display-line-numbers t)) + (t (display-line-numbers-mode -1)))) +#+end_src + In Emacs version 28, we can hide commands in ~M-x~ which do not apply to the current mode. #+begin_src emacs-lisp (setq read-extended-command-predicate diff --git a/ha-general.org b/ha-general.org index 388985e..681ee2d 100644 --- a/ha-general.org +++ b/ha-general.org @@ -370,8 +370,9 @@ The goal here is toggle switches and other miscellaneous settings. "t d" '("debug" . toggle-debug-on-error) "t F" '("show functions" . which-function-mode) "t f" '("auto-fill" . auto-fill-mode) + "t l" '("line numbers" . ha-toggle-relative-line-numbers) "t o" '("overwrite" . overwrite-mode) - "t l" '("line numbers" . display-line-numbers-mode) + "t m" '("menu bar" . menu-bar-mode) "t R" '("read only" . read-only-mode) "t r" '("recentf mode" . recentf-mode) "t t" '("truncate" . toggle-truncate-lines) @@ -380,21 +381,7 @@ The goal here is toggle switches and other miscellaneous settings. "t w" '("whitespace" . whitespace-mode)) #+end_src -* Line Numbers -Since we can't automatically toggle between relative and absolute line numbers, we create this function: -#+begin_src emacs-lisp - (defun ha-toggle-relative-line-numbers () - (interactive) - (if (eq display-line-numbers 'relative) - (setq display-line-numbers t) - (setq display-line-numbers 'relative))) -#+end_src -Add it to the toggle menu: -#+begin_src emacs-lisp - (ha-leader - "t r" '("relative lines" . ha-toggle-relative-line-numbers)) -#+end_src -* Narrowing +** Narrowing I like the focus the [[info:emacs#Narrowing][Narrowing features]] offer, but what a /dwim/ aspect: #+begin_src emacs-lisp (defun ha-narrow-dwim ()