Why does `assoc' return nil in this case? - elisp

I am trying to write a Export Backend for Emacs org-mode. This mode is derived from the ox-latex.el Exporter. I want the Exporter to embed all *.css and *.js files into the resulting .html file.
The Exporter runs but does'nt give any output in my functions, because this
assoc(t (("readthedocs" ("css" "htmlize.css" "readtheorg.css") ("js" "readtheorg.js" "jquery.js" "bootstrap.js"))))
call (it's from the debugger) returns nil.
What am I missing here ?
Any help appreciated :) Full Code can be found here https://pastebin.com/N475Uk9Z
EDIT:
(defconst org-static-html-themes
'(("readthedocs" . (("css" . ("htmlize.css"
"readtheorg.css"))
("js" . ("readtheorg.js"
"jquery.js"
"bootstrap.js"))))))
(defun org-static-html--build-head (info)
"Return information for the <head>..</head> of the HTML output.
INFO is a plist used as a communication channel."
(progn
(debug)
(org-element-normalize-string
(concat
(org-element-normalize-string (plist-get info :html-head))
(org-element-normalize-string (plist-get info :html-head-extra))
(org-element-normalize-string
(mapconcat (lambda (css)
(org-static-html-inline-css
(concat org-static-html-resource-path "/css/" css)))
(cdr (assoc "css"
(assoc
(plist-get info :static-html-theme)
org-static-html-themes))) "\n"))))))
This function is supposed to get all css files associated with the corresponding theme and return then concatenated and wrapped inside style tags.
I should say that I'm using Emacs version 27.0.50.

Your association list contains just one association: between "readthedocs" and (("css" "htmlize.css" "readtheorg.css") ("js" "readtheorg.js" "jquery.js" "bootstrap.js")).
Since nothing is associated with t, (assoc t ...) returns nil.

Related

Elisp function throws error only when called while init.el is open in buffer

I am using Emacs, and wrote a custom function in init.el to make it easier for me to create Anki flashcards upon press of a keybind. This specific function is used to retrieve two values (using Anki-Connect) and let me choose them from a list (the function is based on behaviour found in anki-editor.
In order to do that, I declared a few variables outside the function, so that I can later use their values in a org-capture-template. They are set to nil at the start because I check somewhere else if they have already been set and otherwise call the below function first.
My solution works, but only as long as init.el (or Emacs.org, from which it is compiled by tangle) is closed. If I call the function while init.el is open, I get the following error: "Wrong number of arguments: (3 . 3), 2" - I do not understand why that happens.
How can I fix this problem?
My code looks like this:
(defvar my-anki-deck nil)
(defvar my-anki-notetype nil)
(defvar my-anki-fields nil)
(defun my-anki-set-deck-and-notetype ()
(interactive)
(setq my-anki-deck (completing-read "Choose a deck: "
(sort (anki-editor-deck-names)
#'string-lessp)))
(setq my-anki-notetype (completing-read "Choose a note type: "
(sort (anki-editor-note-types)
#'string-lessp)))
(setq my-anki-fields (progn
(anki-editor--anki-connect-invoke-result
"modelFieldNames"
`((modelName . ,my-anki-notetype))))))
Below is the detailed error message (I tried to format it nicely, this is the best I was able to do):
Debugger entered--Lisp error: (wrong-number-of-arguments (3 . 3) 2)
request--curl-callback(# "finished\n")
anki-editor--anki-connect-invoke("deckNames")
anki-editor-deck-names()
(sort (anki-editor-deck-names) #'string-lessp)
(completing-read "Choose a deck: " (sort (anki-editor-deck-names) #'string-lessp))
(setq my-anki-deck (completing-read "Choose a deck: " (sort (anki-editor-deck-names) #'string-lessp)))
my-anki-set-deck-and-notetype()
funcall-interactively(my-anki-set-deck-and-notetype)
command-execute(my-anki-set-deck-and-notetype record)
counsel-M-x-action("my-anki-set-deck-and-notetype")
ivy-call()
ivy-read("M-x " [evil-collection-magit-toggle-text-minor-mode table--measure-max-width vc-src-responsible-p lsp:omnisharp-run-tests-in-class-request-column nexti tramp-completion-handle-file-name-all-completions term-do-line-wrapping lsp-watch-kind? speedbar-check-vc-this-line access-label curr-btn magit-revision-filter-files-on-follow treemacs-dom-node->set-position! calcFunc-rgrade term-handle-exit &error rng-parse-validate-file magit-xref-insert-button speedbar-file-regexp gnus-agent-group-covered-p evil-collection-org-maps edebug-mode-on-hook message-expand-name-databases C-i autoload-find-file c-make-ml-string-opener-re-function gnus-try-warping-via-registry magit-list-modified-modules pullreq_label:pullreq gnus-server-compact-server :odt-styles-file gdb-thread-number :mac org-table-get-range vc-bzr-shelve-menu rng-match-infer-start-tag-namespace Above nnimap-status-message gnus-summary-limit-to-marks treemacs--get-label-of nnmail-message-id-cache-file treemacs-python-executable article-fill-long-lines smime-buffer-as-string-region lsp:set-file-operation-pattern-options? diredfl-symlink Parchment c-default-value-sentence-end rg-elisp-font-lock-keywords posframe-poshandler-frame-bottom-left-corner ...] :predicate #f(compiled-function (sym) #<bytecode -0x11c32b217e0c370d>) :require-match t :history counsel-M-x-history :action counsel-M-x-action :keymap (keymap (67108908 . counsel--info-lookup-symbol) (67108910 . counsel-find-symbol)) :initial-input nil :caller counsel-M-x)
counsel-M-x()
funcall-interactively(counsel-M-x)
command-execute(counsel-M-x)

Elisp - How to run a shell command and make buffer to be in markdown-mode?

(defun jira-view-git-branch ()
(interactive)
(markdown-mode)
(shell-command (format "./jira-view.sh &")))
So how to make the output buffer to be in markdown mode?
I tried the following
(defun jira-view-git-branch ()
(interactive)
(with-output-to-temp-buffer "*jira*"
(shell-command (format "./jira-view.sh &") "*jira*" "*Messages*")
(pop-to-buffer "*jira*"))
(with-current-buffer "*jira*"
(markdown-mode)))
but got this in *Messages*
error in process filter: read-from-minibuffer: Wrong type argument: markerp, nil
error in process filter: Wrong type argument: markerp, nil
Without knowing what your shell command jira-view.sh does exactly, I find it hard to come up with a good solution for this.
At least, the following should give you some pointers:
(defun jira-md (buffer)
(interactive "Bbuffer name: ")
(let ((b (get-buffer-create buffer)))
(switch-to-buffer b)
(markdown-mode)
(insert (shell-command-to-string "echo '# title'"))))
You can ask for a (possibly not yet existing) buffer when calling this function by having B be the first character in the argument to interactive
Once you have a buffer name, you can switch to that buffer and then set the major mode.
You could also make the setting of major mode optional by first examining if the major mode is not already set to markdown-mode. Something like:
(unless (eq major-mode 'markdown-mode)
(markdown-mode))

edebug-trace ceased to exist

In Emacs 25.2, suddenly the variable edebug-trace ceased to exist. When I set it with setq, it has no effect (the trace buffer does not appear). What could have happened and how can I fix it?
In the meanwhile, is there another way to know which function gets called when I click on an org-mode link
You could use trace.el to trace all org functions like so (I suggest not evaluating this until you're ready to click the link).
(mapatoms
(lambda (sym)
(and (fboundp sym)
(string-prefix-p "org-" (symbol-name sym))
(trace-function-foreground sym))))
Afterwards, you can remove the traces with:
M-x untrace-all RET
Edit: We could also convert that into a command ala elp-instrument-package:
(defun my-trace-package (prefix)
"Trace all functions which start with PREFIX.
For example, to trace all ELP functions, do the following:
\\[my-trace-package] RET elp- RET"
(interactive ;; derived from `elp-instrument-package'.
(list (completing-read "Prefix of package to trace: "
obarray 'my-traceable-p)))
(if (zerop (length prefix))
(error "Tracing all Emacs functions would render Emacs unusable"))
(mapc (lambda (name)
(trace-function-foreground (intern name)))
(all-completions prefix obarray 'my-traceable-p))
(message "Use %s to cease tracing."
(substitute-command-keys "\\[untrace-all]")))
(defun my-traceable-p (fun)
"Predicate for `my-trace-package'."
(or (functionp fun) (macrop fun)))

Elisp/texi2dvi: How to call texi2dvi from Emacs?

I try to write a function based on the code from: Latex, Emacs: automatically open *TeX Help* buffer on error and close it after correction of the error?
I would like to replace latexmk by texi2dvi, but TeX-master-file does not contain the file ending .tex (which seems to be required for texi2dvi). I found out that one can add .tex by using TeX-master-file t. However, I can't make it work (I'm not an elisp programmer). Here is what I tried:
;; texi2dvi
(defun run-texi2dvi ()
(interactive)
(let ((TeX-save-query nil)
(TeX-process-asynchronous nil)
(master-file (expand-file-name (TeX-master-file t)))); append `.tex`
(TeX-save-document "")
(TeX-run-TeX "texi2dvi"
(TeX-command-expand "PDFLATEX='pdflatex -synctex=1' texi2dvi -p %s" 'TeX-master-file)
master-file)
(if (plist-get TeX-error-report-switches (intern master-file))
(TeX-next-error t)
(progn
(demolish-tex-help)
(minibuffer-message "texi2dvi: done.")))))
No clue if there's a better way to do it, but this version should work. Basically, TeX-command-expand was given the function TeX-master-file as a symbol which was called internally, and there it was called without the I-want-the-extension argument. The replacing lambda forces that.
(defun run-texi2dvi ()
(interactive)
(let ((TeX-save-query nil)
(TeX-process-asynchronous nil)
(master-file (expand-file-name (TeX-master-file t)))); append `.tex`
(TeX-save-document "")
(TeX-run-TeX "texi2dvi"
(TeX-command-expand
"PDFLATEX='pdflatex -synctex=1' texi2dvi -p %s"
(lambda (ext-ignored nondir)
(TeX-master-file t nondir)))
master-file)
(if (plist-get TeX-error-report-switches (intern master-file))
(TeX-next-error t)
(progn
(demolish-tex-help)
(minibuffer-message "texi2dvi: done.")))))
See here for a more detailed description of the issue and a simple workaround: https://tex.stackexchange.com/questions/67244/how-to-set-up-texi2dvi-with-synctex-and-error-handling/67384#67384

Racket URL dispatch

I'm trying to hook up URL dispatch with Racket (formerly PLT Scheme). I've taken a look at the tutorial and the server documentation. I can't figure out how to route requests to the same servlets.
Specific example:
#lang scheme
(require web-server/servlet)
(require web-server/dispatch)
(provide/contract (start (request? . -> . response/c)))
(define (start request)
(blog-dispatch request))
(define-values (blog-dispatch blog-url)
(dispatch-rules
(("") list-posts)
(("posts" (string-arg)) review-post)
(("archive" (integer-arg) (integer-arg)) review-archive)
(else list-posts)))
(define (list-posts req) `(list-posts))
(define (review-post req p) `(review-post ,p))
(define (review-archive req y m) `(review-archive ,y ,m))
(require web-server/servlet-env)
(serve/servlet start
#:launch-browser? #t
#:quit? #f
#:listen-ip #f
#:port 8080
#:extra-files-paths (list (build-path "js")
(build-path "css"))
#:servlet-path "")
Assuming the above code, localhost:8080/ goes to a page that says "list-posts". Going to localhost:8080/posts/test goes to a Racket "file not found" page (I'd expect it to go to a page that says "review-post test").
It feels like I'm missing something small and obvious. Can anyone give me a hint?
What you've written is not a whole program, so I cannot debug it.
Here is a program with annotations that does what you want, probably:
#lang scheme ; specify the right language
; include the correct libraries
(require web-server/servlet
; this one gets "serve/servlet"
web-server/servlet-env)
(define (start request)
(blog-dispatch request))
(define-values (blog-dispatch blog-url)
(dispatch-rules
(("") list-posts)
(("posts" (string-arg)) review-post)
(("archive" (integer-arg) (integer-arg)) review-archive)
(else list-posts)))
(define (list-posts req) `(list-posts))
(define (review-post req p) `(review-post ,p))
(define (review-archive req y m) `(review-archive ,y ,m))
; starts a web server where...
(serve/servlet start ; answers requests
#:servlet-path "" ; is the default URL
#:port 8080 ; is the port
#:servlet-regexp #rx"") ; is a regexp decide
; if 'start' should
; handle the request
Because the functions list-posts, review-post, and review-archive don't return sensible xexpr encodings of HTML, you'll have to view source to see them right.
Please feel free to email me directly or email the PLT Scheme mailing list. (Note: We are renaming PLT Scheme to "Racket" so you may see that when you post.)
Jay McCarthy

Resources