id
stringlengths
8
14
url
stringlengths
40
58
title
stringlengths
2
150
date_created
stringdate
2008-09-06 22:17:14
2024-03-31 23:12:03
text
stringlengths
149
7.14M
thread-57942
https://emacs.stackexchange.com/questions/57942
Why does Flycheck complain "mapcar called for effect" when my function returns the result of mapcar by design?
2020-04-21T00:18:32.843
# Question Title: Why does Flycheck complain "mapcar called for effect" when my function returns the result of mapcar by design? Since installing Flycheck I've been bombarded with complaints about the elisp functions I've used reliably for years. This is the first one I can't understand. Here my function is designed to return the result of mapcar, not to produce side effects. The suggested replacement of mapc won't do what I need, though dolist could with a bit more effort. Here's the code: ``` (defun synclient-get-touchpad-config () "Return the touchpad config as a list of strings." (mapcar (lambda (s) (string-join (split-string s))) (seq-drop-while (lambda (s) (not (string-prefix-p " " s))) (process-lines "synclient" "-l"))) (current-buffer)) ``` The exact error message is: ``` ‘mapcar’ called for effect; use ‘mapc’ or ‘dolist’ instead (emacs-lisp) ``` What exactly is flycheck expecting me to do here? # Answer > 4 votes It's mainly just a warning - really a suggestion. It's pointing out that if you don't care to produce a new list from the original one, where the returned list's elements are the results of applying the function argument to the original list's elements, then you might as well just use `dolist` or `mapc` instead of `mapcar`. In this case, your `mapcar` is, yes, returning a list of the function results. But your function `synclient-get-touchpad-config` doesn't do anything with that returned list. Your function instead returns the current buffer. According to your function, you didn't *need* to use `mapcar` \- you made no use of its returned list. You could have just used `mapc`. Using those functions is likely to be more performant. And they make clear to a human reader of your program that the results of applying the function to the list elements are unimportant (not used). Besides being mainly a suggestion, it might sometimes let you know that you forgot to use the results of applying the function, if that was, in fact, your intention. --- Tags: flycheck, list, warning, mapping ---
thread-17527
https://emacs.stackexchange.com/questions/17527
running latex on remote host with tramp
2015-10-20T10:10:00.907
# Question Title: running latex on remote host with tramp I'm trying to run latex on remote host from the local host with tramp. But it seems that it cannot find the file. To be more specific: **Update** 1. start emacs on localhost: 2. /ssh:user@remotehost:/tmp/test.tex 3. compile latex on remote host using C-c C-c 4. error cannot find the file test.tex " ! I can't find file \`test.tex'." so I guess it's trying to find `/ssh:user@remotehost:/tmp/test.tex` but somehow cannot find it. May be it should look for `/tmp/test.tex` I've tried `knitr` as well and found that it tries to execute `/ssh:user@remotehost:foobar.rnw"`. I think it should use the /ssh command since the program is running locally but I can't grasp what's happening. Any help? **Update 2** Works fine when using emacs -Q. See comment below. will keep you posted once I have found what's wrong in the .emacs. **Update 3** The problem does not lies in the .emacs file though. I commented out everything in the .emacs and still got the same issue. I'll continue the investigation. But we are getting there. **Update 4** As suggested in the comments below firing emacs with the -Q option works find. I've got good results even with emacs -q. Launching emacs -q is supposed to prevent loading the .emacs and the default.el files at startup. I place `(setq inhibit-default-init 1)` in my .emacs file and commented the rest of the commands. Therefore only the command `(setq inhibit-default-init 1)` is active in my .emacs file. I launch emacs without any options and load tramp by hand `(require 'tramp)` and tried latex again but still no success. I must be missing something that the -q option does not load but I can't figure it out right now. # Answer > 1 votes I had the same issue: and I learned this patch from this mailing list: https://lists.gnu.org/archive/html/auctex/2008-05/msg00007.html The fix requires changing one line in the file `tex-buf.el` which I was able to find in `.emacs.d/elpa/auctex-12.2.0/tex-buf.el`, although the location of the file may depend on your particular set-up. as you can see, the one function changed was: `start-process` to `start-file-process` ``` *** 577,584 **** (lambda (process name) (message (concat name ": done.")))) (if TeX-process-asynchronous ! (let ((process (start-process name buffer TeX-shell ! TeX-shell-command-option command))) (if TeX-after-start-process-function (funcall TeX-after-start-process-function process)) (TeX-command-mode-line process) --- 577,584 ---- (lambda (process name) (message (concat name ": done.")))) (if TeX-process-asynchronous ! (let ((process (start-file-process name buffer TeX-shell ! TeX-shell-command-option command))) (if TeX-after-start-process-function (funcall TeX-after-start-process-function process)) (TeX-command-mode-line process) ``` --- Tags: tramp ---
thread-57953
https://emacs.stackexchange.com/questions/57953
set org-mode as a source-language in an org-mode document
2020-04-21T10:59:18.517
# Question Title: set org-mode as a source-language in an org-mode document I want to export an org-mode document to markdown. My document contains some content like this: ``` #+BEGIN_SRC * User-defined Markers ** MARKER_1 #+END_SRC ``` I would like to demonstrate how someone could write something in an org-mode document, but when this is exported to markdown, it is interpreted as org-mode text, i.e. instead of seeing a gray code field, the export tries to structure the markdown using 'User-defined Markers' as a headline. Is there any way of exporting so that what's inside of #BEGIN\_SRC is not evaluated? # Answer > 4 votes Any lines that could be confused as Org mode markup (e.g. both of the lines in your example block) can be quoted by preceding them with a `,`: ``` #+BEGIN_SRC ,* User-defined Markers ,** MARKER_1 #+END_SRC ``` See Literal Examples in the manual. As @Tobias and @Hubisan point out in the comments, it's a very good idea to mark the source block as an org source block: ``` #+BEGIN_SRC org ,* User-defined Markers ,** MARKER_1 #+END_SRC ``` There are several advantages: * You get nice highlighting when exporting to HTML (and possibly other formats). * `C-c '` (bound to `org-edit-special`) knows to edit the contents of the source block using the `org-mode` major mode. It also knows to strip the commas when entering and adding them back when exiting, so you don't have to worry about them any more. --- Tags: org-mode, org-export, markdown ---
thread-57951
https://emacs.stackexchange.com/questions/57951
shortname for complex filter in org agenda
2020-04-21T10:01:44.880
# Question Title: shortname for complex filter in org agenda I want to give a shortname to a regular filter I use for agenda. To prepare some meeting, i have a list of task / note with tag. I filter tag in org-agenda and before the meeting, i use org-agenda filter to get note. Filter is like TAG1|TAG2|TAG3 ... I want to just type in filter meeting1-filter. Is-it possible ? Thanks in advance for your feedback. Best regards. # Answer I think the way to go is to write a custom agenda view. You would need to modify the variable `org-agenda-custom-commands` in your init file to add your custom agenda view. Something like this (untested - I'll try to do some testing and fix any problems, but please be forewarned): ``` (setq meeting1-custom-agenda-view '("M" tags "TAG1|TAG2|TAG3")) (eval-after-load 'org-agenda (add-to-list 'org-agenda-custom-commands meeting1-custom-agenda-view)) ``` You can invoke your custom agenda view with `C-c a M` (assuming that `C-c a` is the key that is bound to the agenda dispatcher, `org-agenda`, as recommended in the doc). > 1 votes --- Tags: org-mode, org-agenda, filtering ---
thread-57948
https://emacs.stackexchange.com/questions/57948
How to get to my day page with one key
2020-04-21T04:37:50.060
# Question Title: How to get to my day page with one key To get to my day page (agenda), currently I have to type in the following keys 1. `C-c a` (binded to `(org-agenda)`) 2. `a` (Agenda for current week or day) 3. `d` (to switch from week-view to day-view) 4. `C-c C-x C-c` (to switch to column-view) It's too much! Can I achieve the same thing by pressing just one key say `<f10>`, and hopefully without unnecessary evaluations? It's not as easy as normal key bindings I suppose, since one has to deal with the org agenda dispatcher. ### EDIT: Answer found 1. See NickD's answer. The key is `(org-agenda-list nil nil 1 nil)` and details can be found in the manual of the function `(org-agenda-list)` by `C-h f org-agenda-list <RET>`. This way is much faster than the second answer below. 2. If you accept macro as a solution (which is slower), turn it into an elisp function by using the package `elmacro` and assign a keybind. # Answer > 4 votes You can define your own function that does all the things you want it to do and bind it to a key: ``` (defun my-day-page () (interactive) (org-agenda-list nil nil 1 nil) (org-agenda-columns)) (define-key global-map [f10] 'my-day-page) ``` See the doc for org-agenda-list (`C-h f org-agenda-list RET`) for the meaning of the arguments: the third argument (the 1 above) is the span (i.e. how many days this list should cover). # Answer > 0 votes The easiest way to do this would be a macro, more information can be found on the emacswiki, but essentially all you would do is: 1. `C-x (` * Start Recording a Macro 2. `C-c a a C-c C-x C-c` * Open the Agenda in column view 3. `C-x )` * End the Macro 4. `M-x name-last-kbd-macro my-day-page` * Give the macro a name 5. `M-x insert-kbd-macro` * Insert the Macro 6. `(global-set-key (kbd "C-c b") 'my-day-page)` That macro function and keybinding can now be added to your `~/emacs.d/init.el` file and pressing `C-c b` should now open up the day-page. All together it might look like this: ``` ;; Macro for Day View (global-set-key (kbd "C-c a") 'org-agenda) (fset 'my-day-page (kmacro-lambda-form [?\C-c ?a ?a ?\C-c ?\C-x ?\C-c] 0 "%d")) (global-set-key (kbd "C-c b") 'my-day-page) ``` ### -- EDIT by OP -- If you want to see what a macro is really doing, use the package elmacro, which turns your macro into a elisp function. In your case, after installation of `elmacro` from `melpa`, run `elmacro-mode`. Define the macro as usual `<f3>C-c a a d R C-c C-x C-c<f4>`, and run the magical `M-x elmacro-show-last-macro`. It will generate a buffer with the elisp function! ``` (defun last-macro () (interactive) (org-agenda-list nil) (org-agenda nil) (org-agenda-day-view nil) (org-agenda-clockreport-mode) (org-agenda-columns)) ``` Please note that this result is not completely satisfactory. You want to get rid of `(org-agenda nil)` from the function, ending up give you ``` (defun the-macro-you-like () (interactive) (org-agenda-list nil) (org-agenda-day-view nil) (org-agenda-clockreport-mode) (org-agenda-columns)) ``` Finally, put this function in your config file, and bind it to `<f10>` for example by `(global-set-key (kbd "<f10>") 'the-macro-you-like)` --- Tags: org-mode, key-bindings, org-agenda ---
thread-57957
https://emacs.stackexchange.com/questions/57957
org mode give NAME to clocktable to parse with perl
2020-04-21T15:36:07.500
# Question Title: org mode give NAME to clocktable to parse with perl I try to give a name to a clocktable : ``` #+BEGIN: clocktable :scope file :maxlevel 2 #+NAME: d1 #+CAPTION: Clock summary at [2020-04-21 mar. 14:31] | Headline | Time | |--------------+--------| | *Total time* | *0:15* | |--------------+--------| | t1 | 0:05 | | t2 | 0:10 | #+END: * t1 CLOCK: [2020-04-21 mar. 14:10]--[2020-04-21 mar. 14:16] => 0:05 * t2 CLOCK: [2020-04-21 mar. 14:20]--[2020-04-21 mar. 14:30] => 0:10 ``` To use it in a perl src block : ``` * code #+NAME: t1 #+begin_src perl :var d=d1 $d; #+end_src #+RESULTS: t1 | Headline | Time | | *Total time* | *0:16* | | t1 | 0:06 | | t2 | 0:10 | ``` But When I update the **clocktable**, the **#+NAME: d1** disappear. And If I put it before the #+BEGIN line, the perl block do not find the reference. How could I make the #+NAME line in the clocktable remain after the update of the clocktable ? # Answer > 3 votes You are correct that the `#+NAME:` line has to be attached to the table and therefore has to be *inside* the clocktable block. The cheapest way is to use a `:header` argument to the clocktable: ``` #+BEGIN: clocktable :scope file :maxlevel 2 :header "#+NAME: d1\n" ``` That will add the name, but it will take away the automatic caption. You can add your own caption as well with ``` #+BEGIN: clocktable :scope file :maxlevel 2 :header "#+NAME: d1\n#+CAPTION: my caption\n" ``` but you will have to forego the date insertion that is done by default (although you could perhaps do that using other methods). The most versatile way would be to use your own `:formatter` function to format the clocktable: ``` #+BEGIN: clocktable :scope file :maxlevel 2 :formatter my-org-clocktable-write ``` instead of using the default `org-clocktable-write-default`. The only problem now is to write that function, but unfortunately there is not much support in Org mode for that: you'd have to copy the default function, rename it and then add the additional piece of information you want. You'd probably also want to add another argument to the line above to name the table: ``` #+BEGIN: clocktable :scope file :maxlevel 2 :formatter my-org-clocktable-write :tablename d1 ``` The modification is not difficult to do, but adding the function here would make the answer very long and I don't have time to do it ATM: if I find some time and nobody beats me to it, I might add a diff later on. EDIT: So here is what you need to do to get the modified formatter function. Copy the function `org-clocktable-write-default` from the file `org-clock.el` to the file `org-clocktable-write-default.el` in some temporary working directory. Save the following patch to some file, say `org-clocktable.patch`, in the same temp working directory: ``` --- org-clocktable-write-default.el 2020-04-21 16:59:49.009188899 -0400 +++ my-org-clocktable-write.el 2020-04-21 17:02:14.990787901 -0400 @@ -1,4 +1,4 @@ -(defun org-clocktable-write-default (ipos tables params) +(defun my-org-clocktable-write (ipos tables params) "Write out a clock table at position IPOS in the current buffer. TABLES is a list of tables with clocking data as produced by `org-clock-get-table-data'. PARAMS is the parameter property list obtained @@ -63,17 +63,21 @@ (insert-before-markers (or header ;; Format the standard header. - (format "#+CAPTION: %s %s%s\n" - (org-clock--translate "Clock summary at" lang) - (format-time-string (org-time-stamp-format t t)) - (if block - (let ((range-text - (nth 2 (org-clock-special-range - block nil t - (plist-get params :wstart) - (plist-get params :mstart))))) - (format ", for %s." range-text)) - "")))) + (concat + (let ((tname (plist-get params :tablename))) + (if tname + (format "#+NAME: %s\n" tname))) + (format "#+CAPTION: %s %s%s\n" + (org-clock--translate "Clock summary at" lang) + (format-time-string (org-time-stamp-format t t)) + (if block + (let ((range-text + (nth 2 (org-clock-special-range + block nil t + (plist-get params :wstart) + (plist-get params :mstart))))) + (format ", for %s." range-text)) + ""))))) ;; Insert the narrowing line (when (and narrow (integerp narrow) (not narrow-cut-p)) ``` Now run the following command in that temporary working directory: ``` patch < org-clocktable.patch ``` This will modify the `org-clocktable-write-default.el` file. Now insert the contents of this file into your init file, restart emacs (or eval the defun) and regenerate the clocktable by pressing `C-c C-c` on the `#+BEGIN` line which should now look like this: ``` #+BEGIN: clocktable :scope file :maxlevel 2 :formatter my-org-clocktable-write :tablename d1 #+END: ``` Assuming it all worked, you can delete the temporary directory where you did this work. As you can see, there are two changes to the function: we change the name (that's the name you have to use for the `:formatter` argument in the clocktable line) and we change the header line to concatenate the `#+NAME: ...` line with the `#+CAPTION: ...` line. Note a couple of things: if `header` is non-nil (i.e. you used `:header foo` in the clocktable line), then that's what's used: there is no `#+NAME:...` or `#+CAPTION:...` line produced - that's the same behavior as with the original function; if tablename is nil (i.e. you didn't include a `:tablename foo` argument in the clocktable line), then nothing changes: you just get the `#+CAPTION: ...`; but if tablename is non-nil, then you get the `#+NAME: ...` line and then the `#+CAPTION: ...` line. Finally, it may look complicated, but it's easier done than said. --- Tags: org-mode ---
thread-57926
https://emacs.stackexchange.com/questions/57926
markdown inline preview like it is done with preview-latex
2020-04-20T11:57:33.847
# Question Title: markdown inline preview like it is done with preview-latex I am completely new to markdown and would like to know if there is any package/mode which allows to live preview only parts of the document (mainly equations, tables and images) like it is possible with preview-latex? Until now, I could only see the preview in a different buffer. Thanks! Fab # Answer > 4 votes You can use `texfrag-mode`. It can be installed from melpa. After installation customize the variable `texfrag-setup-alist` by adding `markdown-mode` to the entry for `texfrag-trac-wiki`. Afterwards you can open your markdown file and run `M-x` `texfrag-mode` `RET`. Therewith you get the `preview-latex` menu as `TeX` in the menu bar. If you always want to turn on `texfrag-mode` for a specific document you can run `texfrag-mode` in the local variables. Example: ``` # Some Heading Test of formula: $y=\sqrt{x^2+y^2}$ We also include a picture: \begin{figure} \centering \begin{picture}(30,30) \put(15,15){Test} \put(15,15){\circle{15}} \end{picture} \caption{First picture.} \end{figure} [//]: # Local Variables: [//]: # eval: (texfrag-mode) [//]: # End: ``` The buffer looks like follows after hitting `C-c C-p C-d`. If you want to run `texfrag-mode` for all your markdown files you can add the following line to your init file: ``` (add-hook 'markdown-mode-hook #'texfrag-mode) ``` With that configuration you don't need the local variables section from the last example. # Answer > 1 votes You have a few options to achieve this, from within emacs you can can simply use `org-toggle-latex-fragment` which is the simplest solution, putting the following into your `~/emacs.d/init.el` file will fix the binding to `C-c C-x C-l` just like it is in org-mode: ``` (add-hook 'mardkown-mode-hook (lambda () (local-set-key (kbd "C-c C-x C-l") 'org-toggle-latex-fragment) (local-set-key (kbd "C-c C-x C-u") 'markdown-toggle-url-hiding) )) ``` My current solution is to basically manage all my notes in VNote and org-mode and then build them with mkdocs to read them on a server / gitpage on my phone. So I'll edit them in emacs, manage them in Vnote and then if I want to include some math I usually use vim with a plugin. Another option is to use one of the markdown preview packages that are available, the doom starter kit (which I'm using atm) includes one but I don't use it. An easier option is to use this chrome extension in conjuction with a local server (e.g. `python3 -m http.server`) and view the files in the browser, this also means links will work. It would also be possible to build the markdown with pandoc, tie that to a keybinding and then view the HTML in the browser seperately. I usually write my markdown and LaTeX in vim because the snippets are better and I'll use this function to open vim from emacs, if that's something you're interested in then I'd recommend this plugin. If you don't like any of that you could use the live preview offered by Marktext, Zettlr, VSCode or Typora and simply edit the source in markdown. I would really recommend looking at VNote though, It's become indispensable to me. --- Tags: markdown-mode ---
thread-57967
https://emacs.stackexchange.com/questions/57967
Can orgmode be made to open all property drawers by default upon opening my document?
2020-04-22T00:53:17.817
# Question Title: Can orgmode be made to open all property drawers by default upon opening my document? I'd like all the property drawers of my org document to be expanded by default when opening my document or launching Emacs with the org document already in my persistent desktop file. I have the following options set at the top of the document: ``` #+OPTIONS: toc:nil #+STARTUP: showblocks #+STARTUP: showeverything ``` This shows the tree structure, but keeps property drawers hidden/collapsed. I want the property drawers to be shown/expanded. If no such setting exists, is there a command I can use, and perhaps even bind to a key, to expand all property drawers? The properties I have set contain important data, which I use org's builtin functions to process. If I were to move the data out of the property drawers then I'd have to write functions to parse and process the data. I could, but I'd rather keep the document structure as is. # Answer > 3 votes Note that there is the option `org-custom-properties` and the function `org-toggle-custom-properties-visibility` for that purpose. If you want to open the property drawers in general you can put the following Elisp code below in your init file. ``` (defun org+-show-drawers () "Show all property drawers in current buffer." (interactive) (let ((data (org-element-parse-buffer))) (org-element-map data 'property-drawer (lambda (drawer) (let ((b (org-element-property :begin drawer)) (e (org-element-property :end drawer))) (org-flag-region b e nil 'org-hide-drawer)))))) (put 'org+-show-drawers 'safe-local-eval-function t) ``` If the code is evaluated the following file local variable setting opens all property drawers of the file at startup. ``` Local Variables: eval: (org+-show-drawers) End: ``` --- Tags: org-mode ---
thread-57963
https://emacs.stackexchange.com/questions/57963
mu-query for finding mails with a single and specific recipient (mu4e)
2020-04-21T19:32:56.473
# Question Title: mu-query for finding mails with a single and specific recipient (mu4e) Using **mu4e**, I'm looking for the regex to display mails that have been sent to one specific recipient, and only one recipient (i.e. no cc:, no other name in the to: field). For example, if I use mu4e search and type `to:john@doe.com` as a regex, mu4e will display all mails addressed to `john@doe.com` but also mails addressed to both `john@doe.com` and `jane@doe.com` (jane might be in the **to:** or **cc:** field in some mails). I would like instead to find mails that are only addressed to `john@doe.com`. What would be the right regex for such query using mu4e? # Answer > 1 votes To my understanding you're looking for a *mu query* (and not exactly a *regexp*) which will find emails that: * has `to:`*email* **AND** * has no other `recip:` field so something like this will do it: ``` to:my@email.com (not cc:/.+/ not bcc:/.+/) ``` please, note that: * neither `mu-query` or `mu4e` manuals covers how to search for an empty field, so I faked it using any content regexp, use whatever one fits you better. * logical operators and its grouping for excluding things can be tricky. In this case `AND` is implicit, that may not fit perfectly your use case. Anyway you'll get the idea. * `recip:` fields can be a list of addresses, if you want to cover a list in `to:` extra work will be required. --- **Edit** using `mu-guile` you can retrieve any field entirely and do custom processing instead checking against an index, but that will take things out of mu4e. --- * `mu4e-headers-include-related` may fool you, disable it or press `W` to toggle inclusion in your search results. --- Tags: mu4e ---
thread-32157
https://emacs.stackexchange.com/questions/32157
Should "custom" variables defined without defcustom be set via custom-set-variables or setq?
2017-04-14T23:46:39.073
# Question Title: Should "custom" variables defined without defcustom be set via custom-set-variables or setq? Should I use `custom-set-variables` (as opposed to `setq`) when setting a variable that returns non-nil for `custom-variable-p` but was not defined by `defcustom`? For example, *echo-keystrokes* is defined in keyboard.c via defvar\_lisp, but the following returns non-nil: ``` (custom-variable-p 'echo-keystrokes) ``` The documentation for `custom-variable-p` states: > A customizable variable is either (i) a variable whose property list contains a non-nil ‘standard-value’ or ‘custom-autoload’ property, or (ii) an alias for another customizable variable. This leaves me wondering if the conventional advice to prefer `custom-set-variables` over `setq` when dealing with custom variables (since they may have special setters and/or initialization code) applies to such variables, or whether it's exclusive to variables defined via `defcustom`. If I should only bother with `custom-set-variables` when dealing with those defined by `defcustom`, how can I quickly make that determination? I was hoping to use `custom-variable-p` to programmatically check which variables I should set with `custom-set-variables` instead of `setq`, as I'd rather not have to dig through library source code for every variable I set. # Answer Use **`customize-set-variable`** or `custom-set-variables`, depending on just what you want/need. Both of those make use of any initialization or setter functions (and so on) with which the user option might have been defined. See (elisp) Variable Definitions for information about these things. **If** a given user option is defined without specifying any particular initialization, setter function **then** it is typically OK to simply use `setq` (or `setf`) to set its value. But *if the option has a setter function then do **not** use `setq`*, as it will not do all that is needed. Most abuses of `setq` for options, which can get people into trouble, come from complete ignorance of the possibility of setters etc., not from knowing about them and not worrying about them. IOW, people just get in the habit of using `setq`, and most of the time they are not surprised. A setter function does something *in addition to* setting the option value. It may set the value in a special way, or it may also change other things in Emacs (e.g., the values of other variables) - things that need to go hand in hand with changing the option value. > 6 votes # Answer I've recently also been dealing with this problem and have come up with a working solution. I initially uploaded it to reddit, read `custom-set-variables` and custom file trampling for all the details. I've got the solution in place in my emacs configuration and it is working perfectly. Simply installing a package from melpa no longer clobbers my custom file with the `custom-set-variable` declarations from my config file. It is "a" solution, not "the" solution. It involves 2 vars and 2 pieces of advice. But the solution is, actually, rather "simple" and maybe can point the way for emacs maintainers to provide a similar mechanism out of the box in the future. A brief summary of solution: First, I summarize here the 3 ways to set custom variables properly, with a note on their state as regards this solution to the problem: * `custom-set-variables`: good * `customize-set-variable`: bad (explained later) * `use-package :custom` section: bad (this uses `customize-set-variable`) My solution involves 2 variables (1 is optional, simply used to wrap advices in `if`s if you want to), and 2 pieces of advice. The problem is that the custom system is actually quite good and works entirely as expected EXCEPT they give the user no option to tell emacs to "hey, don't write this out to the custom-file, I'm taking care of it in my config file." Everything boils down to the following `when` statement (in the `custom-save-variables` function in cus-edit.el): ``` ;; Is there anything customized about this variable? (when (or (and spec (eq (car spec) 'user)) comment (and (null spec) (get symbol 'saved-value))) ``` If this evaluates to true then this custom var is written/dumped to custom-file. We can hitchhike on comment and construct a boolean with it. And so my solution uses comment to fix the entire problem. Here are the two variable declarations, the first is optional, the second required. The first is used to construct an `if` in the advice if you so desire: ``` (defvar juus/customize-pinned-use t "Do =NOT= write values of custom variables using `juus/customize-pinned-string'. When this value is t and `juus/customize-pinned-string' is a prefix or suffix of the customization variables' comment then it will not be written out to `custom-file'. If you set this to nil, values will be written to the `custom-file' and will then override your settings in your configuration files since the `custom-file' is loaded after your configuration settings. This can be quite confusing and annoying. So I recommend to not set this to nil unless you are testing or want to copy a formatted variable for use in your config file. In that case I highly recommend that you temporarily setq your `custom-file' to a dump file.") (defvar juus/customize-pinned-string ":PINNED:" "The string used to control writing to `custom-file'. See `juus/customize-pinned-use'.") ``` Now, if we send in a custom variable that has a comment that looks like: `":PINNED:"` or `":PINNED: my comment"` or `"my comment :PINNED:"` ...we have a boolean we can use. To construct the `:around` advice one must copy the entire `custom-save-variables` function from cus-edit.el. Wrap the advice in an `if` if you want to use the boolean var given above. Then change the `when` from above to: ``` ;; Is there anything customized about this variable? (when (and (or (and spec (eq (car spec) 'user)) comment (and (null spec) (get symbol 'saved-value))) (not (or (string-prefix-p juus/customize-pinned-string comment t) (string-suffix-p juus/customize-pinned-string comment t)))) ``` and now add the advice: ``` (advice-add 'custom-save-variables :around #'custom-save-variables--whatever-you-named-it) ``` Now in your config file use this construction for `custom-set-variables` (the 3rd nil parameter is problematic \[see later\] but can be set to `t` instead, and sometimes needs to be): ``` (custom-set-variables '(cust-var cust-val nil nil ":PINNED: my comment") ) ``` You can construct a "helper" function to help automate this (an example in link above) but then you will need to use backtick and comma grammar. This works completely for `custom-set-variables`, but not for `customize-set-variable` which is what `use-package :custom` uses. The reason it doesn't work is the "state" that it saves it in will not pass on the comment to the system. Without a comment we cannot filter it. So another piece of advice is needed for `use-package`, which tells it to use `custom-set-variables` instead, and it will automate the `:PINNED:` for us, meaning that there will be no need to edit `:custom` sections. The original controlling line in use-package-handler/:custom function in use-package is this: ``` `(customize-set-variable (quote ,variable) ,value ,comment))) ``` Replaced with this fixes the issue and automatically prepends `":PINNED:"` to the comment: ``` (setq comment (concat juus/customize-pinned-string " " comment)) `(custom-set-variables '(,variable ,value ,t ,nil ,comment)))) ``` You'll see that I've used `,t` as the 3rd param. This is because due to some internal logic in cus-edit.el involving "rogue" variables the state is set to something other than "Saved and set" which is required for the comment to be passed on, as far as I can see. The ,t was required on my computer to fix a small portion of `:custom`'s that weren't responding correctly. Here is the optional `use-package` advice. I've used `nth` a lot, but `let`s could be used to make it more readable, the original params the function expects are in the document line: ``` (defun use-package-handler/:custom-juus/advice (orig-fun &rest args) "ADVICE for `use-package-handler/:custom'. orig-fun expects: name _keyword args rest state" (if (not juus/customize-pinned-use) (apply orig-fun args) (use-package-concat (mapcar #'(lambda (def) (let ((variable (nth 0 def)) (value (nth 1 def)) (comment (nth 2 def))) (unless (and comment (stringp comment)) (setq comment (format "set by use-package '%s'" (nth 0 args)))) (setq comment (concat juus/customize-pinned-string " " comment)) `(custom-set-variables '(,variable ,value ,t ,nil ,comment)))) (nth 2 args)) (use-package-process-keywords (nth 0 args) (nth 3 args) (nth 4 args))))) ``` Then add the advice to the system: ``` (advice-add 'use-package-handler/:custom :around #'use-package-handler/:custom-juus/advice) ``` CAVEATS: The functions I copied come from emacs 26.3, so don't use my constructions literally maybe unless you are using 26.3, copy from your source code! As you can see this is a real "hands on" fix. I have not (yet) looked at the `custom-set-faces` side of the custom-file because I've not used it yet. Maybe someone out there is interested to let me know if a similar problem exists for `custom-set-faces` and, if so, if a similar solution works??? Don't use `customize-set-variable`, it simply won't work in this system. Convert them to `custom-set-variable` declarations. > 0 votes --- Tags: variables, defcustom, setq ---
thread-57969
https://emacs.stackexchange.com/questions/57969
Auto-generating a fully clocked agenda
2020-04-22T03:42:59.170
# Question Title: Auto-generating a fully clocked agenda Org agenda supports a powerful exporting function `(org-agenda-write)`, which exports your agenda view to `pdf`, `ps`, `html`.. format beautifully. In this post, I hope to make that process automatically. More specifically, I'd like to have a cron job that handles everything. A function `(org-store-agenda-views)` that comes close is described in the same link above. However, after tinkering for two hours, I still can't find what I want. Currently, I have to do it manually: 1. Enter org agenda. 2. Launch log view, so I can see exactly how the entries are clocked. 3. Launch clock report mode, so I get a nice time summary table. 4. Fire `(org-agenda-write)`. As my attempt to do it automatically, I've tried ``` (setq org-agenda-custom-commands '(("X" "EXPORT" ((agenda "" ((org-agenda-span 7) (org-agenda-log-mode-items '(closed clock state)) (org-agenda-clockreport-mode t) (org-agenda-start-on-weekday 0)) )) nil (("~/agenda.html" "~/agenda.pdf")))) ``` as in the link. Notice that `org-agenda-log-mode-items` and `org-agenda-clockreport-mode` are the two closest variables I've found. But it did not affect the generated file.. ### Question How to generate a full clocked agenda view automatically? # Answer > 1 votes Setting `org-agenda-log-mode-items` only affects what items get shown when log mode is on but doesn't turn on log mode. To do that also set `org-agenda-start-with-log-mode` to `t`: ``` (setq org-agenda-custom-commands '(("X" "EXPORT" ((agenda "" ((org-agenda-span 7) (org-agenda-start-with-log-mode t) (org-agenda-log-mode-items '(closed clock state)) (org-agenda-clockreport-mode t) (org-agenda-start-on-weekday 0)) )) nil (("~/agenda.html" "~/agenda.pdf")))) ``` --- Tags: org-mode, org-export, org-agenda, org-clock, org-clock-table ---
thread-57787
https://emacs.stackexchange.com/questions/57787
Babel equivalent for other modes
2020-04-14T14:14:32.763
# Question Title: Babel equivalent for other modes Babel lets you include code blocks of different programming languages inside an Org-mode document, which can be printed and executed. Is there something similar for other modes as well? For example, I would like to include code blocks inside TeX-mode. # Answer What you probably want to do is write your document in org mode, and then export it to LaTeX (`M-x org-export-dispatch` and then `l` `l`). If you're looking for other options: some languages provide their own tools to export literate programs to LaTeX. For example: * Racket has Scribble which can generate LaTeX * R has Sweave which can generate LaTeX But those are obviously language-specific. As far as I know, org-mode and org-babel is the most general solution for this sort of thing. If you really want to *write* in LaTeX rather than in org-mode, some things you can try: * Some LaTeX packages have been created to invoke specific programs from LaTeX. For example, the `gnuplottex` package allows you to specify `gnuplot` source in your LaTeX file, and it will automatically run the `gnuplot` code, generate a graph, and then include the graph in your document. * Otherwise, you can create a simple build pipeline (what some web devs could call an "asset pipeline") that runs your code, creates output files (say, `txt` files), and then in your LaTeX you can `\include` those output files. You could do this with, say, a `Makefile`. > 1 votes --- Tags: org-mode, org-babel ---
thread-57985
https://emacs.stackexchange.com/questions/57985
emacsclient's "--script" option alternatives
2020-04-22T17:45:35.870
# Question Title: emacsclient's "--script" option alternatives To run an elisp file `hello.el` with emacs in cli, do simply ``` $ emacs --script hello.el ``` However, a naive try for `emacsclient` fails, as `--script` is not an option of `emacsclient`. ``` $ emacsclient --script emacsclient: unrecognized option '--script' Try 'emacsclient --help' for more information ``` **Question**: What is a good practice to evaluate an elisp file by a running emacsclient? # Answer > 3 votes `emacsclient -e '(load "hello.el")'` --- Tags: emacsclient, script ---
thread-57984
https://emacs.stackexchange.com/questions/57984
Finding org-mode bindings
2020-04-22T17:44:10.677
# Question Title: Finding org-mode bindings I sometimes want to insert a new heading without first jumping to the end of the current tree. It was fairly simple to guess that this could be achieved by calling `(org-insert-heading)`, but from `C-h f` this function didn't seem to be bound to any key. I discovered by accident, though, that this function is, usually, called after `C-c <return>`. Question: was there any non-accidental and easy way of discovering this? # Answer Org mode does a bunch of context-dependent actions by binding a key (e.g. `C-c C-c` or `C-c RET`) to a generic function (`org-ctrl-c-ctrl-c` or `org-ctrl-c-ret`). The function looks around to determine a context (am I in a header? or a source block? or a table? etc.) and then calls another function (e.g. `org-insert-heading`) depending on that context. I don't know of any way to find these context-dependent actions through general emacs mechanisms. You need to consult the doc string of the specific top level function, e.g. `C-h f org-ctrl-c-ret RET`. You might do `C-h f org-ctrl-c- TAB` to find some of these dispatcher-type functions, but there are others as well: e.g `M-RET` is bound to `org-meta-return`. It might be nice to collect all those in a table somewhere and add them to the Org mode documentation, but AFAIK no such table exists ATM. > 3 votes --- Tags: org-mode, key-bindings, help ---
thread-57989
https://emacs.stackexchange.com/questions/57989
How do I clear all marks from the current buffer mark ring?
2020-04-22T21:34:28.010
# Question Title: How do I clear all marks from the current buffer mark ring? Newbie here, but oddly I couldn't find an answer to this by Googling. How do I clear all marks from the current buffer? I did find how to view the mark ring, but not how to clear all marks from current buffer. # Answer > 2 votes ``` M-: (setq mark-ring ()) ``` That is, just set variable `mark-ring` to `nil`. --- Tags: mark-ring ---
thread-57991
https://emacs.stackexchange.com/questions/57991
How do I highlight the current line?
2020-04-22T22:48:37.467
# Question Title: How do I highlight the current line? I am obviously not well versed in the world of Emacs so I was watching Casey Muratori's Emacs video and whenever he traversed any file in Emacs, the **current** line always had a different background color to the rest of the file. I want that because the cursor alone is sometimes difficult to see especially when the screen is filled with code and all that. I want the entire line to be distinguishable. How can I achieve that? # Answer > 7 votes Likely many ways to do this but the built in package called hl-line works very nicely. M-x hl-line-mode works as a local minor mode. or M-x global-hl-line-mode works as a global mode. goto https://github.com/emacs-mirror/emacs/blob/master/lisp/hl-line.el to see more in the comments section. --- Tags: highlighting, hl-line-mode ---
thread-57988
https://emacs.stackexchange.com/questions/57988
Connect open and close delimiters with a line
2020-04-22T19:13:43.137
# Question Title: Connect open and close delimiters with a line I wonder if emacs has something similar to this VSCode extension (Bracket Pair Colorizer 2) which does the following (screenshot below) which I find is a really helpful UI enhancement \[ In the above screenshot, you can see a yellow line that shows the matching parentheses, I know you can get rainbow parentheses but this isn't the same as the screenshot shown. Does anyone know if this is possible within emacs and if there's a package to enable it? Or how to enable it? # Answer > 0 votes Could something like the highlight-indent-guides package close enough? --- Tags: faces, highlighting, display ---
thread-57995
https://emacs.stackexchange.com/questions/57995
At what point are file-local and dir-local variables applied to a newly-loaded buffer?
2020-04-23T04:11:06.390
# Question Title: At what point are file-local and dir-local variables applied to a newly-loaded buffer? I'm currently attempting to call the function `company-org-roam--init-hook` from `org-mode-hook` in order to enable the `company-org-roam` backend in `org-roam` buffers. In some of the files in which this hook is called, I've used a `.dir-locals.el` file to set `org-roam-directory` to a non-default value. However, when `company-org-roam--init-hook` is called while loading the file, it appears that `org-roam-directory` isn't set to its dir-local value, causing the hook not to enable the Company backend. Is it expected that dir-local variables are applied only after major-mode hooks are run? If so, is there a way to work around this (besides a `run-at-time`)? # Answer > 2 votes > Is it expected that dir-local variables are applied only after major-mode hooks are run? Yes. The local variables are *normally* processed in `run-mode-hooks`, after running the mode hooks and before running `after-change-major-mode-hook`. You could use the latter to deal with your problem. Alternatively you can use `hack-local-variables-hook` which runs after the local variables have been processed -- refer to How can I access directory-local variables in my major mode hooks? n.b. How and when file- and dir-local variables are processed changed in Emacs 26.1, and the linked S.O. Q&A pre-dates that change. I don't believe it affects your question, but the implementation details were different. --- Tags: org-mode, hooks, company-mode, directory-local-variables, file-local-variables ---
thread-58001
https://emacs.stackexchange.com/questions/58001
search-forward-regexp with back reference
2020-04-23T15:27:16.583
# Question Title: search-forward-regexp with back reference I have the following text ``` \begin{comment} TEXT \end{comment} \begin{verbatim} TEXT \end{verbatim} ``` and the regular expression `"\\begin{\([^}]*\)}` to match the `\begin` statements and capture the `comment` or `verbatim` words. Now, I would like to match the `\end` statements. Given I already had a match for `\begin` I thought I could reference the previous match and look for `\\end{\\1}`, however I am getting `Invalid back reference`. Am I doing something wrong? Is there a way to reference previous matches in a regular expression? # Answer > 1 votes The `\\1` construct is typically used when replacing the content. If you do a search you have multiple options. 1) You could search for `\\end{\([^}]*\)}"` and manually check that the parts between the braces match the previous search. 2) You could create a regexp using normal string operations and search for it: ``` (concat "\\\\end{" (match-string 1) "}") ``` --- Tags: regular-expressions, search ---
thread-57997
https://emacs.stackexchange.com/questions/57997
Display inline eps images in Org mode
2020-04-23T06:48:02.887
# Question Title: Display inline eps images in Org mode Maybe quite a noob question, but I can't figure out how to display inline eps images in an org file. There is no problem with png (or jpeg, ...) images, but I can't preview eps images. Here is a minimal example with an R code block that produces a `.eps` file: ``` #+TITLE: Images eps #+begin_src R :results silent :exports none :session *R* postscript("image.eps") data(iris) plot(iris[, 1:2]) dev.off() #+end_src #+CAPTION: Plot [[file:image.eps]] ``` This MWE can be correctly exported as a PDF file, but `image.eps` cannot be displayed inside the org file. I have ImageMagick installed, and I have the following instructions in my init file (*edited after NickD's answer*): ``` (setq imagemagick-enabled-types t) (imagemagick-register-types) (add-to-list 'image-file-name-extensions "eps") (setq org-image-actual-width 400) ``` Here is what I get with those settings, although the file `image.eps` does exist, and is correctly inserted in the PDF/LaTeX export: I guess the solution is some additional tweaking related to ImageMagick. It seems that a similar (old!) question on StackExchange is also unanswered: Org-mode inline .eps images display error. (.eps created by AI ok, .eps created by matplotlib no) Thanks! # Answer > 5 votes There are various things that can go wrong: * does your emacs support ImageMagick? Evaluate `(image-type-available-p 'imagemagick)`; if that returns `t`, this check passes. If not, you'll have to rebuild your emacs, possibly after installing the ImageMagick development libraries. The configure flag is `--with-imagemagick`. * did you call `imagemagick-register-types` after setting `imagemagick-enabled-types`? It's probably OK if you set it in your init file and have restarted emacs, but you might as well make sure. I did ``` (setq imagemagick-enabled-types t) (imagemagick-register-types) ``` * (probably unnecessary) is `eps` an acceptable image file extension? Evaluate the variable `image-file-name-extensions` to find out. This might be unnecessary, but I did `(add-to-list 'image-file-name-extensions "eps")` just to make sure. * (very important) What is the value of `org-image-actual-width`? If it is t, then `org-display-inline-images` sets the width to `nil` (i.e. use the actual width of the image) before calling `org--create-inline-image` which bypasses ImageMagick and lets the `create-image` code do as it wishes: that might work if you don't use the Cairo libraries in your emacs, but not otherwise: the code in `image.c` disables Ghostscript if Cairo is enabled. So it seems that the Org mode handling of images at their actual size is broken ATM. Fortunately for you, you want to set the width explicitly, so all you have to do is set `org-image-actual-width` to nil. That allows ImageMagick to be used and all is well: ``` (setq org-image-actual-width nil) ``` I can then do `C-c C-x C-v` and get inline display of .eps (with a size spec), .png (natural size), .jpg (natural size) and .pdf (with a size spec) - but for this last I *had* to add `pdf` to `image-file-name-extensions` (maybe I'm doing something wrong, but no more time to investigate). EDIT: Here are some additional points that might be helpful: * Did you check that `imagemagick` is available in your emacs? Do `M-: (image-type-available-p 'imagemagick)` \- does it return `t`? * I tried it with `(setq org-image-actual-width 400)` and it works for me. * Maybe post the versions of emacs and Org mode that you are using - things might be version dependent. * When you do `display <image-file-name>` from the command line, do you see your image? Finally, you might want to investigate Edebug which is what I've been using in this investigation. Find the definition of the function `org--create-inline-image` in `org.el`, do `C-u C-M-x` with the point somewhere inside the definition (you should see the message `Edebug: org--create-inline-image` in the echo area) and then try to display inline images again with `C-c C-x C-v` (if they are toggled on, you'll have to toggle them off and then back on again, so `C-c C-x C-v` twice). Code execution should stop when the above function is entered: press `<Space>` repeatedly to step through the function (note that the result of each evaluation is printed in the echo area) until you get to the call to `create-image` and then carefully step through the argument evaluation in that call and write down what the various arguments evaluate to and what the result of the function call is. In my case, I get * file-or-data: `/tmp/image.eps` * image-type: `imagemagick` * remote?: `nil` * props: `:width 400` and `create-image` returns `(image :type imagemagick :file /tmp/image.eps" :scale 1 :width 400)`. If you want, post what you get in your case: it will at the very least decide the question "Is it Org mode or is it image.el that's not working properly?". To restore the instrumented function to its former non-instrumented state, you can do `C-M-x` in the function, or `M-x load-library RET org RET` or `M-x org-reload` or restart emacs. The last one is the safest. --- Tags: org-mode, org-babel, inline-image ---
thread-57998
https://emacs.stackexchange.com/questions/57998
Always show the last lines with a lower indentation than the first line that's visible in a window
2020-04-23T08:41:39.557
# Question Title: Always show the last lines with a lower indentation than the first line that's visible in a window I often find myself scrolling up in a code file to see which context I am in (class/method definition, yaml-key, etc). It would be super handy if I could somehow "freeze" the last lines of each indentation level that's lower than the last currently visible line. For example: ``` class X: def a(): # ... def b(): # ... def some_local_function(): # lots of code # ---- this is last line visible in the buffer/window # more visible code ``` In this case I would like the window to look like this: ``` class X: def b(): def some_local_function(): # some demarcation to indicate the lines above are separate from those below # ---- this is last line visible in the window # more visible code ``` Is there already a way to do this? If not, how would I go about implementing it? # Answer > 3 votes I don't think anyone has already implemented exactly this, but you might look into code folding. Folding allows you to hide and show parts of the buffer on command. There are implementations of code folding for specific languages, as well as some which are more generic. Some are keyed off of indentation, others off of syntax elements (such as curly braces or parentheses). If you do want to "freeze" text at the top of the window, Emacs does support rendering a single line of text as a header for the window which is visible no matter where in the buffer you are. Presumably you could change that header as the cursor moves. # Answer > 1 votes Have you tried the various code navigation bindings? I often set the mark to remember where I start and then do `C-M-u` repeatedly to go up in the code structure. Then `C-x C-x` gets me back to my mark (and `C-g` gets rid of the active region if necessary). There are other such bindings: `C-M-f` goes forward one statement at the same level and `C-M-b` goes back. So you can do `C-M-u` repeatedly until you get to the `def` and then do `C-M-f` repeatedly to get to the end of each subsequent `def`. That allows you to check where in the code you are, but you are still required to remember it: there is no "permanent record" the way that you want. But it is still very useful and it works in *any* programming language that Emacs knows about. You can find more information in the Editing Programs section of the Emacs manual for *much* more information about these and related topics. --- Tags: indentation, window, display ---
thread-58004
https://emacs.stackexchange.com/questions/58004
How to replace strings including `.` (dot) as first character using dired-do-find-regexp-and-replace
2020-04-23T16:20:31.557
# Question Title: How to replace strings including `.` (dot) as first character using dired-do-find-regexp-and-replace ``` (defun my-find-orgfiles () (interactive) (find-name-dired "." "*py")) (global-set-key (kbd "M-n") 'my-find-orgfiles) ``` Than, `t` to toggle marked/unmarked files (thus marking them all, since none were marked). Then I use `Q` to use `query-replace on the marked files`. And enter `.value` to replace with `value`. --- =\> What am I trying to do? Replace a string that is starting or ending with `.` (dot) such as: `.value` or `value.`. =\> What happens instead? During replacement Emacs also finds text such as `(value`, `[space]value`, `[value` and so on. In other words, `.value` is matching any character followed by `value`. =\> How can I force `dired-do-find-regexp-and-replace` (bound to `Q` in Dired buffers) to look for a *literal* **`.`** during string replacement? # Answer > 1 votes This really has nothing to do with `find-name-dired`. This is about `Q` in Dired buffers (including from `find-name-dired`). `Q` is `dired-do-find-regexp-and-replace`. That command treats your first input pattern as a **regexp**. And `.` in a regexp matches any character except newline. What you want to use, instead of `.value`, is **`[.]value`**. That is, you want a pattern that matches only a **`.`** character. --- Tags: dired, regular-expressions, find-dired, query-replace-regexp ---
thread-58006
https://emacs.stackexchange.com/questions/58006
Expand parentheses with smartparens
2020-04-23T18:25:36.227
# Question Title: Expand parentheses with smartparens I want to expand `else {|}` (second parentheses generated by smartparens) into ``` else { | } ``` which is the best sequence of keys or options? # Answer The easiest way I can think of is to open a new line with `C-o` then `RET`. > 1 votes --- Tags: smartparens, parentheses ---
thread-58010
https://emacs.stackexchange.com/questions/58010
In js2-mode, is there a way to goto the other brace/bracket/paren in the pair?
2020-04-23T22:13:35.627
# Question Title: In js2-mode, is there a way to goto the other brace/bracket/paren in the pair? eg. if I have ``` { foo: "bar", fu: {"baz": bar} } ``` And I have my cursor on the last brace, is there a command that will goto the first brace? Also open to more general packages if there is one that does this better. # Answer `C-m-b` (bound to `backward-sexp`) should go to the matching brace at the same level. There are many other useful code navigation commands too: `C-m-f` (bound to `forward-sexp`) and `C-m-u` which goes *up* in the code structure. In combination, these commands are very powerful tools for all sorts of code investigation, as well as editing. And they are available in just about *every* programming language mode. See Editing Programs in the Emacs manual for much more on this. > 1 votes --- Tags: js2-mode ---
thread-58020
https://emacs.stackexchange.com/questions/58020
ivy counsel find-file with similar name
2020-04-24T08:26:08.220
# Question Title: ivy counsel find-file with similar name In the directory I have `mongodb.js`, now I want to create a `db.js` file but if I type the name and press enter counsel-find-file use regex to open mongo**db.js**. How can i create a `db.js` with counsel-find-file in the same directory of `mongodb.js`? # Answer > 6 votes Using `C`-`M`-`j` when you're at prompt line. Binds to `ivy-immediate-done` As manual states it goes with current input instead the current candidate. --- Tags: find-file, ivy, counsel ---
thread-57977
https://emacs.stackexchange.com/questions/57977
tramp: $INSIDE_EMACS isn't defined while .bashrc is processed
2020-04-22T13:49:33.697
# Question Title: tramp: $INSIDE_EMACS isn't defined while .bashrc is processed It seems `INSIDE_EMACS` can be used to determine if tramp is used. I know I could use `test "$TERM" = "dumb"` but `if [[ -z $INSIDE_EMACS ]]; then` is provided by the home-manager tool. If I set `tramp-verbose` I can see that `INSIDE_EMACS` is defined in some tramp sessions but it's not when my `.bashrc` is processed. I wonder if `INSIDE_EMACS` could be set after the shell starts. Any ideas? GNU Emacs 28.0.50 (build 1, x86\_64-pc-linux-gnu, GTK+ Version 3.24.14, cairo version 1.16.0) > Determining a TRAMP session > > ``` > Sometimes, it is needed to identify whether a shell runs under TRAMP control. The setting of environment variable TERM will help: > > if test "$TERM" = "dumb"; then > ... > fi > > Another possibility is to check the environment variable INSIDE_EMACS. Like for all subprocesses of Emacs, this is set to the > > ``` > > version of the parent Emacs process, See (emacs)Interactive Shell. TRAMP adds its own package version to this string, which could be used for further tests in an inferior shell. The string of that environment variable looks always like > > ``` > echo $INSIDE_EMACS > ⇒ 26.2,tramp:2.3.4 > > ``` https://www.gnu.org/software/tramp/ **.bashrc** ``` if [[ -z $INSIDE_EMACS ]]; then eval "$(/nix/store/ni6mmldfii7mljhnism2rn0pwchr2fmz-starship-0.40.1/bin/starship init bash)" fi ``` # Answer > 2 votes `$INSIDE_EMACS` is set when the remote shell is called explicitly. However, this is not given when your login shell is called, due to the `ssh` command. Therefore, if you have `bash` as login shell, that variable is not set yet at this time. --- Tags: tramp ---
thread-58024
https://emacs.stackexchange.com/questions/58024
Understanding precedence of minor modes keymaps
2020-04-24T09:42:19.790
# Question Title: Understanding precedence of minor modes keymaps I would like to understand when keymaps of minor modes get "applied" and how do they get applied exactly? In particular, is there a way to see a list of a active minor-mode maps? I know I can look the list of active minor-modes and check which of them has a keymap, but I am looking for a deeper understanding of the mechanism). One reason I want to understand this is to figure out what happens when I have multiple minor modes mapping the same key sequence. Which one gets precedence and how can I influence this? # Answer > 3 votes ``` minor-mode-map-alist is a variable defined in `C source code'. Documentation: Alist of keymaps to use for minor modes. Each element looks like (VARIABLE . KEYMAP); KEYMAP is used to read key sequences and look up bindings if VARIABLE's value is non-nil. If two active keymaps bind the same key, the keymap appearing earlier in the list takes precedence. ``` https://stackoverflow.com/a/24688860/324105 might also help. --- Tags: keymap, minor-mode ---
thread-58021
https://emacs.stackexchange.com/questions/58021
Switch to custom views in Agenda via org-agenda-view-mode-dispatch
2020-04-24T08:46:57.970
# Question Title: Switch to custom views in Agenda via org-agenda-view-mode-dispatch Is ist possible to add custom views to agenda which can be accessed via org-agenda-view-mode-dispatch? Its very convenient to press just "v" and "l" to make agenda show completed tasks. It would be great to be able to filter the current view for special `TODO` keywords or tags the same way. Like pressing "v" and "n" to only show todos with `NEXT` keyword in the current agenda view. I am fairly new to emacs. # Answer > 0 votes It's not possible out of the box. `org-agenda-view-mode-dispatch` is just a big case statement: if the user presses *this* key, then call *that* function. The set of keys that it recognizes and the set of functions that it calls is fixed beforehand. That does not prevent you from rewriting the function in a more extensible way (and if you do, you might want to propose it for inclusion to Org mode: send mail to the Org mode mailing list). --- Tags: org-mode, org-agenda ---
thread-39106
https://emacs.stackexchange.com/questions/39106
yaml frontmatter in org mode
2018-02-26T21:31:29.843
# Question Title: yaml frontmatter in org mode When exporting and org file in emacs to either html or md for a jekyll-based web page, the `yaml` front matter gets twisted. As suggested here, I have attempted enclosing it in an html block in the org file thus: ``` #+begin_html --- layout: post title: "La redistritación" --- #+end_html ``` It should output this: ``` --- layout: post title: "La redistritación" --- ``` Using `org-html-publish-to-html`, I instead get this: ``` <div class="html"> <p> &#x2014; layout: post title: "La redistritación" &#x2014; </p> </div> ``` I also attempted enclosing in a source block (as suggested here) thus: ``` #+begin_src yaml --- layout: post title: "La redistritación" --- #+end_src ``` which comes close, but prepends empty (code) spaces and is therefore not recognized as front matter by jekyll. (And adding `exports` and `results` specs, as suggested here, returns a `Wrong type argument: stringp, nil` error message.) How should I configure export settings to get proper yaml front matter? # Answer > 2 votes Don't see what version you are running but the solution is crazy simple. Mine didn't work at first (because i used yml not yaml) Those two file types are the same thing. ``` #+BEGIN_SRC yaml #+END_SRC ``` # Answer > 1 votes Here is a filter to post-process the entire document body in order to expand expressions of the form `{{{:ident}}}` by resolving :ident against the communication channel. For example `{{{:title}}}` will be replaced by the document title as set by the `#+title` directive. ``` (defun my-org-body-filter (body backend info) (replace-regexp-in-string "{{{\\(:[^}]+\\)}}}" (lambda (name) (let* ((sym (intern (substring name 3 -3))) (val (plist-get info sym))) (format "%s "(and val (car val))))) body)) (add-to-list 'org-export-filter-body-functions #'my-org-body-filter) ``` --- Tags: org-mode, html, markdown ---
thread-58035
https://emacs.stackexchange.com/questions/58035
Extract value from org-babel-get-src-block-info
2020-04-24T15:13:57.510
# Question Title: Extract value from org-babel-get-src-block-info I have this elisp code: ``` #+BEGIN_SRC emacs-lisp :dir ~/org/test (defun test () (setq args '(org-babel-get-src-block-info)) (cdr (assoc ':dir args))) (test) #+END_SRC ``` But when I execute the code block, I get a message saying that no output was produced... what am I doing wrong? # Answer You should: 1. Unquote `'(org-babel-get-src-block-info)` and 2. Replace `(cdr (assoc ':dir args))` with `(assoc-default :dir (nth 2 args))` That is: ``` #+BEGIN_SRC emacs-lisp :dir ~/org/test (defun test () (setq args (org-babel-get-src-block-info)) (assoc-default :dir (nth 2 args))) (test) #+END_SRC ``` Or: ``` #+BEGIN_SRC emacs-lisp :dir ~/org/test (let* ((info (org-babel-get-src-block-info)) (params (nth 2 info))) (assoc-default :dir params)) #+END_SRC ``` > 1 votes # Answer For a start, you are quoting the call to `org-babel-get-src-block-info`, so the function is never called. Second, you probably want to change the test function to something like this: ``` (defun test() (let ((args (org-babel-get-src-block-info))) args)) ``` until you understand what the call to `org-babel-get-src-block-info` returns. In fact, it would be a good idea to try doing `M-: (org-babel-get-src-block-info) RET`, so you can see clearly what the function returns. Third, babel has strange ideas about what to do with the output. In this particular case, you might want to set `:results raw` (despite the disadvantage that you have to delete the results by hand every time), so as to avoid the strange interpretation. > 0 votes --- Tags: org-mode, org-babel ---
thread-53987
https://emacs.stackexchange.com/questions/53987
Can I open emacs in nw mode with the scratch buffer? (when emacs is aliased to emacsclient session)
2019-11-25T16:40:44.037
# Question Title: Can I open emacs in nw mode with the scratch buffer? (when emacs is aliased to emacsclient session) closed that, re-incarnated here: When starting emacs from the shell command line, if you pass the "dot", it opened emacs with a 'dired' of the current directory. But can I do this? ``` emacs '*scratch*' ``` Basically I want to tell emacs (emacsclient) to be invoked with the argument "the file to be opened" being `*scratch*` It would solve one of the problems I sometimes have: fyi I always start my day with `cd ~/projecta; emacs .` The issue with this is I can't freely kill 'dired' buffers. If I `C-x k` the 'dired' buffer for `projecta` root, emacs frame closes and I get dropped in to the shell. Some context: * using macOS * Uses emacs *only* with Terminal.app ( -nw mode) * Emacs is client/server based, and each of my "customers" get their own entry in my .bashrc ``` function emacs() { emacsclient -a "" -s workspace -nw "$@" } function emacsb() { emacsclient -a "" -s workspaceb -nw "$@" } ``` # Answer One option is `emacs -e '(switch-to-buffer "*scratch*")'` > 1 votes # Answer The first line of the output of `emacsclient --help` is ``` Usage: emacsclient [OPTIONS] FILE... ``` It suggests that a file or directory must be provided to the command. Also, like you, I create per-directory emacs daemons: ``` ec() { SERVER_NAME=$(basename $PWD) emacsclient -a '' -s $SERVER_NAME $* } ``` The advantage of this is that if I close the file or directory that the emacsclient is opened with, the daemon persists. > 0 votes --- Tags: scratch-buffer ---
thread-58040
https://emacs.stackexchange.com/questions/58040
org mode: expand all headings that match a search
2020-04-24T21:16:14.353
# Question Title: org mode: expand all headings that match a search How can I expand all the headings with a name matching a search term? For example, take the following fully expanded document: ``` * Famous Animals ** Pigs - Ace - Babe ** Cats - Duchess - Felix * Musical Characters ** Cats - Demeter - Macavity ** Chicago - Roxie - Velma ``` Now let's collapse it completely: ``` * Famous Animals * Musical Characters ``` I'd like to be able to search for "Cats" and get the following headings to expand: ``` * Famous Animals ** Pigs ** Cats - Duchess - Felix * Musical Characters ** Cats - Demeter - Macavity ** Chicago ``` Extra points if I can do an incremental search and have the headings expand as I type. # Answer > 1 votes `org-sparse-tree` (`C-c /`) does exactly what you want. For example, `C-c / / Cats RET` will expand all content where "Cats" appears, and collapse the rest. --- Tags: org-mode ---
thread-25016
https://emacs.stackexchange.com/questions/25016
Emacs doesn't display color fonts at all
2016-08-02T09:42:36.803
# Question Title: Emacs doesn't display color fonts at all I tried to add `Noto Color Emoji` from Google Noto as my font for Emoji in GNU Emacs, as mentioned in here, but for some reason GNU Emacs doesn't display these characters properly in its window. I'm using GNU Emacs 24.5.1 on GNU/Linux. Is this a bug or am I doing something wrong? # Answer You're not doing anything wrong. Emacs for Linux uses XFT for font rendering, and XFT doesn't yet support the color fonts. See this mailing list thread from Dec 2015. Richard Stallman writes in that thread that it's a low priority and they don't care about color fonts. Also in that thread you can see that they disabled color fonts in Emacs for *Mac*, not for any technical reason but because color fonts are not supported in the Unix version of Emacs and they don't want the Mac version to have a feature that is not in the Unix version. So I wouldn't expect to see this any time soon. > 11 votes # Answer Or you can use Emacs terminal (`emacs -nw`) on a terminal emulator that support color emoji. Edit: Emacs can be run as GUI or terminal application. To start emacs terminal, open your terminal emulator (iTerm or iTerm2 in MacOS, Mate-Terminal or Gnaome-Terminal in Linux) and run the command `emacs -nw` in the terminal emulator. When running in terminal mode, the glyphs and fonts are not in control of Emacs and it must display what the terminal emulator is giving. With a terminal that support color emojis, you can force Emacs terminal to display them. > 5 votes # Answer Color emojis work with the noto color emoji and other emoji fonts in emacs 28 I tried to use emojis in the terminal on emacs 26 but it was glitched when I scrolled up and down. That was fixed when I upgrade as well Now I am using GNU Emacs 28.0.50 > 0 votes --- Tags: fonts ---
thread-58037
https://emacs.stackexchange.com/questions/58037
Is there a standard mode for .ini files?
2020-04-24T19:54:34.983
# Question Title: Is there a standard mode for .ini files? After looking for a mode for `.ini` files, I found `ini-mode` via MELPA, but upon installing it in Emacs 26, there was a message about it being an obsolete mode. What are the alternatives? In my limited testing, `conf-mode` seems to work for `.ini`-style files too, but I'm wondering whether there are other solutions that are specifically about `.ini` files. In terms of functionality, I'm primarily looking for syntax highlighting and indentation. # Answer > 9 votes `conf-mode.el` says: > This mode is designed to edit many similar varieties of Conf/Ini files and Java properties. It started out from Aurélien Tisné's `ini-mode`. `conf-space-keywords` were inspired by Robert Fitzgerald's `any-ini-mode`. So `conf-mode` seems to be what you're looking for (and comes with Emacs). --- Tags: major-mode, syntax-highlighting ---
thread-22428
https://emacs.stackexchange.com/questions/22428
change python indent in a specific file
2016-05-22T15:29:53.043
# Question Title: change python indent in a specific file I have a piece of legacy code in Python that uses inconsistent tabs - 2 spaces in some instances and 4 in others. I have my defaults set in my .emacs file to use 4 spaces, but in this case emacs finds the inconsistent spacing and uses a tab width of 2. I'm working to update the file in other ways, and I'd like to set the tab width, in this specific file, to 4. How can I do this? Thanks! # Answer > 5 votes One method of setting variables on a per-file basis is to write a local variable specification in the first line of the file. The details for doing this are in §48.2.4.1 ‘Specifying File Variables’ of the Emacs manual. A local variable specification takes the following form: ``` -*- mode: MODENAME; VAR: VALUE; ... -*- ``` You can repeat `VAR: VALUE;` for as many variables as you want to set. Assuming you are using `python-mode`, you need to set the variable `python-indent-offset` to 4. Don’t forget to comment out the specification so that the Python interpreter doesn’t attempt to parse it: ``` # -*- mode: python-mode; python-indent-offset: 4 -*- ``` You can do this by hand, or use `M`-`x` `add-file-local-variable-prop-line` and Emacs will prompt you for a variable and its value. It will also take care of commenting out the specification. # Answer > 3 votes Unfortunately, you can't. Consider this piece of code. ``` x = 0 if True: x += 1 x += 2 ``` You can't programmatically decide if that block should become this ``` x = 0 if True: x += 1 x += 2 ``` or this ``` x = 0 if True: x += 1 x += 2 ``` It's almost impossible to fix inconsistent spaces with a program. However you can write a simple function to change indentation level of file, say all 2 spaces can be converted to 4 spaces. I faced the exact problem a year back. I just indented entire file to 4 spaces using `M-x indent-region`. After that I have manually fixed lines which are incorrectly indented. # Answer > 0 votes For switching to tab character for indents, put the following at the top of your file: ``` # -*- mode: python-mode; indent-tabs-mode: t -*- ``` --- Tags: indentation, python, tabs ---
thread-43869
https://emacs.stackexchange.com/questions/43869
Indentation with cdlatex
2018-07-31T14:37:34.703
# Question Title: Indentation with cdlatex I am using Emacs 25.1.1 on Windows 10 OS with *AUCTeX* and the *CDLaTeX* minor mode. CDLaTeX has a very useful feature of command input, which is typing a shortcut followed by `TAB` to expand that shortcut. For instance, when I type `eqt` `TAB`, it will input a whole LaTeX equation environment and move the cursor into this environment. **My question:** Regarding the indentation of this environment input: It just doesn't respect the current indentation (like child, subchild, etc). I search around and there seems no information about this. Is there any *hot fix* for this general environment input indentation thing? Thanks a lot. # Answer Looking at `cdlatex` mode, it doesn't appear to be designed with modifying the inserted templates in mind (I could be wrong). The yasnippet package does offer completely customizable templates, with the option to have them respect indentation. It takes a bit of reading to figure it out, but once you do you can write your own templates to do fairly complex insertions. For your example, the following: ``` # name: eqt # key: eqt # -- \begin{equation} $> $0 \end{equation} ``` Will create a snippet, bound to the text `eqt`, that expands to an equation environment, and the environment will be indented as appropriate based on the surrounding environments (if any). If that looks interesting, check the documentation for `yasnippet`. You need to install the package (via `package-list-packages`), enable the mode for latex files, and write or install the snippets you want to use. > 0 votes # Answer You can define new environments in cdlatex using `cdlatex-env-alist` and assign a hotkey to those with `cdlatex-command-alist`. For your case, ``` (setq cdlatex-env-alist '(("equation" "\\begin{equation}\n\t ? AUTOLABEL \n\\end{equation}" nil))) ``` This will override the default `equation` environment. Note that `\t` inserts the tab just before the cursor. Checkout the documentation for more details. > 0 votes --- Tags: auctex ---
thread-58049
https://emacs.stackexchange.com/questions/58049
How to get ess-describe-object-at-point to delete-window when I am done?
2020-04-25T06:50:28.557
# Question Title: How to get ess-describe-object-at-point to delete-window when I am done? I am reading this function and still don't see why it doesn't delete both the buffer and window. Currently it open a new window, and when I hit `C-g` another buffer (even duplicated to the one I am editing) appears in that window, created unwanted layout. See attach screenshot. What I want is to get the window behavior like `*Help` buffer when one calls `M-x describe-key` for example: It opens its own window, move focus there, and closes it when I hit `q` or `C-g`. # Answer For now I change `(kill-buffer buf)` in the following section to `(delete-window-on buf)`: From: ``` (when (and (commandp command) (bufferp buf) (or (not (symbolp command)) ;; kill on lambdas (not (string-match "window" (symbol-name command))))) (kill-buffer buf)) ;; bury does not work here :( (Emacs bug?) ``` To this: ``` (when (and (commandp command) (bufferp buf) (or (not (symbolp command)) ;; kill on lambdas (not (string-match "window" (symbol-name command))))) (delete-window-on buf)) ;; bury does not work here :( (Emacs bug?) ``` Still feel the window created by `describe-object-at-point` is too intrusive. It should be like `"*Help*"` window. But I don't have time to dig more into this right now. > 1 votes --- Tags: ess ---
thread-57915
https://emacs.stackexchange.com/questions/57915
Use all eight weights of IBM Plex fonts in emacs (including "Text")
2020-04-19T20:48:45.007
# Question Title: Use all eight weights of IBM Plex fonts in emacs (including "Text") I was inspired by Paul Ford to use IBMs font Plex for my emacs config. One of the strengths of IBM Plex is that all the four families each have eight weights. **The families:** *Mono, Sans, Sans Condensed, Serif* **The weights:** *Thin, Extra Light, Light, Regular, Text, Medium, SemiBold, Bold* But I encounter three problems: 1. setting :weight text (in the customize-area) ``` '(variable-pitch ((t (:family "IBM Plex Sans" :height 152 :weight text)))) Error Message: Invalid face weight: text ``` 2. medium and regular seem to be interpreted as the same font weight. At least nothing changes if I use :weight regular or :weight medium. 3. The font on regular looks different (heavier) in emacs than what I see on the "Typetester" (white button) on the font's website. Is there a way to enable all the eight font weights for use in emacs? I am fairly new to emacs. # Answer I maybe found an answer, although I cannot verify it from the output, I think that this hack has the desired effect of being able to use all the eight font weights. First I pasted `(insert (prin1-to-string (x-list-fonts "*")))` into the *scratch* buffer (`Ctrl x` then `b` and type `*scratch*`) Then I ran the command with `Ctrl j` at the end of the line and it printed all the fonts. I did a bit of cleanup (I used `org-mode` with `query-replace` and `org-sort`) and got the following: ``` [...] "-IBM -IBM Plex Mono-bold-italic-normal-*-*-*-*-*-m-0-iso10646-1" "-IBM -IBM Plex Mono-bold-normal-normal-*-*-*-*-*-m-0-iso10646-1" "-IBM -IBM Plex Mono-extralight-italic-normal-*-*-*-*-*-m-0-iso10646-1" "-IBM -IBM Plex Mono-extralight-normal-normal-*-*-*-*-*-m-0-iso10646-1" "-IBM -IBM Plex Mono-light-italic-normal-*-*-*-*-*-m-0-iso10646-1" "-IBM -IBM Plex Mono-light-normal-normal-*-*-*-*-*-m-0-iso10646-1" "-IBM -IBM Plex Mono-normal-italic-normal-*-*-*-*-*-m-0-iso10646-1" "-IBM -IBM Plex Mono-normal-italic-normal-*-*-*-*-*-m-0-iso10646-1" "-IBM -IBM Plex Mono-normal-italic-normal-*-*-*-*-*-m-0-iso10646-1" "-IBM -IBM Plex Mono-normal-normal-normal-*-*-*-*-*-m-0-iso10646-1" "-IBM -IBM Plex Mono-normal-normal-normal-*-*-*-*-*-m-0-iso10646-1" "-IBM -IBM Plex Mono-normal-normal-normal-*-*-*-*-*-m-0-iso10646-1" "-IBM -IBM Plex Mono-semibold-italic-normal-*-*-*-*-*-m-0-iso10646-1" "-IBM -IBM Plex Mono-semibold-normal-normal-*-*-*-*-*-m-0-iso10646-1" "-IBM -IBM Plex Mono-thin-italic-normal-*-*-*-*-*-m-0-iso10646-1" "-IBM -IBM Plex Mono-thin-normal-normal-*-*-*-*-*-m-0-iso10646-1" [...] ``` I got similar output for each IBM Plex font. Interestingly there is three times the same font in XLFD style: ``` "-IBM -IBM Plex Mono-normal-normal-normal-*-*-*-*-*-m-0-iso10646-1" "-IBM -IBM Plex Mono-normal-normal-normal-*-*-*-*-*-m-0-iso10646-1" "-IBM -IBM Plex Mono-normal-normal-normal-*-*-*-*-*-m-0-iso10646-1" ``` I suppose that "Medium" and "Text" are recognized as another "Normal" (Regular). I experimented with the priorities in Org-Mode and formatted every priority in a different face to quickly see the differences when switching. I got the desired effect using the weight in `family` instead of `weight`. Following combinations worked for me (in the customize-section) ``` :family "IBM Plex Mono" :weight normal :family "IBM Plex Mono Medium" :weight normal :family "IBM Plex Mono Text" :weight normal ``` The intuitive way `:family "IBM Plex Mono" :weight medium` did not work. **On my windows machine** I had to use the weight sometimes in the `family` AND the `weight` like: ``` :family "IBM Plex Mono SemiBold" :weight semibold ``` The weight just in the `family` with `:weight normal` did not work for me exept for "Text" and "Medium". My experience was that not every weight in every font has an easy notable difference. But with this hack, I am able to apply all the desired font styles. > 1 votes --- Tags: fonts ---
thread-57698
https://emacs.stackexchange.com/questions/57698
Hide DONE todos of subtrees by setting a special keyword or tag - to support focus
2020-04-10T08:33:55.690
# Question Title: Hide DONE todos of subtrees by setting a special keyword or tag - to support focus I would like to be able to set a keyword or tag for a subtree, which hides all todos in `DONE` states. The Video of John Cleese about creativity states inspired me. He says that we enter a "closed mode" for getting work done, like going through a tunnel and at the end switch back in "open mode" for creative/planning tasks. I would like such a "tunnel"-keyword or tag to help me focus on getting all tasks of a subtree done by hiding the `DONE` tasks (on the fly) as long as the keyword or tag persists. Maybe something similar to the `COMMENT` keyword before the heading. I fear that archiving destroys the tree structure (e. g. for clock reports or later review). I would like to archive the whole project tree after a project is finished. Sparse trees don't update on the fly and I can not close and expand the parent heading without showing all the children again. ``` Example: ``` open mode / normal ``` * Heading 1 ** TODO One Thing ** DONE Other Thing * Heading 2 ** DONE Another Thing ``` variant closed mode - with keyword like COMMENT ``` * TUNNEL Heading 1 ** TODO One Thing * Heading 2 ** DONE Another Thing ``` variant closed mode - with tag ``` * Heading 1 :tunnel: ** TODO One Thing * Heading 2 ** DONE Another Thing ``` I am new to Emacs. # Answer I have a temporary workaround, which does not solve the problem, but lowers the impact of the cause. I apply the `ARCHIVE` tag when marking a task `DONE`. Headlines with the `ARCHIVE` tag can be formatted specially. ``` (setq org-todo-state-tags-triggers (quote (("DONE" ("ARCHIVE" . t)) ;; Set ARCHIVE tag when state changes to DONE ("" ("ARCHIVE")) ;; Unset ARCHIVE tag when state changes to "" (no state) ))) ``` Then I set the org-archived face to a light color via `customize`. I use a white background and also lower the font size a bit. ``` '(org-archived ((t (:foreground honewydew2 :height 0.8)))) ``` Now `DONE` tasks are not really hidden, but loose a lot of visual attention. All headings with the `ARCHIVE` tag are now a lot less visible. Switching to the stateless state removes the `ARCHIVE` tag and makes the headings visible again. For review I use `Ctrl-c @` to mark a subtree. When marked the `DONE` tasks have a black color and are clearly readable again. Headings with the `ARCHIVE` tag can only be expanded by pressing `Ctrl TAB` and not by pressing just `TAB` as usual. Subtrees of those headings are displayed with the normal face. **Update 16. June 2020:** This method has some drawbacks since every task in every file is automatically archived and does not show up in agenda clock report any more and habits can not be tracked like this. > 0 votes --- Tags: org-mode ---
thread-58056
https://emacs.stackexchange.com/questions/58056
Set multiple keys at once with global-set-key?
2020-04-25T20:45:29.643
# Question Title: Set multiple keys at once with global-set-key? Is it somehow possible to set multiple keys with `global-set-key` without having to repeat the statement, like setting multiple variables with `setq`? # Answer > 1 votes In a word, no. `C-h f global-set-key` tells you what the function's signature is: > `global-set-key` is an interactive compiled Lisp function in `subr.el`. > > **`(global-set-key KEY COMMAND)`** > > Give `KEY` a global binding as `COMMAND`. > > ... The function accepts only a single key sequence and a single command. If you really wanted to save multiple occurrences of the text `(global-set-key` and `)` then you could write a function to do that. E.g.: ``` (defun my-g-s-k (&rest k+c) "..." (let (key cmd) (while k+c (global-set-key (car k+c) (cadr k+c)) (setq k+c (cddr k+c))))) (my-g-s-k "\C-o" 'forward-char "\M-o" 'backward-char "\C-\M-o" 'forward-line) ``` --- Tags: key-bindings ---
thread-58057
https://emacs.stackexchange.com/questions/58057
How to save and restore the association of a window to buffer across Emacs sessions?
2020-04-25T20:59:41.370
# Question Title: How to save and restore the association of a window to buffer across Emacs sessions? I have a window layout with three windows and I would like Emacs to remember the buffers even if the buffers don't exist after restart. Context: I am using Spacemacs for Clojure development. In window #1 I have my sourcecode. In window #2 I have `*cider/repl ...`, which is my REPL which is only available after starting it. In window #3 I have `*cider-test-report*` which is my unit test report. Since the buffers in #2 and #3 are temporary, Emacs fills them with `*scratch*` after restart. How to get Emacs to open my usual buffers in windows as soon as the buffers are available? # Answer > 1 votes You can save the current window configuration (as well as other features of your current Emacs session) using `M-x desktop-save`. As node Saving Emacs Sessions of the Emacs manual tells you: > You can also enable automatic saving of the desktop when you exit Emacs, and automatic restoration of the last saved desktop when Emacs starts: use the Customization buffer (\*note Easy Customization::) to set `desktop-save-mode` to `t` for future sessions, or add this line in your init file (\*note Init File::): ``` (desktop-save-mode 1) ``` --- Tags: buffers, window, desktop, window-configuration ---
thread-58055
https://emacs.stackexchange.com/questions/58055
Add compiling option to tex engine
2020-04-25T19:05:07.767
# Question Title: Add compiling option to tex engine I want to use minted package in my tex file. It needs the command-line option `--shell-escape` to allow external pygmentize program execution. How can I add that option to the tex engine? My related code snippets are ``` (add-hook 'LaTeX-mode-hook (lambda () (setq TeX-auto-untabify t ; remove all tabs before saving TeX-engine 'xetex ; use xelatex default TeX-show-compilation t) ; display compilation windows (TeX-global-PDF-mode t) ; PDF mode enable, not plain (setq TeX-save-query nil) (imenu-add-menubar-index) (define-key LaTeX-mode-map (kbd "TAB") 'TeX-complete-symbol))) ``` I tried to add `(add-to-list 'tex-compile-commands '("xelatex --shell-escape -interaction nonstopmode -output-directory %o %f" t "%r.pdf"))`, but that doesn't help. # Answer > 2 votes Add the following line to the list of local variables of the source file: ``` %%% TeX-command-extra-options: "-shell-escape" ``` Then you need to do `M-x revert-buffer` to make it applied. AUCTeX 12.2: 4.1.3 Options for TeX Processors How to pass flags to the LaTeX compiler with AUCTeX? - Emacs Stack Exchange emacs - Adding an option to the PDFLaTeX call from AUCTeX - LaTeX Stack Exchange --- Tags: latex, tex ---
thread-58060
https://emacs.stackexchange.com/questions/58060
Not matching a character at the beginning of line
2020-04-25T22:08:00.787
# Question Title: Not matching a character at the beginning of line I would like to match lines that have the phrase `a test` but not start with `>`. So I want to match ``` This is a test a test this is ``` but not ``` > This is a test ``` I am not sure how to do this without lookahead in emacs. As a first try I tried`^[^>].*a test`. However, for some reason, this matches `> This is a test` when there's a newline before it which I don't understand since the first character in a line should not be `>`. What is the correct regular expression for this case? And why is my regular expression matching lines starting with `>`. # Answer > 3 votes The point is that the construct `[^>]` matches even a newline as stated in https://www.emacswiki.org/emacs/RegularExpression. Indeed such regex matches even the line above. So replacing it with `[^>\n]` solves the problem. # Answer > 0 votes Your problem must be something else; that regex looks fine to me. In fact, I used `M-x regexp-builder` to verify that it does work as expected. --- Tags: regular-expressions ---
thread-57931
https://emacs.stackexchange.com/questions/57931
"python3 -m venv" support in emacs
2020-04-20T15:25:21.620
# Question Title: "python3 -m venv" support in emacs pyvenv and virtualenvwrapper emacs packages work well with virtualenv, but neither appears to support the core venv module which is now packaged with releases of Python. Are there any actively developed packages with support for venv? pyvenv: https://github.com/jorgenschaefer/pyvenv virtualenvwrapper: https://github.com/porterjamesj/virtualenvwrapper.el # Answer > 1 votes Short answer is - pyvenv does support core venv, only as a fallback and only as of Sept 2019. More details as of Apr 2020: * Very basic support is afforded by the emacs `python` module. This is generic enough to work with both virtualenv and venv. See convenience function `python-shell-virtualenv-root`. This will set the virtual environment, but there are no tools to create, workon, delete environments. Ref: https://elpa.gnu.org/packages/python.html * `pyvenv` has support in github as of Sept 2019. Looking at the source it defaults to virtualenv and python, rather than python3 - and this doesn't look to be configurable - so virtualenv must not be on the PATH and python3 must be set interactively to use venv otherwise it will default to calling python(2) on most setups. Still this is perfectly usable. See commit here https://github.com/jorgenschaefer/pyvenv/commit/392e28dad42dc6cc9507e496391a32482f9f1881 * `virtualenvwrapper` doesn't support and seemingly cannot be spoofed into using venv. There is a setting to set the name of the executable but it doesn't allow for setting of parameters. If you create a wrapper script or alias, this doesn't work on Debian based system at least, due to lack of support for ensurepip. I've raised a ticket here, but the wider underlying problem is with Debian not the emacs package: https://github.com/porterjamesj/virtualenvwrapper.el/issues/78 * `anaconda-mode` has basic support from the underlying `pythonic` package. It's basically a wrapper on the core emacs support so should work fine with venv. The wrapper seems to handle TRAMP references to venvs for working with remote virtual environments as well as local ones. I haven't tested this - see https://github.com/pythonic-emacs/anaconda-mode#virtual-environment There are various other projects on github, none of which looked actively maintained and all supporting virtualenv only. For completeness the package bundle `elpy`, uses `pyvenv`, so should inherit support too - see https://elpy.readthedocs.io/en/latest/concepts.html#virtual-envs --- Tags: python, virtualenv ---
thread-58069
https://emacs.stackexchange.com/questions/58069
rust-analyzer completion broken
2020-04-26T13:30:44.897
# Question Title: rust-analyzer completion broken When I try to use auto-completion with `lsp` \+ `rust-analyzer`, all functions inserted like that: ``` shared_state.clone_from(${1:source})$0 ``` I cannot find any way to disable this "arguments". I don't even understand what package is inserting this (I use `prelude` bundle + `company`). Replacing `rust-analyzer` with `rls` as language server helps, at least it looks like: ``` shared_state.clone_from ``` when I hit "Enter", which is better, cuz I don't need to remove anything. Any advise or help would be much appreciated, thx. ## Update 1 Okay, I looked at `lsp` log, and seems like this `(${1:source})$0` is raw response from `rust-analyzer`. So now I need to think a way to convert this representation to something, what, I suppose `company`, will be able to use. # Answer > 1 votes Okay, seems like I missed part that `yasnippet` should be enabled. `yas-minor-mode` fixed it. --- Tags: lsp-mode, rust ---
thread-58072
https://emacs.stackexchange.com/questions/58072
How to describe-mode (but not the current major mode)?
2020-04-26T15:30:37.023
# Question Title: How to describe-mode (but not the current major mode)? I know that `describe-mode` will describe the *current* major mode. Is it possible to describe a mode, and I will input the mode name? # Answer Use `describe-function` by typing `C-h f` and, when asked for the function, type the name of the mode which is itself a function. > 3 votes # Answer You can call `describe-minor-mode` to get help on any minor mode. It prompts you to enter either a symbol or an indicator from your mode line, and gives you the help for that mode. I don't think that there's anying similar for major modes. > 1 votes --- Tags: major-mode, help ---
thread-58064
https://emacs.stackexchange.com/questions/58064
Why are the company-mode's drop downs ragged?
2020-04-26T05:26:22.843
# Question Title: Why are the company-mode's drop downs ragged? Here is how my company-mode's drop-downs look, As you can tell, they are uneven, ugly and somehow a different font than what my Emacs is using (Iosevka). I found this question, but did not quite understand the answer. It was also asked back in 2015 so maybe there is a better answer now? My emacs is `GNU Emacs 26.3 (build 2, x86_64-pc-linux-gnu, GTK+ Version 3.22.30) of 2019-09-16` and company-mode is at `20200324.2145`. I am using doom-theme atom one. I want the drop downs to look like they do in the screenshots present on the company-mode's website. Is there a way to achieve this? I looked for configs pertaining to the company's drop downs but could not find anything. Is this a font issue? If so, could I just use a different font for company's drop downs (something that is not uneven), which font? Any recommendations? Maybe set it using use-package's custom face attribute? Is there anything else I am missing or is there an easier solution? # Answer Looks like you are using a variable-width font, not a fixed-width font, for those menu items. Find out which Emacs face is used for Company menu items, and change its font to a fixed-width font by using `M-x customize-face`. I don't use Company, but a quick look at `company-template.el`, which is where its faces are defined, suggests that maybe the face you need to customize is `company-tooltip`. Try: ``` ;; company (use-package company :ensure t :custom-face (company-tooltip ((t (:family "Iosevka"))))) ``` > 2 votes --- Tags: fonts, company-mode, company ---
thread-58081
https://emacs.stackexchange.com/questions/58081
Org mode HTML export presets
2020-04-26T19:24:27.230
# Question Title: Org mode HTML export presets When I export something with org mode to html, with it comes a load of presets such as id, labels, classes, preambles and post ambles. For example: `<div id="outline-container-org16cf335" class="outline-2">` I would like to remove all of this or to at least be able to edit its patterns. I know I can set it to use the `:CUSTOM-ID:` property instead of the normal cacophony of spontaneously generated ids, but what I would really like is to either remove this automatic id setting or to edit the pattern used by it, but I couldn't manage to find this information yet. # edit: I have found the `ox-slimhtml` package which greatly satisfies this need. # Answer This solved my problem: http://bald.cat/slimhtml I hope this can also be of use to others. It allows one to define classes and ids etc while still in the org buffer. > 1 votes --- Tags: org-mode, org-export, html, template ---
thread-57514
https://emacs.stackexchange.com/questions/57514
Emacs on Windows sets DISPLAY to w32
2020-04-01T14:02:45.127
# Question Title: Emacs on Windows sets DISPLAY to w32 I stumbled upon the fact that Emacs on Windows sets the environment variable `DISPLAY` to `w32` (if the variable is not already set). This causes problems for example with OpenSSH. What is the use case for setting DISPLAY? Something within Emacs or is it meant for external applications only? Is there an example app that behaves differently? Can I safely delete the environment variable? (I know I can do this with `(setenv "DISPLAY")`). Note: I use native Emacs build emacs-27.0.50-snapshot-2019-09-18-x86\_64 # Answer I had very similar problems. I ended up leaving the `DISPLAY` variable at w32. In my user environment I set `GIT_SSH=C:\Windows\System32\OpenSSH\ssh.exe`. In Emacs `~/.emacs` I unset that: `(setenv "GIT_SSH")`. I don't know why it works, now I can `ssh-add` from a cmd prompt and vscode works with the agent, and magit works with the agent. I did not specify an sshCommand in `~/.gitconfig`. > 0 votes --- Tags: microsoft-windows, environment ---
thread-58085
https://emacs.stackexchange.com/questions/58085
How to call xref-find-definitions without being prompted?
2020-04-26T22:48:21.353
# Question Title: How to call xref-find-definitions without being prompted? Is it possible to call `xref-find-definitions` to find the definition at the current point without being prompted to select the default? I'd like to bind this to a key, so it immediately jumps to a definition. Currently it's prompting to select the default. This command is prompting me for input every time: ``` (call-interactively 'xref-find-definitions) ``` # Answer > 2 votes The question is unclear. What identifier do you want it to find the definition of? By default it uses the identifier at point - and it doesn't prompt you. If there's no identifier at point, it prompts you. (To be more precise, it depends on the current command. If `(xref--prompt-p this-command)` returns non-`nil` then it will also prompt you, even if there's an identifier at point. But `(xref--prompt-p 'xref-find-definitions)` returns `nil`.) If you're being prompted, and you think there's an identifier at point, then provide a step-by-step recipe to repro, starting from `emacs -Q` (no init file). --- This is the sexp that's apparently prompting you: ``` (xref--read-identifier "Find definitions of: ") ``` And this is the definition of that function: ``` (defun xref--read-identifier (prompt) "Return the identifier at point or read it from the minibuffer." (let* ((backend (xref-find-backend)) (id (xref-backend-identifier-at-point backend))) (cond ((or current-prefix-arg (not id) (xref--prompt-p this-command)) (completing-read (if id (format "%s (default %s): " (substring prompt 0 (string-match "[ :]+\\'" prompt)) id) prompt) (xref-backend-identifier-completion-table backend) nil nil nil 'xref--read-identifier-history id)) (t id)))) ``` You can see that it shouldn't prompt, in the conditions I described. You can also use `M-x debug-on-entry xref--read-identifier` to see exactly why it's prompting you, if it is. --- Tags: interactive, xref ---
thread-58076
https://emacs.stackexchange.com/questions/58076
Add-advice :before org-edit-special
2020-04-26T17:07:23.723
# Question Title: Add-advice :before org-edit-special I want to advise `org-edit-special` so that a function runs before Emacs enters `org-src-mode`. I am not particularly tied to `org-edit-special`. If there is a hook like `org-src-mode-hook` (but that triggers before `org-src-mode` runs, that would be perfect. So I have the following code: ``` #+BEGIN_SRC emacs-lisp (defun my-function () (message "bingo!")) (add-function :before (org-edit-special) #'(lambda () (my-function))) #+END_SRC ``` When I `C-c C-c` this block, I get `user-error: No special environment to edit here`. Can you see the mistake? # Answer > 1 votes You port the `defadvice` approach from your own answer to nadvice.el like so: ``` #+BEGIN_SRC emacs-lisp (define-advice org-edit-special (:before (&optional arg) my-big-advice) (message "bingo!")) #+END_SRC ``` `define-advice` is largely analogous to the older `defadvice`. # Answer > 0 votes I figured it out. Here is the correct form: ``` #+BEGIN_SRC emacs-lisp (defun my-function () (message "bingo!")) (defadvice org-edit-special (before my-big-advice activate) (my-function)) #+END_SRC ``` And here is a good tutorial on advising functions for anyone else who runs into this. Looking at our revised code from left-to-right: `defadvice` is self-explanatory. `org-edit-special` is the function we are advising. `before` means we want our advice to happen first. `my-big-advice` is the name of our advice (we could have called this `foo-bar` if we wanted). And `activate` tells Emacs to make this work now. --- Tags: org-mode, org-babel, advice ---
thread-58087
https://emacs.stackexchange.com/questions/58087
How to align operands in c++-mode?
2020-04-27T02:31:34.423
# Question Title: How to align operands in c++-mode? I'm trying to get Emacs to align operands vertically. ### Current behaviour ``` #include <iostream> void main() { std::cout << 1 + 2 + 3; return 1 + 2 + 3; } ``` ### Wanted behaviour ``` #include <iostream> void main() { std::cout << 1 + 2 + 3; return 1 + 2 + 3; } ``` My research so far suggests that I probably want to add something to `align-rules-list`, but I can't figure out what. `c-show-syntactic-information` on the continued line returns: > Syntactic analysis: ((statement-cont 76)) ### Update I've found out that I probably can solve my problem with `c-offsets-alist`. The following snippet lines up assignments, strings and cascaded calls correctly, but it doesn't work for streams and `return`. ``` (setq c-offsets-alist '((statement-cont . (c-lineup-assignments c-lineup-math c-lineup-string-cont c-lineup-cascaded-calls +)))) ``` # Answer > 0 votes You can try to adapt the output of ``` c-guess-view ``` It will give you something like: ``` (c-add-style "STYLE NAME HERE" '("gnu" (c-basic-offset . 7) ; Guessed value (c-offsets-alist (defun-block-intro . 4) ; Guessed value (defun-close . 0) ; Guessed value (defun-open . 0) ; Guessed value (statement . 0) ; Guessed value (statement-cont . +) ; Guessed value (topmost-intro . 0) ; Guessed value (access-label . -) ...... ``` Change the guessed value as you wish, and execute the function. --- Tags: c++, align ---
thread-58018
https://emacs.stackexchange.com/questions/58018
How to hide "code actions" from lsp-ui sidebar?
2020-04-24T06:58:02.113
# Question Title: How to hide "code actions" from lsp-ui sidebar? Hi, I want to hide "code actions" which is recommended by lsp-mode from lsp-ui sidebar. How can I do for that? # Answer You can try to set the variable lsp-ui-sideline-show-code-actions to nil ``` (setq lsp-ui-sideline-show-code-actions nil) ``` > 0 votes --- Tags: lsp-mode, lsp-ui ---
thread-58097
https://emacs.stackexchange.com/questions/58097
How to enable python-pylint for the all files by default?
2020-04-27T14:38:45.690
# Question Title: How to enable python-pylint for the all files by default? I can enable `python-pylint` for a opened Python file doing: `M-x flycheck-select-checker` and enter `python-pylint` It think it says `C-c ! s` to enable it on all Python files.(the message hides itself so I couldn't read it). --- =\> Is it possible to do this in `.emacs` for all the Python files by default? My setup: ``` (require 'flycheck) (require 'flycheck-mypy) (add-hook 'python-mode-hook 'flycheck-mode) ;(add-hook 'after-init-hook #'global-flycheck-mode) (add-hook 'python-mode-hook (lambda () (setq flycheck-python-pylint-executable "~/venv/bin/pylint") (setq flycheck-pylintrc "~/.pylintrc"))) ``` # Answer > 0 votes Adding following line solved my problem: `(flycheck-add-next-checker 'python-flake8 'python-pylint)` > `defun flycheck-add-next-checker` checker next & optional append Set next to run after checker. Both arguments are syntax checker symbols. link: https://www.flycheck.org/en/latest/user/syntax-checkers.html (on bottom of the page). --- Tags: python, flycheck ---
thread-58068
https://emacs.stackexchange.com/questions/58068
Emacs keeps overwriting files in Haskell mode
2020-04-26T12:34:28.223
# Question Title: Emacs keeps overwriting files in Haskell mode I'm using emacs: ``` GNU Emacs 26.3 Copyright (C) 2019 Free Software Foundation, Inc. GNU Emacs comes with ABSOLUTELY NO WARRANTY. You may redistribute copies of GNU Emacs under the terms of the GNU General Public License. For more information about these matters, see the file named COPYING. ``` And I seem to be seeing a particularly strange problem: emacs, in `haskell-mode` keeps writing to the file repeatedly after each keystroke (also at times after a few keystrokes). I've read online that some of the common tips to debug issues like these, and to identify the culprit *mode*, one must selectively disable modes one by one and see which one is causing this. However, I was wondering if there was a better and less ad-hoc way for going about this: setting breakpoints. I've tried to set debug points on `save-buffer`, `write-file`, and `save-some-buffers`, but this file-write operation doesn't seem to hit those breakpoints. Are there more functions in elisp that deal with writing to files? If so, which ones? And is my technique in trying to identify the culprit sound? Or is setting breakpoints not the ideal way of going about this? Thanks. --- Edit: similar issue. # Answer > 1 votes In my case, and in case anyone else using `dante` stumbles on this: this seems to be a *feature* of Dante for typechecking to work. And this was removed in favour of using temp. files as discussed in this issue. The resolution, in my case, was to upgrade `dante` from 1.5 -\> 1.6, which doesn't have this issue. You'd want to watch out if you are a heavy user of Indirect buffers, though. --- Tags: evil, haskell-mode ---
thread-58104
https://emacs.stackexchange.com/questions/58104
setq in init file not overriding the default for indent-tabs-mode
2020-04-27T18:47:35.413
# Question Title: setq in init file not overriding the default for indent-tabs-mode It works when using `setq-default` in place of `setq` or when customizing through `C-h v`. `C-h v` reports that it is set in 'C source code'. I was thinking it might be affected by my `c-default-style`, but my `setq` appears after it: ``` (setq c-default-style '((c-mode . "stroustrup") (other . "stroustrup"))) ... (setq indent-tabs-mode nil) ``` I have made sure I am not using smart tabs or any other tab settings. My understanding of setq: 1. Creates and sets the local variable if not present. 2. Sets local variable if present. 3. Does not affect default. My understanding of setq-default: 1. If local variable is present only the default is affected. 2. If no local variable present default and local are set. With this understanding in mind and assuming the local variable takes precedence, why would changing the default value have an effect, but not changing the local value? # Answer > 1 votes You ask, *"assuming the local variable takes precedence, why would changing the default value have an effect, but not changing the local value?"* If you use `setq` in your init file, and if the variable is buffer-local in the buffer that is current when your init file is evaluated, then only the value in that buffer gets set. Probably the problem is that the buffer you expect to be current is not current when that expression is evaluated. `C-h v indent-tabs-mode` tells you this: > Automatically becomes buffer-local when set. That means that it is buffer-local, always. And that means that if you want to set the default value for all buffers then you need to use `setq-default`. After setting that default value, you can use `setq` in any given buffer to set its value to something else. --- Tags: indentation, buffer-local, default, setq ---
thread-58108
https://emacs.stackexchange.com/questions/58108
How to insert a piece of text in a new buffer?
2020-04-27T21:08:41.560
# Question Title: How to insert a piece of text in a new buffer? I have the following code: <pre><code> (defconst cljs-test-report-buffer "*cljs-test-report*" "Buffer name in which to display test reports.") (defun cider-test-show-report () "Show the test report buffer, if one exists." (interactive) (if-let* ((report-buffer (get-buffer cljs-test-report-buffer))) (switch-to-buffer report-buffer) (message "No test report buffer"))) (defun run-cljs-test-in-ns () (interactive) (cider-interactive-eval "(cljs.test/run-tests)")) ;; want to show this result in the ```cljs-test-report-buffer``` </code></pre> And I want to show the result of the `run-cljs-test-in-ns` function in a new buffer, that is cleared every time this function is run. How can I do that? # Answer > 2 votes You can use this, in place of just `(run-cljs-test-in-ns)`: ``` (pp-display-expression (run-cljs-test-in-ns) cljs-test-report-buffer) ``` That assumes that whatever function `run-cljs-test-in-ns` returns is what you want to show, and the value of `cljs-test-report-buffer` is the buffer or name of the buffer where you want to show it. --- Tags: buffers ---
thread-57907
https://emacs.stackexchange.com/questions/57907
Set ESS working directory from header-args with org-babel sessions
2020-04-19T14:23:33.873
# Question Title: Set ESS working directory from header-args with org-babel sessions I am experiencing a very strange behavior with org-babel code blocks. When I operate without the `:session` tag, I am free to use `:dir` to set my working directory. As you can see, the following code runs as expected: but if I now add a `:session` argument, babel ignores my `:dir` tag and instead returns my default working directory: What am I doing wrong? # Answer You are doing nothing wrong, but a `:dir` header arg will not affect an existing session. If you kill the existing session and then re-evaluate the source block, the current directory should be the one you specified in the `header-arg` property. > 1 votes # Answer After several days of hacking my way through eLisp, I may have a working solution. The following code automatically sets the working directory of whichever R process is frontmost to match the `:dir` value of whichever `org-babel` R block you are working from. So suppose you manage all of your R projects from a single `studies.org` file, where each header represents a new project. Your `org` file may look something like this: ``` * Study 1 :PROPERTIES: :header-args: :dir ~/org/studies/study_1 :END: #+BEGIN_SRC R :session *R* getwd() #+END_SRC * Study 2 * Study 3 ... * Study n ``` If you are working on a code in Study 1, you don't want your output saved to a project folder for Studies 2 or your data loaded from a csv from Study 3 (which is entirely possible under the default configuration). The following code is intended to do something about this: ``` ;; Get :dir (defun org-header-arg (p) (setq args (org-babel-get-src-block-info)) (assoc-default p (nth 2 args))) ;; Get language of source block (defun get-src-language () (setq args (org-babel-get-src-block-info)) (nth 0 args)) ;; Send message to R process (defun send-msg-r (w) (ess-send-string (get-process "R") (format "setwd(\"%s\")" w))) ;; If point is in an R code block then if R is running: setwd() ;; Else if R is not running, run R and setwd(). (defun setwd-dir () (if (string= (get-src-language) "R") (if (eq (get-process "R") nil) (progn (setq w (org-header-arg :dir)) ;; Capture before R redirects (defadvice R (after set-working-dir-R activate) (send-msg-r w)) (save-excursion (R))) (send-msg-r (org-header-arg :dir))))) ;; Advise org-edit-special (defadvice org-edit-special (before set-working-dir activate) (setwd-dir)) ;; Advise org-babel-execute-src-block (defadvice org-babel-execute-src-block (before set-working-dir-b activate) (setwd-dir)) ``` > 0 votes --- Tags: org-mode, org-babel, ess, r ---
thread-58103
https://emacs.stackexchange.com/questions/58103
Use structured template in numbered list
2020-04-27T16:55:36.530
# Question Title: Use structured template in numbered list Is there any way to include a structured template (`#+Begin/end_SRC`) in the middle of a numbered list without ruining the numbering? Here is a MWE: ``` 1) First question #+begin_quote Quote needed for first question #+end_quote 1) Second question ``` When I try to export it or update the numbering, the second question is assigned number 1. # Answer Yes, that can be done: do not leave more than one empty line and indent the block properly: ``` * Questions 1) First question #+begin_quote Quote needed for first question #+end_quote 1) Second question ``` You can insert the block properly indented by pressing `TAB` which should indent to the right place (under the F in "First question") and then `C-c C-, q` (`q` for `quote`, but any of the choices will do) to insert the template. After you insert the template, you can add the contents - pressing `TAB` at the end should indent the contents properly. Or you can insert the contents properly indented (`TAB` should work - assuming that the option `org-cycle-emulate-tag` is set to `t`, the default - to get the ball rolling: after entering the first line at the right indentation, the rest should indent properly). Then mark the contents as a region and *then* do `C-c C-, q` to wrap the region inside the template. Thanks to @Tobias for the kick to make me get it right (I think and hope it's right, but if there are problems, let me know). > 1 votes # Answer If you are using `org-tempo` you should first indent the line before inserting the template shortcut `<q` for the quote-block. That means if you have the input ``` 1. First question | ``` where the bar `|` stands for the cursor position, type `TAB` to arrive at the indented position as shown in the following code: ``` 1. First question | ``` then input the structure template `<q`: ``` 1. First question <q| ``` Now, press `TAB` for template expansion and you get: ``` 1. first #+BEGIN_QUOTE | #+END_QUOTE ``` When you place the cursor behind `#+END_QUOTE` and press `M-<RET>` you get the next item with number 2: ``` 1. first #+BEGIN_QUOTE #+END_QUOTE 2. | ``` That already indicates that the numbering is fine. Note that I just corrected org-structtempl.el to obtain a similar behavior with that package. (`org-structtempl.el` gives the old structure template behavior back in Org \> 9.2 and adds some more features, e.g. expansion of LaTeX environments through key `<m`). > 2 votes --- Tags: org-mode, org-export ---
thread-57946
https://emacs.stackexchange.com/questions/57946
Send a single raw keystroke to ansi-term
2020-04-21T03:08:00.177
# Question Title: Send a single raw keystroke to ansi-term Occasionally, I want to send a keystroke to a program in my `ansi-term` buffer that is already mapped to something in emacs. I know that for one I use often I could change my configuration to always send it, but in this case I just need a one-off. Is there any way I can set some key combination to "send the next key as raw" ? # Answer > 1 votes This worked: ``` (defun singpolyma/term-insert-literal (key) "Take a keypress and insert it literally into a terminal." (interactive "cPress key:") (term-send-raw-string (format "%c" key)) ) (add-hook 'term-mode-hook (lambda () (define-key evil-insert-state-map (kbd "C-`") 'singpolyma/term-insert-literal) ) ``` --- Tags: spacemacs, ansi-term ---
thread-58113
https://emacs.stackexchange.com/questions/58113
Working Around the OS X Catalina Conflict with Emacs 26.3
2020-04-28T00:33:05.073
# Question Title: Working Around the OS X Catalina Conflict with Emacs 26.3 I'm struggling to workaround the problem discussed in this post. I'm working through the accepted solution (which also references this post, and getting what I *think* is close, but not quite there. The steps I'm taking—-just to try to recap my integration of multiple SO posts--are: Putting the following script into a file called `emacs_catalina_wrapper`, which now resides in my Laptop-level `Applications` folder (i.e. *not* my user-level `Applications` folder). That script (shell set to `/bin/bash`, which is what I'm using in Terminal) is exactly: ``` if ! pgrep Emacs; then open -a Emacs.app sleep 1 fi for f in "$@" do /usr/local/bin/emacsclient -cn -d localhost:0 "$f" done ``` (I added `-d localhost:0` because I was otherwise getting the error discussed here.) I then run the following from terminal: ``` MyMac:bin$open -a /Applications/emacs_catalina_wrapper.app my_python_script.py ``` Whether or not Emacs is already running, that brings up a *blank* window (which *appears* to bear the name of that script, but contains none of its text -- my\_python\_script.py is not new...it's an existing script I'm looking to *edit*, not create). my\_python\_script.py lives in the directory I'm running this from, btw. What am I missing? I'm not even sure what additional information to add here to help you help me! # Answer OK, whelp, this got me around that, and was a lot less work too! > 0 votes --- Tags: python, osx, emacsclient, bash ---
thread-57901
https://emacs.stackexchange.com/questions/57901
How change directory only in one window
2020-04-19T09:20:13.367
# Question Title: How change directory only in one window Emacs 26.1, Dired+ 1. Open some folder in dired mode. 2. Split buffer by `M-4 (split-window-vertically)` 3. Now I want to open `src` folder but **only in TOP WINDOW**. The bottom window must not be change. I press `Enter` in top window. But folder `src` open in BOTH windows - top and bottom. # Answer I had this settings ``` (with-eval-after-load "dired" (define-key dired-mode-map (kbd "RET") 'dired-find-alternate-file)) ``` So I removed it and the problem is gone. > 0 votes --- Tags: dired ---
thread-58116
https://emacs.stackexchange.com/questions/58116
Opening files in new frame
2020-04-28T03:19:41.850
# Question Title: Opening files in new frame I'm using a fairly frame-oriented workflow (or trying to). I've run into something strange. If I write this: ``` (defun find-file-existing (filename) "Edit the existing file FILENAME. Like \\[find-file], but only allow a file that exists, and do not allow file names with wildcards." (interactive (nbutlast (find-file-read-args "Find existing file: " t))) (if (and (not (called-interactively-p 'interactive)) (not (file-exists-p filename))) (error "%s does not exist" filename) (find-file-other-frame filename) (current-buffer))) ``` Then commands which use `find-file-existing` do what I want, including running the command directly from `SPC SPC`. If I write this: ``` (defalias 'find-file 'find-file-other-frame) ``` Or this: ``` (defun find-file (filename) (interactive (nbutlast (find-file-read-args "Find file: " t))) (if (and (not (called-interactively-p 'interactive)) nil) (error "%s does not exist" filename) (find-file-other-frame filename) (current-buffer))) ``` Then commands which use `find-file` (including running it from `SPC SPC`) do open the file in a new frame, but *also* change to that buffer in the current frame. I've been over the code quite a bit and tried a few other variants, but the code paths seem almost the same to me (just changing if there is a file-existing check or not) and it's so strange that one does something different than the other. Anyone have any ideas how this could be happening? What should I be looking for? # Answer > 0 votes For one thing, this: ``` (if (and (not (called-interactively-p 'interactive)) nil) ``` always evaluates the first `if` clause after that test, since the test always evaluates to `nil`. That's not what you do in the first example. (Indenting your code properly (conventionally) lets you see this kind of thing more easily.) --- Tags: find-file, conditionals ---
thread-58125
https://emacs.stackexchange.com/questions/58125
call org-html-export-to-html from script failure
2020-04-28T15:34:50.233
# Question Title: call org-html-export-to-html from script failure I can run `org-html-export-to-html` on emacs successfully. but when I try to call it in script as below: ``` #!/usr/bin/emacs --script (require 'org) (defun dired-org-to-html () (let* ((org-root ".") (files (append (let ((default-directory org-root)) (mapcar #'expand-file-name (file-expand-wildcards "**/*.org"))) (let ((default-directory org-root)) (mapcar #'expand-file-name (file-expand-wildcards "*.org"))) ) )) (mapc (lambda (f) (print f) (with-current-buffer (find-file-noselect f) (org-html-export-to-html))) files)) ) (dired-org-to-html) ``` It always say `Symbol's function definition is void: org-html-export-to-html`. # Answer > 2 votes It works fine for me, still, you can try to include the ox-html in the top: ``` #!/usr/bin/emacs --script (require 'org) (require 'ox-html) (defun dired-org-to-html () (let* ((org-root ".") (files (append (let ((default-directory org-root)) (mapcar #'expand-file-name (file-expand-wildcards "**/*.org"))) (let ((default-directory org-root)) (mapcar #'expand-file-name (file-expand-wildcards "*.org"))) ) )) (mapc (lambda (f) (print f) (with-current-buffer (find-file-noselect f) (org-html-export-to-html))) files)) ) (dired-org-to-html) ``` It is the package where the function came from. --- Tags: org-mode ---
thread-55360
https://emacs.stackexchange.com/questions/55360
org: move point to beginning of an item
2020-02-07T14:08:58.583
# Question Title: org: move point to beginning of an item When in org-mode, how to move point to the beginning of the current item? (in similar fashion like `back-to-indentation`) *Example*: Imagine following org buffer content ``` * headline - [ ] Z this is an longer item | (Point) is here. And here is some more text. - [X] it should work with that line too! - and with that one also ``` With point at location `|`, in the middle of that item. .oO(or even at the beginning of that line) How can I easily move point to right before the letter `Z`? I always jump around that location before I finaly hit it (i.e `C-a` `M-f` `M-b` or even `C-a` `M-f` `M-f` `M-b`) this is somewhat cumbersome.. # Answer Consider to customize variable `org-special-ctrl-a/e`. Possibly that will ease your flow. From the documentation. Note in particular the "item" part. > When t, ‘C-a’ will bring back the cursor to the beginning of the headline text, i.e. after the stars and after a possible TODO keyword. In an item, this will be the position after bullet and check-box, if any. When the cursor is already at that position, another ‘C-a’ will bring it to the beginning of the line. You can also consider the other documented values for `org-special-ctrl-a/e`. > 10 votes # Answer The existing answer is correct. I just wanted to add for posterity (and i'm not venerable enough to add comments) that for me and some other users enabling `visual-line-mode` remaps the relevant keys and so prevents `org-special-ctrl-a/e` from having any effect. Remapping `C-a` and `C-e` with something like: ``` (define-key org-mode-map "\C-a" 'org-beginning-of-line) (define-key org-mode-map "\C-e" 'org-end-of-line) ``` or your preferred way of doing it, should get it going though. Found it in this reddit post > 3 votes --- Tags: org-mode, motion ---
thread-58118
https://emacs.stackexchange.com/questions/58118
How can I set the indentation offset for `indent-region`
2020-04-28T08:05:52.633
# Question Title: How can I set the indentation offset for `indent-region` I am using spacemacs + lsp layer (ccls) for c/c++ editing Having my `c-basic-offset` set to 4: * if I select a region and press `=` (maybe invoking `indent-region`?), the region is indented by 2 spaces (messages: `Applying [n] edits to [filename]`). * If I press `=` without selecting a region, it indents with 4 spaces. How can I control the indent level when indenting region? # Answer I am not sure if this'll work, but this is out of my configurations adjusted for what you want. ``` (use-package cc-mode :init (defun my-c-mode-hook() (setq c-basic-offset 4 c-label-offset 0 tab-width 4 indent-tabs-mode nil)) (add-hook 'c-mode-hook 'my-c-mode-hook) (add-hook 'c-mode-hook 'lsp)) ``` > 0 votes --- Tags: spacemacs, lsp-mode, ccls ---
thread-58135
https://emacs.stackexchange.com/questions/58135
Executing code within Org mode `begin_src` ... `end_src` blocks
2020-04-28T20:50:11.927
# Question Title: Executing code within Org mode `begin_src` ... `end_src` blocks How to configure Emacs to run code in different languages as shown in this post? Specifically, how to run these type of code blocks `#+begin_src shell :results list` ? After 9 years of vim, that post inspired me to try Emacs. What attracts me is the ability to run a wide range of code within Emacs. I successfully configured Emacs to run in Evil mode with the keybinding I prefer, but I still have difficulties to find how to make it work as demonstrated in the post. # Answer The example you pointed to (as you probably already know) require a certain amount of configuration, and also require understanding of certain concept in order to figure out what is going on. I'm going to execute a trivial shell code block in an emacs after ensuring that I am not relying on any of my personal emacs configuration Concepts: * Skip emacs configuration: run emacs as "emacs -q bar.org" * Org mode buffer - most emacs configs will auto-assign the editing behaviour for a buffer based on the file extension. So the fact that the file I visit is ends in ".org" is critical. * Org babel - this is the function (which allows execution of an embedded code block) that we are using. The manual is at https://orgmode.org/worg/org-contrib/babel/intro.html#fn.1 Steps: 1. emacs -q bar.org 2. Enable handling of shell blocks by executing a lisp expression: * Type in `(org-babel-do-load-languages 'org-babel-load-languages '((shell . t)))` * Execute this block by type `C-x C-e` or `M-x eval-last-sexp` 3. Add example shell call: `#+begin_src shell :results list ls /etc/pam.d #+end_src` 4. Execute this block. Use the key sequence `C-c C-c` for this. Result: If you are on a linux (or maybe mac), you should see a list of the contents of a directory. > 4 votes # Answer Welcome to emacs! I recommend you to check the official org documentation about the evaluation of code blocks here. So, the thing to use is `org-babel`, to evaluate the source code inside org-mode blocks, babel has a default list of languages that can be used out of the box. If one on the languages is not in there, you can try looking for it in MELPA or in ELPA, for example, the ipython babel is on MELPA. So the quick answer is, define the code blocks and evaluate the buffer with: ``` M-x org-babel-execute-buffer ``` You can do that by typing `C-c C-c` anywhere within the code block. For example: ``` #+BEGIN_SRC sh :results output echo "hi" #+END_SRC #+BEGIN_SRC emacs-lisp :results output (print "hello again") #+END_SRC ``` If the command is successful, there will be a `#+RESULTS:` block with the actual result after the evaluated code block. Good luck! > 2 votes --- Tags: org-mode, org-babel ---
thread-58090
https://emacs.stackexchange.com/questions/58090
In Org mode how to link to a specific line or keyword in a Help or Texinfo page?
2020-04-27T06:52:35.790
# Question Title: In Org mode how to link to a specific line or keyword in a Help or Texinfo page? For example, I want to create a link pointing to line 16 or the start of the first found keyword "binding" in the projectile mode help page (`[[help:projectile-mode]]`). I tried the double colon format dealing with normal files such as `[[help:projectile-mode::16]]` and `[[help:projectile-mode::binding]]` but it doesn't work. # Answer Only `file`-type links are allowed to use the search option `::<N>` currently. The code in `org-link-open` is a bit strange to my eyes: it gets the type of the link and the path of the link. In the `file` case, the path does not contain the search option, but in all other cases it does. But then the file case concatenates the search option onto the path and calls `org-link-open-file` with the result (which must take it apart again and do the search). In all other cases, the path is passed as-is (including the search option), but the helper functions (e.g. `org-link-open-help`) just use the thing literally (and presumably fail: there is no help node `org-mode::14`). I'd imagine that the more uniform solution would be to keep the option separate in all cases, and pass it to the helper function explicitly which could use it or throw it away as it saw fit. But that's not the way it's currently done. > 1 votes # Answer You can advice `org-link--open-help` to move the cursor to the specified line number or search string. The last line highlights the matched line. ``` (advice-add 'org-link--open-help :around (lambda (oldfun path _) (let* ((option (and (string-match "::\\(.*\\)\\'" path) (match-string 1 path))) (path (if (not option) path (substring path 0 (match-beginning 0))))) (apply oldfun (list path nil)) (when-let (help-window (and option (get-buffer-window (help-buffer)))) (save-selected-window (select-window help-window) (if (zerop (string-to-number option)) (re-search-forward option nil t) (forward-line (1- (string-to-number option)))) (org-highlight-new-match (line-beginning-position) (line-end-position))))))) ``` > 0 votes --- Tags: org-mode, org-link ---
thread-58140
https://emacs.stackexchange.com/questions/58140
How do I automatically clock-in for SCHEDULED items with org-capture?
2020-04-29T00:08:00.753
# Question Title: How do I automatically clock-in for SCHEDULED items with org-capture? I would like to setup my org-capture template for meetings so that I get automatically clocked into the meeting header on the day and time of the meeting. So given: ``` * Meeting with client SCHEDULED: <2020-05-01 Fri 09:00-09:30> ``` I would like to be clocked into that issue on Friday morning at 9am. # Answer If you just want to have these meetings reflected in your clock data afterwards for reporting purposes, I don't think you need to actually clock in and out? You can just add the clock data directly: ``` CLOCK: [2020-05-01 Fri 09:00]--[2020-05-01 Fri 09:30] => 0:30 ``` You could come up with a capture template to let you enter the start/end times and put them in both the timestamp and the clock record. Another approach might be a function to scan an org file for meetings and add the clock info, i.e. something you run at the time you want to review the clock data. > 2 votes --- Tags: org-mode, org-agenda, org-capture, org-clock ---
thread-58124
https://emacs.stackexchange.com/questions/58124
why is switch-to-buffer effect not visible immediately when called in a list with other functions?
2020-04-28T14:51:56.683
# Question Title: why is switch-to-buffer effect not visible immediately when called in a list with other functions? I have a key bound to some program which prepares a buffer, switches to it via `switch-to-buffer` and afterwards calls some function which modifies the buffer (and can take a few seconds to execute). When pressing the key, this modifying function is executed **before** the buffer is actually switched (noticeable by a considerable lag), although it appears **after** `switch-to-buffer`. Can somebody please explain why this is the case? Here are full details, although I don't think these are relevant for my problem: I'm using elfeed and have set `elfeed-entry-switch`, which by default is just `#'switch-to-buffer`, to `#'my-elfeed-entry-switch`, where ``` (defun my-elfeed-entry-switch (buffer) (with-current-buffer buffer (switch-to-buffer buffer) (org-latex-preview))) ``` The computationally intensive function therefore is `org-latex-preview`, which renders and displays inline latex code and, like I wrote, sometimes takes several seconds to complete. When trying to switch to an entry which contains a lot of latex code, I have to wait for a second or so before the buffer becomes visible. What I actually expect is that the buffer first becomes visible (with unrendered latex code) and then `org-latex-preview` starts its work, which it does if called interactively. **UPDATE** As suggested below, removing `with-current-buffer` does not solve the problem, i.e. ``` (defun my-elfeed-entry-switch (buffer) (switch-to-buffer buffer) (org-latex-preview)) ``` still does not show the buffer before `org-latex-preview` has finished rendering. # Answer > 2 votes The O.P. has indicated in a comment that inserting `(redisplay t)` following the `switch-to-buffer` call resolves the issue outlined in the question. Another idea would be to use `(sit-for 0)`, which also forces a redisplay by the display engine. The function `redisplay` contains a doc-string that states: ``` redisplay is a built-in function in ‘C source code’. (redisplay &optional FORCE) Perform redisplay. Optional arg FORCE, if non-nil, prevents redisplay from being preempted by arriving input, even if ‘redisplay-dont-pause’ is nil. If ‘redisplay-dont-pause’ is non-nil (the default), redisplay is never preempted by arriving input, so FORCE does nothing. Return t if redisplay was performed, nil if redisplay was preempted immediately by pending input. ``` --- Tags: buffers, elisp-macros ---
thread-58144
https://emacs.stackexchange.com/questions/58144
How can I trace source of "No catch for tag: --cl-block-nil--, t" error when trying to run "rtags-start-process-unless-running"
2020-04-29T03:33:40.577
# Question Title: How can I trace source of "No catch for tag: --cl-block-nil--, t" error when trying to run "rtags-start-process-unless-running" I've just found out a way to add "peek definition" functionality to Emacs by installing rtags. I installed rtags through Emacs, and everything seemed to go fine. However, I've run into some trouble: the basic command of `rtags-start-process-unless-running` to start rtags isn't working. If I try to run it in the minibuffer it just says `No catch for tag: --cl-block-nil--, t` I'm using Linux (Arch), if that has any bearing on the problem. I'm just not sure what I should be looking for with an error like this, because I know very little about Lisp. Any guidance would be much appreciated. Here is the backtrace (Sorry if I'm missing something obvious, but this is one of the first times I've even seen the backtrace to Lisp). ``` Debugger entered--Lisp error: (no-catch --cl-block-nil-- t) throw(--cl-block-nil-- t) rtags-start-process-unless-running() eval((rtags-start-process-unless-running) nil) elisp--eval-last-sexp(nil) eval-last-sexp(nil) funcall-interactively(eval-last-sexp nil) call-interactively(eval-last-sexp nil nil) command-execute(eval-last-sexp) ``` # Answer Looks like its just a bug in RTags (at least when installed through Emacs). The package I had the problem with was installed from melpa-stable, and was Rtags 2.38. I tried installing a version 20200221.38 from melpa instead, and it seems to work now. > 1 votes --- Tags: debugging, rtags ---
thread-58150
https://emacs.stackexchange.com/questions/58150
Is it possible to use Emacs to read mail using IMAP without downloading them?
2020-04-29T08:21:08.300
# Question Title: Is it possible to use Emacs to read mail using IMAP without downloading them? I have found that Emacs + mu4e + offlineimap can deal with reading emails from a remote server. However, in this case, what I understand is that the emails are copied locally. Having mailboxes with lots of messages I do not want them to use hard disk space. Did I misunderstand the way offlineimap works or is there another solution to what I want to do ? I am new to Emacs, thanks in advance. # Answer > 0 votes If you are open to using something other than `mu4e` you can use `gnus` to read email via IMAP without storing messages locally. Searching can be a little slow, for me taking one or two seconds on folders with several thousand entries, but that's acceptable to me. Be warned that the learning curve for `gnus` is fairly steep. --- Tags: mu4e, email, remote, imap ---
thread-58129
https://emacs.stackexchange.com/questions/58129
How to use faces to enhance text
2020-04-28T17:45:56.413
# Question Title: How to use faces to enhance text I'm writing some very simple code to get data from a web api, i then parse the response and output the result in a buffer. By default this text is very flat, how can i add keyword highlighting that follows the current theme's colourscheme? For example, the text in the buffer: Title * Keyword1: data1 * Keyword2: data2 How can i define, and most importantly apply faces(i think) to the keywords? # Answer You have to use the `propertize` method for that. For exemple, in your case, to use the `font-lock-builtin-face` on the `Keyword` words, you can do: ``` (save-excursion (goto-char (point-min)) (while (re-search-forward "^Keyword[0-9]:" nil t) (replace-match (propertize (match-string 0) 'face 'font-lock-builtin-face)))) ``` > 1 votes --- Tags: faces, font-lock ---
thread-58153
https://emacs.stackexchange.com/questions/58153
Why does flycheck open a new buffer for error messages?
2020-04-29T09:02:48.450
# Question Title: Why does flycheck open a new buffer for error messages? So I am using flycheck for my C++ projects with this setup: ``` ;; Require flycheck to be present (require 'flycheck) ;; Force flycheck to always use c++11 support. We use ;; the clang language backend so this is set to clang (add-hook 'c++-mode-hook (lambda () (setq flycheck-clang-language-standard "c++14"))) ;; Turn flycheck on everywhere (global-flycheck-mode) ;; Use flycheck-pyflakes for python. Seems to work a little better. (require 'flycheck-pyflakes) ``` And integrate it into irony like so: ``` (eval-after-load 'flycheck '(add-hook 'flycheck-mode-hook #'flycheck-irony-setup)) ``` Now when my irony setup is off and several includes cannot be found, flycheck will open a new buffer after a short delay and that buffer is full of error messages. That buffer then steals the focus. This is annoying and I wonder how I can get rid of that behavior without cancelling my irony experiments. First of all, who is responsible in such a case? Flycheck or irony? Second, how does one debug such an issue? I am using prelude and all packages are installed from melpa if that matters. # Answer > 4 votes I recently experienced the same problem while editing Haskell and Typescript code, so I don't think irony-mode is at fault here. According to the documentation, I understand this is an expected behavior : > By default Flycheck shows the error messages in the minibuffer *or in a separate buffer if the minibuffer is too small to hold the whole error* message but this behaviour is entirely customisable: https://www.flycheck.org/en/latest/user/error-interaction.html#display-errors This can be handled with the `flycheck-display-errors-function`. Flycheck provides two built-ins function to handle how the error messages will be displayed. They both use display-message-or-buffer internally, which pops a new buffer if the error message to display is too big. From there I see two possible solution : * Disable the display of error messages completely with `(setq flycheck-display-errors-function nil)`, and rely on the error message list (`C-! l`) or the mouse tooltip if you use Emacs in GUI mode. * Provide a custom function to `flycheck-display-errors-function`. I'm not a lisper, but I cobbled one together based on the builtin `flycheck-display-error-messages`. Here it is, with the relevant Flycheck setting : ``` (defun flycheck-display-error-messages-truncated (errors) (when (and errors (flycheck-may-use-echo-area-p)) (let ((messages (seq-map #'flycheck-error-format-message-and-id errors))) (message (string-join messages "\n\n") ;; here is the relevant modification flycheck-error-message-buffer) ;; We cannot rely on `display-message-or-buffer' returning the right ;; window. See URL `https://github.com/flycheck/flycheck/issues/1643'. (-when-let ((buf (get-buffer flycheck-error-message-buffer))) (with-current-buffer buf (unless (derived-mode-p 'flycheck-error-message-mode) (flycheck-error-message-mode))))))) (use-package flycheck :ensure t :init (global-flycheck-mode) :config (setq flycheck-check-syntax-automatically '(save)) (setq flycheck-display-errors-function #'flycheck-display-error-messages-truncated)) ``` This works for me for now but again, this is a quick hack and might not handle well some corner cases. The message is only displayed in the echo area, and if I really want to see it in is entirety I'll switch to the error message list. # Answer > 0 votes It would be intersting if you can give us the « new buffer » content or at least its name. Without that, we can only do some basic guessing and it won't be very efficient. To improve error output, you can try `M-x toggle-debug-on-error` which will open a specific buffer with an error stack trace if there is an error. It will help us to find the source of the problem. However, my guess here, is that `flycheck-irony-setup` belongs to flycheck-irony, which may not be started in your config. I would try the following config in your case: ``` ;; Require flycheck to be present ;; if you install flycheck with package, you don't need that line. See bellow why. ;; But it's not wrong to keep it either. (require 'flycheck) (with-eval-after-load 'flycheck (require 'flycheck-irony) (add-hook 'flycheck-mode-hook #'flycheck-irony-setup) ;; Force flycheck to always use c++11 support. We use ;; the clang language backend so this is set to clang (setq flycheck-clang-language-standard "c++14") ;; Use flycheck-pyflakes for python. Seems to work a little better. (require 'flycheck-pyflakes)) ;; Turn flycheck on everywhere ;; No need to explicitly require flycheck as the following function auto-load it. (global-flycheck-mode) ``` --- Tags: flycheck, c++, irony-mode ---
thread-57723
https://emacs.stackexchange.com/questions/57723
Shrink frames in beamer export from orgmode
2020-04-10T20:02:10.910
# Question Title: Shrink frames in beamer export from orgmode How can I send a shrink option to a beamer frame? I already tried with ``` *** frame title :PROPERTIES: :BEAMER_envargs: [shrink=5] :END: ``` as suggested in https://lists.gnu.org/archive/html/emacs-orgmode/2011-01/msg00078.html, but it didn't work. # Answer It should be `BEAMER_opt`, not `BEAMER_envargs`. > 1 votes --- Tags: org-mode, latex, beamer ---
thread-58119
https://emacs.stackexchange.com/questions/58119
Org-mode tables exported as latex arrays within eqnarray environment, how?
2020-04-28T09:26:24.153
# Question Title: Org-mode tables exported as latex arrays within eqnarray environment, how? If I have constructed a blocked array using an org-mode table, I can easily export the table as, e.g., a pmatrix array as presented below. However, the pmatrix is exported within a math environment (\\\[..\\\]). How can I change that to, e.g., an eqnarray environment in order to attach an equation reference? So, I have this code: ``` #+ATTR_LATEX: :environment pmatrix :mode math :math-prefix N= :math-suffix , | A | B | | B^T | D | ``` which is exported to ``` \[ N=\begin{pmatrix} A & B \\ B^T & D \\ \end{pmatrix}, \] ``` I wish to replace the \\\[..\\\] by eqnarray, i.e., produce ``` \begin{eqnarray} N=\begin{pmatrix} A & B \\ B^T & D \\ \end{pmatrix},\label{eq:normal} \end{eqnarray} ``` Is this possible using org-mode options or do I have to re-write the back-end? If so, where in the back-end should I start? # Answer I have found a work-around in the following: ``` \refstepcounter{equation} #+ATTR_LATEX: :environment pmatrix :mode math :math-prefix N= :math-suffix ,\tag{\theequation}\label{eq:blocks} | A | B | | B^T | D | ``` It is however a kludge and gives a different vertical spacing as around an `eqnarray`. Another version that moves all reference stuff into the `#+ATTR_LATEX` block is ``` #+ATTR_LATEX: :environment pmatrix :mode math :math-prefix \refstepcounter{equation}N= :math-suffix ,\tag{\theequation}\label{eq:blocks} | A | B | | B^T | D | ``` However, it does not solve the original problem. > 1 votes --- Tags: org-export, latex, org-table ---
thread-58162
https://emacs.stackexchange.com/questions/58162
Multiple citations with just one pair of braces
2020-04-29T13:34:08.217
# Question Title: Multiple citations with just one pair of braces I want to have multiple citations appear in my exported PDF as below: ``` some well-studied fact [12, 13, 20] blah blah ``` But the only way I know to do this is by using inline latex: ``` some well-studied fact \cite{foo2002, bar1997, baz2019} ``` Is there a way to achieve the same result using the more "org" style citation: ``` some well-studied fact [cite:foo2002, cite:bar1997, cite:baz2019] ``` Note: the above results in this export: ``` some well-studied fact [[1], [2], [3]] ``` ...which I don't want. # Answer Try ``` some well-studied fact [[cite:foo2002,bar1997,baz2019]] ``` That is, mulitple cite labels within a single org link. Note the double \[\[...\]\] although if you simply type cite:xxx it should make it an org link automatically. > 1 votes --- Tags: org-mode, org-ref ---
thread-58166
https://emacs.stackexchange.com/questions/58166
Get org-agenda toggle all agenda and todo below frame (similar to ivy list buffer)
2020-04-29T17:43:00.610
# Question Title: Get org-agenda toggle all agenda and todo below frame (similar to ivy list buffer) I have this function: ``` (defun org-agenda-show-agenda-and-todo (&optional arg) (interactive "p") (org-agenda arg "n")) ``` When calls, it will toggle a window with all of my current agenda and todo, like the pic below: As you can see, it defaults to open a new window in a new vertical split. If i want to close this window, I can just press `q`. The problem comes when I'm already working with 2 windows, like this: ``` | windows 1 | windows 2 | | | | ``` If I call the same function, the org agenda and todo window would occupy `window 2`. So, like this: ``` | windows 1 | org-agenda list | | | | ``` When I press `q`, the org-agenda list window would close, and so does my `window 2` split. In other words, I am left with a single window with only `window 1`. Is there a way or an alternative to show all of my agenda and list without disrupting the current layout of my windows arrangement? I am thinking of something similar to ivy list bookmark, which you can see in the pic below: Here, I can peek at my bookmark and just choose which one I want. If I want to stop peeking, I press `Esc` and it goes away and my window arrangement is kept. # Answer Define a function similar to the one that you want, but save the current frame configuration in some variable: ``` (defvar my-pre-agenda-frame-configuration nil) (defun org-agenda-show-agenda-and-todo (&optional arg) (interactive "p") (setq my-pre-agenda-frame-configuration (current-frame-configuration)) (org-agenda arg "n")) ``` Then define a modified function to quit the agenda that restores the saved frame configuration if it is non-nil: ``` (defun my-org-agenda-quit () (interactive) (org-agenda-quit) (if my-pre-agenda-frame-configuration (set-frame-configuration my-pre-agenda-frame-configuration)) (setq my-pre-agenda-frame-configuration nil)) ``` Finally, bind the modified agenda-quit function to `q` in the agenda keymap: ``` (define-key org-agenda-keymap "q" 'my-org-agenda-quit) ``` If you use `Q` to exit the agenda as well, you might want to redefine that function and rebind the key as well. EDIT: in response to the comment, can you reproduce that behavior starting with `emacs -q -l minimal.el` with the file minimal.el containing ``` (load "org-agenda") ``` and the code above? If that works, there is something wrong with your init file: you will have to debug that, since I certainly cannot. If that does not work, then I'm not sure what the problem could be: the above works perfectly in my experiments. The code above only modifies the binding of `q` in the keymap that org-agenda uses. In all other modes, `q` is unchanged. So if you open a text file (e.g. in fundamental mode, or some text mode including org-mode), and you do `C-h c q` it should say that `q runs the command self-insert-command` (or `org-self-insert-command` if the mode is org-mode). But if you do the same thing in the agenda buffer, it should say `q runs the command my-org-agenda-quit`. > 1 votes --- Tags: org-agenda, window-splitting, window-configuration ---
thread-58169
https://emacs.stackexchange.com/questions/58169
`magit-tag-release` error: "Invalid version syntax: '0.7-5'"
2020-04-29T18:37:06.540
# Question Title: `magit-tag-release` error: "Invalid version syntax: '0.7-5'" I'm unable to tag releases with current Magit from Elpa. Doing: t RET r (`magit-tag-release`) I immediately get the error message: "Invalid version syntax: '0.7-5'" in the minibuffer. This happens either from the magit-log buffer or the main magit buffer. Below is partial output from `git tag`: ``` release-0.7-5 release-0.7-6 release-0.7-7 release-0.7-8 release-0.7-9 ``` which shows the naming pattern of my release tags. Any pointers welcome. # Answer That's due to a recent regression, introduced by pull-request #4075). At the bottom d27d6e4678 is mentioned, which fixes this. > 1 votes --- Tags: magit ---
thread-58117
https://emacs.stackexchange.com/questions/58117
stop stripping result of :session for python print statement
2020-04-28T06:36:05.213
# Question Title: stop stripping result of :session for python print statement Since default value for `:result` header is **value** print statement will only show with `:result output` ``` #+BEGIN_SRC python :results output print(' hello') #+END_SRC #+RESULTS: : hello ``` but same thing in session is trimming *whitespace* trailing and preciding like python `str.strip()` method. ``` #+BEGIN_SRC python :results output :session test print(' hello') #+END_SRC #+RESULTS: : hello ``` according to manual in Results-of-Evaluation **verbatim** which should Interpret literally seem only to work with **value** as stated in manual's usage example: ‘:results value verbatim’ will not show output of print. How to stop the output being trimmed in session. ``` #+BEGIN_SRC python :results value verbatim :session test print(' hello') #+END_SRC #+RESULTS: ``` # Answer > 3 votes Editorial comment: Session handling (at least with python) is very much a hack: there are markers inserted to signal where the current output ends, the code has to wait to make sure that all the output has been... ahem ... output, any errors that creep through somehow may be reported as part of the output, etc. That said, you might want to try the following "fix": in the file `ob-python.el`, lines 332ff, you will see a block of code that looks something like this: ``` (mapconcat #'org-trim (butlast (org-babel-comint-with-output (session org-babel-python-eoe-indicator t body) (funcall input-body body) (funcall send-wait) (funcall send-wait) (insert org-babel-python-eoe-indicator) (funcall send-wait)) 2) "\n"))) ``` Try replacing that `org-trim` with `identity` and reloading with `M-x load-file RET ob-python.el RET` (you might want to byte-compile it, but try it before doing so: you might want to beat a hasty retreat first to the original code). There is no warranty, not even implied, on either the original code or the modified code. If you get errors, try deleting the session and starting it up again. If you still get errors, maybe change it back and live with the current problems. # Answer > 1 votes An alternative to NickD's answer is to not use `:session` header to share code between blocks but instead use `:noweb-ref` syntax to combine code blocks. > **How does this literate programming answer even work?** > > * The first three python blocks have the `:noweb-ref my-code` header added. > * The python code from the first three python blocks are combined in top to bottom order and assigned to the noweb reference named `my-code`. > * The fourth python block headers are `:noweb yes :results output` thereby bypassing `org-trim` issue by not using `:session` header. > * When the fourth code block is executed, the `:noweb yes` header tells org-mode to substitute the `«my-code»` string for lines of code named in `my-code` noweb reference and then executes the updated code block. ### Answer * Example code to bypass `org-trim` issue in `ob-python.el` by not using `:session` header but still combining and/or sharing code between seperate code blocks: Save the following code example into an new org-mode file and then close and open the new file in emacs. > **Note:** When you open the new org-mode file, you will be prompted to accept the new values for `org-babel-noweb-wrap-start: "«"; org-babel-noweb-wrap-end: "»";`. Please type `y` to accept new values temporarily. Otherwise the example code will try to use the default values of `<<` and `>>` instead. ``` # -*- mode: org; org-babel-noweb-wrap-start: "«"; org-babel-noweb-wrap-end: "»"; -*- # # To prevent syntax highlighting conflicts with "<<" and ">>" in your source code I recommend setting variables org-babel-noweb-wrap-start to "«" and org-babel-noweb-wrap-end to "»" in your default emacs configuration. # # TIP: To create the "«" character use the key chord C-x 8 < # TIP: To create the "»" character use the key chord C-x 8 > # TIP: Add "-*- mode: org; org-babel-noweb-wrap-start: "«"; org-babel-noweb-wrap-end: "»"; -*-" to top of your org file just in case another user doesn't want to reset their default values. * Learning Python Syntax with Literate Programming in org-mode In your python script do the following: 1. Define a variable named ~the_message~ in python syntax. #+BEGIN_SRC python :noweb-ref my-code the_message=' hello' #+END_SRC 2. Define a function named ~greeting~ which takes a single parameter named ~msg~ and prints the ~msg~ in python syntax. #+BEGIN_SRC python :noweb-ref my-code # # Define greeting function # def greeting(msg): print msg #+END_SRC 3. Call the ~greeting~ function using the ~the_message~ variable in python syntax. #+BEGIN_SRC python :noweb-ref my-code # # Call greeting function # greeting(the_message) #+END_SRC 4. Execute your python script and you should see the following output. #+BEGIN_SRC python :noweb yes :results output «my-code» #+END_SRC #+RESULTS: : hello ``` --- > **The code in this answer was tested using:** > > **emacs version:** GNU Emacs 25.2.1 (x86\_64-unknown-cygwin, GTK+ Version 3.22.10) > **org-mode version:** 9.1.2 > **python version:** 2.7.13 --- Tags: org-mode, org-babel, python ---
thread-47986
https://emacs.stackexchange.com/questions/47986
Jump to org-mode heading from external application
2019-02-22T08:44:44.577
# Question Title: Jump to org-mode heading from external application I want to create a URL that uses `org-id` to jump to its associated heading in Emacs `org-mode`. I tried using: ``` org-protocol://org-id-goto?id=DC6BC674-8CE1-451D-A45F-05E09F1F743D ``` But this only opens Emacs with a blank `*scratch*` window. It does not actually navigate anywhere... am I missing something? Also, I notice that each time I enter this link in my browser, I get a pop-up message, asking if I want to allow "Safari/Firefox/Chrome/Etc." to open Emacs. Is there anyway to disable this message for the future? # Answer > 6 votes I'm doing the same thing as you under the inspiration of Roam Protocol You can't use the built-in `org-id-goto` directly, you have to custom your own org-protocol handler first. Here's the way I do: ``` (add-to-list 'org-protocol-protocol-alist '("org-id" :protocol "org-id" :function org-id-protocol-goto-org-id)) (defun org-id-protocol-goto-org-id (info) "This handler simply goes to the org heading with given id using emacsclient. INFO is an alist containing additional information passed by the protocol URL. It should contain the id key, pointing to the path of the org id. Example protocol string: org-protocol://org-id?id=309A0509-81BE-4D51-87F4-D3F61B79EBA4" (when-let ((id (plist-get info :id))) (org-id-goto id)) nil) ``` Then, if you open link like `org-protocol://org-id?id=309A0509-81BE-4D51-87F4-D3F61B79EBA4` in a web brower, it will jump directly to the heading with id `309A0509-81BE-4D51-87F4-D3F61B79EBA4` in emacs. Also, here's a snippet for getting this kind of org-protocol link from current heading: ``` (defun org-id-protocol-link-copy () (interactive) (org-kill-new (concat "org-protocol://org-id?id=" (org-id-copy)))) ``` --- Tags: org-mode ---
thread-57499
https://emacs.stackexchange.com/questions/57499
What are my largest org mode sections?
2020-03-31T19:03:34.890
# Question Title: What are my largest org mode sections? My .org file is almost 2MB large. How can I narrow down what headers/sub-headers take so much space? # Answer > 2 votes See org-treeusage.el. It was added recently to the MELPA archive. > This library provides a minor mode for peeking at the line or character usage of each heading in an org-mode file with respect to the parent heading, allowing users with large org files to see the distribution of heading content and make informed decisions on where to prune, refile, or archive. # Answer > 0 votes You can use the Python script org-du to produce line counts per section, using the same format as the `du` command line tool. This can then be piped to `xdu` for a graphical display. --- Tags: org-mode ---
thread-58136
https://emacs.stackexchange.com/questions/58136
How can I change the TODO state of a task in a given date?
2020-04-28T21:03:09.210
# Question Title: How can I change the TODO state of a task in a given date? I want to change the TODO state of a task automatically on a give date. I would expect something like this: ``` * FUTU Some task that only becomes actionable of a given date :PROPERTIES: :ACTIONABLE: some-function(<timestamp>, TODO) :END: ``` This block should automatically change the task to a TODO state once the date is reached. Is there a package that can do this? Regards, # Answer > 0 votes I ended up writing a small functions for this purpose ``` (defun j/org-evaluate-if-actionable () "Returns t if the task at point is actionable or nil if it isn't" (and (org-entry-get (point) "ACTIONABLE") (string< (org-read-date nil nil (org-entry-get (point) "ACTIONABLE")) (org-read-date nil nil "+0")))) (defun j/org-process-task () "Vefifies if a task is actionable. If it is, set it as actionable" (message "PROPIEDAD: %s" (stringp (org-entry-get (point) "ACTIONABLE"))) (message "Tarea: %s" (org-entry-get (point) "ITEM")) (message "Accionable: %s:" (j/org-evaluate-if-actionable)) (when (j/org-evaluate-if-actionable) (org-todo "TODO") (org-delete-property "ACTIONABLE"))) (defun j/org-verify-actionable-tasks () "Goes through al agenda files checking if FUTU tasks are actionable" ;(interactive) (org-map-entries '(j/org-process-task) "/+FUTU" 'agenda)) ;; Ejecutar j/org-verify-actionable-tasks cada vez que se corra la agenda. Lo hace antes de que se calcula le agenda. (add-hook 'org-agenda-mode-hook #'j/org-actionable) (defun j/org-actionable () (j/org-verify-actionable-tasks)) ``` This function will find tasks with a `FUTU` TODO state and an `ACTIONABLE` property prior to today. Then, it changes the TODO state to `TODO` and removes the `ACTIONABLE` property. For example, this task ``` * FUTU Some task :PROPERTIES: :ACTIONABLE: [2020-04-29] :END: ``` Will look like this after the date set in actionable `ACTIONABLE`: ``` * TODO Some task ``` # Answer > 2 votes Not a direct answer, but I would generally use scheduling (`org-schedule`, `C-c C-s`) combined with an agenda view for this sort of workflow. The default agenda view will not include any tasks scheduled for a future date. On that date the item will start to appear. This provides a built in way to set the date when you want a task to start showing up in your daily todo list (or GTD review view, etc). Note that org-mode has different kinds of timestamps with different semantics, see https://emacs.stackexchange.com/a/10506/780. Your task might have a deadline as well as a scheduled time when you want to start thinking about it. (For more detail see Deadlines and Scheduling in the org manual.) --- Tags: org-mode ---
thread-58106
https://emacs.stackexchange.com/questions/58106
How to bind-pack list of null terminated strings?
2020-04-27T19:55:16.227
# Question Title: How to bind-pack list of null terminated strings? According to the bindat spec docs, there are two specs to pack strings. They are `str` and `strz`. Both are for a fixed length string. Now, suppose I want to pack `("some" "list" "of" "string)`, I should do this: ``` (bindat-pack '((elem0 strz 5) (elem1 strz 5) (elem2 strz 3) (elem3 strz 7)) '((elem0 . "some") (elem1 . "list") (elem2 . "of") (elem3 . "string"))) ``` But that is so inflexible for several reasons: 1. I have to put name and length manually. 2. `strz` need to know size of the string before hand instead of just calculate the length of given string. There are `vec` and `repeat` in the bindat spec but both are the same, both need length of the list before hand. So far, I've come up with this: ``` (require 'seq) (require 'bindat) (defun make-strz-spec (name value) (let ((value (cond ((stringp value) value) ((symbolp value) (symbol-name value)) (t (error "%s is neither string nor a symbol" value)))) (sym (make-symbol name))) `((,sym strz ,(+ 1 (string-bytes value))) (,sym . ,value)))) (defun make-strz-spec-list (string-list) (seq-map-indexed (lambda (str idx) (let ((name (concat "elem-" (number-to-string idx)))) (make-strz-spec name str))) string-list)) (defun bindat-pack-list-of-string (string-list) (let ((spec-pair (make-strz-spec-list string-list))) (bindat-pack (mapcar (lambda (elem) (nth 0 elem)) spec-pair) (mapcar (lambda (elem) (nth 1 elem)) spec-pair)))) ;; this (bindat-pack-list-of-string '("some" "list" "of" "string")) ``` But, that introduces more functions globally with very specific purpose. I don't want to pollute programming environment just for this. Since I am still new with emacs-lisp and lisp in general. I am sure there's a better way than mine. So, back to my main question, how can I bind-pack list of null terminated string? # Answer A function or macro that returns what you need isn't necessarly hard, long, or specially heavy; neither needs little more than a few primitives. For example: ``` (defun pack-string-list (l) (setq l (reverse l)) (let* (sym spec strc) (dotimes (i (length l)) (setq sym (make-symbol (concat "elem" (number-to-string i)))) (push (cons sym (list 'strz (+ 1 (string-bytes (nth i l))))) spec) (push (cons sym (nth i l)) strc)) (bindat-pack spec strc))) ``` I don't know `bindat` package beyond this scope, but something easy-to-follow like this function looks like a fair trade-off to me if your concerns, whose meaning I don't understand, are right. Also probably such function could be written more idiomatically or simplified. > 1 votes --- Tags: string, binary ---
thread-58181
https://emacs.stackexchange.com/questions/58181
In auctex, to insert citation, how to display all the search results
2020-04-30T10:19:11.100
# Question Title: In auctex, to insert citation, how to display all the search results In emacs, auctex, when I use `C-c [`, I only get a list of my previous searches When I start typing a search term such as sengul, it highlights my previous search sengul2013 and when I press return, I only get the result sengul2013 and I can not choose another citation which has the search term sengul in it. I am trying to clear the other entries but could not do it. Any help is appreciated. # Answer > 1 votes This is not so much about `auctex` as the fact that you are using `ivy` as a completion mechanism. In yr example, to select the current input rather than any of the choices displayed, hit `C-M-j` which calls `ivy-immediate-done`. If, like me, you get burned by this often, consider setting `ivy-use-selectable-prompt` to `t`. Then you can `C-p` onto the input line and just hit return. --- Tags: auctex ---
thread-58177
https://emacs.stackexchange.com/questions/58177
Hooks for agenda
2020-04-30T04:49:54.370
# Question Title: Hooks for agenda I need to run a function every time I run `org-agenda`. However, I need it to run prior to the agenda. I wasn't able to find any hooks for the agenda command in the documentation. Any guidance is appreciated. # Answer `org-agenda-mode-hook` is run from `org-agenda-mode` which in turn is run from `org-agenda-prepare` which is run by `org-agenda-list` before the agenda is created (and while the buffer is still writable). If that's early enough, you can add your function to the hook with ``` (add-hook 'org-agenda-mode-hook 'my-function) ``` If that's not early enough, then @lawlist's suggestions for a wrapper function or a before advice would be the only solutions I can see. > 3 votes --- Tags: org-mode, hooks ---
thread-58185
https://emacs.stackexchange.com/questions/58185
Unable to authenticate sending mail using smtpmail-send-it to gmail, "Username and Password not Accepted"
2020-04-30T16:29:34.830
# Question Title: Unable to authenticate sending mail using smtpmail-send-it to gmail, "Username and Password not Accepted" I would like mu4e to use smtpmail-send-it to send emails from emacs. I would like smtpmail-send-it to authenticate using pass. I have 2factor auth on my gmail account, so I have to use an App Password. My emacs verison is: GNU Emacs 26.3 (build 2, x86\_64-pc-linux-gnu, GTK+ Version 3.22.30) of 2019-09-16 Based on what I've read of the pass app built into emacs, I've set up my `pass` directory as such: ``` Password Store smtp.gmail.com (user)@gmail.com ``` `(user)@gmail.com` looks like this: ``` (app password, copied from my security profile in google) host: smtp.gmail.com user: (user)@gmail.com port: 465 ``` I'm using this directory structure because later I'd like to add my work account, which also uses gmail. Based on instruction from the above mentioned `pass` library, from the emacs docs on auth-source, and from the mu4e manual, I've set up my config as follows (note spacemacs is involved, but I don't sense this is part of the issue) (this is not a raw copy/paste, I ripped out some stuff I thought unrelated, please ignore if there's mismatched parentheses or similar) ``` (setq smtpmail-stream-type 'tls) (setq smtpmail-default-smtp-server "smtp.gmail.com") (setq smtpmail-smtp-server "smtp.gmail.com") (setq smtpmail-smtp-service 465) (setq message-send-mail-function 'smtpmail-send-it ) (auth-source-pass-enable) (setq auth-sources '(password-store)) (setq auth-source-debug t) (setq auth-source-do-cache nil) (with-eval-after-load 'mu4e (setq mail-user-agent 'mu4e-user-agent) (setq mu4e-user-mail-address-list '("((user)@gmail.com") ) (setq mu4e-context-policy 'ask) (setq mu4e-contexts `( ,(make-mu4e-context :name "Personal" :match-func (lambda (msg) (when msg (string-match-p "^/gmailhome" (mu4e-message-field msg :maildir)))) :vars '( ( user-mail-address . "(user)@gmail.com" ) (smtpmail-smtp-user . "(user)@gmail.com") )) ) ``` The log shows the following: ``` Sending via mail... auth-source-password-store: searching for ’(user)@gmail.com@smtp.gmail.com’ in entry names (user: (user)@gmail.com) auth-source-password-store: no match found auth-source-password-store: searching for ’smtp.gmail.com’ in entry names (user: (user)@gmail.com) Decrypting /home/caleb/.password-store/smtp.gmail.com/(user)@gmail.com.gpg...done auth-source-password-store: found 1 match: smtp.gmail.com/(user)@gmail.com Decrypting /home/caleb/.password-store/smtp.gmail.com/(user)@gmail.com.gpg...done auth-source-password-store: return (:host smtp.gmail.com :port 465 :user (user)@gmail.com) as final result (plus hidden password) auth-source-search: found 1 results (max 1) matching (:host "smtp.gmail.com" :port "465" :user "(user)@gmail.com" :max 1 :require nil :create nil) Decrypting /home/caleb/.password-store/smtp.gmail.com/(user)@gmail.com.gpg...done smtpmail-send-it: Sending failed: 535-5.7.8 Username and Password not accepted. Learn more at 535 5.7.8 https://support.google.com/mail/?p=BadCredentials s69sm87755otb.4 - gsmtp in response to AUTH PLAIN AHJvZ2Vyc2pjYWxlYkBnbWFpbC5jb20AeGZiZ2xyemtpZWRlZ3ZobA== ``` At first I thought this error was because I mistakenly put my normal gmail password into `pass`, but now I've swapped it for a fresh app password, and I'm still getting this error. I looked through a couple other questions on here with similar issues, but none seemed to have similar reasons for authentication failure. How can I successfully authenticate and send mail? EDIT: I read on google's support that I might have a mismatch with my `(setq smtpmail-stream-type 'tls)` and the port number, `(setq smtpmail-smtp-service 465)`, so I changed to: `(setq smtpmail-smtp-service 587)` Now I'm getting the following error: ``` Sending via mail... gnutls.el: (err=[-15] An unexpected TLS packet was received.) boot: (:priority NORMAL:%DUMBFW :hostname smtp.gmail.com :loglevel 0 :min-prime-bits 256 :trustfiles (/etc/ssl/certs/ca-certificates.crt) :crlfiles nil :keylist nil :verify-flags nil :verify-error nil :callbacks nil) gnutls-negotiate: GnuTLS error: #<process smtpmail>, -15 ``` EDIT2: I changed to `starttls` ``` (setq smtpmail-stream-type 'starttls) ``` I also updated my `pass` entry to have \`port: 587 And now am back to a user/password error. Interestingly, the error appears to be identical to the same experiment as above, but when I forgot to change my `pass` entry's port. This makes me suspect that something's wrong with my pass config. Error with wrong port in `pass`: ``` Sending via mail... auth-source-password-store: searching for ’rogersjcaleb@gmail.com@smtp.gmail.com’ in entry names (user: rogersjcaleb@gmail.com) auth-source-password-store: no match found auth-source-password-store: searching for ’smtp.gmail.com’ in entry names (user: rogersjcaleb@gmail.com) Decrypting /home/caleb/.password-store/smtp.gmail.com/rogersjcaleb@gmail.com.gpg...done auth-source-password-store: found 1 match: smtp.gmail.com/rogersjcaleb@gmail.com Decrypting /home/caleb/.password-store/smtp.gmail.com/rogersjcaleb@gmail.com.gpg...done auth-source-password-store: return (:host smtp.gmail.com :port 465 :user rogersjcaleb@gmail.com) as final result (plus hidden password) auth-source-search: found 1 results (max 1) matching (:host "smtp.gmail.com" :port "587" :user "rogersjcaleb@gmail.com" :max 1 :require nil :create nil) Decrypting /home/caleb/.password-store/smtp.gmail.com/rogersjcaleb@gmail.com.gpg...done 535-5.7.8 Username and Password not accepted. Learn more at 535 5.7.8 https://support.google.com/mail/?p=BadCredentials l24sm338725otf.59 - gsmtp 221 2.0.0 closing connection l24sm338725otf.59 - gsmtp smtpmail-send-it: Sending failed: 535-5.7.8 Username and Password not accepted. Learn more at 535 5.7.8 https://support.google.com/mail/?p=BadCredentials l24sm338725otf.59 - gsmtp in response to AUTH PLAIN AHJvZ2Vyc2pjYWxlYkBnbWFpbC5jb20AeGZiZ2xyemtpZWRlZ3ZobA== ``` Error with right port in `pass` ``` Sending via mail... auth-source-password-store: searching for ’rogersjcaleb@gmail.com@smtp.gmail.com’ in entry names (user: rogersjcaleb@gmail.com) auth-source-password-store: no match found auth-source-password-store: searching for ’smtp.gmail.com’ in entry names (user: rogersjcaleb@gmail.com) Decrypting /home/caleb/.password-store/smtp.gmail.com/rogersjcaleb@gmail.com.gpg...done auth-source-password-store: found 1 match: smtp.gmail.com/rogersjcaleb@gmail.com Decrypting /home/caleb/.password-store/smtp.gmail.com/rogersjcaleb@gmail.com.gpg...done auth-source-password-store: return (:host smtp.gmail.com :port 587 :user rogersjcaleb@gmail.com) as final result (plus hidden password) auth-source-search: found 1 results (max 1) matching (:host "smtp.gmail.com" :port "587" :user "rogersjcaleb@gmail.com" :max 1 :require nil :create nil) Decrypting /home/caleb/.password-store/smtp.gmail.com/rogersjcaleb@gmail.com.gpg...done 535-5.7.8 Username and Password not accepted. Learn more at 535 5.7.8 https://support.google.com/mail/?p=BadCredentials z13sm362612oth.10 - gsmtp 221 2.0.0 closing connection z13sm362612oth.10 - gsmtp smtpmail-send-it: Sending failed: 535-5.7.8 Username and Password not accepted. Learn more at 535 5.7.8 https://support.google.com/mail/?p=BadCredentials z13sm362612oth.10 - gsmtp in response to AUTH PLAIN AHJvZ2Vyc2pjYWxlYkBnbWFpbC5jb20AeGZiZ2xyemtpZWRlZ3ZobA== ``` # Answer > 1 votes This issue was solved when I manually edited my password in `pass` via `pass edit smtp.gmail.com/(user)@gmail.com to be equivalent to my app password that's stored elsewhere in`pass\` for imap mail fetching. I don't know why the newly created app password was invalid, and the old one is valid. My config looks like the below now, and works: ``` Password Store smtp.gmail.com (user)@gmail.com ``` smtp.gmail.com/(username)@gmail.com/gpg ``` (old app password i was already using for IMAP) host: smtp.gmail.com user: (user)@gmail.com port: 587 ``` My emacs config: ``` (setq smtpmail-stream-type 'starttls) (setq smtpmail-default-smtp-server "smtp.gmail.com") (setq smtpmail-smtp-server "smtp.gmail.com") (setq smtpmail-smtp-service 587) (setq smtpmail-debug-info t) (setq message-send-mail-function 'smtpmail-send-it ) (auth-source-pass-enable) (setq auth-sources '(password-store)) (setq auth-source-debug t) (setq auth-source-do-cache nil) ``` --- Tags: mu4e, smtpmail, passwords, authinfo ---
thread-58190
https://emacs.stackexchange.com/questions/58190
How to byte-compile a file in the background?
2020-04-30T23:15:02.330
# Question Title: How to byte-compile a file in the background? To cut time on untangling my org setup file, I now only compile on save. However it is somewhat annoying to have the compile buffer popup on every save. ``` ;; Only untangle on a change/save (defun my/tangle-dotfiles () "If the current file is this file, the code blocks are tangled" (interactive) (when (equal (buffer-file-name) (file-truename (expand-file-name "myinit.org" user-emacs-directory))) (org-babel-tangle-file (expand-file-name "myinit.org" user-emacs-directory) (expand-file-name "myinit.el" user-emacs-directory) ) (byte-compile-file (expand-file-name "myinit.el" user-emacs-directory)) ) ) (add-hook 'after-save-hook #'my/tangle-dotfiles) ``` Is there a way to have this statement: ``` (byte-compile-file (expand-file-name "myinit.el" user-emacs-directory)) ``` Run in the background instead in a buffer that pops up every time I save? # Answer > 1 votes Byte-compiling is a CPU-bound activity, unlike with subprocesses and network processes there is no way of doing it asynchronously in the same Emacs instance. What you can do though is launching an Emacs subprocess and making it byte-compile the file. async.el offers support for this, try `async-byte-compile-file` from `async-bytecomp.el`. --- Tags: buffers, byte-compilation, tangle ---
thread-41677
https://emacs.stackexchange.com/questions/41677
mu4e change column width
2018-05-27T19:01:51.137
# Question Title: mu4e change column width I recently switched to mu4e for my mails which is awesome. I changed the date format in the headers view so that it became longer. Unfortunately I cannot see the complete date now because the column width is to small. How can I change this? How can I change the width of all columns? Documentation doesn't mention the column width. # Answer > 1 votes Does customizing `mu4e-headers-fields`, changing the width corresponding to the `:human-date` "header", do the job? (I haven't tested this.) # Answer > 0 votes Documentation on how to change headers can be found here : https://www.djcbsoftware.nl/code/mu/mu4e/Longer-configuration.html Here is the part the op is interested in : ``` ;; the headers to show in the headers list -- a pair of a field ;; and its width, with `nil' meaning 'unlimited' ;; (better only use that for the last field. ;; These are the defaults: (setq mu4e-headers-fields '( (:date . 25) ;; alternatively, use :human-date (:flags . 6) (:from . 22) (:subject . nil))) ;; alternatively, use :thread-subject ``` Note that the order of the fields in the code will be the same in the view. --- Tags: mu4e ---
thread-17811
https://emacs.stackexchange.com/questions/17811
forward-sexp: Scan error: "Unbalanced parentheses", 30586, 41369
2015-11-02T15:38:25.500
# Question Title: forward-sexp: Scan error: "Unbalanced parentheses", 30586, 41369 When using the menu system to modify customizations (Options \> Customize Emacs \> ...etc...), I am * Able to "Apply" the change for the curent session * Unable to "Apply and save" for future sessions The error message I get is 'forward-sexp: Scan error: "Unbalanced parentheses", 30586, 41369'. I have no idea how to deal with this message. Online searches produce random results, none of which relate to my problem. I am exploring and learning about org-mode. About three days ago I was able to make a change related to customizing a default option for org-mode without a problem. Then a few minutes later when I tried to add another custom setting, I got the above "forward-sexp..." error and continue to. I get this error when attempting to "Apply and save" any setting whatsoever, such as changing the color of the default face. I tried swapping in an old "init.el" file, firing up a new emacs session, and making a change, but "Apply and save" also fails under those circumstances, so the problem does not appear related to my "init.el" file being corrupt. Beyond that, I'm clueless. ***Update 2015-11-03*** Thank you Drew for your long and thoughtful reply. I'm still out to sea though. I put `(setq debug-on-error t)` at the top of my init.el file and attempted to change the color of the default face, uisng the Cutsomize option from the emacs menu. I had to try three times before I got any backtrace output. Unfortunately, to me it's meaningless, but here it is... > > Debugger entered--Lisp error: (scan-error "Unbalanced parentheses" 30598 41177) scan-sexps(1 41176) forward-sexp(41176) > > custom-save-delete(custom-set-variables) custom-save-variables() > > custom-save-all() Custom-save((push-button :tag " Apply and Save " :help-echo "Apply settings and save for future sessions." :action Custom-save :button-overlay # :from # :to #) (mouse-1 (# 191 (270 . 121) 23286452 nil 191 (26 . 5) nil (0 . 12) (10 . 25)))) > > widget-apply((push-button :tag " Apply and Save " :help-echo "Apply settings and save for future sessions." :action Custom-save :button-overlay # :from # :to #) :action (mouse-1 (# 191 (270 . 121) 23286452 nil 191 (26 . 5) nil (0 . 12) (10 . 25)))) > > widget-apply-action((push-button :tag " Apply and Save " :help-echo "Apply settings and save for future sessions." :action Custom-save :button-overlay # :from # :to #) (mouse-1 (# 191 (270 . 121) 23286452 nil 191 (26 . 5) nil (0 . 12) (10 . 25)))) #\[0 "\306 r\307\310\311\312\313\314!\315\\"\316\317%DC\216\320\321\300@!\211,@)!\210\212\321\300@!,\322,8\206B\` Then I used diff to compare the resulting modified but unsaved init.el, and an init.el from last May. There were two differences, * (setq debug-on-error t) on line one of today's init.el. and * a macro that I edited about three weeks ago Since I was able to do one customization a couple of days ago with no problem, and unable since then, the macro editing is not an issue The main part of the custom-set-variables secton of the init file hasn't been changed for years. It is... ``` (custom-set-variables ;; custom-set-variables was added by Custom. ;; If you edit it by hand, you could mess it up, so be careful. ;; Your init file should contain only one such instance. ;; If there is more than one, they won't work right. '(auto-save-interval 75) '(auto-save-timeout 10) '(blink-cursor-mode nil) '(bookmark-save-flag 0) '(column-number-mode t) '(dired-listing-switches "-al --group-directories-first --time-style=long-iso") '(display-time-day-and-date t) '(display-time-mode t) '(fill-column 110) '(fringe-mode 2 nil (fringe)) '(inhibit-startup-screen t) '(ispell-highlight-face (quote highlight)) '(ispell-highlight-p t) '(ispell-program-name "aspell" t) '(load-home-init-file t t) '(ls-lisp-dirs-first t) '(make-backup-files nil) '(scroll-bar-mode (quote right)) '(sentence-end-double-space nil) '(sort-fold-case t t) '(tool-bar-mode nil) '(truncate-lines t) '(vc-make-backup-files t) '(version-control t) '(visible-bell t) '(x-select-enable-clipboard t)) ;;(custom-set-faces ;; custom-set-faces was added by Custom. ;; If you edit it by hand, you could mess it up, so be careful. ;; Your init file should contain only one such instance. ;; If there is more than one, they won't work right. ;; ) ``` The other part has been set for many months, and is... `;; make pandoc the default markdown parser (custom-set-variables '(markdown-command "/usr/bin/pandoc"))` Earlier today I reinstalled all the Emacs packages as well, but no change from that either. ***Update 2015-11-06***: Edited. Reply reconfigured and moved into a whole new answer for clarity. # Answer Based on some quick testing of `forward-sexp`, the numbers listed in the error message define where the unbounded sexp are found. Adding a bare `(` to my init file then trying `forward-sexp` I received: `forward-sexp: Scan error: "Unbalanced parentheses", 436, 52245`. `M-: (point)` on the `(` gave `436` and `M-: (point-max)` gave `52245`. In your case: `M-g c` (goto-char) `30586` should send you to the `(` that the file cannot find an end to. > 6 votes # Answer First, there was a suggestion to write my own answer rather than editing the question. Also, thanks to everyone for supplying intelligent and thoughtful comments. I obviously needed the help. --- I had a saved keyboard macro set to produce `&mdash;`, which is an `em dash` for use in HTML. The macro looked like `(global-set-key [?\C-c ?h] [? ?& ?m ?d ?a ?s ?h ?; ? ])`. Me? Clueless, so I just ended the expression with a `semicolon` and a `space`. And oddly enough, it works fine. It did work fine, until I did a bit of customizing via the Emacs menu system while adding a couple of tweaks to make use of some *Org mode* features. Now that I understand where the problem is and why it should be a problem it all (finally) makes sense. The semicolon begins a comment, which causes two parenthetical expressions to be not-closed, i.e. `]` and `)`. This actually is reasonable in the Emacs world. Even I can understand it. But it gets better. The `init.el` file, bent as it was, still let itself be saved without even a tiny squeak of protest, and ran perfectly. It was only when I tried something like changing the face color, for example, that `init.el` would get ornery. And reluctantly throw a an *error message*. I guess we have to call it a *message* even though I've had better communications with a drunken chicken. (Her name was Heather, by the way. She was actually pretty astute at times, besides the eggs too, but then there was that drinking problem. *Anyhow.*) So there I was, up to my elbows in a bucket of snakes all going every whichway and suddenly it all made sense, at which point I knew I'd better start backing away or it would soon be too late. Emacs. Make sense? Ow. So after about six hours more searching, I found `\` (It's how you draw an escape hatch in Emacs). So I added that to the macro and it kept working. And now whenever I get in there and try to do some customizing and things get hot and furious, that little escape hatch pops open and lets out enough steam so things don't blow up any more. The updated macro with the escape hatch now looks like: > `(global-set-key [?\C-c ?h] [? ?& ?m ?d ?a ?s ?h ?\; ? ])`. I guess the moral of the story is that you can stick your head into a fan if you want, or stick it into Emacs. Pretty much the same result, except that Emacs can also do `&mdash;`. If it really has to. > 3 votes # Answer I also had this issue and I couldn't find any error or unbalanced parentheses in my own configuration (I'm using Spacemacs and have a `.spacemacs` file). I tried with a clean `.spacemacs` file and the same problem remained (even the two numbers shown in the error are the same). This led me to conclude that some file must have been messed up in my `.emacs.d` folder. Deleting that folder completely and re-cloning Spacemacs solved the issue (while preserving the original `.spacemacs` file and my configurations of course). > 1 votes # Answer Put this in your init file, near the beginning: ``` (setq debug-on-error t) ``` Post the backtrace you see when you get the error. --- You mention using Customize, as if that is related to your problem. But you don't say just what you did in Customize. If, for example, you customized an option that expects a Lisp value, and you entered a sexp that is missing one or more right parentheses or a string terminator (`"`) or some such, then that could explain the error you are seeing. --- You can try to find what is provoking the problem in your init file by recursively bisecting it, to narrow it down. Use `comment-region` to comment out a selection of sexps (or `C-u` with that command to uncomment a selection). Comment out 1/2, then 3/4, 7/8,... of your init file. If you are convinced that the problem is something you changed using Customize, then you can try just commenting out parts of the `custom-set-variables` part of your init file - each of its parts is a sexp that customizes one option. Comment out 1/2 of them, then 3/4,... until you find the one that is problematic. Then check that one for a missing termination (paren or `"` or `]`) --- But without more information all we can say is that Emacs is trying to evaluate a sexp that is unfinished -- missing something that should end it. > 0 votes --- Tags: init-file ---
thread-58193
https://emacs.stackexchange.com/questions/58193
`rx` form, that is partially compiled, partially variable?
2020-05-01T10:15:51.170
# Question Title: `rx` form, that is partially compiled, partially variable? Is it possible to obtain an `(rx ...)` form, that is expanded at compile time for performance, but partially variable? --- ## `rx-to-string` may be slow For instance I want an expression that behaves equivalent to ``` (rx-to-string `(: "PREFIX" (or "hello" "world" ,@user-defined-words) "SUFFIX)) ``` Written this way, it works, but does an unnecessary amount of work at runtime (especially in more complex real-world examples). In some places, this can become a potential performance issue. What I want to produce at compile time is essentially a partial compile-time expansion, such as ``` (concat "PREFIX\\(?:hello\\|world\\|" (mapconcat #'regexp-quote user-defined-words "\\|") "\\)SUFFIX") ``` --- ## `eval` form does not work I already know that the `(rx ... (eval ...) ...)` form does not work: ``` ;; INCORRECT RESULT; VARIABLE EXPANDED AT COMPILE TIME: (rx "PREFIX" (eval `(or "hello" "world" ,@user-defined-words) "SUFFIX)) ;; When loading from source and user-defined-words is initialized to nil: => "PREFIX\\(?:hello\\|world\\)SUFFIX" ;; When compiling: => Error: Symbol's value as variable is void: user-defined-words ``` # Answer > 1 votes Starting from Emacs 27, `rx` supports this via the following forms: ``` (literal EXPR) Match the literal string from evaluating EXPR at run time. (regexp EXPR) Match the string regexp from evaluating EXPR at run time. ``` n.b. The `regexp` form in earlier versions of rx is less flexible, and only accepts a string argument. # Answer > 0 votes A compiled regexp is just a string, so (a) no, I don't believe you can make any kind of dynamic substitution when the regexp engine processes it; but (b) you *can* search and replace on it yourself -- simply produce a regexp string containing token substrings which you *know* will not otherwise occur, and ensure they occur in a context which will be safe to replace. ``` (rx "PREFIX" (or "hello" "world" (regexp "INFIX")) "SUFFIX") => "PREFIX\\(?:hello\\|world\\|INFIX\\)SUFFIX" ``` If you know that `PREFIX` and `INFIX` and `SUFFIX` are all unique in the regexp, then a simple run-time replacement of those can produce your desired outcome. *Knowing* that your placeholders are unique and replaceable is the part you need to be careful about, so you might take advantage of the fact that the rx form `(regexp FOO)` trusts that `FOO` is a valid regexp string, and instead use it to produce an *invalid* regexp as a placeholder value -- therefore being safe in the knowledge that rx is never going to produce that same value<sup>1</sup>. For example, if you searched for `(rx (regexp "[[:placeholder:]]"))` the regexp engine would signal `(invalid-regexp "Invalid character class name")`. You could therefore do something like this: ``` (defvar my-pattern-template (rx (group (or "hello" "world" (regexp "[[:placeholder:]]")))) "Regexp template with placeholder.") ;; Runtime... (let* ((prefix "PREFIX") (suffix "SUFFIX") (words '("this" "is" "the" "word" "list" "to" "look" "for")) (regexp1 (progn (string-match (rx "[[:placeholder:]]") my-pattern-template) (replace-match (regexp-opt words) nil t my-pattern-template))) (regexp (concat (regexp-quote prefix) regexp1 (regexp-quote suffix)))) (re-search-forward regexp)) ``` --- <sup>1</sup> `"\\[[:placeholder:]]"` is a *valid* regexp containing that placeholder -- equivalent to `"\\[[:placehodr]]"` and matching the text `[:]` for instance -- but `rx` shouldn't ever generate such unnecessary duplication of characters, so it's probably still safe; but these things *are* tricky, and my scheme might yet be flawed, so be suitably careful. In practice, unless the inputs are *truly* arbitrary, you probably have enough control to provide certainty. --- Tags: byte-compilation, rx ---
thread-58196
https://emacs.stackexchange.com/questions/58196
org-mode inline latex dollar sign
2020-05-01T12:15:23.283
# Question Title: org-mode inline latex dollar sign In org mode, this inline latex dollar sign fails to render: ``` $\$$ ``` but this has no problem rendering: ``` \[ \$ \] ``` # Answer > 3 votes Although Org mode allows LaTeX math fragments to be inserted, there are some limitations. This is one of them. The way to get inline math fragments in such cases is to use the `\( ... \)` form that LaTeX allows, e.g. ``` \( \$ \) ``` in this case. See the LaTeX fragments section of the manual, which states: > LaTeX fragments do not need any special marking at all. The following snippets are identified as LaTeX source code: ... Text within the usual LaTeX math delimiters. To avoid conflicts with currency specifications, single ‘$’ characters are only recognized as math delimiters if the enclosed text contains at most two line breaks, is directly attached to the ‘$’ characters with no whitespace in between, and if the closing ‘$’ is followed by whitespace, punctuation or a dash. For the other delimiters, there is no such restriction, so when in doubt, use ‘(...)’ as inline math delimiters. Note that your attempt `$\$$` satisfies all the rules - but it still does not work, so that's a bug in the documentation. --- Tags: org-mode, latex ---
thread-58164
https://emacs.stackexchange.com/questions/58164
How to fix backwards incompatibility of mu 1.4?
2020-04-29T14:22:08.700
# Question Title: How to fix backwards incompatibility of mu 1.4? I upgraded `mu` from 1.2.0\_1 to 1.4.1 and it does not seem backwards compatible. I immediately got a problem of `mu server process ended with exit code 127 error in process sentinel:`, which I solved from this issue with: ``` mu init mu find hello mu index ``` I can now read emails and have two problems in the `mu4e` setup, even after restarting the system. When I compose an email, I get: ``` error in process filter: concat: Symbol’s value as variable is void: mu4e-compose-auto-include-date error in process filter: Symbol’s value as variable is void: mu4e-compose-auto-include-date ``` and when delayed sending timer runs (`mu4e-send-delay`), I get: ``` Error running timer ‘mu4e-send-delay-send-queue’: (void-variable mu4e-maildir) ``` How can I fix these errors in the upgrade from 1.2.1 to 1.4? # Answer > 1 votes I think your problem is more with `mu4e-send-delay` than with `mu4e` itself. Can you confirm which version of `mu4e-send-delay` you are using? That one? I'm asking because I found out several different versions, but the canonical seems to be the one I linked. This plugin seems abandoned by its creator (no update since 3 years). But maybe he will answer if you open an issue there. In the meantime, another solution, instead of changing yourself the code of `mu4e-send-delay`, may be to artificially recreate the missing variable in your Emacs config file: ``` (defvar mu4e-compose-auto-include-date t "Recreate an old mu4e var needed by `mu4e-send-delay'.") ``` For the other error regarding `mu4e-maildir`, it's exactly the same: this is an old variable removed from `mu4e`, but still (as there'd been no update) present in `mu4e-send-delay`. Thus same cure for it: ``` (defvar mu4e-maildir "Path to your maildir" "Recreate an old mu4e var needed by `mu4e-send-delay'.") ``` However, I think it's a bad idea to use this plugin as it is no more compatible with mu4e. It may need a major refactoring to work with last version of mu4e. Thus either you should consider leaving it, or downgrading mu/mu4e if you absolutely need it. # Answer > 1 votes The error is perhaps in the definition of `mu4e-send-delay-setup`. You have to comment the following line ``` ... (when mu4e-compose-auto-include-date ... ``` and also delete a ")" at the end of definition of the function. You should obtain ``` ... (mu4e~draft-header mu4e-send-delay-header mu4e-send-delay-default-delay)))) ``` Restart Emacs and it should be ok. --- Tags: mu4e ---
thread-58198
https://emacs.stackexchange.com/questions/58198
rgrep doesn't search in specified directory
2020-05-01T12:39:30.267
# Question Title: rgrep doesn't search in specified directory According to the documentation : > `(rgrep REGEXP &optional FILES DIR CONFIRM)` > > Recursively grep for `REGEXP` in `FILES` in directory tree rooted at `DIR`. > > \[...\] But when I call it in some Elisp code like this : `(rgrep "test" "*\\.org" "\\~/Org")` It ends up neglecting the third argument `DIR` and instead uses the current directory. The corresponding output and the `find` command of the above code is : ``` -*- mode: grep; default-directory: <current_directory> -*- Grep started at Fri May 1 14:24:46 ``` ``` find . <exclude_expr> -type f \( -name \*\\.org \) -exec grep --color -i -nH --null -e test \{\} + ``` but the output I obtained interactively with `M-X rgrep` ``` -*- mode: grep; default-directory: ~/Org -*- Grep started at Fri May 1 14:24:46 ``` ``` find . <exclude_expr> -type f \( -name \*\\.org \) -exec grep --color -i -nH --null -e test \{\} + ``` is expected. Note: `GNU Emacs 26.3 (build 1, x86_64-pc-linux-gnu, GTK+ Version 3.24.8, cairo version 1.16.0) of 2020-01-13` # Answer > 1 votes I haven't made `rgrep` work at the first time (got an error like `string-match("<c>" nil)` and still don't know why). I tried to escape unnecessarily the three arguments after reading emacs wiki. But the solution is given for GnuWin32... Conclusion, when `rgrep` works, it's as expected: no need to escape anything. I'll ask about the error. No clue why it happens. **EDIT** 1. By Inspecting the `rgrep` source code, `rgrep` use default directory when the given one is not a directory (in my case: syntax error). 2. To prevent `string-match("<c>" nil)`, one must call `(grep-compute-defaults)` before. # Answer > 1 votes It may be possible that `rgrep` doesn't automatically expand DIR. Can you try if you have more success with something like that: ``` (rgrep "test" "*\\.org" (expand-file-name "~/Org")) ``` --- Tags: search, rgrep ---
thread-58210
https://emacs.stackexchange.com/questions/58210
rgrep: string-match("<C>", nil) error
2020-05-01T20:54:48.360
# Question Title: rgrep: string-match("<C>", nil) error I found a weird behaviour with `rgrep`. The following is tested under `emacs 26.3` with `emacs -Q`. 1. Evaluate `(rgrep "test" "*.org" "~/Org/wiki")` gives me a `string-match("<C>" nil)` error: ``` Debugger entered--Lisp error: (wrong-type-argument stringp nil) string-match("<C>" nil) grep-expand-template(nil "test" "\\( -name \\*.org \\)" nil "-type d \\( -path \\*/SCCS -o -path \\*/RCS -o -path \\*/CVS -o -path \\*/MCVS -o -path \\*/.src -o -path \\*/.svn -o -path \\*/.git -o -path \\*/.hg -o -path \\*/.bzr -o -path \\*/_MTN -o -path \\*/_darcs -o -path \\*/\\{arch\\} \\) -prune -o \\! -type d \\( -name .\\#\\* -o -name \\*.pho -o -name \\*.phi -o -name \\*.glob -o -name \\*.vo -o -name \\*.o -o -name \\*\\~ -o -name \\*.bin -o -name \\*.lbin -o -name \\*.so -o -name \\*.a -o -name \\*.ln -o -name \\*.blg -o -name \\*.bbl -o -name \\*.elc -o -name \\*.lof -o -name \\*.glo -o -name \\*.idx -o -name \\*.lot -o -name \\*.fmt -o -name \\*.tfm -o -name \\*.class -o -name \\*.fas -o -name \\*.lib -o -name \\*.mem -o -name \\*.x86f -o -name \\*.sparcf -o -name \\*.dfsl -o -name \\*.pfsl -o -name \\*.d64fsl -o -name \\*.p64fsl -o -name \\*.lx64fsl -o -name \\*.lx32fsl -o -name \\*.dx64fsl -o -name \\*.dx32fsl -o -name \\*.fx64fsl -o -name \\*.fx32fsl -o -name \\*.sx64fsl -o -name \\*.sx32fsl -o -name \\*.wx64fsl -o -name \\*.wx32fsl -o -name \\*.fasl -o -name \\*.ufsl -o -name \\*.fsl -o -name \\*.dxl -o -name \\*.lo -o -name \\*.la -o -name \\*.gmo -o -name \\*.mo -o -name \\*.toc -o -name \\*.aux -o -name \\*.cp -o -name \\*.fn -o -name \\*.ky -o -name \\*.pg -o -name \\*.tp -o -name \\*.vr -o -name \\*.cps -o -name \\*.fns -o -name \\*.kys -o -name \\*.pgs -o -name \\*.tps -o -name \\*.vrs -o -name \\*.pyc -o -name \\*.pyo \\) -prune -o ") rgrep-default-command("test" "*.org" nil) rgrep("test" "*.org" "~/Org/wiki") eval((rgrep "test" "*.org" "~/Org/wiki") nil) eval-expression((rgrep "test" "*.org" "~/Org/wiki") nil nil 127) funcall-interactively(eval-expression (rgrep "test" "*.org" "~/Org/wiki") nil nil 127) call-interactively(eval-expression nil nil) command-execute(eval-expression) read-from-minibuffer("Eval: " nil (keymap (9 . completion-at-point) (27 keymap (9 . completion-at-point)) keymap (18 . counsel-minibuffer-history) (menu-bar keymap (minibuf "Minibuf" keymap (previous menu-item "Previous History Item" previous-history-element :help "Put previous minibuffer history element in the minibuffer") (next menu-item "Next History Item" next-history-element :help "Put next minibuffer history element in the minibuffer") (isearch-backward menu-item "Isearch History Backward" isearch-backward :help "Incrementally search minibuffer history backward") (isearch-forward menu-item "Isearch History Forward" isearch-forward :help "Incrementally search minibuffer history forward") (return menu-item "Enter" exit-minibuffer :key-sequence "\015" :help "Terminate input and exit minibuffer") (quit menu-item "Quit" abort-recursive-edit :help "Abort input and exit minibuffer") "Minibuf")) (10 . exit-minibuffer) (13 . exit-minibuffer) (7 . minibuffer-keyboard-quit) (C-tab . file-cache-minibuffer-complete) (9 . self-insert-command) (XF86Back . previous-history-element) (up . previous-line-or-history-element) (prior . previous-history-element) (XF86Forward . next-history-element) (down . next-line-or-history-element) (next . next-history-element) (27 keymap (114 . previous-matching-history-element) (115 . next-matching-history-element) (112 . previous-history-element) (110 . next-history-element))) t read-expression-history) read--expression("Eval: ") byte-code("\301\302!\303\010!B\207" [current-prefix-arg read--expression "Eval: " eval-expression-get-print-arguments] 3) call-interactively(eval-expression nil nil) command-execute(eval-expression) ``` 2. Then evaluate `(rgrep "test" "*.org")` gives the same error. 3. BUT evaluate `(rgrep "test")` works without any error. 4. The most weird comes: `(rgrep "test" "*.org" "~/Org/wiki")` now works correctly. This is the problematic line in lisp/progmodes/grep.el. # Answer > 1 votes It seems that you need to give a non-`nil` value to variable `grep-find-template`. So **customize** that user option or bind it around your `(rgrep "test" "*.org" "~/Org/wiki")` or call `(grep-compute-defaults)` before evaluating calling `rgrep`. I found this out by looking at the backtrace. The first argument passed to `grep-expand-template` is `nil`. `rgrep-default-command` is what invokes `grep-find-template`. In general, when you want to invoke a *command* from Lisp instead of interactively, you need to check the command's `interactive` spec, to see whatever it might do to come up with appropriate arguments for the command's body. --- Added from OP's comment confirming that `(grep-compute-defaults)` takes care of it: > Just to complete the answer a bit: calling the function `(grep-compute-defaults)` set `grep-find-template` to its default value. So `(progn (grep-compute-defaults) (rgrep "test" "*.org" "~/Org/wiki"))` fix the issue. --- Tags: debugging, interactive, rgrep ---
thread-58204
https://emacs.stackexchange.com/questions/58204
How can I unbind a key in org mode?
2020-05-01T18:40:08.830
# Question Title: How can I unbind a key in org mode? `M-return` is interfering with export (`M-return e e`) and other functions that I use a lot. I tried `(define-key org-mode-map kbd "M-return" nil)`, but after loading that (with `M-m f e r`, since I am using Spacemacs), I still get the binding. # Answer > 0 votes You tried this: ``` (define-key org-mode-map kbd "M-return" nil) ``` Try this instead: ``` (define-key org-mode-map (kbd "<M-return>") nil) ``` You made two mistakes: `kbd` is a function, and you want to pass it as argument the key description that Emacs shows you when you use `C-h k` and hit `Meta` \+ `Return`. That mean use the sexp `(kbd ...)`, where `...` is what `C-h k` shows: `<M-return>`. --- Tags: org-mode, spacemacs ---
thread-58213
https://emacs.stackexchange.com/questions/58213
Run Emacs in GUI mode without X over SSH
2020-05-01T21:22:50.353
# Question Title: Run Emacs in GUI mode without X over SSH With Emacs 26.1 installed on a Linux RedHat flavour without X, I want to run Emacs GUI over an SSH connection with X11 forwarding and Xming server on client. Since there is no X on the machine, Emacs starts in text mode. I know that "emacs -nw" forces Emacs in text mode, but how to force GUI? # Answer Emacs will start "in GUI mode" automatically when possible. There are basically 2 conditions that need to be satisfied: * You must use an Emacs built with GUI support. * There must be an Xserver it can connect to, which is indicated by the usual `$DISPLAY` environment variable. So make sure your Emacs was built with GUI support, and make sure you launch it from a shell where `$DISPLAY` is set properly. > 1 votes --- Tags: ssh, gui-emacs, x11 ---
thread-58212
https://emacs.stackexchange.com/questions/58212
emacs tabbar -- how to get tabs for all buffers displayed in one go, regardless of extension?
2020-05-01T21:17:03.800
# Question Title: emacs tabbar -- how to get tabs for all buffers displayed in one go, regardless of extension? I use, and love, tabs, using the following in my .emacs: `(require 'tabbar) (tabbar-mode 1) (global-set-key [(control shift iso-lefttab)] 'tabbar-backward-tab) (global-set-key [(control tab)] 'tabbar-forward-tab)` Since upgrading my distro a few months back (i'm sure it wasn't true before that), i've found that if i load several files with different extensions, then the tabs appear in different groups; e.g., `emacs junk1.txt junk4.txx junk2.txt junk3.ttx junk9.txt` gives me one "screen" (if you see what i mean) that has tabs for junk1.txt, junk2.txt, and junk9.txt; and another with tabs for both junk4.txx and junk3.ttx (and yes, those two do have different extensions). I can, of course, switch buffers to move between "screens" (and, err, between buffers); but what i want is to have tabs for ALL my files visible in a single "screen", so i can tab through all of them. Any ideas how to achieve that (or for that matter, why i don't currently get that behaviour)? Fwiw: GNU Emacs 26.2 (build 1, x86\_64-mageia-linux-gnu, GTK+ Version 3.24.7) of 2019-04-12 Thanks, ian # Answer Thanks to lawlist's enlightening suggestions, and a bit of subsequent googling, i was able to figure out the fix, defining my tabbing groups as needed by adding this into my .emacs: ``` (defun my-tabbar-buffer-groups () (list (cond ((string-equal "*" (substring (buffer-name) 0 1)) "emacs") ((eq major-mode 'dired-mode) "emacs") (t "user")))) (setq tabbar-buffer-groups-function 'my-tabbar-buffer-groups) ``` > 1 votes --- Tags: tabbar ---
thread-58149
https://emacs.stackexchange.com/questions/58149
Can org-babel filter code blocks?
2020-04-29T08:11:28.357
# Question Title: Can org-babel filter code blocks? I have a general emacs.org file that I load at init time with org-babel. It's made for desktop use, and I load a bunch of IDE features, face customizations, powerline and so on. However, I also sometimes use emacs on a headless server, where such configurations don't make sense but still take time loading (especially since the server is much less powerful than my desktop). But I would still like to keep other blocks (e.g. ivy, undo-tree etc). I could just take my emacs.org and delete unnecessary blocks when putting it on my server, but now I have two different files to manage, which is a pain. Is there a way to tell org-babel "only load these code blocks"? For example by filtering tags of headers? # Answer > 1 votes I think this is pretty easy to do. `:tangle` can take `no` or `yes`, a filename, but also a lisp function. For example: ``` #+BEGIN_SRC bash :tangle (make-string 5 ?x) ls -tr #+END_SRC ``` Recall that header arguments can be set at different levels (for example as a `+#PROPERTY` under a headline) so you can have headlines for different OS, hosts, etc. Create a function that, based on the hostname, returns either `emacs.el` or `no`. When it returns `no` that block won't be tangled. --- Tags: org-mode, org-babel ---
thread-58211
https://emacs.stackexchange.com/questions/58211
How to use concat to get the path in .dir-locals.el with flycheck-clang-include-path
2020-05-01T21:15:52.650
# Question Title: How to use concat to get the path in .dir-locals.el with flycheck-clang-include-path I am using the following content to include headers to my project using `.dir-locals.el` ``` ((c++-mode . ((flycheck-clang-language-standard . "c++14") (flycheck-clang-include-path "/Users/user/Documents/project_name/source" "/Users/user/Documents/project_name/source/library/include") ))) ``` But, I do not want to explicit tell the path when it is located on my computer. I was trying to use `(concat (file-name-directory (or load-file-name buffer-file-name)) "library/include")` for *.../source/library/include* and just `(file-name-directory (or load-file-name buffer-file-name)` for *.../source*. Since .dir-locals.el is located in */Users/user/Documents/project\_name/source* However when I replace the part with its respective instructions I got ``` Error while checking syntax automatically: (error "Value (\"/Users/user/Documents/project_name/source" (eval concat (file-name-directory (or load-file-name buffer-file-name)) \"library/include\") of flycheck-clang-include-path for option \"-I\" is not a list of strings") ``` I tried to use it with eval but did not work, How can I accomplish my goal? EDIT: I test using `eval` as db48x suggested as the following: ``` ((c++-mode . ((flycheck-clang-language-standard . "c++14") (eval . (setq flycheck-clang-include-path '("/Users/user/Documents/project_name/source" "/Users/user/Documents/project_name/source/library/include")) ) ) )) ``` That worked fine, but when adding replacing the second path with `(concat (file-name-directory (or load-file-name buffer-file-name)) "library/include")` got that it is not a list of string. # Answer > 0 votes In this context, `eval` isn't a function, it's just a symbol that tells it to evaluate a form rather than to set a variable. You need to do this instead: ``` ((c++-mode . ((flycheck-clang-language-standard . "c++14") (eval . (setq flycheck-clang-include-path "/Users/user/Documents/project_name/source" (concat (file-name-directory (or load-file-name buffer-file-name)) "library/include"))))) ``` Edit: Oops, you're right. In addition to leaving out a parenthesis, I left out something else that is important: I forgot to build a list of filenames. You almost fixed it correctly by putting the filenames in a quoted list, but the elements of a quoted list are not evaluated, so the quoted list just has the same non-filename stuff in it and gives you the same error. You can call the `list` function instead to build a list out of things that need to be evaluated. For example: ``` ((c++-mode . ((flycheck-clang-language-standard . "c++14") (eval . (setq flycheck-clang-include-path (list "/Users/user/Documents/project_name/source" (concat (file-name-directory (or load-file-name buffer-file-name)) "library/include"))))))) ``` I've actually tested it this time, so I know it works. --- Tags: flycheck, directory-local-variables ---