Toggle menu and line numbers easily

Toggling between relative, absolute and off for line numbers.
This commit is contained in:
Howard Abrams 2024-06-30 11:52:46 -07:00
parent 437f707deb
commit e1897c2e95
2 changed files with 20 additions and 22 deletions

View file

@ -30,12 +30,6 @@ I begin configuration of Emacs that isnt /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

View file

@ -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 ()