help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Automatically set outline patterns and typeface for major modes


From: uzibalqa
Subject: Automatically set outline patterns and typeface for major modes
Date: Wed, 21 Jun 2023 19:09:14 +0000

I have a minor mode that specifies the outline pattern and levels (using 
function outlhg-regexp 
that sets outline-regexp, outline-heading-alist), and via the function 
outlhg-tyface to specify 
the corresponding typeface for each heading level.

The appropriate settings need to be used associated with each major mode.  
Would one make a hook
to each major mode for outlhg-regexp ?  And what about outlhg-tyface, would 
this also be called
through a hook?

Would it be like the following ?

(defun addhook-hgptn ()
  "Remove the outline hierarchy functions from the major mode
hook variables."

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

  (add-hook 'sh-mode-hook         #'outlhg-regexp)
  (add-hook 'sh-mode-hook         #'outlhg-tyface)

  (add-hook 'f90-mode-hook        #'outlhg-regexp)
  (add-hook 'f90-mode-hook        #'outlhg-tyface)

  (add-hook 'fortran-mode-hook    #'outlhg-regexp)
  (add-hook 'fortran-mode-hook    #'outlhg-tyface)

  (add-hook 'latex-mode-hook      #'outlhg-regexp)
  (add-hook 'latex-mode-hook      #'outlhg-tyface)

  (add-hook 'plain-tex-mode-hook  #'outlhg-regexp) 
  (add-hook 'plain-tex-mode-hook  #'outlhg-tyface) )

Here are the actual functions

(defun outlhg-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)
            (setq-local outline-level 'outline-level)))

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

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

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

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

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

(defun outlhg-tyface ()
  (interactive)

  (let* ( (pigment-darkbg  '("#ff62d4" "#9f80ff" "#fe6060" "#fba849"
                             "#4fe42f" "#4fafff" "#f0dd60" "#FFFFFF"))
          (pigment-lightbg '("#1f1fce" "#006800" "#b60000" "#605b00"
                             "#a8007f" "#005f88" "#904200" "#7f10d0"))
          (pigment
           (if (eq (frame-parameter nil 'background-mode) 'dark)
               pigment-darkbg
             pigment-lightbg)) )

    (dotimes (i 8)
      (let ((hkfc (intern (format "outline-%d" (1+ i))))
            (colr (nth i pigment)))
        (set-face-foreground hkfc colr)))))









reply via email to

[Prev in Thread] Current Thread [Next in Thread]