0
votes

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 recommend you don't set outline-regexp and use its default value (which treats comments with 3 or more semi-colons as headings and top-level Lisp code as "subsubsubheadings"). - Stefan

1 Answers

0
votes

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