1

I am working on a minor mode that adds functionality to outline-minor-mode associated with different major modes (e.g. emacs-lisp-mode, fortran-mode).

This is the minor mode file taxocalc.el

;; taxocask.el
(require 'taxocask-elisp)

(defun taxocask-activate ()
   "Activates the minor mode" 
   (do-this))

(defun taxocask-deactivate ()
   "Reverts to default outline settings." 
   (do-that))

(define-minor-mode taxocask-minor-mode
  "Enhances visibility of heading levels and text emphasis."
  :init-value nil
  :lighter " Taxocask"

  (if taxocask-minor-mode
      (taxocask-activate)

    ;; [ELSE] Rvert the functionality provided by minor mode
    (taxocask-deactivate)) )

;;;###autoload
(defun taxocask-enable ()
  "Enables `taxocask-minor-mode'."
  (taxocask-minor-mode 1))

;;;###autoload
(defun taxocask-disable ()
  "Disables `taxocask-minor-mode'."
  (taxocask-minor-mode 0))

(provide 'taxocask)

This is the contents of taxocalc-elisp.el.

;; taxocalc-elisp.el

(defun taxocask-elisp-view ()
  "Viewing emacs-lisp outline structures."
  (define-key emacs-lisp-mode-map (kbd "H-o s") #'outline-show-subtree)
  (define-key emacs-lisp-mode-map (kbd "H-o i") #'outline-show-children)
  (define-key emacs-lisp-mode-map (kbd "H-o k") #'outline-show-branches)
  (define-key emacs-lisp-mode-map (kbd "H-o e") #'outline-show-entry) )

(provide 'taxocask-elisp)

I am struggling to see how the mode be activated for elisp files. I want to allow the user to enable outline-miner-mode in an emacs lisp file (.el), at which point taxocask-elisp is also activated.

1 Answer 1

2

You would (add-hook 'emacs-lisp-mode-hook FUNC) and in that FUNC function you would (add-hook 'outline-minor-mode-hook 'taxocask-minor-mode nil t)

That non-nil LOCAL argument means you're only doing something with outline-minor-mode-hook in the current buffer.


Edit: Assuming you actually want to toggle your mode on and off in alignment with outline-minor-mode-hook you'll want that hook function to be something which tests outline-minor-mode.

Like this:

(add-hook 'emacs-lisp-mode-hook 'foo--enable)

(defun foo--enable ()
  "Enable tracking of `outline-minor-mode' in current buffer."
  (add-hook 'outline-minor-mode-hook 'foo--toggle-with-outline-minor-mode
            nil :local))

(defun foo--toggle-with-outline-minor-mode ()
  "Toggle `foo-mode' with `outline-minor-mode' buffer-locally."
  (foo-mode (if outline-minor-mode 1 0)))

(define-minor-mode foo-mode
  "Foo mode."
  :init-value nil
  (if foo-mode
      (message "Foo enabled.")
    (message "Foo disabled.")))
6
  • Meaning the use of (add-hook 'emacs-lisp-mode-hook #'taxocask-elisp-view) in taxocask.el ? And in taxocask-elisp-view add (add-hook 'outline-minor-mode-hook 'taxocask-minor-mode nil t) ?
    – Dilna
    Jun 5 at 0:39
  • I also need a call to (taxocask-activate). How should this be ?
    – Dilna
    Jun 5 at 0:50
  • I am unsure what to do to make the minor mode word. I have put a call to (taxocask-activate) which is designed to activate the minor mode capability but do not know what to put in it. Your generic suggestion (add-hook 'emacs-lisp-mode-hook FUNC) is not specific enough for me to understand exactly what to do and to what FUNC actually refers to.
    – Dilna
    Jun 5 at 17:33
  • I've added a generic example.
    – phils
    Jun 5 at 23:21
  • Much appreciated. Would I need to call anything specific in the condition (if foo-mode ? Or is the hook for the function 'foo--enable enough to activate foo-minor-mode whenever an elisp file is loaded ?
    – Dilna
    Jun 6 at 5:21

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.

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