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 (";")

  • 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 '23 at 01: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 '23 at 01:35

1 Answers1

1

defalias -> ;;

This can be done by prettify-symbols-mode:

(add-hook 'SOME-mode-hook
  (lambda ()
    (setq-local prettify-symbols-alist '((";;" . ?)))
    (prettify-symbols-mode)))
shynur
  • 4,065
  • 1
  • 3
  • 23
  • Well, it's an idea. Not exactly the same but it's sensible. – Javier Ortega Jul 15 '23 at 10:21
  • I've found only a half way solution. I have put this on early-init.el: (modify-syntax-entry ? "<") See https://www.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 :) – Javier Ortega Jul 15 '23 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 '23 at 01: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 '23 at 01: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 '23 at 05:52
  • OK, I've understood all your comments. Thank you very much for all your help. The point is that someday I would like to understand better all that stuff about compiler implementation, Turing machines and learn more about theoretical computer science. But for the moment I'll have to find some time for that. Well, thank you all of you! – Javier Ortega Jul 16 '23 at 15:07