all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Adding functionality to a minor mode
@ 2022-02-05 10:00 goncholden via Users list for the GNU Emacs text editor
  2022-02-05 18:50 ` goncholden
  0 siblings, 1 reply; 17+ messages in thread
From: goncholden via Users list for the GNU Emacs text editor @ 2022-02-05 10:00 UTC (permalink / raw)
  To: goncholden via Users list for the GNU Emacs text editor

I have made a minor-mode with some defvar and defun. Have added some functionality
for comments, and put everything in the following function definition.

(defun rich-annotation-tools ()
"Aggregates annotation tools for comments."
(rich-annotation-font-weight)
(rich-annotation-low-contrast)
(rich-annotation-keytrigger))

I would expect to add "(rich-annotation-tools)" in define-minor-mode. Would I introduce it
within the "(when rich-minor-mode" part?

;;;###autoload
(define-minor-mode rich-minor-mode
"This is the description."
: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)) )) )

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: Adding functionality to a minor mode
  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
  0 siblings, 1 reply; 17+ messages in thread
From: goncholden @ 2022-02-05 18:50 UTC (permalink / raw)
  To: goncholden; +Cc: goncholden via Users list for the GNU Emacs text editor

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

On Saturday, February 5th, 2022 at 10:00 AM, goncholden via Users list for the GNU Emacs text editor <help-gnu-emacs@gnu.org> wrote:

> I have made a minor-mode with some defvar and defun. Have added some functionality
>
> for comments, and put everything in the following function definition.
>
> (defun rich-annotation-tools ()
> "Aggregates annotation tools for comments."
> (rich-annotation-font-weight)
> (rich-annotation-low-contrast)
> (rich-annotation-keytrigger))
>
> I would expect to add "(rich-annotation-tools)" in define-minor-mode. Would I introduce it
> within the "(when rich-minor-mode" part?
>
> ;;;###autoload
> (define-minor-mode rich-minor-mode
> "This is the description."
> :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)) )) )

What are the standard techniques for defining a minor mode (e.g. should only only use "(when rich-minor-mode"),
and for enabling, disabling minor-mode functionality.







^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: Adding functionality to a minor mode
  2022-02-05 18:50 ` goncholden
@ 2022-02-07  0:09   ` goncholden
  2022-02-07  6:00     ` Eric Abrahamsen
  0 siblings, 1 reply; 17+ messages in thread
From: goncholden @ 2022-02-07  0:09 UTC (permalink / raw)
  To: goncholden; +Cc: goncholden via Users list for the GNU Emacs text editor

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

On Saturday, February 5th, 2022 at 6:50 PM, goncholden <goncholden@protonmail.com> wrote:

> ------- Original Message -------
>
> On Saturday, February 5th, 2022 at 10:00 AM, goncholden via Users list for the GNU Emacs text editor help-gnu-emacs@gnu.org wrote:
>
> > I have made a minor-mode with some defvar and defun. Have added some functionality
> >
> > for comments, and put everything in the following function definition.
> >
> > (defun rich-annotation-tools ()
> >
> > "Aggregates annotation tools for comments."
> >
> > (rich-annotation-font-weight)
> >
> > (rich-annotation-low-contrast)
> >
> > (rich-annotation-keytrigger))
> >
> > I would expect to add "(rich-annotation-tools)" in define-minor-mode. Would I introduce it
> >
> > within the "(when rich-minor-mode" part?
> >
> > ;;;###autoload
> >
> > (define-minor-mode rich-minor-mode
> >
> > "This is the description."
> > :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)
> >
> > (with-no-warnings (font-lock-fontify-buffer)) )) )

Could I get some clarification for using "(when rich-minor-mode" and when not to?






