all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: uzibalqa <uzibalqa@proton.me>
To: uzibalqa via Users list for the GNU Emacs text editor
	<help-gnu-emacs@gnu.org>
Subject: Setting outline-regexp automatically for a major mode
Date: Thu, 22 Jun 2023 12:20:54 +0000	[thread overview]
Message-ID: <3-dqTzBhKN_OT-tYifIAKp0U6Qn5S9lQxyCbL0HvE1UrvfPUAnGvnWuMuaklZgo2gQBnLl8pb1u6z3uWi2OA87SKfYCKU6uxCkQMuOpOTbA=@proton.me> (raw)


I have made a minor mode called tika that gets activated automatically for some
major modes. 

I use hooks for that

(defun tika-addhook ()
  "Activate minor-mode' automatically for specific major-modes."
  (add-hook 'emacs-lisp-mode-hook #'tika-minor-mode)
  (add-hook 'sh-mode-hook         #'tika-minor-mode)
  (add-hook 'f90-mode-hook        #'tika-minor-mode)
  (add-hook 'fortran-mode-hook    #'tika-minor-mode)
  (add-hook 'latex-mode-hook      #'tika-minor-mode)
  (add-hook 'plain-tex-mode-hook  #'tika-minor-mode))

This minor mode also sets the variables outline-regexp and outline-heading-alist
according to the specific major mode using the function tika-outlhg-regexp.  Which
I want to run automatically as soon as a file gets loaded.

Would one make hooks for the function like so, or do something else

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

When should tika-addhook-hgptn be called ?  I have been thinking 
of doing the following

  (require 'tika)
  (tika-addhook)
  (tika-addhook-hgptn)

Or is the above complicating a simple thing ?

This is the function setting outline-regexp and outline-heading-alist

(defun tika-outlhg-regexp ()

  (cond
    ((eq major-mode 'emacs-lisp-mode)
          (let ( (hrklevels tematika-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 tematika-bash-hrklevels) )
            (setq outline-regexp
                  (concat (regexp-opt (mapcar 'car hrklevels)) "\\>"))
            (setq outline-heading-alist hrklevels)))

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

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

    ((eq major-mode 'latex-mode)
          (let ( (hrklevels tematika-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 tematika-tex-hrklevels) )
            (setq outline-regexp
                  (concat (regexp-opt (mapcar 'car hrklevels)) "\\>"))
            (setq outline-heading-alist hrklevels))) ))

;; tematika-outlhg-regexp ends here










                 reply	other threads:[~2023-06-22 12:20 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='3-dqTzBhKN_OT-tYifIAKp0U6Qn5S9lQxyCbL0HvE1UrvfPUAnGvnWuMuaklZgo2gQBnLl8pb1u6z3uWi2OA87SKfYCKU6uxCkQMuOpOTbA=@proton.me' \
    --to=uzibalqa@proton.me \
    --cc=help-gnu-emacs@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.