I want to write a function to check if a buffer is an Org buffer. Here is my attempt.
(defun org_bufferp (buffer)
(if (bufferp buffer)
((setq buffer_name (buffer-file-name buffer))
(if (stringp buffer_name)
(if (string-match ".*\.org$" buffer_name) t "nil1")
"nil2"))
"nil3"))
However, the result surprised me.
(org_bufferp '(current-buffer)) ;; => nil, but should be t!
(org_bufferp (current-buffer)) ;; ===> ERROR! Why?
Questions
- Why does
(org_bufferp '(current-buffer))
returnnil
? I don't even assign anynil
to possible returned values. - Why does
(org_bufferp (current-buffer))
return an error? - I'm new to Elisp, and find it hard to deal with the endless parentheses. What would you suggest in order to make the code cleaner?
elisp
for questions about using Elisp. It's for questions about the nature of the language itself, e.g. compared to other Lisp dialects. Thx. – Drew Apr 20 '20 at 21:33progn
. – Drew Apr 20 '20 at 21:38progn
from your edit since that's exactly what I missed. I hope future user can be benefited by this post. – Student Apr 21 '20 at 1:03