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: Kevin Vigouroux
Subject: Re: Adding functionality to a minor mode
Date: Tue, 08 Feb 2022 08:41:14 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux)

goncholden <goncholden@protonmail.com> writes:

> I am also struck about what happens when "(define-minor-mode rich-minor-mode" 
> is
> used to disable the mode.  I suppose that "(when richerenkov-minor-mode" would
> evaluate to false, but the other parts would evaluate.
>
> Would you be so kind to assist me a little bit, if you please?

I get the impression from reading your code, even though I’m a beginner,
that you want to burn through the steps.

>
> I normally use ultra-bold, but changed comments to use normal weight and 
> included the functionality
> inside a minor mode like this.

With the “little” knowledge gleaned from the manual, it would seem to me
that things are reversed in your design.

• Major modes are designed to be customizable using hooks and minor
  modes.

• Minor modes are generally independent of a major mode.

>
> (defun rich-annotation-font-weight ()
>   "Makes normal font weight for comments."
>   (set-face-attribute 'font-lock-comment-face nil :weight 'normal))
>
> 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.

Comments seems to be handled in a major mode using “Font Lock mode”.

>
> Then I added some additional functionality and put it here
>
> (defun rich-annotation-tools ()
>   "Aggregates annotation tools for comments."
>   (rich-annotation-font-weight)
>   (rich-annotation-low-contrast)
>   (rich-annotation-keytrigger))
>

I couldn’t explain why but it seems strange: I don’t really see the
point of forming a function just to group functions.

> Here is my definition of the minor-mode
>
> ;;;###autoload
> (define-minor-mode rich-minor-mode
>   "Colour Brace Marks according to their depth."
>   :lighter "rich"  ; indicator in mode-line
>
>   (font-lock-remove-keywords nil rich-font-lock)
>
>   (when rich-minor-mode
>     (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)) ))
>

It seems that you are defining a minor mode when you should be defining
a major mode (or derived mode).

>  )
>
> Would it be better to introduce (rich-annotation-tools) in the
> "(when rich-minor-mode" part or outside it.
>
> To enable and disable the minor-mode, I have added
>
> ;;;###autoload
> (defun rich-minor-mode-enable ()
>   "Enable `rich-minor-mode'."
>   (rich-minor-mode 1))
>
> ;;;###autoload
> (defun rich-minor-mode-disable ()
>   "Disable `rich-minor-mode'."
>   (rich-minor-mode 0))
>

-- 
Kevin Vigouroux
Best regards



reply via email to

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