The find-lisp-object-file-name return wrong value - elisp

I'm using Emacs 26.1, and recently I found the find-lisp-object-file-name always return nil when I call it in following ways:
(find-lisp-object-file-name 'call-process nil)
;;=> nil
(find-lisp-object-file-name 'call-process 'defun)
;;=> nil
However, when I use the describe-function to show information about call-process, it shows the call-process is from "C source code". It looks like the function find-lisp-object-file-name is not reliable.
More examples:
(find-lisp-object-file-name 'cond nil)
;;=> nil *WRONG*
(find-lisp-object-file-name 'cdr nil)
;;=> nil *WRONG*
(find-lisp-object-file-name 'user-full-name nil)
;;=> "src/editfns.c" *CORRECT*
The question: how can I always get the correct file name information of a symbol?

Related

Wrong type argument: stringp, nil with org-map-entries

I've encountered an error which I can't resolve. I have a file test.org which simply contains a first level headline: * test
(with-temp-buffer
(insert-file-contents "~/test.org")
(goto-char (point-min))
(org-map-entries
(lambda ()
(compare-strings
"* test\n" nil nil
(thing-at-point 'line t) nil nil
t))
"LEVEL=1"))
This returns Wrong type argument: stringp, nil. The org-map-entries function works normally, but there seems to be a problem when it is used with with-temp-buffer.
The temp buffer is in fundamental mode and nothing you do in your code changes that. OTOH, the org- functions assume that the buffer is in Org mode and (sometimes) barf if that is not the case.
Try this:
(with-temp-buffer
(org-mode)
(insert-file-contents "~/test.org")
(goto-char (point-min))
(org-map-entries
(lambda ()
(compare-strings
"* test\n" nil nil
(thing-at-point 'line t) nil nil
t))
"LEVEL=1"))

errors.Is in Go 1.13

Go 1.13 introduces new features to the errors to simplify working with errors. Before Go 1.13, I checked my code for an error by this way:
if err == nil {
// ...
}
But Go's errors.Is() helps me to do it properly:
It’s a sensible way to future-proof your code and prevent issues
caused by you — or any packages that your code imports — wrapping
errors in the future.
And that is ok for situations like this:
if errors.Is(err, sql.ErrNoRows) {
// ...
}
Does it mean that I have to change all my err == nil statements to:
if errors.Is(err, nil) {
// ...
}
No, you don't. errors.Is checks the underlying error values. If some code returns sql.ErrNoRows and later decides to wrap that error, errors.Is(err, sql.ErrNoRows) continues working as before, but err == sql.ErrNoRows would evaluate to false.
A nil error value means there is no error, so there is nothing to wrap. There is no code you can write that changes what err != nil evaluates to while still returning no error. There is only one way to return no error: nil.
No. Not required. We use errors.Is() when an error is matched to the target, if its equal to the target it returns true. In your case err is nil which can't be used with the target.

Testing user-set variable for equality in ELisp

I am new to Emacs Lisp and changing some code in mu4e-send-delay. I want to test whether the user set a variable to a value, e.g. in the scratch buffer:
(setq mu4e-sent-messages-behavior 'delete)
delete
These three tests return false:
(eq 'mu4e-sent-messages-behavior 'delete)
nil
(equal 'mu4e-sent-messages-behavior 'delete)
nil
(equal 'mu4e-sent-messages-behavior "delete")
nil
And this one returns true, but with the member function for lists:
(if (member mu4e-sent-messages-behavior '(delete)) t nil)
t
If the user keeps the setting at the default set in the code:
(defcustom mu4e-sent-messages-behavior 'sent
...
)
then member also fails:
(when (member mu4e-sent-messages-behavior '(sent)) t nil)
nil
What is wrong with my tests, and how can I test for the value of a variable set by the user?
Don't quote the variable name when passing it to eq:
(eq mu4e-sent-messages-behavior 'delete)
The problem with this piece of code:
(when (member mu4e-sent-messages-behavior '(sent)) t nil)
is that when will either return nil (if the condition is false) or the last value of the body (if the condition is true), which in this case is nil - so this piece of code will always return nil. Use if instead of when, and you should see it returning t.

Golang return nil

I am trying to wrap my head around Golang's types and interfaces but am struggling a bit to do so. Anyways, a common pattern that I see is func Whatever() (thing string, err error). I get how all of that works, but the one thing I am confused on is why it is ok to return "thing", nil. The specific instance that I am looking at is in revel here-
func (c *GorpController) Begin() revel.Result {
txn, err := Dbm.Begin()
if err != nil {
panic(err)
}
c.Txn = txn
return nil
}
revel.Result is an interface with this signature-
type Result interface {
Apply(req *Request, resp *Response)
}
Anyways, I am just curious how returning nil satisfies the compiler in that occasion. Is there a resource that I can be pointed to for that?
This is similar to returning a nil error: see "Why is my nil error value not equal to nil? "
Under the covers, interfaces are implemented as two elements, a type and a value.
The value, called the interface's dynamic value, is an arbitrary concrete value and the type is that of the value. For the int value 3, an interface value contains, schematically, (int, 3).
An interface value is nil only if the inner value and type are both unset, (nil, nil). In particular, a nil interface will always hold a nil type.
If we store a pointer of type *int inside an interface value, the inner type will be *int regardless of the value of the pointer: (*int, nil).
Such an interface value will therefore be non-nil even when the pointer inside is nil.
Here nil is the zero-value of the interface revel.Result.

Can't open any file with emacs-live configuration on OSX

I saw the emacs-live demo by Sam Aaron with overtone. I went to the GitHub repository, got his .emacs.d setup and replaced my setup with it by deleting an existing .emacs file.
Everything seems good, I have most of the emacs-live features but I can't seem to open any existing file.
Every time I do a C-x C-f and select a file, I get this message:
"Searching for program: no such file or directory, git "
Also, it loads a lot of packages and takes time to initialize and gets stuck at a message that reads:
Zoning... (zone-pgm-putz-with-case)
I am new to Emacs, any idea what must be going wrong here?
EDIT 1:
I have Git installed on my system!
Here is the repo that I used: https://github.com/overtone/emacs-live
EDIT 2:
Output from the debugger:
Debugger entered--Lisp error: (file-error "Searching for program" "no such file or directory" "git")
call-process("git" nil (t nil) nil "--no-pager" "rev-parse" "--show-cdup")
apply(call-process "git" nil (t nil) nil ("--no-pager" "rev-parse" "--show-cdup"))
process-file("git" nil (t nil) nil "--no-pager" "rev-parse" "--show-cdup")
apply(process-file "git" nil (t nil) nil ("--no-pager" "rev-parse" "--show-cdup"))
(progn (apply (function process-file) magit-git-executable nil (list t nil) nil (append magit-git-standard-options args)) (if (= (point-m$
(unwind-protect (progn (apply (function process-file) magit-git-executable nil (list t nil) nil (append magit-git-standard-options args))$
(save-current-buffer (set-buffer temp-buffer) (unwind-protect (progn (apply (function process-file) magit-git-executable nil (list t nil)$
(let ((temp-buffer (generate-new-buffer " *temp*"))) (save-current-buffer (set-buffer temp-buffer) (unwind-protect (progn (apply (functio$
magit-git-string("rev-parse" "--show-cdup")
(let* ((default-directory (file-name-as-directory cwd)) (cdup (magit-git-string "rev-parse" "--show-cdup"))) (if cdup (progn (file-name-a$
(progn (let* ((default-directory (file-name-as-directory cwd)) (cdup (magit-git-string "rev-parse" "--show-cdup"))) (if cdup (progn (file$
(if (file-directory-p cwd) (progn (let* ((default-directory (file-name-as-directory cwd)) (cdup (magit-git-string "rev-parse" "--show-cdu$
magit-get-top-dir()
(and magit-turn-on-auto-revert-mode (not auto-revert-mode) (not auto-revert-tail-mode) (not global-auto-revert-mode) (magit-get-top-dir))
(if (and magit-turn-on-auto-revert-mode (not auto-revert-mode) (not auto-revert-tail-mode) (not global-auto-revert-mode) (magit-get-top-d$
magit-maybe-turn-on-auto-revert-mode()
run-hooks(find-file-hook)
after-find-file(nil t)
find-file-noselect-1(#<buffer access.clj> "~/Desktop/hulk/src/core/models/access.clj" nil nil "~/Desktop/hulk/src/core/models/access.clj"$
find-file-noselect("/Users/amogh/Desktop/hulk/src/core/models/access.clj" nil nil)
ido-file-internal(selected-window)
ido-find-file()
call-interactively(ido-find-file nil nil)
Try using exec-path-from-shell.

Resources