help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Changing outline-minor-mode keybindings for texinfo files


From: Yuri Khan
Subject: Re: Changing outline-minor-mode keybindings for texinfo files
Date: Fri, 14 May 2021 23:20:12 +0700

On Fri, 14 May 2021 at 20:33, <michael-franzese@gmx.com> wrote:

> Have wade to following adaptation which seems to work.  Still I would value
> comments and points of view.
>
> (defun vmove-keytrigger ()
>    "Visualises outline and moves texinfo code."

This docstring is inaccurate, and uses the wrong grammatical form.
(Docstrings, by convention, use the imperative form.) Better:

"Set up keys for use in texinfo-mode."

>    (let ( (map texinfo-mode-map) )
>      (define-key map (kbd "H-q") #'outline-hide-sublevels)
>      (define-key map (kbd "H-b") #'outline-hide-body)
>      (define-key map (kbd "H-<up>") #'outline-move-subtree-up)
>      (define-key map (kbd "H-<down>") #'outline-move-subtree-down) ))

The let binding is redundant, you could call ‘define-key’ directly on
‘texinfo-mode-map’:

(defun vmove-keytrigger ()
   "Set up keys for use in texinfo-mode."
   (define-key texinfo-mode-map (kbd "H-q") #'outline-hide-sublevels)
   (define-key texinfo-mode-map (kbd "H-b") #'outline-hide-body)
   (define-key texinfo-mode-map (kbd "H-<up>") #'outline-move-subtree-up)
   (define-key texinfo-mode-map (kbd "H-<down>") #'outline-move-subtree-down) ))


> (add-hook 'texinfo-mode-hook 'vmove-keytrigger)

This too is excessive. You redefine these keys each time you open a
new buffer in texinfo mode, but it is sufficient to define them once
during an Emacs session. You cannot just put (define-key
texinfo-mode-map …) in your init file because the variable
‘texinfo-mode-map’ is probably not defined at the time of
initialization, but you can defer that to the time when ‘texinfo’ is
loaded:

(with-eval-after-load 'texinfo
  (define-key texinfo-mode-map (kbd "H-q") #'outline-hide-sublevels)
  (define-key texinfo-mode-map (kbd "H-b") #'outline-hide-body)
  (define-key texinfo-mode-map (kbd "H-<up>") #'outline-move-subtree-up)
  (define-key texinfo-mode-map (kbd "H-<down>") #'outline-move-subtree-down))


(Note that ‘with-eval-after-load’ is a relatively new macro; on older
Emacs versions, you might have to use ‘eval-after-load’ which is
slightly less easy to use.)



reply via email to

[Prev in Thread] Current Thread [Next in Thread]