dotfiles

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

commit a9e7b42056e5283e1855d97367e7999063a0f730
parent 46b93b6802c3bab25a6814bf5293b9ff37d4b65d
Author: Alex Balgavy <alex@balgavy.eu>
Date:   Wed,  8 Jun 2022 13:36:30 +0200

emacs: add history to helpful-mode

Diffstat:
Memacs/config.org | 66+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
1 file changed, 65 insertions(+), 1 deletion(-)

diff --git a/emacs/config.org b/emacs/config.org @@ -1339,6 +1339,68 @@ Also, counsel doesn't provide some keybindings that I can get from helpful: (za/global-set-key (kbd "C-h k") #'helpful-key) (za/global-set-key (kbd "C-h C") #'helpful-command) #+end_src + +Then, a way to jump forward and backward in the window: + +#+begin_src emacs-lisp + (defvar za/helpful-buffer-ring-size 20 + "How many buffers are stored for use with `helpful-next'.") + + (defvar za/helpful--buffer-ring (make-ring za/helpful-buffer-ring-size) + "Ring that stores the current Helpful buffer history.") + + (defun za/helpful--buffer-index (&optional buffer) + "If BUFFER is a Helpful buffer, return it’s index in the buffer ring." + (let ((buf (or buffer (current-buffer)))) + (and (eq (buffer-local-value 'major-mode buf) 'helpful-mode) + (seq-position (ring-elements za/helpful--buffer-ring) buf #'eq)))) + + (defun za/helpful--new-buffer-a (help-buf) + "Update the buffer ring according to the current buffer and HELP-BUF." + :filter-return #'helpful--buffer + (let ((buf-ring za/helpful--buffer-ring)) + (let ((newer-buffers (or (za/helpful--buffer-index) 0))) + (dotimes (_ newer-buffers) (ring-remove buf-ring 0))) + (when (/= (ring-size buf-ring) za/helpful-buffer-ring-size) + (ring-resize buf-ring za/helpful-buffer-ring-size)) + (ring-insert buf-ring help-buf))) + + (advice-add #'helpful--buffer :filter-return #'za/helpful--new-buffer-a) + + (defun za/helpful--next (&optional buffer) + "Return the next live Helpful buffer relative to BUFFER." + (let ((buf-ring za/helpful--buffer-ring) + (index (or (za/helpful--buffer-index buffer) -1))) + (cl-block nil + (while (> index 0) + (cl-decf index) + (let ((buf (ring-ref buf-ring index))) + (if (buffer-live-p buf) (cl-return buf))) + (ring-remove buf-ring index))))) + + (defun za/helpful--previous (&optional buffer) + "Return the previous live Helpful buffer relative to BUFFER." + (let ((buf-ring za/helpful--buffer-ring) + (index (1+ (or (za/helpful--buffer-index buffer) -1)))) + (cl-block nil + (while (< index (ring-length buf-ring)) + (let ((buf (ring-ref buf-ring index))) + (if (buffer-live-p buf) (cl-return buf))) + (ring-remove buf-ring index))))) + + (defun za/helpful-next () + "Go to the next Helpful buffer." + (interactive) + (when-let (buf (za/helpful--next)) + (funcall helpful-switch-buffer-function buf))) + + (defun za/helpful-previous () + "Go to the previous Helpful buffer." + (interactive) + (when-let (buf (za/helpful--previous)) + (funcall helpful-switch-buffer-function buf))) +#+end_src + ** ace-window Window switching with ~other-window~ sucks when I have more than 2 windows open. Too much cognitive load. This lets me select a window to jump to using a single key, sort of like ~avy~. @@ -1656,7 +1718,9 @@ I want to wrap text at window boundary for some modes: #+begin_src emacs-lisp (defun za/settings-helpful-mode () "Helpful mode settings" - (za/toggle-wrap t)) + (za/toggle-wrap t) + (define-key helpful-mode-map (kbd "l") #'za/helpful-previous) + (define-key helpful-mode-map (kbd "r") #'za/helpful-next)) (add-hook 'helpful-mode-hook #'za/settings-helpful-mode) #+end_src