~protesilaos/modus-themes

3 2

Highlight package/feature name in a bespoke macro form

Details
Message ID
<CADS3Lq7_ZjNbOv6iJAcWMU4bjZBRj6thEjCq5uEvBwKQyDqnNA@mail.gmail.com>
DKIM signature
missing
Download raw message
Firstly, the subject line may not accurately describe my request.  I
hope what follows explains it better.

I use use-package to configure my init.el and the straight.el package
manager to install packages.

A typical form to install and configure a package for me is the following:

(use-package foo
  :init
  (setq foo-variable t)
  :config
  (foo-mode 1))

I also have the following macro defined in my init.el graciously taken
from the init.el of the straight.el's author.

(defmacro use-feature (name &rest args)
  "Like `use-package', but with `straight-use-package-by-default' disabled.
NAME and ARGS are as in `use-package'."
  (declare (indent defun))
  `(use-package ,name
     :straight nil
     ,@args))

This allows me to write forms like the following for built-in packages
which offers a nice distinction from packages that are installed with a
package manager.

(use-feature bar
  :demand t
  :config (bar-mode))

Now "foo" in my first example above is nicely highlighted by the
different modus-themes (and I suspect by your other themes too).
However, "bar" in my second example above is not.  It is instead treated
as normal text.

Is there a way for me to have "bar" highlighted in the same way as
"foo"?

I should make clear if I use the standard use-package form for built-in
packages then the package/feature name is highlighted as "foo" above.

Thank you for modus-themes and your time.
Details
Message ID
<87a5s6efp6.fsf@protesilaos.com>
In-Reply-To
<CADS3Lq7_ZjNbOv6iJAcWMU4bjZBRj6thEjCq5uEvBwKQyDqnNA@mail.gmail.com> (view parent)
DKIM signature
missing
Download raw message
> From: Niall Dooley <dooleyn@gmail.com>
> Date: Wed, 25 Oct 2023 19:51:02 +0200
>
> Firstly, the subject line may not accurately describe my request.  I
> hope what follows explains it better.

Yes, the explanation is fine. No worries about the subject line!

> [... 35 lines elided]

> Is there a way for me to have "bar" highlighted in the same way as
> "foo"?
>
> I should make clear if I use the standard use-package form for built-in
> packages then the package/feature name is highlighted as "foo" above.
>
> Thank you for modus-themes and your time.

You can do it, yes. Though it is not up to the modus-themes to provide
that. You have to set it up yourself.

I think the following will work. Add it to your configuration file where
you define your macro and restart Emacs just to be sure:

    (defvar my-extra-font-lock-keywords
      '(("(\\(use-feature\\)\\_>[ \t']*\\(\\(?:\\sw\\|\\s_\\)+\\)?"
         (2 font-lock-constant-face nil t))))

    (font-lock-add-keywords 'emacs-lisp-mode my-extra-font-lock-keywords)

-- 
Protesilaos Stavrou
https://protesilaos.com
Details
Message ID
<CADS3Lq57+fvbERkRZhRiYfwTxHqhaTHBUqbThVhJWMbO85RRpw@mail.gmail.com>
In-Reply-To
<87a5s6efp6.fsf@protesilaos.com> (view parent)
DKIM signature
missing
Download raw message
On Wed, 25 Oct 2023 at 20:10, Protesilaos Stavrou <info@protesilaos.com> wrote:
> You can do it, yes. Though it is not up to the modus-themes to provide
> that. You have to set it up yourself.
>
> I think the following will work. Add it to your configuration file where
> you define your macro and restart Emacs just to be sure:
>
>     (defvar my-extra-font-lock-keywords
>       '(("(\\(use-feature\\)\\_>[ \t']*\\(\\(?:\\sw\\|\\s_\\)+\\)?"
>          (2 font-lock-constant-face nil t))))
>
>     (font-lock-add-keywords 'emacs-lisp-mode my-extra-font-lock-keywords)

Thanks you for the quick reply and solution.  It works as I hoped.
Details
Message ID
<87msw5ambe.fsf@protesilaos.com>
In-Reply-To
<CADS3Lq57+fvbERkRZhRiYfwTxHqhaTHBUqbThVhJWMbO85RRpw@mail.gmail.com> (view parent)
DKIM signature
missing
Download raw message
> From: Niall Dooley <dooleyn@gmail.com>
> Date: Wed, 25 Oct 2023 23:06:30 +0200
>
> On Wed, 25 Oct 2023 at 20:10, Protesilaos Stavrou <info@protesilaos.com> wrote:
>> You can do it, yes. Though it is not up to the modus-themes to provide
>> that. You have to set it up yourself.
>>
>> I think the following will work. Add it to your configuration file where
>> you define your macro and restart Emacs just to be sure:
>>
>>     (defvar my-extra-font-lock-keywords
>>       '(("(\\(use-feature\\)\\_>[ \t']*\\(\\(?:\\sw\\|\\s_\\)+\\)?"
>>          (2 font-lock-constant-face nil t))))
>>
>>     (font-lock-add-keywords 'emacs-lisp-mode my-extra-font-lock-keywords)
>
> Thanks you for the quick reply and solution.  It works as I hoped.

You are welcome!

-- 
Protesilaos Stavrou
https://protesilaos.com
Reply to thread Export thread (mbox)