Hacker News new | past | comments | ask | show | jobs | submit login
Forbidden Emacs Lisp Knowledge: Block Comments (emacsninja.com)
109 points by hprotagonist on Feb 12, 2022 | hide | past | favorite | 8 comments



I compiled my own emacs to expose internal-interpreter-environment or whatever it’s called. It’s roughly equivalent to the python locals() function. I have no idea why they thought it was a bad idea to expose, but it’s super handy. Also literally forbidden.


Nice! My two-minute thought on your idea, I refactored your code somewhat:

    ;;; test.el ---                                      -*- lexical-binding: t; -*-

    Don't know if it's useful in practice, but if we had multiline comments, we
    could add invisible property on those markers to auto-hide them. Interlaced with
    Emacs Lisp code, it gives a "feel" of literate programming.

    (defun cursed-elisp-block-comment (beg end)
      (interactive "r")
      (save-excursion
        (let ((start (format "#@%d " (+ (- end beg) 2))))
          (goto-char end)
          (insert "\037")
          (put-text-property end (1+ end) 'invisible t)
          (goto-char beg)
          ;; account for space and terminator
          (insert start)
          (put-text-property beg (+ beg (length start)) 'invisible t))))

    (defun make-visible (beg end)
      (interactive "r")
      (remove-text-properties beg end '(invisible t)))

    This file is a little demo of the concept, but to actually be useful, there
    should probably be some routine to automatically mark text paragraphs with
    invisible markers, since it is a bit labourous to do it by hand for each
    paragraph. Surprisingly, indentation engine didn't complain at all, while
    font-lock of course does not know I am in a comment.

    (message "hello multiline comments")

    (provide 'test)
    ;;; test.el ends here
Above file evaled as emacs-lisp buffer:

https://postimg.cc/SnfNNfyh


That's a cool find.

On a practical note, at the top level or in the middle of progn-like constructs, you can do "block comments" with just:

'( ... )

I.e., quote the form to prevent evaluating it.


I’ve always defined a `comment` macro that expands to nil. It works in most situations but it returns a value


Reminds me of comments in MS batch files. I think there is just a program called REM (ie REMark, used to begin comments) which just ignores its arguments and immediately returns.


Clojure has that built-in and it’s great. Works wonders when testing things too: write a small test in a comment block and you can edit/evaluate a function then move to the comment and see the result immediately.


Yeah, that’s where I got the idea.


I always hesitate to return the commented expression or nil or '(:comment expr...)

Nonetheless comment macros are neat. Just like #_(ignored) in clojure or else.




Join us for AI Startup School this June 16-17 in San Francisco!

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: