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

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"))

Related

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.

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

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?

Racket: inserting string variables into xexpression attributes

I'm trying to display an IMG tag using response/xexpr
This works:
(define (start req)
(response/xexpr
'(html (head (title "Racket Heroku App"))
(body
(h1 "Hello World!")
(div "it works!!!!")
(img ([src "https://docs.racket-lang.org/pict/pict_196.png"]))))))
This does not:
(define example-url "https://docs.racket-lang.org/pict/pict_196.png")
(define (start req)
(response/xexpr
'(html (head (title "Racket Heroku App"))
(body
(h1 "Hello World!")
(div "it works!!!!")
(img ([src example-url]))))))
The error shown is the following:
response/xexpr: contract violation;
Not an Xexpr. Expected an attribute value string, given 'a
Context:
'(html
(head (title "Racket Heroku App"))
(body
(h1 "Hello World!")
(div "it works!!!!")
(img
((src
'a)))))
What am I doing wrong?
You're not evaluating the value of the example-url variable, you're literally passing example-url as the URL. Try this instead:
(define example-url "https://docs.racket-lang.org/pict/pict_196.png")
(define (start req)
(response/xexpr
`(html (head (title "Racket Heroku App"))
(body
(h1 "Hello World!")
(div "it works!!!!")
(img ([src ,example-url]))))))
In the above, I'm using quasiquoting for evaluating the variable.

Chicken Scheme and malformed definitions

Chicken Scheme 4.8.0.5
Greetings all,
Here's a snippet of a malformed definition of a list of lists. I say malformed because the
variable name lies outside the leftmost parenthesis and there is no explicit define statement ie.
(define techDisplays ((AG1 fillerIgnore....nil nil))
snippet.il
techDisplays(
;( LayerName Purpose Packet Vis Sel C2C Drg Val )
;( --------- ------- ------ --- --- --- --- --- )
( AG1 fillerIgnore AG1_fillerIgnore t t nil t nil )
( AG2 drawing AG2_drawing t t nil t t )
( AG2 fillerIgnore AG2_fillerIgnore t t nil t nil )
( AG2 frame AG2_frame t t nil t t )
( AG2 frameOnly AG2_frameOnly t t nil t t )
( AG2 frameOnlyHole AG2_frameOnlyHole t t nil t t )
( y0 flight y0_flight t t t t nil )
( y1 flight y1_flight t t t t nil )
( y2 flight y2_flight t t t t nil )
( y3 flight y3_flight t t t t nil )
( y4 flight y4_flight t t t t nil )
( y5 flight y5_flight t t t t nil )
( y6 flight y6_flight t t t t nil )
( y7 flight y7_flight t t t t nil )
( y8 flight y8_flight t t t t nil )
( y9 flight y9_flight t t t t nil )
( border boundary border_boundary t nil t t nil )
( snap grid snap_grid t nil t nil nil )
) ;techDisplays
Problem: I need to get Scheme to recognise this as a valid top-level definition
Further problem: Solution must be scalable as there's 100s more where this one came from that
I must read in as well
Constraint: I would very very much like NOT to have to write some parsing routine as it'd very likely
turn out wrong what with all the parenthesis-counting , matching, and layering.
Any ideas, hints, constructive critisisms are all welcome.
TIA,
Still-learning Steve
Consider this,
; this is structured as your input with just a space after the first name
#;1> (define inp
'(techdisps (foo bar baz)
(foo1 bar1 baz1)
(foo2 bar2 baz2)))
#;2> inp
(techdisps (foo bar baz) (foo1 bar1 baz1) (foo2 bar2 baz2))
#;3> (define techdisps cdr)
;get all the displays from you input
#;4> (techdisps inp)
((foo bar baz) (foo1 bar1 baz1) (foo2 bar2 baz2))
;this should be just a tech display, let's see how it parses.
#;5> (car (techdisps inp))
(foo bar baz)
#;6> (define foo car)
#;7> (define bar cadr)
#;8> (define baz caddr)
;this will give us all the bazes
#;9> (map baz (techdisps inp))
(baz baz1 baz2)
If you think this won't scale (although 100s more won't be something that a modern scheme interpreter in a decent box will have trouble crunching) we can suggest alternatives.
Hope this helps.
Cheers.

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