Search code examples
elisp

Defining an emacs minor mode


Have coded an emacs minor mode with the definition shown below.

Would it be possible to simplify this, to perhaps call a function instead? Or is it not such a big deal having a minor-mode defined in this way ?

What would be the general way to set a minor-mode in terms of functionality (e.g. enable, disable, ...) ?

(defcustom komis-luna-signal t
  "todo"
  :group 'komis-luna)

;;;###autoload
(define-minor-mode komis-luna-minor-mode
  "Uses large geometric shapes for displaying heading levels."
  nil nil nil

  (let*
      (($keyword
        `(("^\\*+ "
           (0 (let* ( ($kondor
                         (- (match-end 0) (match-beginning 0) 1))
                      ($inline-task
                         (and (boundp 'org-inlinetask-min-level)
                              (>= $kondor org-inlinetask-min-level))) )
                ;;--------------------------------------
                (compose-region (- (match-end 0) 2)
                                (- (match-end 0) 1)
                                (komis-luna-shape-select $kondor))
               ;;---------------------------------------
               (when $inline-task
                  (compose-region (- (match-end 0) 3)
                                  (- (match-end 0) 2)
                                  (komis-luna-shape-select $kondor)))
               ;;---------------------------------------
               (when (facep komis-luna-typeface)
                  (put-text-property
                     (- (match-end 0) (if $inline-task 3 2))
                     (- (match-end 0) 1)
                     'face komis-luna-typeface))
               ;;---------------------------------------
               (put-text-property
                  (match-beginning 0)
                  (- (match-end 0) 2)
                  'face (list :foreground
                        (face-attribute 'default :background)))
               ;;---------------------------------------
               (put-text-property (match-beginning 0)
                                  (match-end 0)
                                  'keymap komis-luna-mouse-sweep)
               ;;---------------------------------------
               nil )) ))))

    (if komis-luna-signal

        (progn
          (font-lock-add-keywords nil $keyword)
          (font-lock-fontify-buffer))

      (save-excursion
        (goto-char (point-min))
        (font-lock-remove-keywords nil $keyword)
        (while (re-search-forward "^\\*+ " nil t)
          (decompose-region (match-beginning 0) (match-end 0)) )
        (font-lock-fontify-buffer)) ) ))

Solution

  • I think you did it the proper way.

    Next would be to toggle your minor mode in your emacs configuration file .emacs.d/init.el with a hook probably like this :

    (add-hook 'org-mode-hook 'komis-luna-minor-mode)
    

    If you want your minor mode to be enable when entering org-mode.

    For further and more specifics questions and problems, you should probably take this post to Emacs Stack Exchange.