0

I have a function (tika-outlhg-regexp) that sets custom outline headings based on major mode.

I activate this with major-mode hooks. Is there some other way?

(defun tika-addhook-hgptn ()
   (add-hook 'emacs-lisp-mode-hook #'tika-outlhg-regexp)
   (add-hook 'sh-mode-hook         #'tika-outlhg-regexp)
   (add-hook 'f90-mode-hook        #'tika-outlhg-regexp)
   (add-hook 'fortran-mode-hook    #'tika-outlhg-regexp)
   (add-hook 'latex-mode-hook      #'tika-outlhg-regexp)
   (add-hook 'plain-tex-mode-hook  #'tika-outlhg-regexp) )

Here is the major mode dependent function for setting custom outline headings.

(defun tika-outlhg-regexp ()

  (cond
    ((eq major-mode 'emacs-lisp-mode)
          (let ( (hrklevels tika-elisp-hrklevels) )
            (setq outline-regexp
                  (concat (regexp-opt (mapcar 'car hrklevels)) "\\>"))
            (setq outline-heading-alist hrklevels)
            (setq-local outline-level 'outline-level)))

    ((eq major-mode 'sh-mode)
          (let ( (hrklevels tika-bash-hrklevels) )
            (setq outline-regexp
                  (concat (regexp-opt (mapcar 'car hrklevels)) "\\>"))
            (setq outline-heading-alist hrklevels)))

    ((eq major-mode 'f90-mode)
          (let ( (hrklevels tika-fortran-hrklevels) )
            (setq outline-regexp
                  (concat (regexp-opt (mapcar 'car hrklevels)) "\\>"))
            (setq outline-heading-alist hrklevels)))

    ((eq major-mode 'fortran-mode)
          (let ( (hrklevels tika-f77-hrklevels) )
            (setq outline-regexp
                  (concat (regexp-opt (mapcar 'car hrklevels)) "\\>"))
            (setq outline-heading-alist hrklevels)))

    ((eq major-mode 'latex-mode)
          (let ( (hrklevels tika-latex-hrklevels) )
            (setq outline-regexp
                  (concat (regexp-opt (mapcar 'car hrklevels)) "\\>"))
            (setq outline-heading-alist hrklevels)
            (setq-local outline-level 'outline-level)))

    ((eq major-mode 'plain-tex-mode)
          (let ( (hrklevels tika-tex-hrklevels) )
            (setq outline-regexp
                  (concat (regexp-opt (mapcar 'car hrklevels)) "\\>"))
            (setq outline-heading-alist hrklevels))) ))
7
  • 2
    Does this answer your question? How to customize major mode initialization with local variables?
    – Drew
    Jun 23, 2023 at 19:24
  • If you suggest use of a local variable, how would that be implemented ? Would I still need the function tika-outlhg-regexp ?
    – Dilna
    Jun 23, 2023 at 20:09
  • The question is about adding a major-mode hook function. What that function does can be anything. It can set buffer-local or non-buffer-local variables. And you can use a different hook function for each mode, instead of using the same function, which then dispatches on the mode. IOW, a mode-hook function should already be in the right mode. All of that - what you do in a hook function - is up to you.
    – Drew
    Jun 23, 2023 at 20:54
  • Would you be ok with my approach of having tika-outlhg-regexp with a cond for each mode. Then using hooks as in tika-addhook-hgptn ?
    – Dilna
    Jun 23, 2023 at 21:21
  • What? Both OP’s name and the number of his/her reputation changed! @Drew, did you notice that? Two days ago, his/her name was ‘Randy’; today, it is ‘Bennings’; now it is ‘Dilna’. His/Her reputation was 100-200 several hours ago and now it becomes 1000+! Drew, I have some screenshots that prove it.
    – shynur
    Jun 23, 2023 at 21:55

1 Answer 1

-1

Would I activate this with hooks, or some other way?

Yes.

1
  • So I can keep things as they are using the function tika-addhook-hgptn?
    – Dilna
    Jun 23, 2023 at 20:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.