local keymap for emacs outline-minor-mode

自古美人都是妖i 提交于 2019-12-11 14:15:29

问题


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

回答1:


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


来源:https://stackoverflow.com/questions/17173148/local-keymap-for-emacs-outline-minor-mode

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!