Defaultcontent.el - @@ LISP tag - read-closeest-sexp?

I started using defaultcontent.el to populate newly created buffers with content. Apparently, this module is not widely used. I think there are 3 people, including me and the author, who use it, because when I search on it, my published emacs.el appears as the first hit.

Despite this, I find it useful. I specify a template for each file type, and every time I create a new file of this type (or extension), it is filled with the contents in the template file. The template supports well-known tags marked with "@@", which are replaced at runtime:

  • AUTHOR inserts the username;
  • DATE (obviously);
  • FILENAME, inserts the name of the file to be created;
  • ENV (xxx), inserts the value of the environment variable xxx;
  • and there are several other tags.

for example, whereever @@ AUTHOR @@ is in the template, it is replaced by the username at runtime in the newly created file.

ok, this is not an advertisement for defaultcontent.el, I just thought I'd explain it a bit.


here is the question.

One of the famous tags in the LISP template is to run arbitrary elisp code to generate content to be inserted into a new buffer. (usage: @@ LISP (lisp is displayed here) @@). It depends on the function read-closest-sexp, which, I think, would just read sexp at a point.

I can not find this function. It is not included in defaultcontent.el, and I am not sure enough about elisp to create it easily. I looked in emacs-w132> \ lisp.el for tips, but this seemed unobvious.

:, sexp ?

, 2 elisp...

0
1

:

(require 'thingatpt)
(let ((sexp (thing-at-point 'sexp)))
  (do-something-with sexp))

, , do-something:)

+3

Source: https://habr.com/ru/post/1762737/


All Articles