^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: Adding functionality to a minor mode
  2022-02-07  0:09   ` goncholden
@ 2022-02-07  6:00     ` Eric Abrahamsen
  2022-02-07 13:56       ` goncholden
  0 siblings, 1 reply; 17+ messages in thread
From: Eric Abrahamsen @ 2022-02-07  6:00 UTC (permalink / raw)
  To: help-gnu-emacs

goncholden <goncholden@protonmail.com> writes:

> ------ Original Message -------
>
> On Saturday, February 5th, 2022 at 6:50 PM, goncholden <goncholden@protonmail.com> wrote:
>
>> ------- Original Message -------
>>
>> On Saturday, February 5th, 2022 at 10:00 AM, goncholden via Users
>> list for the GNU Emacs text editor help-gnu-emacs@gnu.org wrote:
>>
>> > I have made a minor-mode with some defvar and defun. Have added some functionality
>> >
>> > for comments, and put everything in the following function definition.
>> >
>> > (defun rich-annotation-tools ()
>> >
>> > "Aggregates annotation tools for comments."
>> >
>> > (rich-annotation-font-weight)
>> >
>> > (rich-annotation-low-contrast)
>> >
>> > (rich-annotation-keytrigger))
>> >
>> > I would expect to add "(rich-annotation-tools)" in
>> > define-minor-mode. Would I introduce it
>> >
>> > within the "(when rich-minor-mode" part?
>> >
>> > ;;;###autoload
>> >
>> > (define-minor-mode rich-minor-mode
>> >
>> > "This is the description."
>> > :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)
>> >
>> > (with-no-warnings (font-lock-fontify-buffer)) )) )
>
> Could I get some clarification for using "(when rich-minor-mode" and when not to?

What's happening here is that, when you define a minor mode, it also
defines a variable of the same name, which can be tested as a boolean to
see if the minor mode is currently enabled or not.

The only thing you need to know is that, when the minor mode is turned
on or off, the variable is set *before* the body is run. So if you test
the boolean variable in the body code of the minor mode, it will be t if
you've just turned the mode on, and nil if you've just turned it off.

For some reason, when I first started playing with minor modes, this
struck me as backwards. I can no longer say why, exactly, but I remember
it did.




^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: Adding functionality to a minor mode
  2022-02-07  6:00     ` Eric Abrahamsen
@ 2022-02-07 13:56       ` goncholden
  2022-02-07 18:05         ` Michael Heerdegen
                           ` (2 more replies)
  0 siblings, 3 replies; 17+ messages in thread
From: goncholden @ 2022-02-07 13:56 UTC (permalink / raw)
  To: Eric Abrahamsen; +Cc: help-gnu-emacs


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

On Monday, February 7th, 2022 at 6:00 AM, Eric Abrahamsen <eric@ericabrahamsen.net> wrote:

> goncholden goncholden@protonmail.com writes:
>
> > ------ Original Message -------
> >
> > On Saturday, February 5th, 2022 at 6:50 PM, goncholden goncholden@protonmail.com wrote:
> > > ------- Original Message -------
> > > On Saturday, February 5th, 2022 at 10:00 AM, goncholden via Users
> > > list for the GNU Emacs text editor help-gnu-emacs@gnu.org wrote:
> > >
> > > > I have made a minor-mode with some defvar and defun. Have added some functionality
> > > > for comments, and put everything in the following function definition.
> > > >
> > > > (defun rich-annotation-tools ()
> > > > "Aggregates annotation tools for comments."
> > > > (rich-annotation-font-weight)
> > > > (rich-annotation-low-contrast)
> > > > (rich-annotation-keytrigger))
> > > >
> > > > I would expect to add "(rich-annotation-tools)" in
> > > > define-minor-mode. Would I introduce it
> > > > within the "(when rich-minor-mode" part?
> > > >
> > > > ;;;###autoload
> > > >
> > > > (define-minor-mode rich-minor-mode
> > > >
> > > > "This is the description."
> > > > :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)
> > > >
> > > > (with-no-warnings (font-lock-fontify-buffer)) )) )
> >
> > Could I get some clarification for using "(when rich-minor-mode" and when not to?
>
> What's happening here is that, when you define a minor mode, it also
> defines a variable of the same name, which can be tested as a boolean to
> see if the minor mode is currently enabled or not.
>
> The only thing you need to know is that, when the minor mode is turned
> on or off, the variable is set before the body is run. So if you test
> the boolean variable in the body code of the minor mode, it will be t if
> you've just turned the mode on, and nil if you've just turned it off.
>
> For some reason, when I first started playing with minor modes, this
> struck me as backwards. I can no longer say why, exactly, but I remember
> it did.

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 normally use ultra-bold, but changed comments to use normal weight and included the functionality
inside a minor mode like this.

(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.

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))

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)) ))

 )

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))










^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: Adding functionality to a minor mode
  2022-02-07 13:56       ` goncholden
