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

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

Re: Adding functionality to a minor mode


From: goncholden
Subject: Re: Adding functionality to a minor mode
Date: Tue, 08 Feb 2022 17:05:53 +0000


Sent with ProtonMail Secure Email.

------- Original Message -------

On Tuesday, February 8th, 2022 at 1:27 PM, Stefan Monnier via Users list for 
the GNU Emacs text editor <help-gnu-emacs@gnu.org> wrote:

> Is there a way that I can remember the :weight used initially,
>
> "(set-face-attribute 'default nil :height 160 :weight 'ultra-bold)"
>
> so I can set comments to ultra-bold again when the minor-mode is disabled.

Rather than `set-face-attribute` you want to go through Customize's
face settings.

E.g. you can get the above behavior using a "Custom theme", which you
can then enable&disable at will.

Custom themes are conceptually very similar to (global) minor modes.

Stefan

I already use modus-themes.  How does custom theme work?

Have done this way by calling

  (set-face-attribute 'font-lock-comment-face nil
     :weight (face-attribute 'default :weight))

Here is the code

;;;###autoload
(define-minor-mode rich-minor-mode
  "Colour Comments."
  :lighter "rich"  ; indicator in mode-line

  (font-lock-remove-keywords nil rich-font-lock)
  (set-face-attribute 'font-lock-comment-face nil
     :weight (face-attribute 'default :weight))

  (when rich-minor-mode  ; evaluates true when mode enabled
    (font-lock-add-keywords nil rich-font-lock 'append)
    (set (make-local-variable 'jit-lock-contextually) t)
    (rich-annotation-tools))

  (when font-lock-mode
    (if (fboundp 'font-lock-flush)
        (font-lock-flush)
      (with-no-warnings (font-lock-fontify-buffer)) )) )




reply via email to

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