unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
From: Kevin Vigouroux via Users list for the GNU Emacs text editor <help-gnu-emacs@gnu.org>
To: help-gnu-emacs@gnu.org
Subject: Re: Adding functionality to a minor mode
Date: Tue, 08 Feb 2022 08:41:14 +0100	[thread overview]
Message-ID: <874k59rejp.fsf@laposte.net> (raw)
In-Reply-To: <RHmsTTPOdg581D8XUDSsdjLdnC821jaMocUhiOmhjoiQNIePGcMFAEGeKOuBjBfFOKPcH-BWoSBuo5P3Y6JCh8mEW7TTe58FJvJp_UasZEU=@protonmail.com> (goncholden@protonmail.com's message of "Mon, 07 Feb 2022 13:56:52 +0000")

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



  parent reply	other threads:[~2022-02-08  7:41 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-02-05 10:00 Adding functionality to a minor mode goncholden via Users list for the GNU Emacs text editor
2022-02-05 18:50 ` goncholden
2022-02-07  0:09   ` goncholden
2022-02-07  6:00     ` Eric Abrahamsen
2022-02-07 13:56       ` goncholden
2022-02-07 18:05         ` Michael Heerdegen
2022-02-07 19:18           ` goncholden
2022-02-07 20:26             ` [External] : " Drew Adams
2022-02-07 20:38               ` goncholden
2022-02-07 20:59                 ` Drew Adams
2022-02-07 21:40             ` Michael Heerdegen
2022-02-07 22:15               ` goncholden
2022-02-07 22:26                 ` Michael Heerdegen
2022-02-08  7:41         ` Kevin Vigouroux via Users list for the GNU Emacs text editor [this message]
2022-02-08 13:27         ` Stefan Monnier via Users list for the GNU Emacs text editor
2022-02-08 17:05           ` goncholden
2022-02-08 22:47             ` goncholden

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=874k59rejp.fsf@laposte.net \
    --to=help-gnu-emacs@gnu.org \
    --cc=ke.vigouroux@laposte.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).