Simplifying elisp code based on major mode

30 Views Asked by At

What can I do to simplify the following elisp code, as I will also have many more hook functions for the different major modes. Am also wondering whether one needs the "\\>" at the end of outline-regexp ?

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

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

(defun elisp-addhook-hgptn ()
   "Set outline hierarchy to the elisp hook."

   (add-hook 'emacs-lisp-mode-hook #'outlhg-regexp))

(defun bash-addhook-hgptn ()
   "Set outline hierarchy to the elisp hook."

   (add-hook 'sh-script-mode-hook #'outlhg-regexp))
0

There are 0 best solutions below