简体   繁体   中英

local keymap for emacs outline-minor-mode

I want to set the outline-minor-mode for init.el file and when TAB key is pressed on the lines starting with ; the function outline-toggle-children should be called in order to fold and expand the sub headings.

Below is the code for hook. But it does not work for the "TAB" key binding as expected.

(add-hook 'emacs-lisp-mode-hook
      (lambda ()           
        (if (equal (buffer-name) "init.el")
        (progn
          (outline-regexp "^;+")
          (outline-minor-mode 1)
          (local-set-key (kbd "TAB") ; this does not work
                 (lambda ()
                   (if (string-match outline-regexp (thing-at-point 'line))
                       (outline-toggle-children))))))))

I presume that the error you get is wrong-type-argument commandp . This happens because functions bound to keys must be "interactive" functions. You need to add an (interactive) declaration to the function, so that Emacs knows how to invoke the function in response to an event:

 (lambda ()
   (interactive)
   (if (string-match outline-regexp (thing-at-point 'line))
       (outline-toggle-children)))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM