unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* implementing a reader macro
@ 2022-07-22 18:40 Ag Ibragimov
  2022-07-22 20:32 ` Stefan Monnier
  2022-07-22 20:51 ` Lars Ingebrigtsen
  0 siblings, 2 replies; 7+ messages in thread
From: Ag Ibragimov @ 2022-07-22 18:40 UTC (permalink / raw)
  To: emacs-devel


How difficult is it to implement a new reader macro for Elisp?
The one I particularly wish to be ported from Clojure is the "discard
macro" - `#_`. What it does is that it ignores the next form completely.

e.g., 
#+begin_src clojure
    #_(list 1 2 3)

    (list 1 #_2 3)
#+end_src

And it can be stacked to omit multiple forms:

#+begin_src clojure
  (foo 1
     #_#_(bar)       ; both, (bar) and 
     (zap "zop"))    ;       (zap "zop") will be ignored
#+end_src

It is a very nice way of (usually temporarily) commenting out sexps
without disrupting the structure too much. Of course, we can employ nice
tricks such as one described by Malabarba:
http://endlessparentheses.com/a-comment-or-uncomment-sexp-command.html
But wouldn't it be nice to have something even better?



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

* Re: implementing a reader macro
  2022-07-22 18:40 implementing a reader macro Ag Ibragimov
@ 2022-07-22 20:32 ` Stefan Monnier
  2022-07-22 21:18   ` Jose A. Ortega Ruiz
  2022-07-22 22:12   ` Ag Ibragimov
  2022-07-22 20:51 ` Lars Ingebrigtsen
  1 sibling, 2 replies; 7+ messages in thread
From: Stefan Monnier @ 2022-07-22 20:32 UTC (permalink / raw)
  To: Ag Ibragimov; +Cc: emacs-devel

> How difficult is it to implement a new reader macro for Elisp?
> The one I particularly wish to be ported from Clojure is the "discard
> macro" - `#_`. What it does is that it ignores the next form completely.

Does `clojure-mode` support that correctly?
Scheme has a similar construct and I found it difficult to make
`scheme-mode` handle it correctly (so: it doesn't).

I don't think we want to add to ELisp a feature that our support tools
can't handle well.

> It is a very nice way of (usually temporarily) commenting out sexps
> without disrupting the structure too much. Of course, we can employ nice
> tricks such as one described by Malabarba:
> http://endlessparentheses.com/a-comment-or-uncomment-sexp-command.html
> But wouldn't it be nice to have something even better?

I don't think this feature pays for itself, personally.
There are plenty of alternative solutions that don't require changing
the syntax of the language.


        Stefan




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

* Re: implementing a reader macro
  2022-07-22 18:40 implementing a reader macro Ag Ibragimov
  2022-07-22 20:32 ` Stefan Monnier
@ 2022-07-22 20:51 ` Lars Ingebrigtsen
  2022-07-22 22:16   ` Ag Ibragimov
  1 sibling, 1 reply; 7+ messages in thread
From: Lars Ingebrigtsen @ 2022-07-22 20:51 UTC (permalink / raw)
  To: Ag Ibragimov; +Cc: emacs-devel

Ag Ibragimov <agzam.ibragimov@gmail.com> writes:

> How difficult is it to implement a new reader macro for Elisp?
> The one I particularly wish to be ported from Clojure is the "discard
> macro" - `#_`. What it does is that it ignores the next form completely.

This has already been implemented more than a couple of times (but using
the Common Lisp versions of this, i.e.,

  #+nil(this is commented out)

and

  #| this too |#

Adjusting the reader to allow these forms is pretty trivial, but the
reason this hasn't been added to Emacs is that nobody has stepped up to
adjust the tooling (font locking, sexp movement, etc), too.

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no



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

* Re: implementing a reader macro
  2022-07-22 20:32 ` Stefan Monnier
@ 2022-07-22 21:18   ` Jose A. Ortega Ruiz
  2022-07-22 22:12   ` Ag Ibragimov
  1 sibling, 0 replies; 7+ messages in thread
From: Jose A. Ortega Ruiz @ 2022-07-22 21:18 UTC (permalink / raw)
  To: emacs-devel

On Fri, Jul 22 2022, Stefan Monnier wrote:

>> How difficult is it to implement a new reader macro for Elisp?
>> The one I particularly wish to be ported from Clojure is the "discard
>> macro" - `#_`. What it does is that it ignores the next form completely.
>
> Does `clojure-mode` support that correctly?

in my experience (i edit clojure daily), it does (FSVO "correctly",
defined by my usage patterns, of course).  at the language level, i find
this feature extremely useful, and i'm a very happy user inside
clojure-mode.

cheers,
jao
-- 
Poetry is the art of creating imaginary gardens with real
toads. -Marianne Moore, poet (1887-1972)




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

* Re: implementing a reader macro
  2022-07-22 20:32 ` Stefan Monnier
  2022-07-22 21:18   ` Jose A. Ortega Ruiz
@ 2022-07-22 22:12   ` Ag Ibragimov
  2022-07-22 23:07     ` Stefan Monnier
  1 sibling, 1 reply; 7+ messages in thread
From: Ag Ibragimov @ 2022-07-22 22:12 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: emacs-devel

Stefan Monnier <monnier@iro.umontreal.ca> writes:

>> How difficult is it to implement a new reader macro for Elisp?
>> The one I particularly wish to be ported from Clojure is the "discard
>> macro" - `#_`. What it does is that it ignores the next form completely.
>
> Does `clojure-mode` support that correctly?

AFAIK it works very well in clojure-mode.

> I don't think this feature pays for itself, personally.

Well, to be honest, initially, it does look like a gimmick that doesn't add much
value. But once you get used to having it, it really feels nice.

> There are plenty of alternative solutions that don't require changing
> the syntax of the language.

Can you show some examples? I think most of them still require you to
change the structure - you either have to wrap the form or prepend every line, etc.



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

* Re: implementing a reader macro
  2022-07-22 20:51 ` Lars Ingebrigtsen
@ 2022-07-22 22:16   ` Ag Ibragimov
  0 siblings, 0 replies; 7+ messages in thread
From: Ag Ibragimov @ 2022-07-22 22:16 UTC (permalink / raw)
  To: Lars Ingebrigtsen; +Cc: emacs-devel

Lars Ingebrigtsen <larsi@gnus.org> writes:

> Adjusting the reader to allow these forms is pretty trivial, but the
> reason this hasn't been added to Emacs is that nobody has stepped up to
> adjust the tooling (font locking, sexp movement, etc), too.

Since we have those implemented in clojure-mode, maybe it can be
adapted for elisp? Reader macro itself of course is implemented in clojure
codebase, but font-locking, et al, [I think] is all in clojure-mode.el.



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

* Re: implementing a reader macro
  2022-07-22 22:12   ` Ag Ibragimov
@ 2022-07-22 23:07     ` Stefan Monnier
  0 siblings, 0 replies; 7+ messages in thread
From: Stefan Monnier @ 2022-07-22 23:07 UTC (permalink / raw)
  To: Ag Ibragimov; +Cc: emacs-devel

>>> How difficult is it to implement a new reader macro for Elisp?
>>> The one I particularly wish to be ported from Clojure is the "discard
>>> macro" - `#_`. What it does is that it ignores the next form completely.
>> Does `clojure-mode` support that correctly?
> AFAIK it works very well in clojure-mode.

That's actually not quite an answer to my question.

AFAICT clojure-mode just "manually" highlights those comments with
`font-lock-comment-face`, so sexp navigation will not handle them
properly w.r.t `parse-sexp-ignore-comments`, and `forward-comment` won't
skip them either.

Also this relies on the `font-lock-multiline` variable, which is a kind
of "best effort", so if the beginning of the comment is never displayed
(because it's never between `window-start` and `window-end`) the rest of
the comment may end up displayed without the `font-lock-comment-face`.

> Can you show some examples? I think most of them still require you to
> change the structure - you either have to wrap the form or prepend
> every line, etc.

My go-to key sequence for that is:

    C-M-SPC M-;

but in most circumstances there are other approaches that depend on the
specific situation.  E.g. often just adding a ' does the trick (tho
I usually prefer `M-;`).


        Stefan




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

end of thread, other threads:[~2022-07-22 23:07 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-07-22 18:40 implementing a reader macro Ag Ibragimov
2022-07-22 20:32 ` Stefan Monnier
2022-07-22 21:18   ` Jose A. Ortega Ruiz
2022-07-22 22:12   ` Ag Ibragimov
2022-07-22 23:07     ` Stefan Monnier
2022-07-22 20:51 ` Lars Ingebrigtsen
2022-07-22 22:16   ` Ag Ibragimov

Code repositories for project(s) associated with this public inbox

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

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