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
Related
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)
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.
(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))
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)))
If my current buffer is foo, and I run C-x C-b (aka list-buffers), my Emacs window splits in two, with foo occupying one of the two resulting windows, and a dedicated *Buffer List* buffer occupying the other one. At the end of this operation, foo remains the active buffer, and point remains were it was before C-x C-b was executed.
I want to write an interactive function that displays a multi-page output in a similar way: split window if necessary, bring up a dedicated buffer, leave the active buffer as it was before the function was run.
The best I've managed to do is a function with the following structure:
(defun my-func ()
(interactive)
(let ((this-buffer (current-buffer))
(other-buffer (get-buffer-create "*my-func's Dedicated Buffer*")))
(switch-to-buffer-other-window other-buffer)
(erase-buffer)
(insert (compute-pages-and-pages-of-stuff))
(beginning-of-buffer)
(switch-to-buffer-other-window this-buffer)))
This works, more or less, but I thought that Emacs already had built-in syntax to streamline such code.
IOW, I thought there was a special form analogous to the (fictional) WITH-BUFFER-OTHER-WINDOW in the snippet below:
(defun my-func ()
(interactive)
(let ((other-buffer (get-buffer-create "*my-func's Dedicated Buffer*")))
(WITH-BUFFER-OTHER-WINDOW other-buffer
(erase-buffer)
(insert (compute-pages-and-pages-of-stuff))
(beginning-of-buffer))))
or maybe even
(defun my-func ()
(interactive)
(let ((other-buffer (get-buffer-create "*my-func's Dedicated Buffer*")))
(WITH-BUFFER-OTHER-WINDOW other-buffer
(compute-pages-and-pages-of-stuff))))
I've tried forms like save-excursion and save-current-buffer, but they don't reproduce the desired behavior.
Is there a built-in way to carry out the operation described above?
This is the shortest you can get by leveraging the built-ins display-buffer and with-current-buffer:
(defun my-func ()
(interactive)
(let ((buffer (get-buffer-create "*my-func's Dedicated Buffer*")))
(with-current-buffer buffer
(erase-buffer)
(insert (compute-pages-and-pages-of-stuff))
(goto-char (point-min)))
(display-buffer buffer)))
If you use this pattern so much that it starts annoying you, feel free to define a helper macro:
(defmacro my-setup-and-display-buffer (name &rest body)
(declare (indent 1))
(let ((buffer (make-symbol "buffer")))
`(let ((,buffer (get-buffer-create ,name)))
(with-current-buffer ,buffer
,#body)
(display-buffer ,buffer))))
(my-setup-and-display-buffer "*my-func's Dedicated Buffer*"
(erase-buffer)
(insert (compute-pages-and-pages-of-stuff))
(goto-char (point-min)))