* Is there symbol-plist functionality in Emacs Lisp?
@ 2021-05-08 7:28 Jean Louis
2021-05-08 13:54 ` Stefan Monnier via Users list for the GNU Emacs text editor
0 siblings, 1 reply; 8+ messages in thread
From: Jean Louis @ 2021-05-08 7:28 UTC (permalink / raw)
To: Help GNU Emacs
The function `symbol-plist' in Emacs Lisp returns only properties:
> (symbol-plist SYMBOL)
> This function does not change global state, including the match data.
While `symbol-plist' in Common Lisp returns the definition as below.
Is there equivalent Emacs Lisp function that could return me the full
definition of a function?
(symbol-plist 'save-function)
(SYSTEM::DEFINITION
((DEFUN SAVE-FUNCTION (F)
"Saves the function in the file *my-function-dir*/function-name.lisp.
Invoke it as: (SAVE-FUNCTION 'FUNCTION-NAME) or (SAVE-FUNCTION \"FUNCTION-NAME\")"
(LET
((FUNCTION-NAME (CAR (CADR (SYMBOL-PLIST (INTERN (STRING-UPCASE F))))))
(FUNCTION-FILE
(FORMAT NIL "~a/~a.lisp" *MY-FUNCTION-DIR*
(STRING-DOWNCASE
(SUBSTITUTE #\- #\? (IF (SYMBOLP F) (SYMBOL-NAME F) (SYMBOL-NAME (INTERN (STRING-UPCASE F)))))))))
(WITH-OPEN-FILE (STR FUNCTION-FILE :DIRECTION :OUTPUT :IF-DOES-NOT-EXIST :CREATE)
(PRINT FUNCTION-NAME STR))))
.
#(NIL NIL NIL NIL
((DECLARATION OPTIMIZE DECLARATION DYNAMICALLY-MODIFIABLE SYSTEM::IMPLEMENTATION-DEPENDENT))))
SYSTEM::DOC (SYSTEM::FILE ((SYSTEM::DEFUN/DEFMACRO #P"/home/data1/protected/bin/rcd/save-lisp.lisp" 8 8))))
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/
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: Is there symbol-plist functionality in Emacs Lisp?
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 15:32 ` Jean Louis
0 siblings, 2 replies; 8+ messages in thread
From: Stefan Monnier via Users list for the GNU Emacs text editor @ 2021-05-08 13:54 UTC (permalink / raw)
To: help-gnu-emacs
> While `symbol-plist' in Common Lisp returns the definition as below.
Is that really true of Common Lisp, or just of some implementations?
I can't seem to find that documented in the CLHS.
Stefan
^ permalink raw reply [flat|nested] 8+ messages in thread
* FW: [External] : Re: Is there symbol-plist functionality in Emacs Lisp?
2021-05-08 13:54 ` Stefan Monnier via Users list for the GNU Emacs text editor
@ 2021-05-08 14:38 ` Drew Adams
2021-05-08 16:23 ` Jean Louis
2021-05-08 23:13 ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-05-08 15:32 ` Jean Louis
1 sibling, 2 replies; 8+ messages in thread
From: Drew Adams @ 2021-05-08 14:38 UTC (permalink / raw)
To: Help-Gnu-Emacs (help-gnu-emacs@gnu.org); +Cc: Stefan Monnier
[Forwarding to the list. Bitten again by "Reply All"
not including the list, for some reason.]
> > While `symbol-plist' in Common Lisp returns the definition as below.
>
> Is that really true of Common Lisp, or just of some implementations?
> I can't seem to find that documented in the CLHS.
What Stefan said. AFAIK, the specs (CLTL2, CLHS)
say nothing about what is or might be in the plist.
I think the answer to the question of why Elisp
`symbol-plist' doesn't return the function def
in the plist is because in Elisp the function
def isn't in the plist.
As for how to get the function def, the answer
is `symbol-function', AFAIK.
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: Is there symbol-plist functionality in Emacs Lisp?
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 15:32 ` Jean Louis
2021-05-08 15:47 ` Stefan Monnier
1 sibling, 1 reply; 8+ messages in thread
From: Jean Louis @ 2021-05-08 15:32 UTC (permalink / raw)
To: Stefan Monnier; +Cc: help-gnu-emacs
* Stefan Monnier via Users list for the GNU Emacs text editor <help-gnu-emacs@gnu.org> [2021-05-08 17:01]:
> > While `symbol-plist' in Common Lisp returns the definition as below.
>
> Is that really true of Common Lisp, or just of some implementations?
> I can't seem to find that documented in the CLHS.
True, it works just in CLISP. Is there equivalent in Emacs that I can
get a function definition this way?
[1]> (defun myfn (a) a)
MYFN
[2]> (SYMBOL-PLIST (INTERN (STRING-upcase "myfn")))
(SYSTEM::DEFINITION
((DEFUN MYFN (A) A) .
#(NIL NIL NIL NIL
((DECLARATION OPTIMIZE DECLARATION DYNAMICALLY-MODIFIABLE SYSTEM::IMPLEMENTATION-DEPENDENT)))))
--
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/
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: Is there symbol-plist functionality in Emacs Lisp?
2021-05-08 15:32 ` Jean Louis
@ 2021-05-08 15:47 ` Stefan Monnier
2021-05-08 16:36 ` Jean Louis
0 siblings, 1 reply; 8+ messages in thread
From: Stefan Monnier @ 2021-05-08 15:47 UTC (permalink / raw)
To: help-gnu-emacs
>> > While `symbol-plist' in Common Lisp returns the definition as below.
>> Is that really true of Common Lisp, or just of some implementations?
>> I can't seem to find that documented in the CLHS.
> True, it works just in CLISP. Is there equivalent in Emacs that I can
> get a function definition this way?
Depends what you mean by "function definition", IOW depends what you
want to do with it. There `symbol-function` of course, and there are
also things like `find-function-noselect`.
Stefan
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: FW: [External] : Re: Is there symbol-plist functionality in Emacs Lisp?
2021-05-08 14:38 ` FW: [External] : " Drew Adams
@ 2021-05-08 16:23 ` Jean Louis
2021-05-08 23:13 ` Emanuel Berg via Users list for the GNU Emacs text editor
1 sibling, 0 replies; 8+ messages in thread
From: Jean Louis @ 2021-05-08 16:23 UTC (permalink / raw)
To: Drew Adams; +Cc: Help-Gnu-Emacs (help-gnu-emacs@gnu.org), Stefan Monnier
* 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/
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: Is there symbol-plist functionality in Emacs Lisp?
2021-05-08 15:47 ` Stefan Monnier
@ 2021-05-08 16:36 ` Jean Louis
0 siblings, 0 replies; 8+ messages in thread
From: Jean Louis @ 2021-05-08 16:36 UTC (permalink / raw)
To: Stefan Monnier; +Cc: help-gnu-emacs
* Stefan Monnier <monnier@iro.umontreal.ca> [2021-05-08 18:48]:
> >> > While `symbol-plist' in Common Lisp returns the definition as below.
> >> Is that really true of Common Lisp, or just of some implementations?
> >> I can't seem to find that documented in the CLHS.
> > True, it works just in CLISP. Is there equivalent in Emacs that I can
> > get a function definition this way?
>
> Depends what you mean by "function definition", IOW depends what you
> want to do with it. There `symbol-function` of course, and there are
> also things like `find-function-noselect`.
Thank you.
When I was working in Common Lisp REPL, I have used CLISP, and it was
handy to save a function that is deleted from file.
(defun save-function ()
"Saves function at point"
(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))))))
(defun save-function-delete ()
(save-function)
(beginning-of-line)
(mark-sexp)
(delete-active-region))
Now if I wish to delete a function, but save it before hand, I would
go to "save-function-delete" and invoke the key to run
`safe-function-delete'
It would save itself from memory, not from file as for future possible
introspection and delete it from the file in the same time.
--
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/
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: FW: [External] : Re: Is there symbol-plist functionality in Emacs Lisp?
2021-05-08 14:38 ` FW: [External] : " Drew Adams
2021-05-08 16:23 ` Jean Louis
@ 2021-05-08 23:13 ` Emanuel Berg via Users list for the GNU Emacs text editor
1 sibling, 0 replies; 8+ messages in thread
From: Emanuel Berg via Users list for the GNU Emacs text editor @ 2021-05-08 23:13 UTC (permalink / raw)
To: help-gnu-emacs
Drew Adams wrote:
> AFAIK, the specs (CLTL2, CLHS) say nothing about what is or
> might be in the plist.
CLTL2 = Common Lisp the Language, 2nd Edition,
https://www.cs.cmu.edu/Groups/AI/html/cltl/cltl2.html
CLHS = Common Lisp HyperSpec,
http://www.lispworks.com/documentation/lw50/CLHS/Front/Contents.htm
"HyperSpec" BTW :)
--
underground experts united
https://dataswamp.org/~incal
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2021-05-08 23:13 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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
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
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).