From: Jean Louis <bugs@gnu.support>
To: Drew Adams <drew.adams@oracle.com>
Cc: "Help-Gnu-Emacs \(help-gnu-emacs@gnu.org\)"
<help-gnu-emacs@gnu.org>,
Stefan Monnier <monnier@iro.umontreal.ca>
Subject: Re: FW: [External] : Re: Is there symbol-plist functionality in Emacs Lisp?
Date: Sat, 8 May 2021 19:23:35 +0300 [thread overview]
Message-ID: <YJa7B3J4/KSX2CSA@protected.localdomain> (raw)
In-Reply-To: <SA2PR10MB44742ADC44E310B14693E876F3569@SA2PR10MB4474.namprd10.prod.outlook.com>
* Drew Adams <drew.adams@oracle.com> [2021-05-08 17:39]:
> As for how to get the function def, the answer
> is `symbol-function', AFAIK.
That is it.
(symbol-function 'rcd-markdown) ⇒ (closure (t) (text) "Markdown processing" (if text (rcd-command-output-from-input "markdown" text) ""))
I see what it means in the manual:
,----
| Currently, an Emacs Lisp closure object is represented by a list with
| the symbol ‘closure’ as the first element, a list representing the
| lexical environment as the second element, and the argument list and
| body forms as the remaining elements:
|
| ;; lexical binding is enabled.
| (lambda (x) (* x x))
| ⇒ (closure (t) (x) (* x x))
`----
If not defined under lexical scoping it looks like:
(symbol-function 'myfn) ⇒ (lambda (a) a)
Thank you, yhat is good enough, as it is list and I can, under
conditions, change it to become able to save the function. It
serves tracking of some unused and soon to be deleted functions.
(defun save-function (f)
(let* ((fun (symbol-function f))
(type (car fun)))
(cond ((eq type 'lambda) (setq fun (append (list 'defun f) (cdr fun))))
((eq type 'closure) (setq fun (append (list 'defun f) (nthcdr 2 fun)))))
;; save to file comes here
fun))
(defun myfn (a) (+ 2 2 a))
(save-function 'myfn) ⇒ (defun myfn (a) (+ 2 2 a))
(save-function 'rcd-markdown) ⇒ (defun rcd-markdown (text) "Markdown processing" (if text (rcd-command-output-from-input "markdown" text) ""))
(defun string-to-file-force (string file)
"Prints string into file, matters not if file exists. Returns FILE as file name."
(with-temp-file file
(insert string))
file)
Then now I can save at least those functions defined by myself, it
serves my long term introspection, and preservation of single, from
file deleted functions.
(defun save-function ()
(interactive)
(let ((function (function-called-at-point)))
(when (and (symbolp function)
(y-or-n-p (format "Save `%s'" (symbol-name function))))
(let* ((fun (symbol-function function))
(type (car fun))
(file (concat "/tmp/function-" (symbol-name function) ".el")))
(cond ((eq type 'lambda) (setq fun (append (list 'defun function) (cdr fun))))
((eq type 'closure) (setq fun (append (list 'defun function) (nthcdr 2 fun)))))
(message (string-to-file-force (prin1-to-string fun) file))))))
(define-key emacs-lisp-mode-map (kbd "<f6>") 'save-function)
It gives output like this, that is acceptable:
(defun save-function nil (interactive) (let (#'(function-called-at-point)) (if (and (symbolp function) (y-or-n-p (format "Save `%s'" (symbol-name function)))) (progn (let* ((fun (symbol-function function)) (type (car fun)) (file (concat "/tmp/function-" (symbol-name function) ".el"))) (cond ((eq type 'lambda) (setq fun (append (list 'defun function) (cdr fun)))) ((eq type 'closure) (setq fun (append (list 'defun function) (nthcdr 2 fun))))) (message (string-to-file-force (prin1-to-string fun) file)))))))
--
Jean
Take action in Free Software Foundation campaigns:
https://www.fsf.org/campaigns
Sign an open letter in support of Richard M. Stallman
https://stallmansupport.org/
https://rms-support-letter.github.io/
next prev parent reply other threads:[~2021-05-08 16:23 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-05-08 7:28 Is there symbol-plist functionality in Emacs Lisp? Jean Louis
2021-05-08 13:54 ` Stefan Monnier via Users list for the GNU Emacs text editor
2021-05-08 14:38 ` FW: [External] : " Drew Adams
2021-05-08 16:23 ` Jean Louis [this message]
2021-05-08 23:13 ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-05-08 15:32 ` Jean Louis
2021-05-08 15:47 ` Stefan Monnier
2021-05-08 16:36 ` Jean Louis
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=YJa7B3J4/KSX2CSA@protected.localdomain \
--to=bugs@gnu.support \
--cc=drew.adams@oracle.com \
--cc=help-gnu-emacs@gnu.org \
--cc=monnier@iro.umontreal.ca \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).