0

I have made a minor mode that is supposed to customise outline-minor-mode.

(defun tematika-tools ()
   "Define Heading Patterns and Levels for different major modes"

   (require 'tematika-elisp)
   (tematika-elisp-launch)

   (require 'tematika-bash)
   (tematika-bash-launch))

;;;###autoload
(define-minor-mode tematika-minor-mode
  "Enhances visibility of heading levels and text emphasis."
  :lighter " Tematika"

  (if tematika-minor-mode

      (progn (tematika-tools)
             (outline-minor-mode 1))

    (outline-minor-mode 0)) )

The problem is that I have two files that are loaded, one for elisp, the other for bash.

(defvar tematika-elisp-hglevels
  '( (";;; H1" . 1) (";;; H2" . 2) (";;; H3" . 3) (";;; H4" . 4)
     (";;; H5" . 5) (";;; H6" . 6) (";;; H7" . 7) (";;; H8" . 8) )

  "Set outline levels for standard (canonical) headings.")

(defvar tematika-elisp-mglevels
  '( (";;; M1" . 1) (";;; M2" . 2) (";;; M3" . 3) (";;; M4" . 4)
     (";;; M5" . 5) (";;; M6" . 6) (";;; M7" . 7) (";;; M8" . 8) )

  "Set outline levels for Marginal headings.")

(defvar tematika-elisp-hrklevels
  (append tematika-elisp-hglevels
          tematika-elisp-mglevels)
  "Set the hierarchical levels for outlines in Elisp Major-Mode.")

(defun tematika-elisp-outl ()
  "Recognise elisp outlines and associate corresponding level."
  (interactive)

  (let ( (hrklevels tematika-elisp-hrklevels) )

    (setq outline-regexp
           (concat (regexp-opt (mapcar 'car hrklevels)) "\\>"))
    (setq outline-heading-alist hrklevels)) )

I have the same thing for bash except that the outline patterns are different

(defvar tematika-bash-hglevels
  '( ("## H1" . 1) ("## H2" . 2) ("## H3" . 3) ("## H4" . 4)
     ("## H5" . 5) ("## H6" . 6) ("## H7" . 7) ("## H8" . 8) )

  "Set outline levels for for command shell outline headings.")

(defvar tematika-bash-mglevels
  '( ("## M1" . 1) ("## M2" . 2) ("## M3" . 3) ("## M4" . 4)
     ("## M5" . 5) ("## M6" . 6) ("## M7" . 7) ("## M8" . 8) )

  "Set outline levels for in Marginalia and levels for command
shell marginal headings.")


(defun tematika-bash-outl ()
  "Recognise bash outlines and associate corresponding level."
  (interactive)

  (let ( (hrklevels tematika-bash-hrklevels) )

    (setq outline-regexp
           (concat (regexp-opt (mapcar 'car hrklevels)) "\\>"))
    (setq outline-heading-alist hrklevels)) )

I have a problem devising a scheme that uses tematika-elisp-hglevels or tematika-bash-hglevels depending upon what type of file gets loaded. Somehow tematika-minor-mode must understand the major mode and use either tematika-elisp-outl or tematika-bash-outl for setting the outline patterns via outline-regexp and outline-heading-alist.

6
  • So the question is "how do I detect the major mode?". If so, the answer is to inspect the variable major-mode. Jun 10 at 7:09
  • I think that I need to detect it because if I call (require 'tematika-elisp) and then (require 'tematika-bash), the result would be that outline-regexp and outline-heading-alist would get overwritten.
    – Dilna
    Jun 10 at 8:37
  • But need a good scheme to make this happen.
    – Dilna
    Jun 10 at 8:43
  • This is another basic Lisp question: use a conditional (cond e.g.)
    – NickD
    Jun 10 at 18:58
  • Where would be most convenient to introduce it ? Make a new function tematika-outl to replace tematika-elisp-outl and tematika-bash-outl ?
    – Dilna
    Jun 10 at 19:16

0

Your Answer

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

Browse other questions tagged or ask your own question.