@ 2022-02-07 18:05         ` Michael Heerdegen
  2022-02-07 19:18           ` goncholden
  2022-02-08  7:41         ` Kevin Vigouroux via Users list for the GNU Emacs text editor
  2022-02-08 13:27         ` Stefan Monnier via Users list for the GNU Emacs text editor
  2 siblings, 1 reply; 17+ messages in thread
From: Michael Heerdegen @ 2022-02-07 18:05 UTC (permalink / raw)
  To: help-gnu-emacs

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.

Yes.  Whenever you turn the mode on or off, the complete body is
evaluated normally, with the mode variable bound to a non-nil value when
the mode has been enabled and nil else.

M-: (macroexpand-1 '(define-minor-mode rich-minor-mode ...)) RET to see
the macroexpanded code of your definition - helps in understanding.

Michael.




^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: Adding functionality to a minor mode
  2022-02-07 18:05         ` Michael Heerdegen
@ 2022-02-07 19:18           ` goncholden
  2022-02-07 20:26             ` [External] : " Drew Adams
  2022-02-07 21:40             ` Michael Heerdegen
  0 siblings, 2 replies; 17+ messages in thread
From: goncholden @ 2022-02-07 19:18 UTC (permalink / raw)
  To: Michael Heerdegen; +Cc: help-gnu-emacs

------- Original Message -------
On Monday, February 7th, 2022 at 6:05 PM, Michael Heerdegen <michael_heerdegen@web.de> wrote:
> 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.
>
> Yes. Whenever you turn the mode on or off, the complete body is
> evaluated normally, with the mode variable bound to a non-nil value when
> the mode has been enabled and nil else.
>
> M-: (macroexpand-1 '(define-minor-mode rich-minor-mode ...)) RET to see
> the macroexpanded code of your definition - helps in understanding.
>
> Michael.

Am not sure whether I am executing your suggestion good.  What should I look for?

--------

Debugger entered--Lisp error: (wrong-type-argument stringp \.\.\.)
  string-match("\\bARG\\b" \.\.\. nil)
  easy-mmode--mode-docstring(\.\.\. "Rich minor mode" rich-minor-mode-map)
  #f(compiled-function (mode doc &optional init-value lighter keymap &rest body) #<bytecode 0x1578375e6509>)(rich-minor-mode \.\.\.)
  apply(#f(compiled-function (mode doc &optional init-value lighter keymap &rest body) #<bytecode 0x1578375e6509>) (rich-minor-mode \.\.\.))
  macroexpand-1((define-minor-mode rich-minor-mode \.\.\.))
  eval((macroexpand-1 '(define-minor-mode rich-minor-mode \.\.\.)) t)
  eval-expression((macroexpand-1 '(define-minor-mode rich-minor-mode \.\.\.)) nil nil 127)
  funcall-interactively(eval-expression (macroexpand-1 '(define-minor-mode rich-minor-mode \.\.\.)) nil nil 127)
  call-interactively(eval-expression nil nil)
  command-execute(eval-expression)




^ permalink raw reply	[flat|nested] 17+ messages in thread

* RE: [External] : Re: Adding functionality to a minor mode
  2022-02-07 19:18           ` goncholden
@ 2022-02-07 20:26             ` Drew Adams
  2022-02-07 20:38               ` goncholden
  2022-02-07 21:40             ` Michael Heerdegen
  1 sibling, 1 reply; 17+ messages in thread
From: Drew Adams @ 2022-02-07 20:26 UTC (permalink / raw)
  To: goncholden, Michael Heerdegen; +Cc: help-gnu-emacs@gnu.org

> Am not sure whether I am executing your suggestion good.
> What should I look for?
> 
> Debugger entered--Lisp error: (wrong-type-argument stringp \.\.\.)
>   string-match("\\bARG\\b" \.\.\. nil)
...
>   macroexpand-1((define-minor-mode rich-minor-mode \.\.\.))

I'm not following this thread, but it looks like you
passed a symbol `...' as the doc-string argument.
That arg needs to be a string.

See `C-h f define-minor-mode'.

^ permalink raw reply	[flat|nested] 17+ messages in thread

* RE: [External] : Re: Adding functionality to a minor mode
  2022-02-07 20:26             ` [External] : " Drew Adams
@ 2022-02-07 20:38               ` goncholden
  2022-02-07 20:59                 ` Drew Adams
  0 siblings, 1 reply; 17+ messages in thread
From: goncholden @ 2022-02-07 20:38 UTC (permalink / raw)
  To: Drew Adams; +Cc: Michael Heerdegen, help-gnu-emacs@gnu.org


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

On Monday, February 7th, 2022 at 8:26 PM, Drew Adams <drew.adams@oracle.com> wrote:

> Am not sure whether I am executing your suggestion good.
>
> What should I look for?
>
> Debugger entered--Lisp error: (wrong-type-argument stringp \.\.\.)
>
> string-match("\\bARG\\b" \.\.\. nil)

...

> macroexpand-1((define-minor-mode rich-minor-mode \.\.\.))

I'm not following this thread, but it looks like you
passed a symbol `...' as the doc-string argument. That arg needs to be a string. See` C-h f define-minor-mode'.

Am figuring out "(when rich-minor-mode" works.  Looks like it evaluates false when one calls
"(rich-minor-mode 1)".  It was suggested to use macroexpand to help my understanding.




^ permalink raw reply	[flat|nested] 17+ messages in thread

* RE: [External] : Re: Adding functionality to a minor mode
  2022-02-07 20:38               ` goncholden
@ 2022-02-07 20:59                 ` Drew Adams
  0 siblings, 0 replies; 17+ messages in thread
From: Drew Adams @ 2022-02-07 20:59 UTC (permalink / raw)
  To: goncholden; +Cc: Michael Heerdegen, help-gnu-emacs@gnu.org

Please quote mail you're replying to properly.
It's not clear who said what in your reply to
my reply.  Thx.

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: Adding functionality to a minor mode
  2022-02-07 19:18           ` goncholden
  2022-02-07 20:26             ` [External] : " Drew Adams
@ 2022-02-07 21:40             ` Michael Heerdegen
  2022-02-07 22:15               ` goncholden
  1 sibling, 1 reply; 17+ messages in thread
From: Michael Heerdegen @ 2022-02-07 21:40 UTC (permalink / raw)
  To: help-gnu-emacs

goncholden <goncholden@protonmail.com> writes:

> > M-: (macroexpand-1 '(define-minor-mode rich-minor-mode ...)) RET to see
> > the macroexpanded code of your definition - helps in understanding.
> Debugger entered--Lisp error: (wrong-type-argument stringp \.\.\.)

You should of course macroexpand your complete definition, not the one I
abbreviated.

Michael.




^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: Adding functionality to a minor mode
  2022-02-07 21:40             ` Michael Heerdegen
@ 2022-02-07 22:15               ` goncholden
  2022-02-07 22:26                 ` Michael Heerdegen
  0 siblings, 1 reply; 17+ messages in thread
From: goncholden @ 2022-02-07 22:15 UTC (permalink / raw)
  To: Michael Heerdegen; +Cc: help-gnu-emacs

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

On Monday, February 7th, 2022 at 9:40 PM, Michael Heerdegen <michael_heerdegen@web.de> wrote:

> goncholden goncholden@protonmail.com writes:
>
> > > M-: (macroexpand-1 '(define-minor-mode rich-minor-mode ...)) RET to see
> > >
> > > the macroexpanded code of your definition - helps in understanding.
> > >
> > > Debugger entered--Lisp error: (wrong-type-argument stringp \.\.\.)
>
> You should of course macroexpand your complete definition, not the one I abbreviated.
>
> Michael.

I would have to copy the whole function on the minibuffer.  Is there an easier way to call macroexpand on rich-minor-mode?





^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: Adding functionality to a minor mode
  2022-02-07 22:15               ` goncholden
@ 2022-02-07 22:26                 ` Michael Heerdegen
  0 siblings, 0 replies; 17+ messages in thread
From: Michael Heerdegen @ 2022-02-07 22:26 UTC (permalink / raw)
  To: help-gnu-emacs

goncholden <goncholden@protonmail.com> writes:

> I would have to copy the whole function on the minibuffer.
> Is there an easier way to call macroexpand on rich-minor-mode?

You mean, to macroexpand the mode definition?  If you don't want to use
the minibuffer, use either use the *scratch* buffer (hit C-x C-e with
cursor at the end of an expression to be evaluated; with prefix arg, the
result is inserted) -- or M-x ielm, if you prefer something shell-like.

Michael.




^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: Adding functionality to a minor mode
  2022-02-07 13:56       ` goncholden
  2022-02-07 18:05         ` Michael Heerdegen
@ 2022-02-08  7:41         ` Kevin Vigouroux via Users list for the GNU Emacs text editor
  2022-02-08 13:27         ` Stefan Monnier via Users list for the GNU Emacs text editor
  2 siblings, 0 replies; 17+ messages in thread
From: Kevin Vigouroux via Users list for the GNU Emacs text editor @ 2022-02-08  7:41 UTC (permalink / raw)
  To: help-gnu-emacs

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



^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: Adding functionality to a minor mode
  2022-02-07 13:56       ` goncholden
  2022-02-07 18:05         ` Michael Heerdegen
  2022-02-08  7:41         ` Kevin Vigouroux via Users list for the GNU Emacs text editor
@ 2022-02-08 13:27         ` Stefan Monnier via Users list for the GNU Emacs text editor
  2022-02-08 17:05           ` goncholden
  2 siblings, 1 reply; 17+ messages in thread
From: Stefan Monnier via Users list for the GNU Emacs text editor @ 2022-02-08 13:27 UTC (permalink / raw)
  To: help-gnu-emacs

> 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




^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: Adding functionality to a minor mode
  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
  0 siblings, 1 reply; 17+ messages in thread
From: goncholden @ 2022-02-08 17:05 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: help-gnu-emacs



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)) )) )




^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: Adding functionality to a minor mode
  2022-02-08 17:05           ` goncholden
@ 2022-02-08 22:47             ` goncholden
  0 siblings, 0 replies; 17+ messages in thread
From: goncholden @ 2022-02-08 22:47 UTC (permalink / raw)
  To: goncholden; +Cc: Stefan Monnier, help-gnu-emacs

------- Original Message -------
On Tuesday, February 8th, 2022 at 5:05 PM, goncholden <goncholden@protonmail.com> wrote:
> 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, my setup involved using modus-vivendi to which I add a bold font
for everything.  But I want a special customisation for comments.  Customisations
include having a normal weight, and having a keybinding that changes the contrast
ratio between the comment colour and the background.

My first thought has been to define a minor mode.  But from the comments from this
mailing list, I has been put forward to mo that what I am doing could be a very
non-standard customisation.  What would be the most appropriate way to customise
comments as described.  I would be grateful for examples on how I should approach
the task.

Cholden





^ permalink raw reply	[flat|nested] 17+ messages in thread

end of thread, other threads:[~2022-02-08 22:47 UTC | newest]

Thread overview: 17+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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
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

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.