0

I hope this doesn't sound too crazy. One of the traditions of the Lisp language is that one can create custom languages. I've customized minor things of Emacs Lisp like creating aliases like: def -> defun. This way I can run code with functions created with "def" AND can also run existing code with "defun".

Where I am stuck is creating and additional symbol for comments. I would like to use an unicode character as an alternative to introduce comments (besides ";;") Could I use defalias? in that case I don't know how to write it. something like:

defalias 🔲 -> ;;

On the other hand I've found this in Emacs source code: in the file lisp-mode.el one can find this assignment

(setq-local comment-start "; ")

But I don't know how to change the major mode. I mean, what I'd like is to use the new character besides the old one (";")

2
  • 1
    You can't (in lisp) change the lisp reader, which is what looks for the character ; and ignores the remainder of the line. All you can do is change how ; is displayed in the buffer. To change the lisp reader you would have to change its C code and recompile Emacs.
    – phils
    Jul 15, 2023 at 1:28
  • As @phils said, if you indeed want to change this syntax rule, modifying and recompiling are required. And yes, it is crazy.
    – shynur
    Jul 15, 2023 at 1:35

1 Answer 1

1

defalias 🔲 -> ;;

This can be done by prettify-symbols-mode:

(add-hook 'SOME-mode-hook
  (lambda ()
    (setq-local prettify-symbols-alist '((";;" . ?🔲)))
    (prettify-symbols-mode)))
6
  • Well, it's an idea. Not exactly the same but it's sensible. Jul 15, 2023 at 10:21
  • I've found only a half way solution. I have put this on early-init.el: (modify-syntax-entry ?🔲 "<") See emacswiki.org/emacs/EmacsSyntaxTable and then syntax highlighter recognizes it as a comment. But the scripts doesn't run. I think I've broken it :) Jul 15, 2023 at 19:00
  • Please see my earlier comment. You cannot change the comment character for Emacs Lisp without modifying C code and recompiling Emacs. You can make the syntax highlighting do whatever you want, but that doesn't change the implementation of the language.
    – phils
    Jul 16, 2023 at 1:13
  • You could make it so that typing X inserts ; and then have ; rendered as X. @shynur has shown you how to do the second half of that, so you can combine that with a key binding to insert ; when you type something else.
    – phils
    Jul 16, 2023 at 1:20
  • @JavierOrtega: It seems like you don’t know what a syntax table is. That’s okay, I don’t know either. But if you’ve tried looking at the documentation, you should easily discover that it can’t determine the implementation of Emacs Lisp at all.
    – shynur
    Jul 16, 2023 at 5:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.