New user option follow-mode-prefix-key

* lisp/follow.el (Commentary): Document modern keymap functions.
(follow-mode-prefix): Make obsolete in favor of...
(follow-mode-prefix-key): ...this new user option.  Allow changing the
prefix using `setopt`.
(follow-mode-submap): New variable.
(follow-mode-map): Define using defvar-keymap.
This commit is contained in:
Stefan Kangas 2025-02-25 02:58:09 +01:00
parent 40d8650d51
commit 27b31ebeaf
2 changed files with 60 additions and 41 deletions

View file

@ -1438,6 +1438,12 @@ Display of tooltips on text-only terminals now happens after
'tooltip-delay' as it does on GUI terminals. To get back the old
behavior, customize the value of 'tooltip-delay' to zero.
---
*** New user option 'follow-mode-prefix-key'.
This user option replaces 'follow-mode-prefix', which had to be set
before loading Follow mode. This new option allows you to change the
prefix even after it was loaded, using 'customize-option' or 'setopt'.
---
*** cdl.el is now obsolete.
Use 'shell-command' and 'shell-command-on-region' instead.

View file

@ -75,7 +75,7 @@
;; immediately below the end of the left-hand window. As long as
;; `follow-mode' is active, the two windows will follow each other!
;;
;; * Play around and enjoy! Scroll one window and watch the other.
;; * Play around and enjoy! Scroll one window and watch the other.
;; Jump to the beginning or end. Press `Cursor down' at the last
;; line of the left-hand window. Enter new lines into the
;; text. Enter long lines spanning several lines, or several
@ -90,11 +90,11 @@
;; visible area of the current buffer.
;;
;; I recommend adding it, and `follow-mode', to hotkeys in the global
;; key map. To do so, add the following lines (replacing `[f7]' and
;; `[f8]' with your favorite keys) to the init file:
;; key map. To do so, add the following lines (replacing "<f7>" and
;; "<f8>" with your favorite keys) to your init file:
;;
;; (global-set-key [f8] #'follow-mode)
;; (global-set-key [f7] #'follow-delete-other-windows-and-split)
;; (keymap-global-set "<f8>" #'follow-mode)
;; (keymap-global-set "<f7>" #'follow-delete-other-windows-and-split)
;; There exist two system variables that control the appearance of
@ -104,8 +104,8 @@
;; To make sure lines are never truncated, place the following lines
;; in your Init file:
;;
;; (setq truncate-lines nil)
;; (setq truncate-partial-width-windows nil)
;; (setopt truncate-lines nil)
;; (setopt truncate-partial-width-windows nil)
;; One way to configure Follow mode is to create one or more functions
@ -116,11 +116,9 @@
;; `follow-mode'.
;;
;; Example:
;; (add-hook 'follow-mode-hook 'my-follow-mode-hook)
;;
;; (defun my-follow-mode-hook ()
;; (define-key follow-mode-map "\C-ca" #'your-favorite-function)
;; (define-key follow-mode-map "\C-cb" #'another-function))
;; (with-eval-after-load 'follow
;; (keymap-set follow-mode-map "C-c a" #'your-favorite-function)
;; (keymap-set follow-mode-map "C-c b" #'another-function))
;; Usage:
@ -181,7 +179,7 @@
;; be reactivated by hitting the same key again.
;;
;; Example from my ~/.emacs:
;; (global-set-key [f8] #'follow-mode)
;; (keymap-global-set "<f8>" #'follow-mode)
;; Implementation:
;;
@ -230,39 +228,54 @@ The value of this variable is checked as part of loading Follow mode.
After that, changing the prefix key requires manipulating keymaps."
:type 'string
:group 'follow)
(make-obsolete-variable 'follow-mode-prefix 'follow-mode-prefix-key "31.1")
(defvar follow-mode-map
(let ((mainmap (make-sparse-keymap))
(map (make-sparse-keymap)))
(define-key map "\C-v" #'follow-scroll-up)
(define-key map "\M-v" #'follow-scroll-down)
(define-key map "v" #'follow-scroll-down)
(define-key map "1" #'follow-delete-other-windows-and-split)
(define-key map "b" #'follow-switch-to-buffer)
(define-key map "\C-b" #'follow-switch-to-buffer-all)
(define-key map "\C-l" #'follow-recenter)
(define-key map "<" #'follow-first-window)
(define-key map ">" #'follow-last-window)
(define-key map "n" #'follow-next-window)
(define-key map "p" #'follow-previous-window)
(defcustom follow-mode-prefix-key (key-description follow-mode-prefix)
"Prefix key to use for follow commands in Follow mode.
(define-key mainmap follow-mode-prefix map)
Setting this variable with `setq' has no effect; use either `setopt'
or `customize-option' to change its value."
:type 'string
:set (lambda (symbol value)
(defvar follow-mode-map) (defvar follow-mode-submap)
(keymap-unset follow-mode-map (symbol-value symbol))
(keymap-set follow-mode-map value follow-mode-submap)
(set-default symbol value))
:group 'follow
:version "31.1")
;; Replace the standard `end-of-buffer', when in Follow mode. (I
;; don't see the point in trying to replace every function that
;; could be enhanced in Follow mode. End-of-buffer is a special
;; case since it is very simple to define and it greatly enhances
;; the look and feel of Follow mode.)
(define-key mainmap [remap end-of-buffer] #'follow-end-of-buffer)
(defun follow--prefix-key (key)
(concat follow-mode-prefix-key " " key))
(define-key mainmap [remap scroll-bar-toolkit-scroll] #'follow-scroll-bar-toolkit-scroll)
(define-key mainmap [remap scroll-bar-drag] #'follow-scroll-bar-drag)
(define-key mainmap [remap scroll-bar-scroll-up] #'follow-scroll-bar-scroll-up)
(define-key mainmap [remap scroll-bar-scroll-down] #'follow-scroll-bar-scroll-down)
(define-key mainmap [remap mwheel-scroll] #'follow-mwheel-scroll)
(defvar-keymap follow-mode-submap
"C-v" #'follow-scroll-up
"M-v" #'follow-scroll-down
"v" #'follow-scroll-down
"1" #'follow-delete-other-windows-and-split
"b" #'follow-switch-to-buffer
"C-b" #'follow-switch-to-buffer-all
"C-l" #'follow-recenter
"<" #'follow-first-window
">" #'follow-last-window
"n" #'follow-next-window
"p" #'follow-previous-window)
mainmap)
"Minor mode keymap for Follow mode.")
(defvar-keymap follow-mode-map
:doc "Minor mode keymap for Follow mode."
follow-mode-prefix-key follow-mode-submap
;; Replace the standard `end-of-buffer' when in Follow mode. (I don't
;; see the point in trying to replace every function that could be
;; enhanced in Follow mode. End-of-buffer is a special case since it
;; is very simple to define and it greatly enhances the look and feel
;; of Follow mode.)
"<remap> <end-of-buffer>" #'follow-end-of-buffer
"<remap> <scroll-bar-toolkit-scroll>" #'follow-scroll-bar-toolkit-scroll
"<remap> <scroll-bar-drag>" #'follow-scroll-bar-drag
"<remap> <scroll-bar-scroll-up>" #'follow-scroll-bar-scroll-up
"<remap> <scroll-bar-scroll-down>" #'follow-scroll-bar-scroll-down
"<remap> <mwheel-scroll>" #'follow-mwheel-scroll)
;; When the mode is not activated, only one item is visible to activate
;; the mode.