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-59359
https://emacs.stackexchange.com/questions/59359
Icicles error: Cannot decrease the defualt face height more than it already
2020-06-30T17:12:51.663
# Question Title: Icicles error: Cannot decrease the defualt face height more than it already On `icy-mode` is enabled, I keep getting following error while I am typing, which makes it very difficult to type: ``` Cannot decrease the defualt face height more than it already. ``` Example case: `M-x` =\> `ibuf [TAB]` and when enter a character it gives the warning message. **\[Q\]** Can I supress/fix this error? Based on the windows lise sometime mini buffer also open vertically or horizontally. My Setup: ``` (add-to-list 'load-path "~/.emacs.d/lisp/icicles") (require 'icicles) (icy-mode 1) (set-face-attribute 'default nil :height 100) (variable-pitch-mode t) ``` # Answer This solved my issue: I added following line into .emacs file. `(setq icicle-Completions-text-scale-decrease 0.00)` This was set to `0.75` on the `icicles-opt.el` file. From the original file `L2451`: > <pre><code>icicle-Completions-text-scale-decrease 0.75 > "*Initial height decrease for text in buffer `*Completions*'. A value of 0.0 means the height is not decreased at all. This is used as > the argument to function `text-scale-decrease'. ``` > </code></pre> > 0 votes --- Tags: icicles ---
thread-59347
https://emacs.stackexchange.com/questions/59347
How to delete the contents of a buffer by name
2020-06-30T10:11:59.123
# Question Title: How to delete the contents of a buffer by name For example in gdb mode, there is a buffer named `*input/output of <program name>*`, that I want to clear each time I press `C-c l`. # Answer > 1 votes In general, if you don't know the exact name of the buffer, you need to call `buffer-list` to obtain the list of buffers and filter the result to only act on the desired buffer(s). Untested code: ``` (defun erase-buffers-matching (regexp) "Erase the content of all buffers whose name matches REGEXP." (interactive "sErase buffers matching: ") (save-match-data (mapc (lambda (buffer) (cond ((not (string-match regexp (buffer-name buffer)))) ((and (buffer-file-name buffer) (buffer-modified-p buffer)) (message "Skipping buffer %s with unsaved data" (buffer-name buffer)) (t (with-current-buffer buffer (erase-buffer))))) (buffer-list)))) ``` **For the specific case of the GDB program output buffer**, GDB keeps track of it. It's the `gdb-inferior-io` buffer. ``` (defun erase-gdb-inferior-io-buffer () (interactive) (with-current-buffer (gdb-get-buffer 'gdb-inferior-io) (erase-buffer))) (global-set-key (kbd "C-c l") 'erase-gdb-inferior-io-buffer) ``` # Answer > 0 votes If this is something you want to do often, you could define a function for it in your .emacs file. Otherwise you could type it out in *scratch*, evaluate it and then assign it a key binding? You could try: ``` (defun my/clear_buffer () (interactive) (let ((tmp (buffer-name))) (if (get-buffer "<buffer name>") ;; check if buffer exists (progn (switch-to-buffer "<buffer name>") ;; switch to the buffer (erase-buffer) ;; erase it (switch-to-buffer tmp))))) ;; switch back ``` --- Tags: buffers, gdb, deletion ---
thread-59365
https://emacs.stackexchange.com/questions/59365
icicles: How set set Ctrl+p for [up] and Ctrl+n for [down]
2020-06-30T19:40:49.587
# Question Title: icicles: How set set Ctrl+p for [up] and Ctrl+n for [down] In the minibuffer for Icicles when I press `C-p` or `C-n` the minibuffer says `beginning of the buffer`, `end of the buffer` respectively. Instead want to move around the found candidate using `C-p` and `C-n` instead of using arrow keys `[up]`, `[down]`. I want to keep following setup (Using \`C-n\` and \`C-p\` to iterate as cycle in \`find-file\` instead of up/down arrow keys) for all the minibuffers except one for `Icicles`. If I have it for Icicles: `C-n` and `C-p` moves around the action keys as equivalent to `M-n` and `M-p`. ``` (define-key minibuffer-local-map (kbd "C-n") #'next-line-or-history-element) (define-key minibuffer-local-map (kbd "C-p") #'previous-line-or-history-element) ``` --- I have also try to set from group-custumization adding `[C-p]` into the array list but it did not helped. ``` (custom-set-variables '(icicle-modal-cycle-down-keys (quote ([C-n] [down] [nil mouse-5] [mouse-5]))) ... ``` # Answer > 1 votes In Icicles, like in vanilla Emacs, the minibuffer is a normal editing buffer in most respects, i.e., aside from keys that have particular behavior, such as `TAB` during completion. In particular, Icicles does not bind keys such as `C-p` and `C-n`, so they have their usual, global behavior, including in the minibuffer: `previous-line` and `next-line`, respectively. As such, they're useful when you have multiple-line minibuffer input and you want to move the cursor among the lines. That's an important use case, but otherwise, those keys aren't useful in the minibuffer. So no, those keys don't "close" the minibuffer (unless you've got something else going on, e.g. your global binding of those keys causes the minibuffer to be exited). Your real question, I guess, is how to "move among" the current completion candidates. That can mean at least 3 things in Icicles (actually more): 1. Cycle among them, make each in turn the current completion candidate. For this you use keys such as `<up>` and `<down>` (vertical arrows). 2. Cycle among them (#1), and *act* on each of them in turn, using the command's action. For this you use keys such as `<C-up>` and `<C-down>` (Control + vertical arrows). 3. Cycle among them (#1), and show help for each of them in turn. For this you use keys such as `<C-M-up>` and `<C-M-down>` (Control + Meta + vertical arrows). The actual keys are the values of these user options: * `icicle-modal-cycle-down-keys` (`down`) * `icicle-modal-cycle-up-keys` (`up`) * `icicle-modal-cycle-down-action-keys` (`C-down`) * `icicle-modal-cycle-up-action-keys` (`C-up`) * `icicle-modal-cycle-down-help-keys` (`C-M-down`) * `icicle-modal-cycle-up-help-keys` (`C-M-up`) This is all described clearly in the doc. Here's a page about customizing key bindings. --- Update after you edited the question to ask how to customize option `icicle-modal-cycle-down-keys`: You say that you set that option value to `([C-n] [down] [nil mouse-5] [mouse-5])`, and that didn't help. That's because *`[C-n]` is not a valid key representation for `C-n`*. *Instead, try `"C-n"`, or `[(control ?n)]`, or `[?\C-n]`, or `"^N"` (where you use `C-q C-n` to insert the `^N` (Control N) character - it's not the 2 chars `^N`, but I can't show that here).* (And you need to toggle `icy-mode` off and on again, for the key-bindings change to take effect.) See (emacs) Init Rebinding. --- Tags: key-bindings, icicles ---
thread-27918
https://emacs.stackexchange.com/questions/27918
Why is exec-path different in emacsclient / emacsserver than in emacs?
2016-10-19T01:37:17.830
# Question Title: Why is exec-path different in emacsclient / emacsserver than in emacs? I am trying to run an identical emacsserver setup as the emacs I normally use. I am having issues because the emacsserver has a different `exec-path` variable when it starts than when normal `emacs` does. To start emacsserver I am using: `/usr/bin/emacs --daemon` in a systemd script. To start emacs normally I just type `emacs` emacsserver (which I connect to by typing emacsclient`) has the following value for`exec-path\`: ``` exec-path is a variable defined in `C source code'. Its value is ("PATH" "/usr/local/sbin" "/usr/local/bin" "/usr/sbin" "/usr/bin" "/sbin" "/bin" "/usr/lib/emacs/24.5/x86_64-linux-gnu") ``` Whereas "normal" emacs has the full path I normally use: ``` exec-path is a variable defined in `C source code'. Its value is ("/usr/local/sbin" "/usr/local/bin" "/usr/sbin" "/usr/bin" "/sbin" "/bin" "/usr/games" "/usr/local/games" "/snap/bin" "/bin" "/usr/local/bin" "/sbin" "/usr/bin" "/usr/local/sbin" "/opt/node-v4.2.1-linux-x64/bin" "/opt/node-v4.2.1-li\ nux-x64/bin/node" "/home/optonox/.npm-global/bin" "/usr/local/mongodb/bin" "/snap/bin" "/bin" "/usr/local/bin" "/sbin" "/usr/bin" "/usr/local/sbin" "/opt/node-v4.2.1-linux-x64/bin" "/opt/node-v4.2.1-linux-x64/bin/node" "/home/optono\ x/.npm-global/bin" "/usr/local/mongodb/bin" "/usr/lib/emacs/24.5/x86_64-linux-gnu") ``` Why is this happening / can I start it normally somehow? # Answer > 4 votes `exec_path` is initialized from the `EMACSPATH` and `PATH` environment variables. Emacs also adds the directory containing the emacs binary to the end. This is done at startup by `init_callproc_1` in `callproc.c` (http://git.savannah.gnu.org/cgit/emacs.git/tree/src/callproc.c#n1466) The `systemd.exec` man page has a section about the environment variables it sets whenever it starts a process. Here's what it has to say about `PATH`: ``` $PATH Colon-separated list of directories to use when launching executables. Systemd uses a fixed value of /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin. ``` Since that matches very well with your `exec-path`, the only real mystery is why you're ending up with the string `"PATH"` in there; that's kinda weird. # Answer > 1 votes Old question, new answer... I was in the same position, and met success following the advice in to install the package `exec-path-from-shell` and add to my `~/.emacs.d/init.el` ``` (require 'exec-path-from-shell) (exec-path-from-shell-initialize) ``` For me, this solution was necessitated by not having any other means than `systemd` to get an `emacs --daemon` to reliably persist between between (dropped) sessions. --- Tags: emacsclient, path, exec-path ---
thread-59375
https://emacs.stackexchange.com/questions/59375
Emails from multiple accounts go to the same trash folder
2020-07-01T11:30:14.363
# Question Title: Emails from multiple accounts go to the same trash folder I use Emacs and mu4e for email. I set up multiple accounts as in the manual. I also included this snippet from here to send deleted messages to a folder instead of deleting them permanently: ``` (add-to-list 'mu4e-marks '(trash :char ("d" . "▼") :prompt "dtrash" :dyn-target (lambda (target msg) (mu4e-get-trash-folder msg)) :action (lambda (docid msg target) (mu4e~proc-move docid (mu4e~mark-check-target target) "-N")))) ``` The problem is that all deleted messages are marked to go to the Trash of the main account instead of the Trash of their own account. Running help on key `d` shows: ``` d runs the command mu4e-headers-mark-or-move-to-trash (found in mu4e-headers-mode-map), which is an interactive compiled Lisp function in ‘/usr/local/Cellar/mu/1.4.1/share/emacs/site-lisp/mu/mu4e/mu4e-headers.el’. It is bound to d, . (mu4e-headers-mark-or-move-to-trash) ``` which in turn shows: ``` mu4e-headers-mark-or-move-to-trash is an interactive compiled Lisp function in ‘/usr/local/Cellar/mu/1.4.1/share/emacs/site-lisp/mu/mu4e/mu4e-headers.el’. It is bound to d, . (mu4e-headers-mark-or-move-to-trash) Mark message for "move" to the trash folder if the message maildir matches any regexp in ‘mu4e-move-to-trash-patterns’. Otherwise mark with the "trash" flag. Also see ‘mu4e-view-mark-or-move-to-trash’. ``` The variable `mu4e-move-to-trash-patterns` is set to `nil`, and `mu4e-view-mark-or-move-to-trash` shows: ``` mu4e-view-mark-or-move-to-trash is an interactive compiled Lisp function in ‘/usr/local/Cellar/mu/1.4.1/share/emacs/site-lisp/mu/mu4e/mu4e-view.el’. (mu4e-view-mark-or-move-to-trash &optional N) See ‘mu4e-headers-mark-or-move-to-trash’. ``` How can I send each message to the trash of its own mailbox? # Answer > 0 votes The answer was in that same tutorial with the use of contexts: ``` (setq mu4e-contexts `( ,(make-mu4e-context :name "Gmail" :match-func (lambda (msg) (when msg (string-prefix-p "/Gmail" (mu4e-message-field msg :maildir)))) :vars '( (mu4e-trash-folder . "/Gmail/[Gmail].Trash") (mu4e-refile-folder . "/Gmail/[Gmail].Archive") )) ,(make-mu4e-context :name "Exchange" :match-func (lambda (msg) (when msg (string-prefix-p "/Exchange" (mu4e-message-field msg :maildir)))) :vars '( (mu4e-trash-folder . "/Exchange/Deleted Items") (mu4e-refile-folder . exchange-mu4e-refile-folder) )) )) ``` --- Tags: mu4e ---
thread-59372
https://emacs.stackexchange.com/questions/59372
Is there a more convenient way to find out what keys do in org-agenda than looking it up or just pressing them?
2020-07-01T06:35:45.240
# Question Title: Is there a more convenient way to find out what keys do in org-agenda than looking it up or just pressing them? Sometimes just pressing keys until one does what I want works, but this feels rather unelegant. Is there an easier way of finding out what keys do what? # Answer > 1 votes When you're in the agenda buffer try `C-h m` which should give an overview of the current mode, show which commands are available and list their keybindings. There are a few other ways to access the built in documentation (as found in the manual) that you might want to explore. # Answer > 0 votes 1. Use `kc-mode` or `kc-auto-mode`, from library **Key See** (code: **`keysee.el`**). (It, in turn, requires library Sortie (`sortie.el`). * **`kc-mode`** shows you, *on demand*, at any time, all of the keys you can use then, along with the commands they are bound to. * **`kc-auto-mode`** does the same as `kc-mode`, but it also shows you *automatically* all of the keys you can use after you use a prefix key (e.g. `C-x`), along with their commands. 2. Even better: use **Icicles** key completion. (*Key See* behavior is a simplified version of this.) In addition to what KC shows you, you can immediately get complete help on any key/command shown - its full doc string is shown in buffer `*Help*`. --- Tags: key-bindings, org-agenda, help ---
thread-59339
https://emacs.stackexchange.com/questions/59339
In magit, the log '-s' option shows ESCAPE characters instead of changing the color of the selected text
2020-06-29T23:49:45.570
# Question Title: In magit, the log '-s' option shows ESCAPE characters instead of changing the color of the selected text Here is an example of a copy of the output of the magit log output with `-s` with the actual names omitted. (The ESC character precedes each of the \[31 and \[32 sequences in the following example in the Emacs output.) ``` b1fe5d2 Ignore files in the template Author: omit Committer: omit .gitignore | 142 [32m+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++[m[31m--[m 1 file changed, 138 insertions(+), 4 deletions(-) ``` **Update 2020-07-01** My `~/.gitconfig` file had ``` [color] ui = true ``` as surmised by @phils After the change to ui = auto, the colors in the diff stats are properly drawn, even when I add show graph in color `-c` flag as well. # Answer Note Well: If @phils would like to post an answer I would be happy to delete this one. Let me know by tomorrow. As @phils suggested in the comments to the OP, the problem was solved by using the following in the `~/.gitconfig` file: ``` [color] ui = auto ``` The problem was caused by the following stanza in the `~/.gitconfig` file ``` color ui = true ``` > 1 votes --- Tags: magit ---
thread-59361
https://emacs.stackexchange.com/questions/59361
Link to mu4e e-mails in MacOS
2020-06-30T18:01:18.060
# Question Title: Link to mu4e e-mails in MacOS My e-mail client is mu4e. I can easily create links to org-mode files via `org-mu4e-store-and-capture`, as described here https://www.djcbsoftware.nl/code/mu/mu4e/Org\_002dmode-links.html, for instance. Now I would like to additionally link from some non-emacs MacOS app, such as the calendar, to e-mails in mu4e. I have to solve two problems for this: (1) When I have already a link to an e-mail message of the form `mu4e:msgid:....@....com` (like the links stored in org mode). How can I open such a link via emacsclient? I would like to run the command ``` /usr/local/bin/emacsclient --eval 'SOMEFUNCTION "mu4e:msgid:....@....com"' ``` in a shell, where `SOMEFUNCTION` is the function that org-mode calls when a link of the form `mu4e:msgid:....@....com` is clicked. How can I determine the name of this function, in order to use it in the above shell command? (2) When I am viewing an e-mail in mu4e, I would like to call a function that provides me with the `mu4e:msgid:....@....com` link to this e-mail. This happens (among other things) in `org-mu4e-store-and-capture`, how can I use this to copy a link to the clipboard in order to paste it to another MacOS application? Thanks in advance for any advice! # Answer 1. To open a link from a string: ``` (org-link-open-from-string "mu4e:msgid:....@....com") ``` 2. To make the stored link the latest kill in the kill ring: ``` (advice-add 'org-store-link :after (lambda (arg &optional interactive?) (when (or (eq major-mode 'mu4e-headers-mode) (eq major-mode 'mu4e-view-mode)) (kill-new (caar org-stored-links))))) ``` > 0 votes --- Tags: mu4e ---
thread-59371
https://emacs.stackexchange.com/questions/59371
Fractional vertical scrolling
2020-07-01T06:18:45.080
# Question Title: Fractional vertical scrolling I found this link About fractional verticle scrolling for emacs. However there was not any explanation about how to configure this for scrolling of normal files. How do I configure a fractional scroll step? I am thinking of implementing a smooth scrolling configuration. # Answer > 3 votes That's to be expected because this is the Emacs Lisp reference, not the Emacs manual. It explains how a developer can adjust the vertical scrolling in a fine-grained way. Emacs 26.1 introduced `pixel-scroll-mode` which demonstrates this capability. --- Tags: scrolling ---
thread-59387
https://emacs.stackexchange.com/questions/59387
Is it possible to force `markdown-mode` during git commit?
2020-07-01T19:14:27.740
# Question Title: Is it possible to force `markdown-mode` during git commit? I was using following answer: https://emacs.stackexchange.com/a/57535/18414 to set markdown on the `.git/COMMIT_EDITMSG` file. ``` (add-to-list 'auto-mode-alist '("/\\.git/COMMIT_EDITMSG\\'" . markdown-mode)) ``` --- My `.gitconfig` file, to open commit message with `emacs`: ``` [core] editor = TERM=xterm-256color emacsclient -t -q ``` --- On my emacs-daemon `magit-git` was enable. Now during the commit (due to some squash operations in git), I see the commit messag along with the opened `magit-diff:` window. Example image: When I check the `major-mode` it became `Local in buffer COMMIT_EDITMSG; global value is fundamental-mode`. Afterwards, when I added into `COMMIT_EDITMSG` file and do `C-s C-x`, commit fails and I get following message: `fatal: could not read commit message: No such file or directory` But instead if I re-enable `markdown-mode`, save and exit there would be no error. **\[Q\]** Is it possible to force `markdown-mode` during git commit? # Answer You're using a package which is very opinionated about how things with Git should work, so don't be surprised if related Emacs configuration which works *without* Magit gets clobbered when you *do* use Magit. In this instance, Magit uses `git-commit.el` which provides the variable `git-commit-major-mode` for controlling this. If you want to control how things happen in Magit, you want to be checking the Magit documentation firstly. > 2 votes --- Tags: magit, git, markdown-mode ---
thread-59322
https://emacs.stackexchange.com/questions/59322
How to count number of times a recurring task is marked done after logging is enabled?
2020-06-29T04:00:30.710
# Question Title: How to count number of times a recurring task is marked done after logging is enabled? I had a task in my org file for which I wanted to keep track of the number of times a task is marked as DONE when it's recurring. I am logging my change to the drawer and thus it should be possible to get the count. Currently, I count the number of times the task was executed manually but want to automate this effort. This option would help me keep track of the number of times the task was marked DONE. It would also be amazing if we could reset the count after getting it done a fixed number of times. I am not a programmer so I'm struggling with implementing a solution in elisp to do the same. Thanks for all your help. # Answer We write two functions: one to count the number of DONE entries in the drawer and one to add the count as a property to the headline. Here's an example Org mode document delineating the basic assumptions: ``` * TODO foo SCHEDULED: <2020-07-07 Tue +1d> :PROPERTIES: :LOG_INTO_DRAWER: logging :VISIBILITY: folded :LAST_REPEAT: [2020-07-01 Wed 16:03] :END: :logging: - State "DONE" from "TODO" [2020-07-01 Wed 16:03] - State "DONE" from "TODO" [2020-07-01 Wed 16:03] - State "DONE" from "TODO" [2020-07-01 Wed 16:03] - State "DONE" from "TODO" [2020-07-01 Wed 15:58] - State "DONE" from "TODO" [2020-07-01 Wed 13:38] - State "DONE" from "TODO" [2020-07-01 Wed 13:38] :END: ``` We assume that there is a `LOG_INTO_DRAWER` property naming the drawer where the logging is done (`logging` in this case), and we have transitioned to DONE a number of times. Here's the (decidedly less clunky, thanks to @erikstokes's comment) code: ``` (defun ndk/count-done () (interactive) (save-excursion ;; we need to end up *before* the start of the drawer in order ;; to parse it correctly, so we back up one line from where org-log-beginning tells us. (goto-char (org-log-beginning)) (forward-line -1) (let ((contents (cadr (org-element-drawer-parser nil nil)))) (count-lines (plist-get contents :contents-begin) (plist-get contents :contents-end))))) (defun ndk/put-count () (interactive) (let ((count (ndk/count-done))) (org-entry-put (point) "done-count" (format "%d" count)))) ``` We assume that `point` is at the beginning of the headline. Both functions are declared `interactive` so you can call them with `M-x ndk/count-done` or `M-x ndk/put-count` for debugging, but only the second really needs to be. So if you place the cursor on the `*` of the headline and say `M-x ndk/count-done` you should get `6` as a result in the echo area. The function gets to the beginning of the log and then calls `org-element-drawer-parser` to parse the drawer and extract the beginning and end of the contents of the drawer. It then passes those two to `count-lines` and returns the result. Doing `M-x ndk/put-count` at the same point calls the previous function to count the number of `DONE` lines and then inserts the count as a property `done-count` in the property drawer. Resetting the count after every N times that the task is done is just a matter of calculating a remainder when dividing the count by N. Here's an implementation where N is obtained as the value of the `reset-count` property (but if there is no such property, we take N=10): ``` (defun ndk/count (count) (let* ((reset-count-prop (org-entry-get (point) "reset-count")) (reset-count (or (and reset-count-prop (string-to-number reset-count-prop)) 10))) (% count reset-count))) (defun ndk/put-count () (interactive) (let ((count (ndk/count-done))) (org-entry-put (point) "done-count" (format "%d" (ndk/count count))))) ``` > 1 votes --- Tags: org-mode ---
thread-59378
https://emacs.stackexchange.com/questions/59378
How can I kill buffers based on mode?
2020-07-01T12:01:14.090
# Question Title: How can I kill buffers based on mode? I know about `kill-matching-buffers` but that searches buffer names, I want instead to search buffer **modes**. For example, I might want to kill all buffers that have "notmuch-" or "\[Notmuch\]" as substrings in the mode column in the \*Buffer List\*. # Answer You can use `M-x ibuffer` which I recommend binding to `C-x``C-b` to replace the default (or whatever binding you prefer). Use `%``m` to mark buffers by matching a regexp against the displayed mode-name (e.g. `Emacs-Lisp`). Then use `D` to kill the marked buffers. > "notmuch-" or "\[Notmuch\]" Note that, as we're dealing with regexps, you would need to enter `\[Notmuch\]` for the latter. --- You could alternatively use `*``M` to match a specific mode symbol (e.g. `emacs-lisp-mode`). You get completion for the possible values with this approach. `ibuffer` is very powerful; be sure to use `C-h``m` to learn about its grouping and filtering abilities, amongst other features. > 9 votes # Answer You can do this with Helm by entering a partial major-mode name prefixed with `*`. For example: `*lisp`, `*sh` etc. You can also use negation, e.g. `!*org` to narrow down all non-Org mode buffers, or specify multiple major modes, e.g. `*!lisp,!sh,!fun` etc. Then press `M-a` to mark those buffers and `M-D` to kill them. For example, to kill all dired buffers: 1. `M-x helm-buffer-list` 2. `*dired` 3. `M-a` 4. `M-D` > 3 votes # Answer If you use Icicles then, with any command that completes against buffer names, you can filter (include or exclude) the candidates by mode (either exact mode match or `derived-mode-p`). And with Icicles you can *act on all* matching candidates at once, with **`C-!`**. If you use a plain prefix arg (**`C-u`**) with a command with buffer candidates then the candidates are only buffers with the *same mode* (or a mode derived from the same mode) as the current buffer. So for example, if you use **`C-u C-x k`** then the only candidates for completion are buffers in the same mode as the buffer you're currently in. You can then use **`C-!`** to kill them all. Or you can use `C-x k` (no prefix arg), and then hit a key to *remove some candidates*, then use `C-!` to kill all the remaining candidate buffers. To remove buffer candidates that have a given mode, you can use **`C-x C-m -`**. You're prompted for the mode. Or to remove all candidates *except* those with a given mode (i.e., *keep only* buffers with that mode), use **`C-x C-m +`**. Again, once you've filtered out candidates, you can kill all remaining candidate buffers using `C-!`. --- More generally, when you use *any* Icicles command that completes against buffer names, you can filter the candidates (by mode, as indicated above, or in other ways) and then use *`C-u S-delete`* to kill all remaining candidates. So you need not use `C-x k` \- you can kill buffers even when you use `C-x b` or whatever. Obviously, since this is not the main purpose of a command such as `C-x b`, if you use `S-delete` you're asked to *confirm* killing. > 0 votes --- Tags: buffers, kill-buffer ---
thread-59398
https://emacs.stackexchange.com/questions/59398
How to code a command to `write-region` to a particular file?
2020-07-02T06:22:01.153
# Question Title: How to code a command to `write-region` to a particular file? I have a system that I am not allowed permissions to install software but need to copy text from the remote server to the host computer's system clipboard. Because I can't install xclip or xsel and I am using emacs with tmux, the formatting of text gets all screwed up because of the newlines that tmux introduces. I thought of the possibility of writing regions to a file that I can remotely open the file and manually copy the properly formatted text. I've created my own keyboard defined macro using write-regions that worked during a current open session of emacs but would have problems upon reopening. Error along the lines of command terminated by ringing the bell. I've also used the following answer's code but the OP wanted to interactively set the file but in my case the file is known already so there is no need for me to set it each time I use the function. Is there a way for me to write this function such that the a region automatically writes to `~/copybuffer.txt` and doesn't delete the region afterwards. See original QA here and my code edits. Unfortunately, in my code I see variable is void: start. I clearly don't understand something about defining lisp functions. ``` (defun copybuffer "function takes current region, and writes it to specified file" (write-region region-beginning region-end '~/copybuffer.txt' t))) ``` # Answer > 3 votes It's only you're having syntax issues, try this: ``` (defun copybuffer () "function takes current region, and writes it to specified file" (interactive) (write-region (region-beginning) (region-end) "~/copybuffer.txt")) ``` Summary: * `region-beginning` and `region-end` are functions, so they have to be between parenthesis to be recognized as functions. * `start` and `end` should be variables which you haven't defined in your code, so I used region's limits, which should fit the bill in this case. * `copybuffer` didn't conform to the function definition syntax, and was closed early after `write-region`. * Added `interactive`to be able to call it with `M-x`. * Removed `t` as this is an optional argument that appends to file instead of overwrites Take a look to the elisp intro: `C-h i m Emacs elisp intro`. --- Tags: region, elisp-macros ---
thread-59392
https://emacs.stackexchange.com/questions/59392
org agenda not loading org-agenda-files funkiness
2020-07-01T20:58:50.670
# Question Title: org agenda not loading org-agenda-files funkiness My config file has the following funkiness: I have the line `(setq org-agenda-files '("~/org/tktodos.org" ))` followed by the line `(org-agenda nil "a")`. When my org file loads, I can see my todos in my agenda. If I then press C-h v org-agenda-files, the value is set to nil, so if I exit and reopen, none of my todos will show. If I move the line `(setq org-agenda-files '("~/org/tktodos.org" ))` to the very end of the config file, nothing changes. If I re-evaluate the line `(setq org-agenda-files '("~/org/tktodos.org" ))`, org-agenda works again. What's going on? # Answer > 0 votes So the best "temporary" (may not be temporary xD ) solution I have is to just customize the org-agenda-files variable and save it for all future sessions. Not my fave, but ya gotta do what ya gotta do xP --- Tags: init-file, org-agenda ---
thread-18586
https://emacs.stackexchange.com/questions/18586
Strange behaviour of Solarized-theme in Org-mode
2015-12-03T18:32:39.327
# Question Title: Strange behaviour of Solarized-theme in Org-mode I installed the Solarized theme through package-install RET solarized-theme, and it went largely well but .org files have a strange appearance: Note how it hides the line numbers. Here is how it looks on other files: How do I make it so that org files have the same appearance as other files? Please note that I am new to this so I may not understand some things that are obvious to more experienced Emacs hackers. My init.el file: ``` (package-initialize) ;;settings files location (add-to-list 'load-path "~/.emacs.d/settings") (add-to-list 'load-path "~/.emacs.d/elpa/") ;;import settings from other files (require 'general-settings) ;;theme loading (add-to-list 'load-path "~/.emacs.d/elpa/") (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. '(custom-enabled-themes (quote (solarized-dark))) '(custom-safe-themes (quote ("8aebf25556399b58091e533e455dd50a6a9cba958cc4ebb0aab175863c25b9a4" default))) '(inhibit-startup-screen t) '(package-selected-packages (quote (solarized-theme)))) (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. ) (load-theme 'solarized-dark t) ;;ido (require 'ido) (ido-mode t)(package-initialize) (setq package-archives '(("gnu" . "http://elpa.gnu.org/packages/") ("marmalade" . "http://marmalade-repo.org/packages/") ("melpa" . "http://melpa.milkbox.net/packages/"))) ;;org-mode ;;markdown (autoload 'markdown-mode "markdown-mode" "Major mode for editing Markdown files" t) (add-to-list 'auto-mode-alist '("\\(.text\\|.markdown\\|.md\\)'" . markdown-mode)) (setq markdown-enable-math t) ;;enables math functions ``` my settings file (some useful things I borrowed from a friend): ``` ;;------------------------------;; ;; Global Editor Settings ;; ;;------------------------------;; (setq current-language-environment "English") ;; Language (setq inhibit-startup-screen t) ;; Don't show the start-up Screen (menu-bar-mode 0) ;; Toggle menu bar (require 'tool-bar) ;; Toggle toolbar (tool-bar-mode 0) (global-hl-line-mode 1) ;; Highlight line with cursorx (if window-system (scroll-bar-mode 0)) ;; Toggle scroll bar (require 'mwheel) ;; Toggle mouse wheel support for scrolling (mouse-wheel-mode 1) (transient-mark-mode 1) ;; Transient-Mark Mode (highlight selection (global-linum-mode t) ;; Display line number at left (line-number-mode 1) (column-number-mode 1) ;; Text decoration ;; Window resizing bindings (global-set-key (kbd "S-C-<left>") 'shrink-window-horizontally) (global-set-key (kbd "S-C-<right>") 'enlarge-window-horizontally) (global-set-key (kbd "S-C-<down>") 'shrink-window) (global-set-key (kbd "S-C-<up>") 'enlarge-window) (provide 'general-settings) ``` # Answer > 1 votes For those with this problem, I solved it as follows: Solarized theme has a toggle to scale font sizes of org headings. Disable that with this line in the init file to fix the issue: ``` (setq solarized-scale-org-headlines nil) ``` # Answer > 0 votes You need to set solarized-scale-org-headlines to nil before loading the theme ``` (setq solarized-scale-org-headlines nil) (load-theme 'solarized-zenburn t) ``` --- Tags: org-mode, themes ---
thread-59408
https://emacs.stackexchange.com/questions/59408
How to print escaped characters with princ
2020-07-02T14:41:40.160
# Question Title: How to print escaped characters with princ When Emacs shows an integer value in the minibuffer, or as an output to IELM, it shows three representations of it -- octal, hex and as character: ``` ELISP> 10 10 (#o12, #xa, ?\C-j) ``` This is really nice, and I'd like to use something like that in my programs. Now, while I can use `format` to show an integer as octal (with `%o`) or with hex (with `%x`), I don't know how to get the nice formatted character as the above. `%c` will actually print the character without escaping, and will, for example, print a line feed for 10. I have tried the `print-escape-*` variables, without success: ``` ELISP> (let ((print-escape-newlines t) (print-escape-nonascii t) (print-escape-multibyte t) (print-escape-control-characters t)) (concat "char: " (string 10))) "char: " ELISP> (let ((print-escape-newlines t) (print-escape-nonascii t) (print-escape-multibyte t) (print-escape-control-characters t)) (format "char: %s" (string 10))) "char: " ELISP> (let ((print-escape-newlines t) (print-escape-nonascii t) (print-escape-multibyte t) (print-escape-control-characters t)) (format "char: %s" 10)) "char: 10" ELISP> (let ((print-escape-newlines t) (print-escape-nonascii t) (print-escape-multibyte t) (print-escape-control-characters t)) (format "char: %c" 10)) "char: " ``` What I want is to get a string with the escaped character, to later print with `princ`. I've tried looking into the source for IELM and the minibuffer, but they seem to delegate printing to other parts of Emacs, and I couldn't find how it's done. How can I get those printed the way I described? # Answer > 0 votes Try this: `(format "(#o%o, #x%x, ?\\%s)" 10 10 (single-key-description 10))` You might need to use `(princ (format "(#o%o, #x%x, ?\\%s)" 10 10 (single-key-description 10))`, depending on what you're doing with it. You can get this yourself by looking at the code that implements `M-:`: command `eval-expression`. You'll see that it uses this, for a character: `(eval-expression-print-format 10)` That's an equivalent answer to what I show above. (To see `eval-expression` at work, step by step, you can use `M-x debug-on-entry`.) --- Tags: display, characters, print ---
thread-59410
https://emacs.stackexchange.com/questions/59410
Display Δ in the *Shell Command Output* Buffer
2020-07-02T17:05:46.780
# Question Title: Display Δ in the *Shell Command Output* Buffer I have a shell command I'm running from Emacs that has a Δ character in its output. How can I configure the `*Shell Command Output*` buffer to display UTF-8 by default? edit: There could also be something else weird going on. It displays `Î8 μs` when it should be `Δ15 μs` # Answer You can use the per-command setting of the encoding that @choroba mentions in his comment (`C-x RET c utf-8`) which will only affect the next command, but you can also set UTF-8 to be the default encoding everywhere. Add ``` (set-language-environment "UTF-8") ``` to your init file and restart emacs. Or for the current session, click on "Options/Multilingual Environment/Set Language Environment" and select "UTF-8". Unless you have very specific needs (CJK characters with special encodings, Microsoft Code Page stuff etc), I believe that UTF-8 is safe: I have never regretted setting it globally, but I cannot guarantee that you will not run into problems. IME, the problems tend to be few and far-between and have to do with the special encodings I mentioned (and in those cases, you can use the one-off setting of the encoding to deal with the problem). But you might want to wait for other opinions before switching over wholesale, and in the meantime deal with the problem one case at a time, using the `C-x RET c utf-8` method for each command. > 1 votes --- Tags: character-encoding, shell-command, display, characters ---
thread-59412
https://emacs.stackexchange.com/questions/59412
Can I navigate Bookmark+ bookmarks like I can with e.g. helm-bookmark?
2020-07-02T19:12:27.007
# Question Title: Can I navigate Bookmark+ bookmarks like I can with e.g. helm-bookmark? I am experimenting with Bookmark+ and would like to be able to navigate to a bookmark using a similar workflow to that which I currently use to navigate bookmarks. For example, previously in order to navigate to a bookmark I am used to using something like `helm-bookmarks`, then entering some text which Emacs will use to filter the set of bookmarks to the one I want. If I am explicit enough, the correct bookmark is highlighted at the top of the list as I type, I hit enter and am transported to the bookmark position. All is good. With Bookmark+ however, I am opening the bookmark list, which I can then filter by typing `/<search text>`. The matching set of bookmarks is shown to me dynamically, as before (although the UI is different), but the focus does not shift to any of the matching bookmarks. That then entails a number of rapid hits on the down cursor key to go to the bookmark I want. Is there a way to navigate to a Bookmark+ bookmark in a similar way to that when I use `helm-bookmarks` (or `bookmark-jump` for that matter)? # Answer Bookmark+ does not offer or impose any particular completion mechanism. It uses vanilla Emacs completion functions such as `completing-read`. If you have a completion framework, such as Icicles, that can enhance the usual completion functions then it will naturally enhance completion with bookmarks etc. For example, you can then filter completion candidates on the fly, cycle among them, act on any number of them, etc. But that behavior comes from Icicles, not from Bookmark+ itself. \[Icicles and Bookmark+ in fact purposely play well together. There are 168 Icicles commands that are specific to bookmarks, most making use of Bookmark+ features. And in the other sense, there are 5 Bookmark+ commands that are specific to Icicles features (all having to do with Icicles search hits).\] In particular, the bookmark-list display, whether in Bookmark+ or vanilla Emacs, does not introduce anything special for completion or bookmark selection. As you noted, you can dynamically filter the bookmarks shown, but none of them is automatically "selected". The only sense in which there's an automatic selection is this: if no bookmarks are marked, then actions apply to the bookmark of the current line. In this, and in many other respects, the bookmark listing is like a Dired listing. If Helm can use regular Emacs bookmarks, providing some completion features that you like, then it should be able to do the same with bookmarks you create with Bookmark+. (But there may be some bookmark types that Helm doesn't recognize and can't handle specifically - dunno.) You can do a lot without using the bookmark-list display at all. Bookmark+ offers many jump commands that are specific to different contexts and different kinds of bookmark. For example, regardless of what mix of bookmarks you currently have loaded, type-specific jump commands offer candidates of particular types. "Type" here has a broad meaning, including things like bookmarks that target only the current file or buffer, bookmarks whose names match a given regexp, bookmarks whose tags match a given logical combination (AND, OR, NOT) of tags or a given regexp, etc., as well as bookmarks of a type in the sense of EWW, Info, Dired, autofile, autonamed, temporary, etc. bookmarks. But you mentioned "navigation", not just completion. Bookmark+ lets you cycle among the bookmarks in a navigation list. You can have any number of navlists, and some are available automatically. Consult the Bookmark+ doc for more info about what's available. > 0 votes --- Tags: completion, bookmarks, navigation ---
thread-59364
https://emacs.stackexchange.com/questions/59364
Changing text size doesn't work on all fonts in org-mode
2020-06-30T19:09:40.833
# Question Title: Changing text size doesn't work on all fonts in org-mode I have the following in my config: ``` ;; set a non programming font for text (when (member "Lucida Sans Unicode" (font-family-list)) (set-face-attribute 'variable-pitch nil :font "Lucida Sans Unicode")) ;; set a default font (when (member "Cascadia Code" (font-family-list)) (set-face-attribute 'default nil :font "Cascadia Code") (set-face-attribute 'fixed-pitch nil :font "Cascadia Code")) ;; specify font for all unicode characters (when (member "DejaVu Sans Mono" (font-family-list)) (set-fontset-font t 'unicode "DejaVu Sans Mono" nil 'prepend)) (add-hook 'org-mode-hook 'variable-pitch-mode) (custom-theme-set-faces 'user '(org-code ((t (:inherit (shadow fixed-pitch)))))) ``` This gives me the following result: As you can see, under the header Fonts that is in the font `Lucida Sans Unicode`, there is a line ``` : ezaeaz ``` that is correctly displayed in `Cascadia Code`. However, when I increase the font size with `Ctrl + mouse wheel` or by using `C-x C-+`, here is what happens: Org-mode being in variable pitch, the default font for the mode is `Lucida Sans Unicode`, which scaled up correctly. However the `Cascadia Code` font didn't, I assume because of the `custom-theme-set-faces` call that forces it to be something. How can I make it so that both fonts are always the same size, or a ratio of one another? # Answer > 0 votes Have variable-pitch inherit the scaling face: ``` (when (member "Lucida Sans Unicode" (font-family-list)) (set-face-attribute 'variable-pitch nil :font "Lucida Sans Unicode" :inherit t)) ``` --- Tags: org-mode, faces, fonts, variable-pitch ---
thread-59304
https://emacs.stackexchange.com/questions/59304
Find file in a project in a mono-repo like `projectile-find-file`
2020-06-27T14:31:56.453
# Question Title: Find file in a project in a mono-repo like `projectile-find-file` My code base consists of a "mono-repo". A single large repository containing a flat structure of projects. ``` Top Project1 Project2 Project3 Library Library ``` I've been using Projectile to navigate this so far, but I'm starting to get to the point where I want to be able to search within a given library or project. I have a function that will return the root of a library or project. How can I use `projectile-find-file`, or something like it, within one of these projects? # Work so far I found the following command `(helm-find-1 (my-mono-find-root))` that does something close to what I want. I'd quite like it to ignore some files tho. # Answer > 1 votes To look within a particular project, I often use `ag`. It is a front end for The Silver Searcher which allows you to recursively search a directory for a regexp in a file or filename. The `ag` package presents a nice list of matches with links to their source. Similar packages exist for `grep` (`(emacs) Grep Searching` or via `C-h i d m emacs <RET> m Grep Searching`) and `ripgrep` (`rg.el`). --- Tags: projectile ---
thread-59415
https://emacs.stackexchange.com/questions/59415
How can I set and jump to file-specific Bookmark+ bookmarks
2020-07-02T23:45:33.763
# Question Title: How can I set and jump to file-specific Bookmark+ bookmarks I am trying to use Bookmark+ because I would like the ability to create bookmarks with the same name that jump to locations in different files. E.g. I have files foo and bar open in emacs. I would like to create bookmarks named a, b and c that map to three different locations in foo. I would also like to create three additional bookmarks also named a, b and c, and these should allow me to jump to different locations in bar. Then, if the file foo is loaded in the current buffer I would like to jump to bookmark a in foo. If I then switch the current buffer to file bar and jump to bookmark a, I would like to be directed to the location of a within file bar. I have read the Bookmark+ docs and believe this to be possible. I have tried creating bookmarks with `C-x p m` and `C-u C-x p m`, and jumping to them using `C-x j f` and `C-x j , ,` but often I end up being directed to the wrong file. Which commands should I be using to set and navigate to these types of file-specific bookmark? -- Follow up Thanks @Drew for this clear explanation, I think I understand now. I have recently tried to play with icicles but I think the install didn't go quite right and I got errors. Maybe I'll have another go. Why do I want to do this? Mostly idle curiosity I have to admit. I really like the idea of not having to worry about duplicating bookmark names, and as I understand it this is supported and works if I use the bookmark-list display. The reason for trying to use the jump commands is to save keystrokes. I can navigate to a vanilla bookmark in three keystrokes: one bound to a command to list bookmarks, one character to filter to a specific bookmark, enter and I'm there. To do the same using bookmark+ I'm currently doing: one key bound to `C-x p ,`, `/` to start search, a filter character, `Enter`, then multiple `Down` key to get to the bookmark I want, then enter. Four plus at least three or four cursor downs (I'm working from memory here). # Answer > 0 votes **Updated after bug fix** Your observations were correct - you weren't imagining things. If you used the bookmark-list display there was no problem. But for most jump commands there was a bug. I think I've fixed the bug now. (Lightly tested.) Please download and try the latest. Thanks for inciting me to fix this. --- This was the problem, FYI: `C-x j , ,` (`bmkp-this-buffer-jump`) reads a bookmark name, completing against names of bookmarks for the current buffer (only). But the string returned from `completing-read` is unpropertized -- it's just `"a"` (in your example), with no information about the bookmark itself (position, file, etc.). That string name was being passed to the general jump function, which looks up the name in the current full current bookmark list, not in just the bookmarks for that buffer. So it can get the wrong bookmark named `"a"`. Likewise for other type-specific jump commands - they were reading the bookmark name correctly, using only a specific list of bookmarks as completion domain, but the bookmark name read was getting looked up in the general bookmark alist, not the list of bookmarks relative to the command. --- On the other hand, if you used Icicles then in Icicle mode the same Bookmark+ jump keys have enhanced behavior, and there what you want was already what happens. When you use an Icicles bookmark jump command, you see, as the completion candidates, both the bookmark name and the file name, and you can complete against either or both. So there's no such confusion/bug, for you or for the completion function. The fact that I myself use both Bookmark+ and Icicles is maybe one reason I hadn't bothered to fix this for just Bookmark+. --- Tags: bookmarks ---
thread-59357
https://emacs.stackexchange.com/questions/59357
Custom agenda view based on effort estimates
2020-06-30T15:49:56.340
# Question Title: Custom agenda view based on effort estimates I have currently a very simple custom agenda view, which displays a daily view, important tasks (those tasks with priority A), and pending tasks (those tasks whose todo keyword is WAITING). I would like to add another category in this agenda view, which would be the "quick picks", i.e. those tasks whose effort estimates are lower than 0:15. Until now, I have only managed to filter the tasks whose effort estimates are *exactly equal* to 0:15, and I struggle to find an easy solution for all tasks *inferior to* 0:15. Here is the piece of code I use: ``` (defun perso/quickpick (arg) "Display entries that have effort estimate equal to ARG." (org-tags-view t (format "Effort=\"%s\"" arg))) (setq org-agenda-custom-commands '(("d" "Custom daily agenda" ((agenda "" ((org-agenda-span 'day))) (tags "PRIORITY=\"A\"" ((org-agenda-skip-function '(org-agenda-skip-entry-if 'todo 'done)) (org-agenda-overriding-header "Important tasks"))) (todo "WAITING" ((org-agenda-overriding-header "Pending tasks"))) (perso/quickpick "0:15" ((org-agenda-overriding-header "Quickies"))))))) ``` Is there a simple solution to adapt `perso/quickpick` and/or `org-agenda-custom-commands` to get what I want? Thanks! --- Addendum: A MWE org file with one item per category: ``` #+PROPERTY: Effort_ALL 0:05 0:10 0:15 0:20 0:30 0:45 1:00 1:30 2:00 3:00 * TODO Wash the car SCHEDULED: <2020-07-01> * WAITING Fix a bug * TODO A quick task :PROPERTIES: :Effort: 0:15 :END: * TODO [#A] An important task ``` # Answer Maybe not really elegant, but I finally found a way to do this by writing two custom functions. The first one simply extracts the property value "Effort" of a given org headline (maybe there was a built-in way to do this, but I could not find it): ``` (defun fs/org-get-effort-estimate () "Return effort estimate when point is at a given org headline. If no effort estimate is specified, return nil." (let ((limits (org-get-property-block))) (save-excursion (when (and limits ; when non-nil (re-search-forward ":Effort:[ ]*" ; has effort estimate (cdr limits) t)) (buffer-substring-no-properties (point) (re-search-forward "[0-9:]*" (cdr limits))))))) ``` The second one is a function that will be passed to `org-agenda-skip-function`: it skips those org entries that do not have an effort estimate, or that have an effort estimate \> 0:15. ``` (defun fs/org-search-for-quickpicks () "Display entries that have effort estimates inferior to 15. ARG is taken as a number." (let ((efforts (mapcar 'org-duration-from-minutes (number-sequence 1 15 1))) (next-entry (save-excursion (or (outline-next-heading) (point-max))))) (unless (member (fs/org-get-effort-estimate) efforts) next-entry))) ``` Finally, a custom agenda view which does the trick: ``` (setq org-agenda-custom-commands '(("d" "Custom daily agenda" ((agenda "" ((org-agenda-span 'day)) (org-agenda-overriding-header "Agenda du jour")) (tags "PRIORITY=\"A\"" ((org-agenda-skip-function '(org-agenda-skip-entry-if 'todo 'done)) (org-agenda-overriding-header "Tâches importantes à finaliser"))) (todo "WAITING" ((org-agenda-overriding-header "Tâches en attente"))) (alltodo "" ((org-agenda-skip-function 'fs/org-search-for-quickpicks) (org-agenda-overriding-header "Tâches rapides"))))))) ``` > 0 votes --- Tags: org-mode, org-agenda ---
thread-59425
https://emacs.stackexchange.com/questions/59425
how to make emacs follow links to files outside of org mode?
2020-07-03T13:24:30.423
# Question Title: how to make emacs follow links to files outside of org mode? I'd like to embed a link to a file in say Python code, is there a way to let emacs know to look for org style links outside of org files? Or is there a better way of achieving this? Cheers # Answer An Org mode link is just text (although its appearance may be modified using text properties), so you can add it to any text file, including a python file: ``` def main(options, args): # [[file:/path/to/some/file][some file]] print options print args return 0 ``` For external links, you can open the link using `M-x org-open-at-point`. Internal links probably will not work: they probably require that the underlying buffer is an Org mode buffer. This is just a guess however, so feel free to amend the answer if your experiments prove otherwise. Unless you muck around with text properties in the python buffer, it just won't look pretty, but it will (mostly) work. > 2 votes # Answer You could try going in the other direction and embed your python code in an org file. There's a good introduction to Literate Programming with Org-mode and if you need further details the section on Evaluating Code Blocks in the org manual could help. > 0 votes --- Tags: org-mode ---
thread-51156
https://emacs.stackexchange.com/questions/51156
Cargo-process does not accept user input
2019-06-20T19:39:03.487
# Question Title: Cargo-process does not accept user input Using the Emacs mode for Cargo, I'm able to build and run Rust code inside Emacs. However, the terminal that opens when executing `cargo-process-run` does not accept user input. For example, when running ``` use std::io; fn main() { let mut input = String::new(); io::stdin() .read_line(&mut input) .expect("Failed to read line."); } ``` the terminal will hang without being capable of receiving keyboard input. I've read that a similar problem can occur when executing `compile`, but this could somehow be resolved by starting in `comint-mode`. Unfortunately, I have not found a way to translate that solution to this scenario. How can I resolve this? # Answer > 3 votes After some research, I was able to solve it by adding this to my init.el: ``` (with-eval-after-load 'rust-mode (define-key rust-mode-map (kbd "C-r") 'my-cargo-run)) (defun my-cargo-run () "Build and run Rust code." (interactive) (cargo-process-run) (let ( (orig-win (selected-window)) (run-win (display-buffer (get-buffer "*Cargo Run*") nil 'visible)) ) (select-window run-win) (comint-mode) (read-only-mode 0) (select-window orig-win) ) ) ``` The function `my-cargo-run` calls `cargo-process-run`, enables comint-mode and disables the read-only mode of the terminal. The first two lines bind the function to `C-r`. I've asked the author of cargo.el to include this in the package. # Answer > 1 votes Another possibility: ``` (defun rust-compile-send-input () "Read string from minibuffer and send it to the rust process of the current buffer." (interactive) (let ((input (read-from-minibuffer "Send input to rust process: ")) (proc (get-buffer-process (current-buffer))) (inhibit-read-only t)) (process-send-string proc (concat input "\n")))) ``` --- Tags: term, comint, rust ---
thread-39019
https://emacs.stackexchange.com/questions/39019
xclip hangs shell-command
2018-02-23T04:51:53.127
# Question Title: xclip hangs shell-command I like to use the `xclip` utility to capture the output of commands on the clipboard. However, when I try to use it with `shell-command` it seems to hang. In a "normal" shell I can run a command such as `echo "hello world" | xclip -selection clipboard` and it will return almost immediately and copy `hello world` to the clipboard. When I try to run the same command from `shell-command` the command seems to "hang": the focus stays in the minibuffer and I can't do anything until I cancel the command with `C-g`. After cancelling the command the text has been copied to the clipboard though. I'm running emacs 24.4.1 on Debian 8.6 Any idea why the xclip command hangs? # Answer > 4 votes `xclip` has to "hang" around to own the clipboard, as X uses asynchronous clipboards which belong to a process. You should be able to get away with just using `async-shell-command`, which is bound to `M-&` by default. Another solution would be to use some clipboard manager instead. # Answer > 0 votes Right, Commands such as `(shell-command "xclip -selection clipboard -o")` hang unless the clipboard has the "right" content either text or image. As a workaround, you can terminate it by using `timeout TIMEOUT`. # An example: When only plain text exists in the clipboard and you use ``` (shell-command (format "xclip -selection clipboard -t image/png -o > %s" image-file)) ``` to get the plain text saved as an `image-file`, emacs will hang until you `Ctrl-g` to terminate it by force. Adding `Timeout 0.05` as ``` (shell-command (format "timeout 0.05 xclip -selection clipboard -t image/png -o > %s" image-file)) ``` will end the `xclip` process after `0.05`. --- Tags: linux, shell-command ---
thread-59439
https://emacs.stackexchange.com/questions/59439
What is the runtime complexity of using beginning-of-line?
2020-07-04T10:39:07.280
# Question Title: What is the runtime complexity of using beginning-of-line? I did a test where going to from the end to the beginning of a 50 million length line happens instantly when using **beginning-of-line**. I wonder if this is because it is a C primitive or because Emacs implements this and related functions in an efficient way. For example, it could keep a mapping from line numbers to the positions of those lines within the buffer (this is just a guess). Why is it so fast? Does the runtime depend on the number of characters on the line, or is it constant? # Answer The underlying function is `find_newline` in `emacs/src/search.c`. It uses a cache of sections of text that contain no newlines, so the function can skip over them quickly. The cache is controlled by the variable `cache-long-scans`, whose doc string says: > Non-nil means that Emacs should use caches in attempt to speedup buffer scans. > > There is no reason to set this to nil except for debugging purposes. > > Normally, the line-motion functions work by scanning the buffer for newlines. Columnar operations (like ‘move-to-column’ and ‘compute-motion’) also work by scanning the buffer, summing character widths as they go. This works well for ordinary text, but if the buffer’s lines are very long (say, more than 500 characters), these motion functions will take longer to execute. Emacs may also take longer to update the display. > > If ‘cache-long-scans’ is non-nil, these motion functions cache the results of their scans, and consult the cache to avoid rescanning regions of the buffer until the text is modified. The caches are most beneficial when they prevent the most searching---that is, when the buffer contains long lines and large regions of characters with the same, fixed screen width. > > When ‘cache-long-scans’ is non-nil, processing short lines will become slightly slower (because of the overhead of consulting the cache), and the caches will use memory roughly proportional to the number of newlines and characters whose screen width varies. > > Bidirectional editing also requires buffer scans to find paragraph separators. If you have large paragraphs or no paragraph separators at all, these scans may be slow. If ‘cache-long-scans’ is non-nil, results of these scans are cached. This doesn’t help too much if paragraphs are of the reasonable (few thousands of characters) size. > > The caches require no explicit maintenance; their accuracy is maintained internally by the Emacs primitives. Enabling or disabling the cache should not affect the behavior of any of the motion functions; it should only affect their performance. > 5 votes --- Tags: performance ---
thread-59438
https://emacs.stackexchange.com/questions/59438
switch-to-buffer from org mode code block
2020-07-04T06:27:10.917
# Question Title: switch-to-buffer from org mode code block Evaluating a code block containing `(switch-to-buffer "test-buffer")` does not display test-buffer. It creates the buffer, but it does not switch to it. ``` #+BEGIN_SRC emacs-lisp (switch-to-buffer "test-buffer") #+END_SRC #+RESULTS: : #<buffer test-buffer> ``` Evaluating the the function within the code block, running `eval-last-sexp`, does display the buffer. I cannot find any switches or header arguments controlling this behaviour, which might well be intended. From what I can gather this is a more more specific instance of the same issue. How can I obtain the desired behaviour? # Answer Lisp code is evaluated by Org babel inside a `save-window-excursion`, so when you do `switch-to-buffer` in your code, you *do* switch to the buffer momentarily, but as soon as the evaluation is over, you are back in the Org mode buffer in order to format and print the result of the evaluation. The doc string of `save-window-excursion` says: > Execute BODY, then restore previous window configuration. This macro saves the window configuration on the selected frame, executes BODY, then calls ‘set-window-configuration’ to restore the saved window configuration. The return value is the last form in BODY. The window configuration is also restored if BODY exits nonlocally. In short, there is no (easy) way to do what you want with Org babel: it's not designed to work as an interactive evaluator - it's more of a batch processor. But you do have an interactive evaluator: emacs itself. What stops you from asking it to do a `switch-buffer`? In fact, if you just place the cursor after the closing paren of the form and do `C-x C-e`, you have switched to that buffer. EDIT: although I think my answer stands, I wanted to preserve the link in @gregoryg's comment as part of the answer: it points to a tour-de-force answer by @Tobias that reimplements `save-window-excursion` so that it can be controlled by header-line arguments and that will allow window/buffer changes in source code blocks to be preserved. The hair-raising aspect of it is the surgery he does to the babel evaluator in order to use the reimplemented macro: this is code-modifying code and not for the faint-hearted. > 2 votes --- Tags: org-mode, org-babel ---
thread-58303
https://emacs.stackexchange.com/questions/58303
Error in newly installed magit -head branch header wrong type argument
2020-05-05T20:54:28.660
# Question Title: Error in newly installed magit -head branch header wrong type argument I just installed the magit package in emacs 26.3 (using CentOS 7 OS). When I start it with `M-x magit`, I get the error below. It works fine for me in an older installation, and the only difference I can see is that the one I just set up is using newer versions of some magit related packages. I don't see any issues posted on GitHub related to this even though it renders magit nonfunctional, so I'm wondering if anyone has a tip on how to resolve the error. Error: ``` Turning on magit-auto-revert-mode...done magit-insert-head-branch-header: Wrong type argument: stringp, nil Error in post-command-hook (magit-section-update-highlight): (wrong-type-argument number-or-marker-p nil) ``` # Answer See https://github.com/magit/magit/issues/3458 to learn how to figure out what is wrong. See https://github.com/magit/magit/issues/3444 to learn why you did not get a more useful error message right away and that we are aware of this and will eventually do something about it. > 1 votes --- Tags: magit, debugging ---
thread-59346
https://emacs.stackexchange.com/questions/59346
run-at-time in the future only
2020-06-30T09:46:33.880
# Question Title: run-at-time in the future only I want to capture a journal entry several times a day. Here was my initial solution: ``` (setq org-capture-templates '(("w" "Weekly" item (file+olp+datetree "/home/joe/org-files/goodtime.org") "%?" :tree-type week))) (mapc (lambda (slot) (run-at-time slot (* 60 60 24) ; repeat each day at the same time if Emacs is still running (lambda () (interactive) (org-capture nil "w") (insert (format-time-string "%-H:%M " nil t))))) '("09:00am" "12:00pm" "3:00pm" "6:00pm" "9:00pm")) ``` This seems to work as expected if I start Emacs before 9AM. However, if I start Emacs later than that, the Org Capture runs immediately, once for each time of day that has been missed. I see now that this is explained in the answer here: Is it possible to execute a function or command at a specific time? The problem is that I want to run the task exactly at the times mentioned, not potentially at some other time. Thinking out loud, one solution would be to write in an explicit conditional that takes note of the time when Emacs starts, checks whether that was within the last 24 hours, and runs the capture event or not as required. This seems pretty heavy for a one-off solution, and I wonder if actually `run-at-time` should be patched? --- Before trying to do this with `run-at-time` I tried to use `emacsclient` inside of a `cron` job, but that didn't work for me. The script runs on its own, but I wasn't able to get it to work from within `cron`, which apparently doesn't play nicely with interactive "desktop" jobs. # Answer Here's some code that converts simple `HH:MM` time specifications to encoded times for either today or tomorrow, depending on whether the given time is later or earlier than the current time. There are three main functions: * `convert-hh:mm-to-decoded` converts a simple time spec in `HH:MM` format (N.B. no `AM/PM` specification - use 24-hour time instead) into the complete `decode-time` format assuming today's date. * `shift-to-tomorrow` takes a decoded-time format spec and shifts the date part to tomorrow. * `shift-to-tomorrow-maybe` takes a decoded-time format spec and figures out whether the time is earlier than now (in which case it calls `shift-to-tomorrow` on it) or later than now (in which case it returns it unchanged. The functions can be pipelined together through `mapcar`. Since `run-at-time` takes encoded times as arguments, the only thing that changes in your code is the `slot` calculation, so the literal list of times becomes instead: ``` (mapcar #'encode-time (mapcar #'shift-to-tomorrow-maybe (mapcar #'convert-hh:mm-to-decoded '("09:00" "12:00" "15:00" "18:00" "21:00")))) ``` Here's an Org mode document with the functions in a source block, so they can be executed easily and the output checked (note that the last form does two of the three \`mapcar's above, for ease of checking): ``` * Code #+begin_src emacs-lisp (defun convert-hh:mm-to-decoded (ts) (interactive "sHH:MM: ") (let* ((split (split-string ts ":")) (h (string-to-number (nth 0 split))) (m (string-to-number (nth 1 split)))) (append (list 0 m h) (date-part (today))))) (defun date-part (td) (nthcdr 3 td)) (defun today () (decode-time (current-time))) (defun tomorrow () (decode-time (time-add 86400 (current-time)))) (defun shift-to-tomorrow (time-date) (let ((td time-date)) (setf (nthcdr 3 td) nil) (append td (date-part (tomorrow))))) (defun shift-to-tomorrow-maybe (time-date) (let ((td (encode-time time-date))) (if (time-less-p td nil) (shift-to-tomorrow time-date) time-date))) (setq times (mapcar #'shift-to-tomorrow-maybe (mapcar #'convert-hh:mm-to-encoded '("09:00" "12:00" "15:00" "18:00" "21:00")))) ; (mapcar #'encode-time times) #+end_src #+RESULTS: | 0 | 0 | 9 | 5 | 7 | 2020 | 0 | t | -14400 | | 0 | 0 | 12 | 5 | 7 | 2020 | 0 | t | -14400 | | 0 | 0 | 15 | 5 | 7 | 2020 | 0 | t | -14400 | | 0 | 0 | 18 | 4 | 7 | 2020 | 6 | t | -14400 | | 0 | 0 | 21 | 4 | 7 | 2020 | 6 | t | -14400 | ``` > 1 votes --- Tags: timers ---
thread-59451
https://emacs.stackexchange.com/questions/59451
Asterisk in interactive specification
2020-07-04T21:51:50.427
# Question Title: Asterisk in interactive specification Just when is it appropriate to put the asterisk `*` into the interactive spec of a command function? The elisp manual says the effect is to cause an error if the command is attempted in a read only buffer, so clearly this should be done when, in some sense, the command modifies the current buffer. But this is not precise enough; is the mere *possibility* of a modification sufficient grounds? What about a command like `untabify` which *could* potentially modify my buffer but in fact it never does because I never use physical tab characters? On the other hand, pretty much any command can be made a no-op by a zero prefix argument, so I guess if I wanted to be sure a modification would in fact occur I'd never use the asterisk. I just wish the manual were more explicit about this. What is your interpretation? # Answer First, this is untrue, assuming I understand what you mean: > *On the other hand, pretty much any command can be made a no-op by a zero prefix argument* Beyond that, the answer, IMO, is that you do what you like when defining commands. The point of the `*` and its doc is to let you know *what it does*. How/when you *decide to use it* is up to you. It's you who answers the question, ***"Do I want invocation of this command to raise an error if the buffer is read-only?"*** That's all - there's nothing more to it. Some particular command, or some particular command author, might well want the error to be raised only if the command *would be sure to modify* the buffer. But that's not what `*` does. I raises an error systematically, anytime the command is invoked in a read-only buffer. --- You can see for yourself what `*` would do for `untabify` in a read-only buffer with no `TAB` chars: ``` (defun my-untabify () (interactive "*") (untabify (region-beginning) (region-end))) ``` --- You ask, in a comment, whether there is some convention regarding the use of `*` in `interactive`. My answer is no, not as far as I know. I don't believe there's anything in Coding Conventions, for example. And I've tried to give a reason why: The behavior of `*` is just to raise an error whenever the command is invoked interactively in a read-only buffer. What convention could there possibly be about that? If you use `*` then it'll do just that. Whether you *want* it to raise an error in such a context depends on you and what you expect your users will expect in the particular context. How could there be any general guideline about that? That's a judgment call based on the *context*; it can't be something context-independent. I suppose you could imagine trying to categorize situations that combine a read-only buffer with various kinds of commands, and come up with some general rules for which kinds of commands in which read-only contexts might be better candidates for raising such an error. I don't expect that exercise would be worthwhile, but I could be wrong. In any case, I don't think such a classification has been done - I know of no such guideline. > 3 votes --- Tags: commands, interactive, read-only-mode ---
thread-59449
https://emacs.stackexchange.com/questions/59449
How do I save raw bytes into a file?
2020-07-04T17:26:26.413
# Question Title: How do I save raw bytes into a file? I'm trying to make a .wav file generator in Emacs Lisp. I have some binary data, as a sequence of bytes: ``` (setq binary-data (list 62 236 60)) ``` I would like to insert that data into a file. I expect that file to be three bytes long. If I try to insert it into a buffer, then write that buffer to a file, I get a file that consists of four bytes: ``` (with-temp-buffer (seq-doseq (char binary-data) (insert char)) (write-region nil nil "~/char-inserted.wav")) $ hd ~/char-inserted.wav 00000000 3e c3 ac 3c |>..<| 00000004 ``` So it seems like I'm having problems with inserting that single byte. I've also tried converting the data into a unibyte string, but that still gives me a four-byte file: ``` (with-temp-buffer (seq-doseq (char (apply #'unibyte-string binary-data)) (insert char)) (write-region nil nil "~/unibyte-string.wav")) $ hd ~/unibyte-string.wav 00000000 3e c3 ac 3c |>..<| 00000004 ``` I've also converted the unibyte string to a multibyte string: ``` (with-temp-buffer (seq-doseq (char (string-as-multibyte (apply #'unibyte-string binary-data))) (insert char)) (write-region nil nil "~/multibyte-string.wav")) ``` But this gives me an error: ``` > These default coding systems were tried to encode text in the buffer ‘ *temp*-110101’: (utf-8-unix (2 . 4194284)) However, each of them encountered characters it couldn’t encode: utf-8-unix cannot encode these: ``` It suggests I select one of the coding systems "raw-text" or "no-conversion", but I'm unsure how to do that, or if it will even help. How do I save these three bytes into a file that ends up as a three-byte file? What's going on here? # Answer > 3 votes At a minimum, if by default your buffers are multibyte, you will need to toggle this specific buffer to unibyte; you also need to set the file coding system of the buffer to `raw-text`: ``` (with-temp-buffer (toggle-enable-multibyte-characters) (set-buffer-file-coding-system 'raw-text) (seq-doseq (char binary-data) (insert char)) (write-region nil nil "~/char-inserted.wav")) ``` You might also have to specify `no-conversion` for the write, but I'm not sure. Something like this perhaps: ``` (let ((coding-system-for-write 'no-conversion)) (with-temp-buffer (toggle-enable-multibyte-characters) (set-buffer-file-coding-system 'raw-text) (seq-doseq (char binary-data) (insert char)) (write-region nil nil "~/char-inserted.wav"))) ``` But there may be other gotcha's as well: it would be good to have an answer by an expert. --- Tags: files, saving ---
thread-59430
https://emacs.stackexchange.com/questions/59430
How to diagnose emacs running at 100% cpu
2020-07-03T15:34:57.040
# Question Title: How to diagnose emacs running at 100% cpu I'm having a problem where occassionally emacs will run at 100% cpu, and just hang forever. I've attached `gdb` to the process, and this is the stacktrace: ``` #0 0x00007fc210e5c5bb in pthread_sigmask () from /lib64/libpthread.so.0 #1 0x00000000005f5f95 in really_call_select () #2 0x00000000005f6d5d in thread_select () #3 0x00000000005d0fd7 in wait_reading_process_output () #4 0x00000000004f819e in wait_for_property_change () #5 0x00000000004fad93 in x_handle_selection_event () #6 0x0000000000515a10 in process_special_events () #7 0x0000000000516431 in swallow_events () #8 0x0000000000435a46 in sit_for () #9 0x000000000051c4cd in read_char () #10 0x000000000051c8a5 in read_key_sequence () #11 0x000000000051dfdc in command_loop_1 () #12 0x000000000058bec7 in internal_condition_case () #13 0x000000000050eef4 in command_loop_2 () #14 0x000000000058be09 in internal_catch () #15 0x000000000050ee93 in command_loop () #16 0x000000000051447a in recursive_edit_1 () #17 0x00000000005147b6 in Frecursive_edit () #18 0x000000000042c564 in main () ``` Running `strace -f` I get the following: ``` strace: Process 2689 attached with 4 threads [pid 2692] restart_syscall(<... resuming interrupted read ...> <unfinished ...> [pid 2691] restart_syscall(<... resuming interrupted read ...> <unfinished ...> [pid 2689] rt_sigprocmask(SIG_SETMASK, [], <unfinished ...> [pid 2693] restart_syscall(<... resuming interrupted read ...> <unfinished ...> [pid 2689] <... rt_sigprocmask resumed>NULL, 8) = 0 [pid 2689] pselect6(18, [3 6 13 17], NULL, NULL, {tv_sec=0, tv_nsec=0}, {NULL, 8}) = 1 (in [3], left {tv_sec=0, tv_nsec=0}) [pid 2689] rt_sigprocmask(SIG_BLOCK, [INT], [], 8) = 0 [pid 2689] rt_sigprocmask(SIG_SETMASK, [], NULL, 8) = 0 [pid 2689] rt_sigprocmask(SIG_BLOCK, [INT], [], 8) = 0 [pid 2689] rt_sigprocmask(SIG_SETMASK, [], NULL, 8) = 0 [pid 2689] pselect6(18, [3 6 13 17], NULL, NULL, {tv_sec=0, tv_nsec=0}, {NULL, 8}) = 1 (in [3], left {tv_sec=0, tv_nsec=0}) [pid 2689] rt_sigprocmask(SIG_BLOCK, [INT], [], 8) = 0 [pid 2689] rt_sigprocmask(SIG_SETMASK, [], NULL, 8) = 0 [pid 2689] rt_sigprocmask(SIG_BLOCK, [INT], [], 8) = 0 [pid 2689] rt_sigprocmask(SIG_SETMASK, [], NULL, 8) = 0 [pid 2689] pselect6(18, [3 6 13 17], NULL, NULL, {tv_sec=0, tv_nsec=0}, {NULL, 8}) = 1 (in [3], left {tv_sec=0, tv_nsec=0}) [pid 2689] rt_sigprocmask(SIG_BLOCK, [INT], [], 8) = 0 [pid 2689] rt_sigprocmask(SIG_SETMASK, [], NULL, 8) = 0 [pid 2689] rt_sigprocmask(SIG_BLOCK, [INT], [], 8) = 0 [pid 2689] rt_sigprocmask(SIG_SETMASK, [], NULL, 8) = 0 [pid 2689] pselect6(18, [3 6 13 17], NULL, NULL, {tv_sec=0, tv_nsec=0}, {NULL, 8}) = 1 (in [3], left {tv_sec=0, tv_nsec=0}) ``` and it just continues in the select loop forever. These are the 4 listed file descriptors ``` emacs 2689 steve 3u a_inode 0,14 0 11756 [timerfd] emacs 2689 steve 6u unix 0x0000000098aa0ced 0t0 18247 type=STREAM emacs 2689 steve 13u unix 0x00000000db5acbc0 0t0 18252 type=STREAM emacs 2689 steve 17r a_inode 0,14 0 11756 inotify ``` That's as far as I can get. Any ideas on how to diagnose what is happening here? --- **Edit:** It happened again, with slightly different stacktrace and strace results. Here is the stacktrace from gdb: ``` #0 0x000000000050b847 in process_special_events () #1 0x000000000050c2c1 in swallow_events () #2 0x00000000005ce14a in wait_reading_process_output () #3 0x00000000004eb806 in x_get_foreign_selection () #4 0x0000000000580dec in Ffuncall () #5 0x00000000005c207c in exec_byte_code () #6 0x0000000000580d7b in Ffuncall () #7 0x00000000005829a2 in Fapply () #8 0x0000000000580dec in Ffuncall () #9 0x00000000005c207c in exec_byte_code () #10 0x0000000000580d7b in Ffuncall () #11 0x00000000005c207c in exec_byte_code () #12 0x0000000000580d7b in Ffuncall () ``` and the strace output: ``` strace: Process 22077 attached with 4 threads [pid 22081] restart_syscall(<... resuming interrupted read ...> <unfinished ...> [pid 22079] restart_syscall(<... resuming interrupted read ...> <unfinished ...> [pid 22080] restart_syscall(<... resuming interrupted read ...> <unfinished ...> [pid 22077] brk(NULL) = 0xa39e6000 [pid 22077] brk(0xa3a08000) = 0xa3a08000 [pid 22077] brk(NULL) = 0xa3a08000 [pid 22077] brk(0xa3a2a000) = 0xa3a2a000 [pid 22077] brk(NULL) = 0xa3a2a000 [pid 22077] brk(0xa3a4c000) = 0xa3a4c000 [pid 22077] brk(NULL) = 0xa3a4c000 [pid 22077] brk(0xa3a6e000) = 0xa3a6e000 [pid 22077] brk(NULL) = 0xa3a6e000 [pid 22077] brk(0xa3a90000) = 0xa3a90000 [pid 22077] brk(NULL) = 0xa3a90000 [pid 22077] brk(0xa3ab2000) = 0xa3ab2000 ``` `brk` just continues forever... until suddenly, after several minutes, it comes back ``` [pid 22077] brk(NULL) = 0xb2450000 [pid 22077] brk(0xb2472000) = 0xb2472000 [pid 22077] brk(NULL) = 0xb2472000 [pid 22077] brk(0xb2494000) = 0xb2494000 [pid 22077] --- SIGIO {si_signo=SIGIO, si_code=SI_KERNEL} --- [pid 22077] rt_sigreturn({mask=[]}) = 64 [pid 22077] recvmsg(6, {msg_name=NULL, msg_namelen=0, msg_iov=[{iov_base="X\2%8\342\345\223\0\3\24\4\0\20\0\0\0\0\0\0\24\24\24\24\24\0\0\3\37%\2\0\0", iov_len=4096}], msg_iovlen=1, msg_controllen=0, msg_flags=0}, 0) = 32 [pid 22077] recvmsg(6, {msg_namelen=0}, 0) = -1 EAGAIN (Resource temporarily unavailable) [pid 22077] poll([{fd=6, events=POLLIN}, {fd=7, events=POLLIN}, {fd=8, events=POLLIN}], 3, 0) = 0 (Timeout) [pid 22077] poll([{fd=6, events=POLLIN}, {fd=7, events=POLLIN}, {fd=8, events=POLLIN}], 3, 0) = 0 (Timeout) [pid 22077] recvmsg(6, {msg_namelen=0}, 0) = -1 EAGAIN (Resource temporarily unavailable) [pid 22077] poll([{fd=6, events=POLLIN}, {fd=7, events=POLLIN}, {fd=8, events=POLLIN}], 3, 0) = 0 (Timeout) ``` and emacs' usage drops back down to idle. --- **Resolution?** I found a few threads referencing the X11 clipboard being the cause of hangs. I added `(setq select-enable-clipboard nil)` to my `init.el`, and have not had a hang since. Can anyone explain what is causing this, and whether there is a better resolution? # Answer Well, just from the `brk` calls it looks like it allocated about 230 megs, which is on the large side for the clipboard. Maybe whatever was in the clipboard at the time really was that large, or maybe Emacs failed to parse it correctly and ran away for a bit. If you want to figure out what the problem really is, you either need to find a reliable way to reproduce it, or you need to make a reproducible recording of the problem as it happens. You can probably use rr (rr-project.org) to make the recording. Once you have the recording, you can replay it as often as is required in order to understand what was going on. rr is light-weight enough that you can even record your ordinary Emacs sessions until you see the problem, then go back to using Emacs with `select-enable-clipboard` unset. > 1 votes --- Tags: debugging, performance ---
thread-59458
https://emacs.stackexchange.com/questions/59458
How to call an interactive function and pass arguments to it from within Elisp?
2020-07-05T08:43:30.653
# Question Title: How to call an interactive function and pass arguments to it from within Elisp? I'm trying to compose a link to the `describe-package` help buffer to the `xref` package like this: ``` [[(elisp:(describe-package "xref"))][xref]] ``` But it can't execute. So I wonder how to pass arguments to an interactive function from within Elisp. I don't believe anyone has asked this question, and after much searching I still couldn't find the answer. I've tried the following forms and none of them worked. ``` (describe-package "xref") (call-interactively 'describe-package "xref") (call-interactively (describe-package "xref")) (call-interactively (lambda () (interactive) (describe-package '("xref")))) (command-execute (describe-package "xref")) (command-execute 'describe-package "xref") ``` # Answer > 1 votes According to the docs, `describe-package` takes a symbol as argument not a string so you need: ``` (describe-package 'xref) ``` --- Tags: interactive ---
thread-46993
https://emacs.stackexchange.com/questions/46993
Outside of Emacs what other software supports org-mode syntax?
2019-01-08T23:19:24.417
# Question Title: Outside of Emacs what other software supports org-mode syntax? ## Context In my spare time, I've been adding **very limited support** for org-mode syntax in the Atom text editor for my friends that absolutely will not switch to Emacs. Over the last few years I've found approximately 10 org syntax parsers which all focus on converting org-mode files into markdown or other file formats. The 2 most popular parsers that I use everyday and recommend are: ## Question Outside of Emacs what other software supports org-mode syntax? > **Note:** I acknowledge that StackExchange platform is not really ideal for this type of question but I believe the Emacs StackExchange community would benefit from multiple well researched answers about this topic. ## How to Answer this Question Each answer should: * Limit answer scope to a single software source, e.g. discuss pandoc or org-ruby but not both in the same answer. * Briefly describe what software can do with org-mode file, e.g. pandoc can convert org-mode to docx, markdown and json file formats. * Provide a simple example of using the software, e.g. `pandoc --from org --to docx -o example.docx example.org`. * List dependencies, e.g. ruby is required to use org-ruby. * Link to official software page. ## Vote for the most useful answer # Answer > 2 votes ### Atom org-mode Package * The Atom `org-mode` package provides syntax highlighting for org files in the Atom editor. * Most of the package files are managed from a central literate programming file and tangled or exported directly from Emacs. * After the syntax highlighting grammar is completed, a JavaScript org syntax parser will be added to facilitate more comprehensive functionality. * Use the Atom editor built in package management tool to install the package including the dependencies. # Answer > 0 votes ### org-js * `org-js` coverts org syntax into html. * Code Example Quoted from README > Simple example of `org -> HTML` conversion > > ``` > > var org = require("org"); > > var parser = new org.Parser(); > var orgDocument = parser.parse(orgCode); > var orgHTMLDocument = orgDocument.convert(org.ConverterHTML, { > headerOffset: 1, > exportFromLineNumber: false, > suppressSubScriptHandling: false, > suppressAutoLink: false > }); > > console.dir(orgHTMLDocument); // => { title, contentHTML, tocHTML, toc } > console.log(orgHTMLDocument.toString()) // => Rendered HTML > > ``` * Requires Javascript > `npm install org`. # Answer > 0 votes ### org-ruby * `org-ruby` is a ruby gem which converts org syntax into `html`, `textile` and `markdown`. * The gem is used by Github, Gitlab, and Gollum projects to provide org syntax support for documentation. * Code Example Quoted from README > ``` > require 'org-ruby' > > # Renders HTML > Orgmode::Parser.new("* Hello world!").to_html > # => "<h1>Hello world!</h1>\n" > > # Renders Textile > Orgmode::Parser.new("* Hello world!").to_textile > # => "h1. Hello world!\n" > > # Renders Markdown > Orgmode::Parser.new("* Hello world!").to_markdown > # => "# Hello world!\n" > > # Renders HTML with custom markup > Orgmode::Parser.new("* *Custom* /Markup/", { markup_file: "html.tags.yml" }).to_html > # => "<h1><strong>Custom</strong> <em>Markup</em></h1>\n" > > # Renders Markdown with custom markup > Orgmode::Parser.new("* *Custom* /Markup/", { markup_file: "md.tags.yml"}).to_markdown > # => "# __Custom__ _Markup_\n" > > ``` > > The supported output exporters can be also called from the command line: > > ``` > org-ruby --translate html sample.org > org-ruby --translate textile sample.org > org-ruby --translate markdown sample.org > org-ruby --markup html.tags.yml sample.org > org-ruby --markup md.tags.yml --translate markdown sample.org > > > ``` * Requires ruby > `gem install org-ruby` --- Tags: org-mode ---
thread-59456
https://emacs.stackexchange.com/questions/59456
Derived major mode: new keyword fontification not playing nice with parent mode's
2020-07-05T06:06:04.447
# Question Title: Derived major mode: new keyword fontification not playing nice with parent mode's I am writing a major mode derived from `f90-mode` in order to fontify the syntax of a commonly used Fortran preprocessor, `fypp` (similar to `jinja2` for HTML templating). Here's a contrived example of what that looks like, with plain `f90-mode` highlighting on the left and my `fypp-mode` on the right. The `#:` directive and the `${...}$` evaluator are new syntax atop Fortran, which is why `f90-mode` does not color them properly. I want my major mode to inherit the fontifications defined in `f90-mode.el` and add to them. Here's a minimal but representative implementation ``` ;;; fypp-mode.el (setq fypp-highlights '(("#:set" . font-lock-preprocessor-face) ("\\${\\|}\\$" . font-lock-preprocessor-face))) (define-derived-mode fypp-mode f90-mode "fypp" "Major mode for editing Fortran code with fypp extensions" (font-lock-add-keywords nil fypp-highlights)) ``` I have two complaints with this, seen in the right-side image above: 1. The `${...}$` syntax in the subroutine name declaration breaks the fontification of the subroutine name. 2. The `${...}$` inside a string literal does not get fontified, but I would like it to. Issue #1 I am able to solve by modifying the syntax table entries for `{` and `}` to make them word class instead of parentheses. I do wonder if this is likely to bite me later, though. Issue #2 is the trickier matter for me. Normally, you want strings fontified as strings, even if they happen to contain keywords. Here, though, the string `"Hello, ${whom}$!"` will get expanded by the preprocessor to `"Hello, world!"`, so I want the `${...}$` to be fontified. I still want string literals to be fontified, I just want my preprocessing tokens to "take precedence". But I don't know how to do this cleanly, if at all. # Answer For issue #1, setting `{` and `}` to word syntax is wrong. You can give them "symbol constituent" syntax, but not "word" (otherwise you break the expected behavior of `M-f` and friends). This said, it may indeed bite you later, depending on what the rest of `f90.el` does. For Issue #2, you simply want to use the *OVERRIDE* field in your font-lock rule. See `C-h o font-lock-keywords` for details. > 2 votes --- Tags: font-lock, derived-mode ---
thread-59463
https://emacs.stackexchange.com/questions/59463
WoMan italic `\,VARIABLE\/ representation
2020-07-05T12:52:44.267
# Question Title: WoMan italic `\,VARIABLE\/ representation When I do `M-x woman => ln` , as you can see italic variables are represened as in between following pattern `\,` \- `\/`. How could I revmoe or fix it? ## Setup: ``` (setenv "MANWIDTH" "72") (defadvice man (before my-woman-prompt activate) (interactive (progn (require 'woman) (list (woman-file-name nil))))) (require 'woman) (set-face-attribute 'woman-bold nil :inherit font-lock-type-face :bold t) (set-face-attribute 'woman-italic :inherit font-lock-keyword-face :underline t) ``` Bug track link: https://debbugs.gnu.org/cgi/bugreport.cgi?bug=42219 # Answer > 3 votes Congratulations, you've found a bug. `\,` and `\/` are space-adjusting escape sequences for groff this package doesn't handle yet. https://www.gnu.org/software/groff/manual/groff.html#Ligatures-and-Kerning explains how they work, but it's unclear what part of the package to adjust for that. I suggest you to use `M-x report-emacs-bug` and edit the link to the bug report into this question for tracking. --- Tags: man ---
thread-36790
https://emacs.stackexchange.com/questions/36790
Using `emacsclient` as `git config core.editor` and invoking `git commit` as `shell-command` in Emacs?
2017-11-10T22:54:31.863
# Question Title: Using `emacsclient` as `git config core.editor` and invoking `git commit` as `shell-command` in Emacs? I am trying to use Emacs 25.1.1 (graphical version, Windows 10) as both the primary editor and the editor for git operations. In my workflow, I invoke git through `M-x shell-command`. I tried the following two options so far: 1. `git config --global core.editor "emacs -Q"` With this, `M-x shell-command RET git commit` works just fine, as a new light-weight instance of emacs is used. Downside: Completion with `M-/` aka `dabbrev-expand` is less useful than it could be. 2. `git config --global core.editor "emacsclient --no-wait --create-frame"` With this setting, trying to execute git synchrnously as `M-x shell-command RET git commit` on the other hand causes the `emacsclient` and server `emacs` processes to hang indefinitely, until \`emacsclient is killed, while the asynchrnous invocation `M-x shell-command RET git commit &` works, but this setup is too brittle, as forgetting the & causes Emacs to all but crash. Is there some way to use `emacsclient` as git editor, that is compatible with `M-x shell-command`? # Answer If you run git within a posix environment (cygwin or msys, I believe git-bash uses msys), you could create a function in your ~/.profile: ``` function already_emacsing () { emacsclient --eval '(find-file-other-window $1)' } EDITOR="already_emacsing" ``` I can't test it on your setup right now, but the individual parts all work and I can't see any reason they shouldn't fit together well enough. I can't think of a way to do the same with batch scripting, but it's probable you could do the same emacsclient call with a powershell script or something as well. > 1 votes # Answer Does Emacs 25.1.1 not have `async-shell-command`? Per the docstring, > Like ‘shell-command’, but adds ‘&’ at the end of COMMAND to execute it asynchronously. It is bound to `M-&` by default. > 1 votes --- Tags: git, shell-command ---
thread-59468
https://emacs.stackexchange.com/questions/59468
Open folder in emacs and type name to match file
2020-07-05T16:57:51.180
# Question Title: Open folder in emacs and type name to match file I have this line in my init.el: ``` (global-set-key (kbd "C-c g") (lambda() (interactive) (find-file "~/Dropbox/myorgfiles"))) ``` So when I type `C-c g` I get the directory contents of the `myorgfiles` folder. But I would like to be able to start typing and get search results for that pattern within that `myorgfiles` folder. How could I manage to do this? At the moment the individual keyboard strokes have different functions. # Answer As @NickD said in a comment, what you want is just to call `find-file` interactively. But you want it to do its thing in folder `~/Dropbox/myorgfiles`. So you just need to bind `default-directory` to `~/Dropbox/myorgfiles/`. ``` (global-set-key (kbd "C-c g") (lambda () (interactive) (let ((default-directory "~/Dropbox/myorgfiles/")) (call-interactively #'find-file)))) ``` > 3 votes --- Tags: find-file ---
thread-59444
https://emacs.stackexchange.com/questions/59444
Excluding frames from handout when exporting to LaTeX Beamer
2020-07-04T14:01:05.637
# Question Title: Excluding frames from handout when exporting to LaTeX Beamer I would like to exclude certain slides when I export my document as a handout using the corresponding option `#+LaTeX_CLASS_OPTIONS: [handout]`. I know what I need to arrive at in LaTeX to achieve this: ``` \begin{frame}<handout:0> ... \end{frame} ``` And I know that I can use the property `BEAMER_OPT` in Org Mode to specify frame arguments like `shrink` that will be passed on as optional frame options in square brackets to get, e.g., `\begin{frame}[shrink]`: ``` * Slide title :PROPERTIES: :BEAMER_OPT: shrink :END: ``` However, how can I use Org Mode to properly pass on the `<handout:0>` option in the required format in angle brackets? # Answer > 0 votes You can pass overlay specifications to the frame using the following command: ``` :PROPERTIES: :BEAMER_ACT: <handout:0> :END: ``` --- Tags: org-export, latex, beamer ---
thread-47206
https://emacs.stackexchange.com/questions/47206
mu4e adds sender with reply-all
2019-01-17T09:13:17.153
# Question Title: mu4e adds sender with reply-all I use `mu4e`. When I reply-all to an email, my own email appears in CC. I have these lines in my configuration: ``` (setq mu4e-compose-dont-reply-to-self t) (setq message-send-mail-function 'smtpmail-send-it user-mail-address "email@domain.com" ... ) ``` I don't have multiple accounts as in this Github issue. The value of the variable `mu4e-user-mail-address-list` is my `username@hostname.domain.tld`, where `username` is my login name and `hostname.domain.tld` is the hostname of the computer. When I click `Customize this variable`, I see that it was changed, but not by me: ``` INS DEL Address: username@hostname.domain.tld INS State : CHANGED outside Customize. ``` How can I avoid my email when replying to all? # Answer Old question, but since it is the first thing that pops up in google (at least for me), I guess it is worth updating. The answer provided by @miguelmorin no longer works, see the manual for Writing messages, C.4.9: > You need list your personal addresses by passing one or more --my-address=... to mu init. Note that the mu4e-user-mail-address-list which was used in older mu4e versions is no longer used. Also see the entries for version 1.4 in NEWS.org (N) in the main-menu. You now have to use `mu` to register your email address: ``` mu init --maildir=/path/to/mail/folder --my-address=example@example.com ``` After this, you can control the inclusion of your email address in CC while a reply-to-all configuring the `mu4e-compose-keep-self-cc` in `~/.emacs` (it defaults to `nil`). If you have multiple email addresses, you need to include that many `--my-address=...` parameters, per the documentation: ``` mu init --maildir=~/Maildir --my-address=jim@example.com --my-address=bob@example.com ``` > 5 votes # Answer **Update**: This answer is for `mu4e` before version 1.4. See above for the solution with the more recent version. It seems that `mu4e` does not pick up the email address from the `sendmail` settings. The variable `mu4e-user-mail-address-list` was changed outside of the initialisation file and one can override it with: ``` (setq mu4e-user-mail-address-list (quote ("email@domain.com"))) ``` Evaluate the region or reload the file, and now `mu4e` no longer includes the email in reply-all. And when you reply to an email sent from one person to you, it does not ask you whether to reply all or just to the sender. > 1 votes --- Tags: mu4e ---
thread-59482
https://emacs.stackexchange.com/questions/59482
Display a horizontal underline on every line
2020-07-06T12:59:06.787
# Question Title: Display a horizontal underline on every line I recently saw this image on r/unixporn. How can I recreate the 'notebook' effect: the broad line-height and underline of each line, but in Emacs (iiuc this is achieved using rxvt + pixmaps in Linux). # Answer **Edit: I've added some Elisp code at the end of the answer that performs all of the changes mentioned and then evaluates the buffer it is run in.** One way to get this effect is by making some simple modifications to Steve Purcell's `page-break-lines.el`. (To future-proof this answer as much as possible, I am referring specifically to this version of the file from a March 4th 2020 commit). I can't post the code for this mode here since it is GPLv3. Fortunately, the changes necessary to get what you want are easy to make. Note: before going any further, I highly recommend changing the names of all of these variables and functions so as they do not clash with those of the real `page-break-lines`. My recommendation is to use the prefix `my-ruled-lines`. This can be done by running `(replace-string "page-break" "my-ruled")`. Note that this and all other `replace-string` function calls in this answer should be run with the point at the top of the buffer containing the code. You should also change the minor-mode lighter too (`(replace-string "PgLn" "Ruled")`). This package causes Emacs to display a customizable character repeated enough times to fit the width of the window every time it sees a form-feed character (e.g. by using a line of dashes). The only changes we need to make are to: 1. have it work on the new-line character rather than the form-feed character 2. still display the new-line character in addition to the replacement line Accomplishing the first part is very easy, and can be done by running the function `(replace-string "^L" "^J")`. However, just making this change will make it so that Emacs doesn't display any newlines at all, which is not what we want. Fortunately, all we have to do is to wrap our replacement characters with a newline on either side. This will put the put the replacement character line on a newline (but won't affect the line-numbering) and will put all future characters on the line after that. This can be done by modifying the following line in the function `page-break-lines--update-display-table` (which should now be renamed to something like `my-ruled-lines--update-display-table`). Note that this is line number 143 in Github's line numbering, but Emacs seems to eat an empty line when I paste it in: ``` (new-display-entry (vconcat (make-list width glyph)))) ``` which should be changed to: ``` (new-display-entry (vconcat (list ?\^J) (make-list width glyph) (list ?\^J)))) ``` Now you need to evaluate all of these functions (or save them to a `.el` file and load them). Now run the command `M-x my-ruled-lines-mode` (or whatever that command has been renamed to) in your desired buffer and it should work. After you've done all of this you may want to tweak the face `my-ruled-lines` to get your ruled lines to appear more to your liking. One caveat: it appears these changes break the ability of this minor mode to remove the display changes from the buffer-display-table. You can use the following function to turn off the ruled lines if disabling the minor mode alone does not work: ``` (defun turn-off-my-ruled-lines-mode () (interactive) (my-ruled-lines-mode -1) (aset buffer-display-table ?\^J nil)) ``` --- **Script to make these changes** Since there are several individual steps to follow here, I've packaged all of the steps into a single Elisp function call. The code from `page-break-lines.el` should be pasted into a buffer then this code should be evaluated (i.e. by using `M-:`). This will make the changes and then define the minor mode. ``` (save-excursion (goto-char (point-min)) (replace-string "page-break" "my-ruled") (goto-char (point-min)) (replace-string "PgLn" "Ruled") (goto-char (point-min)) (replace-string "^L" "^J") (goto-char (point-min)) (replace-string "(new-display-entry (vconcat (make-list width glyph))))" "(new-display-entry (vconcat (list ?\\^J) (make-list width glyph) (list ?\\^J))))") (goto-char (point-max)) (newline) (insert "(defun turn-off-my-ruled-lines-mode ()\n (interactive)\n (my-ruled-lines-mode -1)\n (aset buffer-display-table ?\\^J nil))") (eval-buffer)) ``` Here is what the results look like when run on default Emacs 26.3: > 1 votes --- Tags: faces, themes ---
thread-26821
https://emacs.stackexchange.com/questions/26821
File error: Cannot open load file
2016-09-04T08:13:43.977
# Question Title: File error: Cannot open load file I have the following ~/.emacs: ``` ;; Added by Package.el. This must come before configurations of ;; installed packages. Don't delete this line. If you don't want it, ;; just comment it out by adding a semicolon to the start of the line. ;; You may delete these explanatory comments. (package-initialize) (require 'highlight-symbol) (global-set-key [(control f3)] 'highlight-symbol) (global-set-key [f3] 'highlight-symbol-next) (global-set-key [(shift f3)] 'highlight-symbol-prev) (global-set-key [(meta f3)] 'highlight-symbol-query-replace) ``` Then I added the file highlight-symbol.el to my ~/.emacs.d folder. However when I start emacs I get: ``` Warning (initialization): An error occurred while loading ‘~/.emacs’: File error: Cannot open load file, No such file or directory, highlight-symbol ``` I am new to emacs, what am I doing wrong? # Answer > 9 votes Looking at the help from `require` (`C-h f require`) > (require FEATURE &optional FILENAME NOERROR) > > If feature FEATURE is not loaded, load it from FILENAME. If FEATURE is not a member of the list 'features', then the feature is not loaded; so load the file FILENAME. If FILENAME is omitted, the printname of FEATURE is used as the file name, and 'load' will try to load this name appended with the suffix '.elc' or '.el', in that order. So let's look at `load` help (either `C-h f load` or simply use `TAB` to navigate to the blue link then use`RET`): > This function searches the directories in \`load-path'. Again we can have a look at `load-path` help (either `C-h v load-path`, since it's a variable, or navigating to the link) and, probably, find that `.emacs.d` is not in the list. This can be fixed by adding this to the init file: > (add-to-list 'load-path "~/.emacs.d") For it to take effect immediately you can use `C-x C-e` (`eval-last-sexp`) with point at end of line. # Answer > 1 votes I'm not sure about the time this question was asked, but today (Emacs 26.3) I've run into the same error. My config was basically like so: ``` (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. '(package-selected-packages (quote (expand-region)))) (require 'expand-region) ``` The reason it didn't work was because by the time `require` was executed, `~/.emacs.d/elpa/expand-region-XXXXXXXX.XXXX` was not in `load-path`. I fixed by putting `require` inside `after-init-hook`: ``` (add-hook 'after-init-hook (lambda () (progn (require 'expand-region) ))) ``` --- Tags: package ---
thread-59448
https://emacs.stackexchange.com/questions/59448
Pre-populate property entry menu with items from setup file
2020-07-04T17:12:46.217
# Question Title: Pre-populate property entry menu with items from setup file I have a collection of Org files that all link to a central properties file in which I specify `_ALL` properties so that I can get uniform entry of information across many files: ``` #+SETUPFILE: ../../properties.org ``` I have also tried adding properties set to `<unspecified>` in the hopes that they would pre-populate the property entry list because it is easier not to retype the same property names every time I open a new file. Thus, a snippet of my `properties.org` looks like: ``` #+PROPERTY: GENRE <unspecified> #+PROPERTY: GENRE_ALL Commentary Theology History Biography Philosophy Sermons ``` However, I was wrong about how this works. The properties menu seems to be only populated from properties that are physically in the file, not from properties that are imported from the `SETUPFILE`. **Is there some way I can pre-populate the property menu so that I don't have to fully retype the property names every time I start entering them in a new file?** # Answer I think this is an omission, so I'm going to send the following patch to the Org mode mailing list as an enhancement. The patch is against latest (as of now) Org mode, but it is simple enough to apply by hand, if you'd like to try it out (or you might wait for a little while and see what happens to it upstream before doing anything): ``` diff --git a/lisp/org.el b/lisp/org.el index 748c058ca..0ca7f3e92 100644 --- a/lisp/org.el +++ b/lisp/org.el @@ -13084,6 +13084,12 @@ COLUMN formats in the current buffer." (props (append (and specials org-special-properties) (and defaults (cons org-effort-property org-default-properties)) + ;; Get property names from #+PROPERTY keywords as well + (mapcar (lambda (s) + (nth 0 (split-string s))) + (cdar (org-collect-keywords '("PROPERTY")))) nil))) (org-with-wide-buffer (goto-char (point-min)) ``` If you want to try it, but the line numbers don't match up, the modification is to the function `org-buffer-property-keys`: you can easily add the hunk by hand at the proper place. See this thread for the current state. EDIT: the patch, slightly enhanced, has now been applied, but you will only be able to get it if you install Org mode from git (and you use the development ("master") branch, not the stable ("maint") branch). It will be part of Org mode 9.4 when that gets released. Note that the patch that was applied adds the "bare" property `foo` if it finds a `foo_ALL` property, so you don't need to do ``` #+PROPERTY: foo_ALL foo bar baz #+PROPERTY: foo <unspecified> ``` Just the first one is enough. > 9 votes --- Tags: org-mode ---
thread-59484
https://emacs.stackexchange.com/questions/59484
Add last review date for a heading
2020-07-06T15:38:26.167
# Question Title: Add last review date for a heading I want to add a last-reviewed date for some headings. And in org agenda view, I want to filter outer the headings that have not been reviewed for some days. What's the org tools/functions/setup that are involved here? # Answer You can store the review date as an org-mode timestamp in a property, say `LAST_REVIEW`. To help input them, you can use `org-property-set-functions-alist` to give function that will be called when setting the property with `C-c C-x p`: ``` (add-to-list 'org-property-set-functions-alist '("LAST_REVIEW" . (lambda (&rest args) (format "[%s]" (org-read-date nil nil nil "Last Reviewed on") )))) ``` (Here I'm using an inactive timestampe. Change "\[%s\]" to "\<%s\>" if you prefer active.) You can query properties in the agenda view. For example the query `LAST_REVIEW<"<-1m>"` Will find entries whose `LAST_REVIEW` property is older than 1 month. You can save it in a custom agenda view: ``` (add-to-list 'org-agenda-custom-commands '("r" "Items to review" tags "LAST_REVIEW<\"<-1m>\"" )) ``` > 5 votes --- Tags: org-mode ---
thread-59497
https://emacs.stackexchange.com/questions/59497
How to override Q in term-mode with passthrough if the shell process is still live?
2020-07-07T05:01:56.823
# Question Title: How to override Q in term-mode with passthrough if the shell process is still live? I wrote the following emacs lisp procedure to kill a dead ansi-term buffer. It works well if called with M-x. Also, it appears to run correctly when the called in a living term buffer. However, dead buffers happily insert Q anyways. Why is that and how can I make it actually kill the buffer when the process is dead without calling M-x? ``` (defun terminal-burn-when-dead-or-insert-Q () (interactive) (setq buf (current-buffer)) (if (not (process-live-p (get-buffer-process buf))) (kill-buffer buf) (insert "Q"))) (define-key term-raw-map (kbd "Q") #'terminal-burn-when-dead-or-insert-Q) (define-key term-mode-map (kbd "Q") #'terminal-burn-when-dead-or-insert-Q) ``` # Answer > ``` > (define-key term-raw-map (kbd "Q") #'terminal-burn-when-dead-or-insert-Q) > > ``` That's definitely not going to do what you wanted it to in char mode. You need to send something to the *process* (like the regular binding `term-send-raw` does), not just insert some text into the *buffer* (which tells the process nothing). It's also not clear from the question whether you'd loaded `term.el` before those `define-key` calls happened. If not, then those keymaps didn't exist (and you should have been seeing errors), in which case `Q` might never have been calling your custom command at all. I would typically use: ``` (with-eval-after-load "term" (define-key term-mode-map ...)) ``` --- Regarding your main question, when the process is killed, `term-sentinel` does this: ``` (with-current-buffer buffer ... ;; Get rid of local keymap. (use-local-map nil) (term-handle-exit (process-name proc) msg) ...) ``` I suggest you piggy-back onto the latter like so: ``` (define-advice term-handle-exit (:after (&rest _) Q-for-quit) "Make Q kill the buffer once the process is dead." (use-local-map (let ((map (make-sparse-keymap))) (define-key map "Q" #'kill-current-buffer) map))) ``` You don't need any of your existing code. > 1 votes --- Tags: ansi-term, term ---
thread-59499
https://emacs.stackexchange.com/questions/59499
sectioning in org-mode to beamer does not work
2020-07-07T09:01:26.270
# Question Title: sectioning in org-mode to beamer does not work I am trying to subdivide my presentation further into section and according to the org docs, setting #+BEAMER\_FRAME\_LEVEL: 2 should allow for top-level headlines to be interpreted as sections, whereas not the second level headlines, i.e. \** are defining individual pages. However, in my minimal example below, setting the value from 1 to 2 does not make any difference. What am I missing here? ``` #+TITLE: Abandon all hope #+startup: beamer #+LaTeX_CLASS: beamer #+LaTeX_CLASS_OPTIONS: [bigger] #+BEAMER_FRAME_LEVEL: 2 * First page ** Stuff larifari ** second stuff larifari * Second page ** fdjsfsd larfdfj ** fjs iiinfdnf ``` # Answer > 4 votes (If I understand well,) the correct way to do this is to replace `#+BEAMER_FRAME_LEVEL: 2` by `H:2` in the global options: ``` #+TITLE: Abandon all hope #+startup: beamer #+LaTeX_CLASS: beamer #+LaTeX_CLASS_OPTIONS: [bigger] #+options: H:2 * First page ** Stuff larifari ** second stuff larifari * Second page ** fdjsfsd larfdfj ** fjs iiinfdnf ``` See for example here: https://github.com/fniessen/refcard-org-beamer, or directly in the current Org manual: > Org headlines become Beamer frames when the heading level in Org is equal to org-beamer-frame-level or ‘H’ value in a ‘OPTIONS’ line --- Tags: org-mode, beamer ---
thread-59504
https://emacs.stackexchange.com/questions/59504
How to see brief location in the code in C/C++ mode
2020-07-07T15:45:22.573
# Question Title: How to see brief location in the code in C/C++ mode While editing a long C++ file, I use `rtags` to jump around. It would be very handy for me to know where I am in terms of where the cursor is relative to the classes-functions. For example, it would be great if I could have something similar to `imenu` that would echo `Class A -> function F` for the current position of the cursor. I believe that some version of this does exist even in vanilla Emacs, it's only that I cannot find it. # Answer I think you're looking for `which-function-mode` (which is indeed a standard feature). > 2 votes --- Tags: c++, c, imenu ---
thread-59493
https://emacs.stackexchange.com/questions/59493
critical markup in org-mode or emacs?
2020-07-07T01:48:08.097
# Question Title: critical markup in org-mode or emacs? *Is there support for Critical Markdown in org-mode or in Emacs text editing in general?* I am interested in MSWord style track-changes in plain text, and learned that Critical Markdown fits the bill. On their website, they listed a number of supporting editors such as a BBEdit Plugin and a Sublime Text Plugin. Is there a similar mode in Emacs for this? # Answer Yes, I know of at least criticmarkup modes. Here are the links: https://github.com/joostkremers/criticmarkup-emacs https://github.com/syohex/criticmarkup-emacs > 1 votes --- Tags: org-mode, writing ---
thread-59483
https://emacs.stackexchange.com/questions/59483
How to list a key binding in any modes?
2020-07-06T13:19:14.960
# Question Title: How to list a key binding in any modes? For a given command, lets say `C-c C-k`, how to list the bindings of this key for all modes ? `C-h k KEY` show bindings only for the current mode. It's the same for invert commands like `C-h f` and `C-h b`. Purpose of this is I wrote a new function, usable in different modes. I want to bind it to a key, but I first want to know if it is already bound. # Answer phils is correct; if you use `C-c`*`letter`* for your personal customizations then you're not supposed to have to worry about conflicts with the key bindings from a mode. As for actually enumerating all possible keymaps to check if they would define the same shortcut… that's a bit difficult. As far as I know, there's no global list of all keymaps. There's no global list of all variables that are defined, so you can't enumerate all variables and check for keymaps either. In fact, there's no requirement that a keymap has to be stored in a variable at all; it can be created on the fly for transient use. Finally, most keymaps aren't even in memory at all until they are first used. All that Emacs knows at startup is that some symbols are defined but not yet loaded, and what file to load them from. I wouldn't say that it's completely impossible, however. With sufficient determination, you could take advantage of the autoloader system to get a list of variables that hold keymaps. Each variable that is to be autoloaded has to be declared as such by calling the `autoload` function (Use `C-h f autoload` to see the documentation). You could advise the `autoload` function and save a list of keymaps to a variable of your choosing. Something like this: ``` (define-advice autoload (:before (function file &optional docstring interactive type) stash-keymap-names) "stashes the names of symbols holding autoloaded keymaps in *my-list-of-keymaps*" (when (eq type 'keymap) (add-to-list '*my-list-of-keymaps* function))) ``` However, there is another wrinkle: the autoload declarations are not read in by Emacs on every startup. That would be too slow. Instead, the list of autoload declarations is created during the Emacs build process. This list is then read in once by Emacs (along with a number of other lisp files). The running Emacs then dumps it's own memory out into a new Emacs executable, so that everything created by those lisp files that it read in is automatically available the next time Emacs is run, without having to load any lisp files at all. So what you need to do is to define this advice very early on in the boostrap process, before it reads the autoload declarations. The variable you're stashing keymap names into will then be baked into the resulting Emacs executable. You can then run the new executable and use the list of symbols to enumerate most of the keymaps that Emacs will ever use. > 2 votes # Answer A partial answer, just to say how you can get a list of all variables currently bound to keymaps: ``` (let ((symbs ())) (mapatoms (lambda (s) (when (and (boundp s) (keymapp (symbol-value s))) (push (indirect-variable s) symbs)))) symbs) ``` > 1 votes # Answer I've taken @Drew's answer and blended it with https://stackoverflow.com/a/36994486/324105 to produce this command: ``` (defun my-describe-all-keymaps () "Describe all keymaps in currently-defined variables." (interactive) (with-output-to-temp-buffer "*keymaps*" (let (symbs seen) (mapatoms (lambda (s) (when (and (boundp s) (keymapp (symbol-value s))) (push (indirect-variable s) symbs)))) (dolist (keymap symbs) (unless (memq keymap seen) (princ (format "* %s\n\n" keymap)) (princ (substitute-command-keys (format "\\{%s}" keymap))) (princ (format "\f\n%s\n\n" (make-string (min 80 (window-width)) ?-))) (push keymap seen)))) (with-current-buffer standard-output ;; temp buffer (setq help-xref-stack-item (list #'my-describe-all-keymaps))))) ``` > 1 votes --- Tags: key-bindings ---
thread-59508
https://emacs.stackexchange.com/questions/59508
How to show C/C++ doxygen section titles in the mode-line?
2020-07-08T03:09:39.487
# Question Title: How to show C/C++ doxygen section titles in the mode-line? For C/C++ code that use doxygen sections, it would be useful to show these in the mode-line, without slowing down the mode-line display significantly. Is there a good way to add context information to the mode-line? # Answer > 0 votes The built-in `which-function` package already does something similar, getting the function. You can extend this using advice, this way `which-function` handles the timers and accesses the current function, you can add extra information to this as needed. ``` (with-eval-after-load 'which-func (defun which-function--add-comment-section (orig-fn) (let ((result (funcall orig-fn))) (when result (setq result (propertize result 'face 'font-lock-keyword-face))) ;; Error's are very unlikely, this is to ensure even the most remote ;; chance of an error, don't cause which-func to fail. (condition-case err (let ((section nil)) (cond ((member major-mode '(c-mode c++-mode glsl-mode)) (save-match-data (save-excursion (when (re-search-backward "\\([\\\@]\}\\|[\\\@]\{\\)" nil t 1) (pcase (char-after (+ 1 (point))) (?{ ;; Section Start (let ((section-start-pt (point))) ;; Find start of comment. (when (re-search-backward "\\/\\*" nil t 1) (when (re-search-forward "[\\@]name[[:blank:]]+\\(.*\\)" section-start-pt t 1) (setq section (propertize (match-string-no-properties 1) 'face 'font-lock-comment-face)))))) (?} ;; Section End ;; Do nothing, we're not in a section. nil))))))) (when section (setq result (concat section ": " (or result which-func-unknown))))) (error (message "Error creating vc-backend root name: %s" err))) result)) (advice-add 'which-function :around #'which-function--add-comment-section)) ``` This matches sections written in this style. ``` /** \name Main Function * * Body text. * \{ */ /* --- your code --- */ /** \} */ ``` When the cursor is in "your code" the mode line will show the function name and section text. The mode line needs to include something like this: ``` '(:eval (when (bound-and-true-p which-func-mode) (list " (" which-func-current ")"))) ``` --- Tags: mode-line ---
thread-59514
https://emacs.stackexchange.com/questions/59514
How to invoke another function only if there is some error with a given function?
2020-07-08T04:58:18.337
# Question Title: How to invoke another function only if there is some error with a given function? Assume that I have two functions, say `function1` and `function2`. I would like to execute `function2` **only if** there is some error during the execution of `function1`. So far, I have tried the below code ``` (ignore-errors (function1) (function2)) ``` This executes `function2` if there is some error with `function1`, but it executes `function2` if there is no error with `function1` as well. How to correct the code? # Answer Read about `condition-case` in `C-h``i``g` `(elisp)Handling Errors` ``` (condition-case nil (function1) (error (function2))) ``` > 3 votes --- Tags: error-handling, conditionals ---
thread-36705
https://emacs.stackexchange.com/questions/36705
How to build Emacs for an embedded ARM Linux system
2017-11-08T08:34:12.523
# Question Title: How to build Emacs for an embedded ARM Linux system I am trying to build Emacs for an embedded ARM Linux system. Unfortunately, it is proving to be more difficult than I anticipated. I have the device mounted at `/mnt/my_device`. Now I am not sure exactly how to go about building Emacs from source. I know I can set the prefix of the install via `--prefix=/mnt/my_device/usr/local`. However, beyond that, things get more difficult. How can I `configure` my Emacs build for my ARM system? After configuration, how do I compile Emacs? Using an ARM toolchain in QEMU or something? I know that there are cross-compiler tools that run on x86 systems, but should I use those given that `configure` may get the wrong info if I run it on my x86 system? Also, I need this installation of Emacs to be quite minimal, as this *is* an embedded system and there's not a lot of room. Any tips that would help cohere and streamline this build process would be most appreciated. # Answer First: do you need to run Emacs on that system? Emacs can access remote files easily. Typically you just run it on your local machine. If you only ever access the system remotely, it probably doesn't need Emacs. ARM covers a very wide range of system sizes, from appliances with only a few megabytes of memory to equivalents of a 10-year old PC such as the latest Raspberry Pi model. Second: do you need to compile Emacs yourself? There are plenty of Linux distributions that have ARM binaries and include Emacs. Distributions intended for smaller systems usually don't have it, but see “First” above. On “larger” distributions such as Debian or Arch, just install the package. If you determine that you do need to compile Emacs, then you have a choice of cross-compiling or not. Emacs is written in C, and C compilers can work in relatively small amounts of memory. For example, you could compile on something like a Pi — but even a slightly aging PC will do it faster. If the device is powerful enough to cross-compile, then you'll probably want to run a distribution that has an Emacs package anyway. If you do want to cross-compile, you'll need a cross-compiler. This can be a bit painful to set up sometimes. However, the distribution you're running on the device probably already has a cross-compiler setup. This is your most promising route: use whatever toolchain the distribution uses for its own packages. Regarding Emacs itself, there are a few instructions in the `INSTALL` file. You'll need to pass the `--host` option to `./configure`. The argument depends on the exact platform, depending on whether it has floating point registers and which standard library it runs. It might look something like `arm-linux-gnueabihf` (with GNU libc and Hardware Floating point). Usually the argument is the same name that the toolchain is installed under; for example a compiler for the `arm-linux-gnueabihf` target is typically called `arm-linux-gnueabihf-gcc`. > 2 votes # Answer try chrooting to the root filesystem - assuming it has a build environment... you can then use the arm compiler.... something like:- ``` cd arm/rootfs sudo su cp /usr/bin/qemu-aarch64-static usr/bin cp /run/systemd/resolve/stub-resolv.conf run/resolvconf/resolv.conf mount /sys ./sys -o bind mount /proc ./proc -o bind mount /dev ./dev -o bind sudo LC_ALL=C chroot . /bin/bash # we are not in kansas anymore! root@jw-XPS-13-9370:/# gcc -dumpmachine aarch64-linux-gnu ``` > 0 votes --- Tags: linux, install, build ---
thread-59502
https://emacs.stackexchange.com/questions/59502
Is there a way to mark certain file types as binary for magit, so that they are not diffed?
2020-07-07T11:27:01.327
# Question Title: Is there a way to mark certain file types as binary for magit, so that they are not diffed? Magit sometimes becomes very slow, when it thinks that certain large files should be diffed. Examples for this are SVG graphics or SQL dumps (technically seen as text files). The files are small enough that they should be controlled by git, but seemingly too large (and with very long lines) for magit to display. Is there a way to tell magit not to create the diff for certain file types? Maybe something like a blacklist? # Answer > 5 votes This can be done for a whole repository with a `.gitattributes` file (or globally with `$XDG_CONFIG_HOME/git/attributes`): ``` # content of .gitattributes *.svg -diff *.sql -diff ``` --- Kudos to @phils for the comment which led me to write this answer. --- Tags: magit ---
thread-59460
https://emacs.stackexchange.com/questions/59460
mu4e: Refiling email while making an org-todo
2020-07-05T10:34:49.347
# Question Title: mu4e: Refiling email while making an org-todo ## Background: I read my email through mu4e in (Doom) emacs. I set up an org-capture template that stores a TODO with a link to the current email I'm viewing, all working great. Typically I do this from the inbox email folder, and I like to keep that clean, so I refile emails to my "All email" folder when I'm done with it. If I refile *after* I added the org-todo, then the contained link no longer works (points to where the email *used* to be). I'd like to keep my email inbox empty when I already track the todo elsewhere. ## My question: Is there a way to refile a message in mu4e, and at the same time add an org-todo with a *valid* link to the email? I imagine I could write a custom elisp function to do it, but I'm not too comfortable with elisp in particular. I don't expect a copy-paste complete solution, but any help or pointers would be much appreciated! **Config:** I'm using Doom emacs with very little additional config, with ``` (doom! ;; ... ;; lots of unrelated modules ;; ... :email (mu4e +gmail)) ``` The capture template I have looks as follows: ``` (setq org-capture-templates '(("m" "Mail" entry (file+headline "~/org/gtd.org" "Tasks") "* TODO Mail: (%:fromname) %:subject\nSCHEDULED:%t\n:PROPERTIES:\n:CREATED: %U\n:END:\n %a" :immediate-finish t :prepend t)) ``` # Answer > 1 votes As you can see in the manual, what you store is either a link to a particular message (from message-view) or the last know query to it (from headers view). I guess the latter, the query, is what gives you trouble. To avoid that, with the minimum fuss you can, either: * Link from the message view. * Refile first, then link. or with a little work, pack everything in your own command skipping capture interface. --- Although this is what the 1.4.6 manual states, I'm using 1.4.10 and I'm getting the same behavior of linking to the message id no matter from where I capture, and it doesn't get affected by refiles, or so it seems in a quick test. --- Tags: org-mode, mu4e, org-capture, doom ---
thread-59494
https://emacs.stackexchange.com/questions/59494
How to wrap / intercept commands bound to a given key?
2020-07-07T01:49:55.953
# Question Title: How to wrap / intercept commands bound to a given key? I am trying to have a global override for a binding, where I am checking for some specific conditions to hold. If they don't, I would like that binding to do whatever it was going to without my intercept. I.e., something like the following: ``` (global-set-key <existing-binding> 'foo-wrapper) (defun foo-wrapper () (interactive) (if my-condition-holds #'my-foo <whatever existing-binding would have otherwise done here>)))) ;; ``` How can I programmatically delegate to `<whatever existing-binding would have otherwise done here>`? Please note: I am looking to **not** hard-code any commands into the wrapper that are not part of my custom logic. I'm looking at keybindings that are frequently overridden in various mode maps, and it seems impractical to have to manually figure out which command to dispatch. Edited to add: concrete example is special handling of parentheses. In this case, `<existing-binding>` is simply `(kbd "(")`, and `my-condition` could be something like `(and current-prefix-arg (eq major-mode 'foo-mode))`. Crucially, if `my-condition` does not hold, I need to delegate to the default behavior, which is highly context-specific: it may be handled by paredit, or smartparens, or evil, or be a self-insert-command. # Answer I had this problem before and came up with this solution. Make a minor mode where you define your conditional commands: ``` (defvar conditional-overriding-mode-map (make-sparse-keymap)) (define-minor-mode conditional-overriding-mode "a minor mode for commands that only work if a certain condition holds." t nil conditional-overriding-mode-map) ``` The argument t means that the minor mode is on by default. Then bind keys in this minor mode as follows: ``` (define-key conditional-overriding-mode-map KEY (lambda () (interactive) (if COND COMMAND (conditional-overriding-mode 'toggle) (execute-kbd-macro (this-command-keys)) (conditional-overriding-mode 'toggle)))) ``` What this does is what you want. You will have to adjust this if you want to pass arguments to your COMMAND or to whatever happens when COND fails. For this to work all the time conditional-overriding-mode has to be at the front of minor-mode-map-alist. The answer in How to set a rule for the order of minor-mode-map-alist gives a way to do this. > 1 votes # Answer The easiest way is to just call whatever function would have been called when the original key binding was used. Suppose it was function `foo`: ``` (global-set-key <existing-binding> 'foo-wrapper) (defun foo-wrapper (arg1 arg2) (interactive) (if my-condition-holds (my-foo arg1 arg2) (foo arg1 arg2))) ``` Note that you have to pass along any arguments that `foo` needs, and `my-foo` might need them as well. There's another way to do this called advice. Advice is an additional function that is called before, after, around, or in some other combination with the original function. This happens automatically and transparently any time the original function is called, and when done correctly shows up in the documentation for the original function. It's documented in chapter 13.11 Advising Emacs Lisp Functions in the Elisp manual, which is also included with Emacs (use `C-h i` to open the info browser). Again, assuming the original function is called `foo`, then you could write something like this: ``` (define-advice foo (:before-until (arg1 arg2) my-foo) "documentation for your advice here" (when my-condition-holds (progn (my-foo arg1 arg2) t))) ``` After this, whenever `foo` is called, your advice will be called first. Your advice should return `t` if it handled everything itself, or `nil` if the original function should be called. If `my-foo` returns anything non-nil, then you could simplify it to this: ``` (define-advice foo (:before-until (arg1 arg2) my-foo) "documentation for your advice here" (when my-condition-holds (my-foo arg1 arg2))) ``` Either way, the name `my-foo` and the docstring that you supply will show up as part of the documentation for the original function `foo` when you type `C-h f foo`. Edit: Since you've edited your question to include details about what the condition looks like, there is a better answer. When the condition involves checking the current major mode you should simply add a new key binding to that mode's keymap (usually of the form `foo-mode-map`) instead of wrapping anything. That way Emacs implicitly does this part of the check for you; that keymap won't be active in other modes so you won't have to check. On the other hand, if you still need to check for other conditions such as the prefix arg then you might need to wrap the function anyway. Another Edit: Oh, and I forgot to mention that if you're going to want this modification to be present in multiple modes, then instead of modifying multiple keymaps you might want to define a minor mode instead. You can add your new binding to the minor mode's keymap, which will be active any time the minor mode is active. See the `define-minor-mode` macro as well as chapter 23.3 Minor Modes of the Elisp manual as well as chapter 23.3 Choosing File Modes of the Emacs manual. > 2 votes # Answer You can do this: ``` ;; Dynamic bindings. A filter function returns the command to ;; call. If the function returns nil, Emacs treats it as if ;; no binding exists in that keymap, and continues looking for ;; a binding elsewhere. (define-key <map> <key> `(menu-item "" <my-cmd> :filter ,(lambda (cmd) (if <my-predicate> cmd)))) ``` E.g.: ``` (define-key my-dynamic-override-map (kbd "(") `(menu-item "" my-foo :filter ,(lambda (cmd) (if (my-predicate) cmd)))) ``` You (probably) won't want to use the global key map, because *any* other active keymap with a binding would take precedence; so you'd typically be using a minor mode key map, and taking steps to keep that at the front of the minor mode map priority list (which is what I do). The other answers have already indicated how to do that with a minor mode, so for variety I'm using the even-higher-priority `emulation-mode-map-alists` here. I don't feel it's quite intended for this usage, but I suspect it'd be fine in practice. ``` (defun my-foo () (interactive) (insert "foo")) (defun my-predicate () (eql 0 (random 5))) (defun my-filter (cmd) (if (my-predicate) cmd)) (defvar my-dynamic-override-map (make-sparse-keymap)) (define-key my-dynamic-override-map (kbd "(") `(menu-item "" my-foo :filter ,#'my-filter)) (defvar my-emulation-mode-map-alist `((my-dynamic-override-map . ,my-dynamic-override-map))) (add-to-list 'emulation-mode-map-alists 'my-emulation-mode-map-alist) ``` (If you use a minor mode instead, simply define the key in the minor mode's keymap instead of the separate keymap I've made here, and ignore the 'emulation-mode-map' parts.) See also: How can I 'layer' a keybinding? > 0 votes --- Tags: key-bindings ---
thread-3063
https://emacs.stackexchange.com/questions/3063
Recently opened files in ido-mode
2014-11-04T08:00:52.493
# Question Title: Recently opened files in ido-mode I use `ido-mode`, but one thing I hate about it is that after `C-x C-f` I cannot use `up/down` keys to cycle through recently opened files, as it used to be for example with `iswitchb`. How can I set `ido` to work this way? # Answer Looking at the customization options for `ido-mode` (`M-x` `customize-group` `RET` `ido` `RET`), I don't see any options for enabling the cycling behavior you describe. You can, however, add the following to your init-file: ``` (require 'recentf) (defun ido-recentf-open () "Use `ido-completing-read' to find a recent file." (interactive) (if (find-file (ido-completing-read "Find recent file: " recentf-list)) (message "Opening file...") (message "Aborting"))) (global-set-key (kbd "C-x C-r") 'ido-recentf-open) ``` With this in place you can press `C-x C-r` to get Ido completion for selecting recently opened files. By default, the 20 most recent files will be kept in the history. I suggest you crank that up to something like 150 by setting `recentf-max-saved-items`: ``` (setq recentf-max-saved-items 150) ``` --- ### Bonus: Accessing recent files, on-steroids edition I don't see it mentioned in a lot of places, but **Ido Virtual Buffers** make it *super easy* to access recent files. Enable them like so: ``` (setq ido-use-virtual-buffers t) ``` The behavior you get is this: > If non-`nil`, refer to past ("virtual") buffers as well as existing ones. > > Essentially it works as follows: Say you are visiting a file and the buffer gets cleaned up by `midnight.el`. Later, you want to switch to that buffer, but find it's no longer open. With virtual buffers enabled, the buffer name stays in the buffer list (using the `ido-virtual` face, and always at the end), and if you select it, it opens the file back up again. This allows you to think less about whether recently opened files are still open or not. Most of the time you can quit Emacs, restart, and then switch to a file buffer that was previously open as if it still were. > 16 votes # Answer Though the bindings have evolved over time, as of today, when you invoke `ido-find-file` or `ido-find-file-read-only`, you can use the following bindings available in the default configuration: * `M-o` invokes `ido-prev-work-file` * `C-M-o` invokes `ido-next-work-file` Apart from these not being as ergonomically pleasant as the `M-p` and `M-n` bindings I had been used to before trying *ido*, they're also slow, and the consequent minibuffer chatter is distracting and confusing. *ido* does something more than just show a recently opened file name; it reports that it's "Searching for '*file name*'...", perhaps out of reluctance to offer a name for a file that no longer exists. The "Searching for" message comes from function `ido-make-merged-file-list`. Reading the source, I don't see any way to disable whatever magic this function is doing. You may consider rebinding the `ido-prev-work-file` and `ido-next-work-file` pair to something more natural like `C-M-p` and `C-M-n`, or swapping the current `M-p` (`ido-prev-work-directory`) and `M-n` (`ido-next-work-directory`) bindings for these. Here is the Emacs Lisp code to restore `M-p` and `M-n` to cycle through recent files, moving the default directory-focused bindings to `C-M-p` and `C-M-n` respectively: ``` (add-hook 'ido-setup-hook (lambda () (let ((kmap ido-file-dir-completion-map)) (let ((key '(meta ?n))) (define-key kmap (vector (cons 'control key)) (lookup-key kmap (vector key))) (define-key kmap (vector key) 'ido-next-work-file)) (let ((key '(meta ?p))) (define-key kmap (vector (cons 'control key)) (lookup-key kmap (vector key))) (define-key kmap (vector key) 'ido-prev-work-file))))) ``` > 4 votes # Answer what I've resorted to in this case is going back to normal minibuffer behaviour by typing C-f in idomode. Then you'll have normal history browsing keys. If you know it in advance, it can be quick : C-x-f-f :-) > 3 votes # Answer The answer given by @itsjeyd is pretty complete. Let me just suggest a function: ``` (defun ido-choose-from-recentf () "Use ido to select a recently visited file from the `recentf-list'" (interactive) (find-file (ido-completing-read "Open file: " recentf-list nil t))) ;; bind it to "C-c f" (global-set-key (kbd "C-c f") 'ido-choose-from-recentf) ``` Courtesy of WikEmacs > 1 votes # Answer I found `helm-for-files` works better than any of the above answers for the purpose of file name auto-completion and having nice search interface. Also, you can configure it to include any search items you like. > 1 votes # Answer On mac, while `ido-mode` is on, after you type `C-x C-f` you can browse the recent files with `fn-up` and `fn-down` keys. > 0 votes --- Tags: ido, find-file, cycling ---
thread-59520
https://emacs.stackexchange.com/questions/59520
Is it possible to configure a org file for paper as well as presentation using beamer?
2020-07-08T08:31:40.850
# Question Title: Is it possible to configure a org file for paper as well as presentation using beamer? I am documenting my work using *org mode* and *babel*. I am exporting it to a LaTeX based pdf document by using the header: ``` #+TITLE: Document Title #+AUTHOR: Author #+EMAIL: author@somewhere.com #+LaTeX_HEADER: \usepackage{charter} #+OPTIONS: toc:nil ``` I use `C-c C-e l o` to export the document to latex and then pdf. I would like to convert the same document with **Beamer** presentation for headings and subheadings. By default the document class is `\documentclass[11pt]{article}`. Can I have more than one class definition in the same org file or is there any other method to the same? # Answer The default LaTeX class can be set with ``` #+LATEX_CLASS: article ``` or ``` #+LATEX_CLASS: beamer ``` at the top of the file, so you can have them commented out: ``` # #+LATEX_CLASS: article ``` and select which one you want by uncommenting one or the other. This should be enough for manual export: when you automate the process, you will probably want to use a different method, but this is enough to start (particularly in the light of the comments that follow, which are much more important than how exactly you do the switchover). But I think you will find that it is difficult to write a document that behaves properly under both exporting methods. You will have to experiment. I would begin by writing two (small, example) files: one that looks good to you under "normal" export and a corresponding one for beamer export. Then worry about how to merge them together, or perhaps how to use one to produce the other (probably the full one to produce the beamer one). Once you have examples that work for you, you might want to come back with a more detailed question of how to do these steps. > 1 votes --- Tags: org-mode, latex, beamer ---
thread-59522
https://emacs.stackexchange.com/questions/59522
difference between properties and tags in the upper right corner
2020-07-08T09:20:44.327
# Question Title: difference between properties and tags in the upper right corner I dont get the difference between the actual property, enabling the respective funtionality and the tag on the right upper side? ``` *** Number 5 :B_example: :PROPERTIES: :BEAMER_env: example :END: 5 can only be divided evenly by 1 or 5, so it is a prime number. ``` Can someone explain that to me? # Answer > 3 votes See the footnote in the Frames and Blocks in Beamer section of the Org mode manual: > (1) If ‘BEAMER\_ENV’ is set, Org export adds ‘B\_environment’ tag to make it visible. The tag serves as a visual aid and has no semantic relevance. --- Tags: org-mode, pdf, beamer ---
thread-59488
https://emacs.stackexchange.com/questions/59488
How do I make emacs indent relative to the beginning of the previous line?
2020-07-06T23:04:35.090
# Question Title: How do I make emacs indent relative to the beginning of the previous line? Here's how `emacs` indents e.g. Python code: ``` a = myfun(b, c) ``` I'd like it to be this way: ``` a = myfun(b, c) ``` Reasoning? If I later replace `myfun` with `myfunction`, in the first case it becomes: ``` a = myfunction(b, c) ``` I can probably use `aggressive-indent-mode`, but not everybody uses `emacs`. If I'd like to contribute to, say, an open source project, I can't just impose it on other people. Is there a way out? For Python? Ruby? Or Javascript? Any of these? # Answer > 2 votes You might want to stick to the defaults, since: ``` r = my_long_function_name( param1, param2) ``` is arguably preferable over: ``` r = my_long_function_name(param1, param2) ``` But if you care (Emacs 26.3), for Python: ``` (eval-after-load "python" (lambda () (fset 'old-python-indent--calculate-indentation (symbol-function 'python-indent--calculate-indentation)) (defun python-indent--calculate-indentation () (save-excursion (pcase (python-indent-context) (`(,:inside-paren . ,start) (goto-char start) (+ (current-indentation) python-indent-offset)) (_ (old-python-indent--calculate-indentation))))) ;; Alternatively, use advice-add ;; (defun my/python-indent--calculate-indentation (orig-fun &rest args) ;; ... ;; (apply orig-fun args)) ;; (advice-add 'python-indent--calculate-indentation :around #'my/python-indent--calculate-indentation) )) ``` For Javascript: ``` (setq js-indent-align-list-continuation nil) ``` For Ruby I tried to monkey-patch the Ruby mode, but by default it uses `smie-indent-line`. Which in its turn might be used not only by the Ruby mode. And I didn't see a better way than to copy the `smie-indent-keyword` and fix a thing or two. But I'm far from understanding how it works, so I decided to go with the Enhanced Ruby Mode. After installation, you need to add: ``` (require 'ruby-mode) ;; https://emacs.stackexchange.com/questions/59782/autoloaded-variable-overrides-the-one-from-the-init-file#comment93779_59782 (setq auto-mode-alist (mapcar (lambda (x) (if (eq (cdr x) 'ruby-mode) (cons (car x) 'enh-ruby-mode) x)) auto-mode-alist)) (setq interpreter-mode-alist (mapcar (lambda (x) (if (eq (cdr x) 'ruby-mode) (cons (car x) 'enh-ruby-mode) x)) interpreter-mode-alist)) ``` Then to fix the indentation: ``` (setq enh-ruby-deep-indent-paren nil) ``` --- Tags: python, indentation, javascript, ruby-mode, ruby ---
thread-59532
https://emacs.stackexchange.com/questions/59532
Stringify a list to a string without truncation
2020-07-08T22:44:06.117
# Question Title: Stringify a list to a string without truncation I am working on improving the org babel racket mode and am running into issues with inserting longer vars Whether I do ``` (format "%S" '((2 0 0 4 2 0 0 3 0 0 4 0 0 7))) ``` or ``` (with-output-to-string (princ '((2 0 0 4 2 0 0 3 0 0 4 0 0 7)))) ``` I always get back the truncated ``` ((2 0 0 4 2 0 0 3 0 0 ...)) ``` not the full object in a string. How do I stringify the list without truncation? # Answer I suspect that the full value is returned, but you are being fooled by printing that elides part of the returned value. Try `C-h v print-length`, to see how to control such elision. If you don't believe that the returned value is correct (full length), apply function `length` to it, to see (to the list's car, in this case, or to the final string). > 1 votes --- Tags: string ---
thread-59537
https://emacs.stackexchange.com/questions/59537
Color words based on gramatical categories?
2020-07-09T01:34:23.317
# Question Title: Color words based on gramatical categories? Does there exist any package to color words based on grammatical class? (Noun, verb, adjective... etc). Something like `rainbow-mode` for grammar instead of colors. # Answer I'm sure you could cobble one together; there has been software that analyses the structure of sentences for decades. I wouldn't set your expectations too high though. Consider the following sentences: ``` Time flies like an arrow. Fruit flies like a banana. ``` Unless the software understands context the way a human would, it will be guessing most of the time. > 1 votes --- Tags: syntax-highlighting, writing ---
thread-59517
https://emacs.stackexchange.com/questions/59517
Org-plot with gnuplot (searching for program: No such file or direcotry, aspell)
2020-07-08T07:11:27.623
# Question Title: Org-plot with gnuplot (searching for program: No such file or direcotry, aspell) I am trying to plot simple examples in org-mode by using gnuplot. But it keeps telling me `"Searching for program: No such file or directory, aspell"`. I installed gnuplot both to on emacs and on system wide. Also installed gnuplot-mode in emacs. The table that I am trying to plot is: ``` #+PLOT: title:"Grades in Physics and Mathematics" ind:2 deps:(3 4) type:2d with:histograms set:"yrange [0:]" set:"xlabel 'Student'" set:"ylabel 'grades'" set:"output './img/gnuplot-grades.png'" set:"terminal png size 600,500" |---+--------+-------------+---------| | | Grades | Mathematics | Physics | |---+--------+-------------+---------| | # | Ben | 9.2 | 9.9 | | # | Tom | 6.7 | 7.7 | | # | Tim | 7.5 | 6.7 | | # | Dean | 8.0 | 7.0 | ``` I am using org-mode 9.3.7 which came by default. Is the issue related with emacs/org-mode version? B.R. # Answer Check that: * `gnuplot` is installed: just run it from the shell to make sure it's present and if so, just exit out of it (I have version 5 and that worked). * gnuplot-mode is installed; checking e.g. with `C-h f gnuplot-mode RET` should be enough. * make sure that there is a subdirectory `img` under the directory where the Org mode file lives: the options specify `set:"output './img/gnuplot-grades.png'"` but if the `img` directory does not exist, this will fail. With all conditions satisfied, I was able to produce the output file. If you still have trouble, check your `*Messages*` buffer for messages like this: ``` gnuplot-mode 0.6.0 (gnuplot 5.0) -- report bugs with "C-c C-u" ``` which shows that both `gnuplot-mode` and `gnuplot` are installed and what the versions are (my `gnuplot mode` is old: 0.7.0 is available). If you see such messages, then there should also be a buffer named`*gnuplot*` that `gnuplot-mode` creates and uses to send commands to the underlying `gnuplot` process. Switch to that buffer and see if any commands failed and what the errors are. Good luck! > 1 votes --- Tags: org-mode, org-table ---
thread-59480
https://emacs.stackexchange.com/questions/59480
Adding a new code formatter
2020-07-06T11:11:53.123
# Question Title: Adding a new code formatter How can I add a custom formatter that will be picked up by doom-emacs' `format` (`(format +onsave)`) module? I want to run the `erlfmt` program on save when editing Erlang files, but I'm not sure how I should configure that. Doom seems to be using https://github.com/lassik/emacs-format-all-the-code under the hood, so I tried adding the following to `config.el`: ``` (define-format-all-formatter erlfm (:executable "erlfm") (:install (macos "brew install erlfmt")) (:languages "Erlang" (:format (format-all--buffer-easy executable "-"))) ``` However, this just gives me the error “Don't know how to format erlang-mode code” when I run `format-all-buffer`. (I get the same error if I change to `:languages "erlang-mode"`.) # Answer > 2 votes In the end, putting the following in `config.el` worked: ``` (set-formatter! 'erlfmt "erlfmt -" :modes '(erlang-mode)) ``` --- Tags: doom, erlang-mode ---
thread-59534
https://emacs.stackexchange.com/questions/59534
Use template in the middle of a sentence
2020-07-08T23:08:52.797
# Question Title: Use template in the middle of a sentence `tempo-define-template` allows defining a custom template, and one can use it with `<key` \+ TAB; however, this works only in the beginning of the line, it there a way to do that in middle of a sentence? # Answer I think the right tool to use in this case is `yasnippet`: https://joaotavora.github.io/yasnippet/ > 1 votes --- Tags: org-mode ---
thread-59544
https://emacs.stackexchange.com/questions/59544
Is there a way to generally search package or language documentation within emacs?
2020-07-09T10:09:04.703
# Question Title: Is there a way to generally search package or language documentation within emacs? In this case, I'm most interested in Rust's documentation, which lives at doc.rust-lang.org/std. `eww` is incompatible with JS, so the documentation doesn't play nice, thus my general current soln is to just pop over to a browser. I'd be interested to know what other people do for documentation reading. # Answer > 1 votes There are solutions for specific languages (such as `eldoc-mode`), but since every language's documentation is in a different format and style, there is no general solution. For Rust use `lsp-mode` with either rls or rust-analyzer. --- Tags: documentation, web-browser, rust ---
thread-59423
https://emacs.stackexchange.com/questions/59423
Can I make projectile open a default file when I switch to a project?
2020-07-03T11:22:12.713
# Question Title: Can I make projectile open a default file when I switch to a project? I'm using helm-projectile in spacemacs. `SPC``p``p` runs `helm-projectile-switch-project`, which gives me a helm completion buffer for projectile projects. When I choose a project and hit enter, I then get a completion buffer to choose which file I want to open in that project. I'd like to skip that second step, and just have a default file associated with a project that always opens first when I open that project. Is that possible? # Answer There is no official support for that in projectile (I think) but, you can use dir-local-variables and a little bit of hacking code like this: ``` (defun open-local-file-projectile (directory) "Helm action function, open projectile file within DIRECTORY specify by the keyword projectile-default-file define in `dir-locals-file'" (let ((default-file (f-join directory (nth 1 (car (-tree-map (lambda (node) (when (eq (car node) 'projectile-default-file) (format "%s" (cdr node)))) (dir-locals-get-class-variables (dir-locals-read-from-dir directory)))))))) (if (f-exists? default-file) (find-file default-file) (message "The file %s doesn't exist in the select project" default-file) ) ) ) (add-to-list 'helm-source-projectile-projects-actions '("Open default file" . open-local-file-projectile) t) ``` This code search for the file defined in dir-locals-file (by default ".dir-locals.el") and search for the key: projectile-default-file, that should be the file route, without the projectile root, then we concat the path of the project root with the default-file relative route, and check if the default-file exist, if it exist, we open it as desired. We can trigger the "Open default file" action by pressing the tab key in the helm menu. This code requires the libraries dash and to work. Feel free to ask any question about this messy code, good luck! > 1 votes --- Tags: spacemacs, projectile, helm-projectile ---
thread-59545
https://emacs.stackexchange.com/questions/59545
Exported org file to pdf with content out of page
2020-07-09T10:35:32.590
# Question Title: Exported org file to pdf with content out of page I'm writing a document with some long strings on it, then I export the org file to pdf with the classic `C-c C-e l p` . Then when I check the document, the long string are out of the page. How can I fix this? My code is: ``` *** Setting up the environment setup to build The code must be compiled in a docker container, this docker container can be generated from the image described in the file _Dockerfile_ which can be found in the repository thisis@a-very-long-line-which-will-be.at.doc/with/a/commit/that/will/not/gonna/appear/where/is/supposed at commit a59590ee2c2bc02d5e71b0a944d927e181d93aeb ``` As you can see the document run off of document. This happens in several places with large words, what must I do to prevent this? # Answer > 1 votes This is a LaTeX problem and has to be solved at that level. Org mode delegates all the formatting to it for PDF output. There are many tips and tricks that can be used to get LaTeX to do a better job of line breaking, but the most important rule is to not give it long things that it cannot break - and if you have to, you have to help it to decide where to break the line. For this particular case, the culprit is the long URL of the repo: you can deal with that problem by using the `\url` macro, like this: ``` *** Setting up the environment setup to build The code must be compiled in a docker container, this docker container can be generated from the image described in the file _Dockerfile_ which can be found in the repository \url{thisis@a-very-long-line-which-will-be.at.doc/with/a/commit/that/will/not/gonna/appear/where/is/supposed} at commit a59590ee2c2bc02d5e71b0a944d927e181d93aeb. ``` which will produce In general, these problems are usually resolved by small tweaks in the input (adding hyphenation points to long words, changing the text slightly by choosing different words or changing the word order), by small modifications to allow LaTeX to find better breaking points (e.g. by changing the `\tolerance` value), by using the appropriate construct (e.g. the above use of `\url`) or by other ad-hoc methods (of which there are many). Search for `overfull box` in the TeX SE site for many examples. --- Tags: org-mode, org-export, exporting ---
thread-59560
https://emacs.stackexchange.com/questions/59560
How to stop Emacs from using LaTeX mode key bindings for `*.tex` files?
2020-07-09T23:27:14.603
# Question Title: How to stop Emacs from using LaTeX mode key bindings for `*.tex` files? It seems that Emacs tries to autodetect the type of file and changes some of its behaviors accordingly. I don't want any of this behavior. I just want Emacs to treat every file as if it were some generic text file. The thing that is currently annoying me is that when Emacs thinks I'm editing a LaTeX file, it won't let me type the `"` character without changing it to tex-style quotes. Is there a line I can put in my `.emacs` file to simply turn off all of this kind of stuff completely? From googling, it looks like this is called an "input method," but the only lisp code I can find doesn't seem like it would do what I want. For example, there is a function called `set-input-mode`, but it doesn't seem to allow control over this. There are also things like `toggle-input-method` and `(setq-default default-input-method ...`, but those don't seem like what I'm looking for either. # Answer After some more googling, I think I found the answer to my own question. The following code works: ``` (setq auto-mode-alist ()) ``` The list `auto-mode-alist` seems to be a hash that has file extensions as keys and major modes as values: https://www.emacswiki.org/emacs/AutoModeAlist > 2 votes --- Tags: latex, debugging, auto-mode-alist ---
thread-59550
https://emacs.stackexchange.com/questions/59550
Heading of higher level in agenda view?
2020-07-09T14:21:56.410
# Question Title: Heading of higher level in agenda view? I often collect several meetings under one heading in my org files, e.g.: ``` * Interdisciplinary studies ** Paracelsus reading group *** Meeting <2020-01-07> ... *** Meeting <2020-01-14> ... *** Meeting <2020-01-21> ``` In my agenda view, each such meeting will show up just with its headline `Meeting`. It would be much more informative if the heading of the next higher level (`Paracelsus reading group`) were also displayed. Is there any way to achieve this? Or should I rather structure my org files differently? # Answer > 1 votes You can add `breadcrumbs` to org-agenda-prefix-format: ``` (setq org-agenda-prefix-format '((agenda . " %i %-12:c%?-12t% s %b") (todo . " %i %-12:c") (tags . " %i %-12:c") (search . " %i %-12:c"))) ``` That `%b` in the agenda entry adds higher level info: ``` foo: 21 d. ago: Foo->Type 1->TODO Item 1 :type1:: Org: Sched. 3x: Bills->Misc->TODO Water ``` Do `C-h v org-agenda-prefix-format RET` for all the place-holders you can use: ``` Format specifications for the prefix of items in the agenda views. An alist with one entry per agenda type. The keys of the sublists are ‘agenda’, ‘todo’, ‘search’ and ‘tags’. The values are format strings. This format works similar to a printf format, with the following meaning: %c the category of the item, "Diary" for entries from the diary, or as given by the CATEGORY keyword or derived from the file name %e the effort required by the item %l the level of the item (insert X space(s) if item is of level X) %i the icon category of the item, see ‘org-agenda-category-icon-alist’ %T the last tag of the item (ignore inherited tags, which come first) %t the HH:MM time-of-day specification if one applies to the entry %s Scheduling/Deadline information, a short string %b show breadcrumbs, i.e., the names of the higher levels %(expression) Eval EXPRESSION and replace the control string by the result ``` # Answer > 2 votes Not as complete a solution as https://emacs.stackexchange.com/a/59556/21368, but if you move the point to an item on the agenda, the full list of headings is displayed in the mini-buffer. So in your case: `foo.org/Interdisciplinary studies/Paracelsus reading group/Meeting <2020-01-07>` --- Tags: org-agenda ---
thread-3302
https://emacs.stackexchange.com/questions/3302
live refresh of inline images with org-display-inline-images
2014-11-08T18:04:10.123
# Question Title: live refresh of inline images with org-display-inline-images Recently I've noticed the function I had been using to do refresh had stopped working and I had to change to a simpler call. I used to have: ``` (defun k/org-babel-refresh-inline-images () (org-display-inline-images nil t)) (add-hook 'org-babel-after-execute-hook 'k/org-babel-refresh-inline-images) ``` which had been recommended on the mailing list. However, that stopped working and I've found: ``` (add-hook 'org-babel-after-execute-hook 'org-display-inline-images) ``` to work, but I'm not sure why the original stopped working. Presumably, the original version might be more efficient if it worked. Why doesn't it, and why was the original preferred? # Answer > 9 votes This works for me on Emacs 24.4.1 with OS X using the included `org-mode` (note the use of redisplay vs. display). ``` (defun shk-fix-inline-images () (when org-inline-image-overlays (org-redisplay-inline-images))) (after-loading 'org (add-hook 'org-babel-after-execute-hook 'shk-fix-inline-images)) ``` # Answer > 2 votes For me, only the snippet below worked: ``` ;; Always redisplay inline images after executing SRC block (eval-after-load 'org (add-hook 'org-babel-after-execute-hook 'org-redisplay-inline-images)) ``` For details, in my case, `org-inline-image-overlays` was behaving in the opposite manner as it should in the "when" statement: it was being set to a value only when an overlay was being shown. Maybe due to changes in later versions? --- Tags: org-mode, org-babel ---
thread-38780
https://emacs.stackexchange.com/questions/38780
Cua-mode and keyboard macros
2018-02-12T09:34:52.020
# Question Title: Cua-mode and keyboard macros I have just started using emacs, so I decided to use cua-mode. I got this weird problem when I'm using macros and copy/cut (`C-c`/ `C-x`). let's assume this simple macro for example: `<F3> C-S-right C-c C-v <F4>` When I execute it I'm getting this message: `After 0 kbd macro iterations: keyboard macro terminated by a command ringing the bell` After some digging I found this at the recording (`C-x C-k C-e`): Macro: ``` <C-S-right> C-c C-c <============== C-c twice!!!! <timeout> C-v ;; yank ``` I think the problem is the second `C-c`. When I remove the second `C-c` the macro works as expected. More info `from C-h l` (after making the macro): ``` <f3> [kmacro-start-macro-or-insert-counter] <C-S-right> [right-word] C-c [cua--prefix-override-handler] C-c <timeout> [cua-copy-region] C-v [cua-paste] <f4> [kmacro-end-or-call-macro] ``` I'm guessing that I'm not the first one who uses cua-mode and macro, but I didn't found anything on it :(. How do I fix this problem? Stop using `cua-mode` is not an option of me right now. # Answer > 2 votes I wrote some lisp code to fix this. I just added this to my init.el ``` ;; fix problem of cua-mode and macro ;; fix function (defun cua-macro-fix() (kmacro-edit-macro) ;; fix the C-c C-c (goto-char (point-min)) (forward-line 7) (while (search-forward "C-c C-c" nil t) (replace-match "C-c")) ;; fix the C-x C-x (goto-char (point-min)) (forward-line 7) (while (search-forward "C-x C-x" nil t) (replace-match "C-x")) (edmacro-finish-edit)) ;;bind the two functions (defun end-kbd-macro-with-fix() (interactive) (end-kbd-macro) (cua-macro-fix)) ;;bind the function to f4 (global-set-key (kbd "<f4>") 'end-kbd-macro-with-fix) ``` hope it will help someone. # Answer > 0 votes Another simple solution is to use Ctrl+Ins/Shift-Delete instead of Ctrl+C/Ctrl-X when recording the macro. --- Tags: key-bindings, keyboard-macros, cua-mode ---
thread-59569
https://emacs.stackexchange.com/questions/59569
"not in compilation buffer" error using compilation-next-error in elisp function
2020-07-10T18:38:39.927
# Question Title: "not in compilation buffer" error using compilation-next-error in elisp function I am getting an elisp error that fails at `lisp/progmodes/compile.el` within `compilation-next-error` function that reads `"Not in a compilation buffer"`. The elisp function I am writing attempts to automatically jump to the first error within the compilation buffer, then copies the error and writes it to file. Here is the function. I've tried a few things so I've left the tried stuff commented while the function itself will produce the error. Perhaps the error is an obvious one for trained eyes. ``` (defun write-first-error-to-file() "function copies first error in compilation buffer and writes it to specified file" (interactive) ;;; (select-window (previous-window)) ;;; (switch-to-buffer "*compilation*") ;;; (goto-char (compilation-next-error)) (let ((display-buffer-overriding-action '(display-buffer-same-window))) (compilation-next-error)) ;;; (set-mark-command nil) ;;; (goto-char (compilation-next-error)) ;;; (setq deactivate-mark nil) (kill-ring-save (region-beginning) (region-end)) (write-region (region-beginning) (region-end) "~/copybuffer.txt")) ``` The function attempts to do the following: 1. Declares the function as an interactive form 2. Display the compilation buffer and within it go to the next error within compilation buffer. Note, it should be the first error if this is the first command executed. This is where I am getting the aforementioned error. 3. Commented, set mark to select region 4. Commented, Advance cursor to next compilation-next-error 5. Commented, deactivate mark. At this point, the region should have been selected programmatically perhaps?? 6. Save region to kill-ring 7. Write region to file! :D As you can see there are quite a few issues with this function, perhaps someone can see what I am missing. Thanks for any help anyone can provide. For reference, the above function produces the following error with strange error output. You can see the "Not in compilation buffer" within the error output. ``` ×H^N%W\204s^A^N&\203þ^A^M× ÌH^K>\204ô^AÈÍÎÏ#\210 ÐH8\211^U=\204s^A^N'\203^Y^BÞ ÌH^K>\204^R^BÈÍÎÏ#\210 ÐH\233\204s^A^N(\2034^B ÌH^K>\204,^BÈÍÎÏ#\210 ÐH^L=\204s^A^N\"T\211^V\"\202u^A) b\210 \206J^BÈá^N$\"+\207" [buffer pt msg cl-struct-compilation--message-tags loc last local-variable-p compilation-locs error "Not in a compila\ tion buffer" ...] 7 ("/usr/share/emacs/24.5/lisp/progmodes/compile.elc" . 69981) "p"], 0 ``` # Answer > 2 votes Try the following: ``` (defun write-first-error-to-file() "function copies first error in compilation buffer and writes it to specified file" (interactive) (let (beg) (set-buffer "*compilation*") (goto-char (point-min)) (compilation-next-error 1) (setq beg (point)) (compilation-next-error 1) (write-region beg (point) "~/copybuffer.txt"))) ``` Execute it with `M-x write-first-error-to-file`. In words: * switch to the compilation buffer * set point to the beginning of the buffer * go to the next error * remember the position of point in `beg` * go to the next error * write the region between `beg` and the current position of point to a file. Note that you *have to* switch to the compilation buffer: otherwise `compilation-next-error` will fail with exactly the error message you got. Note also that `compilation-next-error` takes a mandatory argument, a number telling it how many errors to move forwards (or backwards if negative). It also does not return anything useful: you seem to think that it returns the position of `point` in the buffer, but that's not true. Do `C-h f compilation-next-error RET` to get information about the function. Finally, note that all you need to know to define a region are its beginning and its end. That means that you do not have to set a mark in your function, which is a *Good Thing*(TM): marks are generally used by *users* for navigation and having functions munge them can be very confusing. See the doc for the functions `set-mark-command` and `set-mark` (using `C-h v <func> RET` as above) for some additional guidance and warnings about setting marks. --- Tags: terminal-emacs, compilation-mode ---
thread-59562
https://emacs.stackexchange.com/questions/59562
How can I access Mac menu bar help via keyboard?
2020-07-10T01:09:48.883
# Question Title: How can I access Mac menu bar help via keyboard? I'd like to be able to search Emacs's Mac menu bar entries using the keyboard, as you normally do in most other Mac applications using `s-?` (this answer suggest that it should be possible?). I've unbound `s-?` from calling `info`, but that has not helped in allowing me to access the help search via the keyboard. # Answer I don't believe there is a way to access the menu search feature from Emacs directly, but there is a workaround if you are using the Mitsuharu version of Mac Emacs: use `M-x` `menu-bar-open`, then type the standard key `Cmd-?` to open the menu search. You might try binding `s-?` to `menu-bar-open` so that you can get to the search by pressing it twice. > 1 votes --- Tags: key-bindings, osx, menu-bar, mac ---
thread-59564
https://emacs.stackexchange.com/questions/59564
Return all time today spent on tasks that include a particular tag
2020-07-10T05:29:12.903
# Question Title: Return all time today spent on tasks that include a particular tag As the title. I have come *so close* but can't get past this last hurdle. The below returns all time today that has been spent on headings where the tag is 'billable'. However it fails when there are also other tags. I've tried to replace string= with a test for the string containing billable, but for some reason it fails. You can see some of my attempts commented out below. Tia. ``` (defun my-broken-function () (interactive) (let ((files (org-agenda-files)) (total 0)) (org-agenda-prepare-buffers files) (dolist (file files) (with-current-buffer (find-buffer-visiting file) (setq total (+ total (org-clock-sum-today (lambda () (string= (org-entry-get (point) "TAGS") ":billable:") ;; (string-match ":billable:" (org-entry-get (point) "TAGS")) ;; (not (not (string-match-p (regexp-quote "billable") (org-entry-get (point) "TAGS")))) )))))) (message (number-to-string total)) )) ``` # Answer > 1 votes As per NickD's comment: "org-entry-get may return nil which is not a string, so it will cause any string functions to barf. Try replacing any such call with (or (org-entry-get (point) "TAGS") ""), effectively replacing the nil with the empty string." What worked is replacing the ninth line with: ``` (string-match ":billable:" (or (org-entry-get (point) "TAGS") "")) ``` --- Tags: org-mode ---
thread-59575
https://emacs.stackexchange.com/questions/59575
Continue comment while editing lisp and when hitting enter
2020-07-11T11:02:51.423
# Question Title: Continue comment while editing lisp and when hitting enter If I'm writing a comment ``` ;; this is a comment ;; this is its second line ``` And I hit enter, I get a new line like this: ``` ;; this is a comment ;; this is its second line ``` Instead of getting a new line with comments continued, like this: ``` ;; this is a comment ;; this is its second line ;; ``` How do I get the latter behavior? I'm editing clojure if that matters # Answer > 2 votes The standard key for this behaviour is `M-j`. It is bound to `indent-new-comment-line` by default but, depending on the buffer, may be bound to some other mode-specific analog. These commands take care of indentation, and also comment continuation when you're inside one. In programming modes I make `RET` do whatever `M-j` does: ``` (defun my-coding-config () "Custom behaviours for most programming modes." ;; Make RET maintain indentation and comments. (local-set-key (kbd "RET") (key-binding (kbd "M-j"))) (local-set-key (kbd "<S-return>") 'newline)) (mapc (lambda (language-mode-hook) (add-hook language-mode-hook 'my-coding-config)) '(prog-mode-hook ;; plus anything not derived from prog-mode: inferior-emacs-lisp-mode-hook css-mode-hook python-mode-hook)) (add-hook 'js-mode-hook 'my-js-mode-hook) (defun my-js-mode-hook () "Custom behaviours for `js-mode'." ;; Fix M-j behaviour in block comments in js-mode (setq-local comment-multi-line t) (local-set-key [remap indent-new-comment-line] 'c-indent-new-comment-line)) ``` --- Tags: comment, newlines ---
thread-59546
https://emacs.stackexchange.com/questions/59546
Getting rid of plain text timestamp entry in agenda export
2020-07-09T12:23:44.240
# Question Title: Getting rid of plain text timestamp entry in agenda export I am trying to create a weekly agenda that I can print out and use without having to be at the computer To best explain my problem I will use some screenshots This is the normal org file that I will export as an agenda These are the settings I have in for exporting my agenda ``` (setq org-agenda-exporter-settings '((ps-number-of-columns 1) (ps-landscape-mode nil) (org-agenda-add-entry-text-maxlines 5) )) (setq org-agenda-prefix-format "[ ] %t ") (setq org-agenda-entry-text-mode t) (setq org-agenda-entry-text-maxlines 5) (setq org-agenda-skip-additional-timestamps-same-entry nil) (setq org-agenda-use-time-grid nil) (setq org-agenda-with-colors t) (setq org-agenda-remove-tags nil) (setq ps-print-header nil) ``` And a screen shot below shows the result of the export (as a pdf file) The problem here is that I am interested in displaying extra information under each headline (for example ring exercise has a sub list of different exercises to do) however when I do this I am forced to print out the whole time stamp and its syntax as well. But I don't need this since I already formatted the prefix to display the time. This time stamp also takes up to much space. I was wondering if there was any way that I can get rid of just the timestamp line but preserve the rest of the text under each headline? I tried searching for ways to do this but to avail. I just continually found ways to edit, filter and organize specific agenda headings but not edit the info underneath. If there is no function or variable that I can use, how can I structure my org file to avoid this problem? # Answer Just to make it clear, this is not a problem with exporting, but of showing entry text in the agenda. Turns out there is a variable to exclude text that matches a list of regular expressions. You can exclude anything that looks like an active timestamp (there is also the variable `org-element--timestamp-regexp` but that did not work in my tests): ``` (setq org-agenda-entry-text-exclude-regexps '("<[0-9]\\{4\\}-[0-9]\\{2\\}-[0-9]\\{2\\}[^>]*>")) ``` That does not exclude the whole line, so you will still have an indicator showing an empty line, like this ``` Day-agenda (W30): 2020-07-24 Fri _________________________________________________________________ [ ] 7:00- 8:30 TODO Ring exercise > > - [ ] angled pullups (for back) > - [ ] angled pushups (for chest) > - [ ] squats (for legs) > - [ ] lunges (for legs) [ ] 12:00-13:00 TODO Check weight and record it on calendar ``` To get rid of the now-empty lines, you can add a finalizer hook ``` (defun gg/entry-text-nix-empty-line () "Delete empty entry text lines in agenda" (goto-char (point-min)) (replace-regexp (concat "^ *" org-agenda-entry-text-leaders " *\n") "")) (add-hook 'org-agenda-finalize-hook 'gg/entry-text-nix-empty-line) ``` > 2 votes --- Tags: org-mode, org-agenda, formatting ---
thread-59583
https://emacs.stackexchange.com/questions/59583
Does anyone know of a quick method to get hexadecimal line numbers in emacs?
2020-07-11T23:04:02.250
# Question Title: Does anyone know of a quick method to get hexadecimal line numbers in emacs? Does anyone know of a quick method to get hexadecimal line numbers in emacs? I am using linum for line numbers. I suppose I could hack it, but just thought to ask first. # Answer Linum mode provides the `linum-format` customizable variable that allows you to format how you want your line numbers to appear. Set this variable to have the value `"%x"` to get hexadecimal line numbers. This can be done either through the built-in customization process or by running `(setq linum-format "%x")`. **Edit:** *You may only want to have hexadecimal line numbers for certain buffers and decimal numbers for the rest. In that case you will want to make a buffer local version of that variable (`(make-variable-buffer-local 'linum-format)`) and then set `linum-format` to be `"%x"` for each buffer you want to display hexadecimal numbers.* **Edit 2:** *I'm not sure why I didn't include this before, but here's a function that makes sure linum is turned on, creates the buffer local variable and sets it to display hexadecimal line numbers (and a corresponding function to delete this buffer local variable):* ``` (defun my-display-hexadecimal-line-numbers () (interactive) (linum-mode t) (make-variable-buffer-local 'linum-format) (setq linum-format "%x")) (defun my-return-to-default-linum () (interactive) (kill-local-variable 'linum-format)) ``` As an aside, if you are using Emacs 26 or later, you may want to use the built-in `display-line-numbers-mode` instead of linum. This built-in mode is much faster and doesn't suffer the lags that sometimes occur when using linum. The downside is that I'm not sure if there is as easy of answer to this question when using `display-line-numbers-mode`. > 6 votes --- Tags: linum-mode, numbers ---
thread-59462
https://emacs.stackexchange.com/questions/59462
Can I set MANPAGER to open a man page with emacs?
2020-07-05T11:44:31.260
# Question Title: Can I set MANPAGER to open a man page with emacs? I am able to use `man` inside emacs. `M-x man , <ln> , [enter]`. **=\>** From the shell can I open man pages from the shell? For examlpe doing `$ man ln` can open the man page inside the `emacs`? --- ``` $ export MANPAGER='emacsclient -t -q' $ man ln ❯ # opens the `*scratch*` file ``` # Answer Define a shell function that uses the first argument to `man` as a parameter ``` macsman() { emacsclient -c -e "(man \"$1\")" } alias man=macsman ``` You could invoke the function without the alias (e.g. `macman ls`), but it may be useful to set the alias for specific shells. One note: You may want to assure your Man page is visible in the Emacs session as soon as it is invoked. Check the settings of the `Man-notify-method` variable to achieve that. Either set it using `customize-variable`, or set it explicitly as part of the function, i.e. ``` emacsclient -c -e "(let ((Man-notify-method 'bully)) (man \"$1\"))" ``` (Hat tip to @phils) > 4 votes --- Tags: man ---
thread-59589
https://emacs.stackexchange.com/questions/59589
compilation sentinel: symbol's value as variable is void for quote, >, <, =, etc
2020-07-12T02:31:40.590
# Question Title: compilation sentinel: symbol's value as variable is void for quote, >, <, =, etc I'm working on a script that can compile multiple directories and then provide the first error to a file. Currently, I am tackling the issue of running make in multiple directories portion. I am making use of the compilation-finish-function hook in order to continue the compilation in the next directory. However, in this function, I get the following error: `error in process sentinel: Symbol's value as variable is void: >` The way the following script works is as follows: * Currently (and unfortunately) using a globally defined DIRS symbol that stores the list of directories * my-compilation-finish-function operates on the DIRS list, popping the first element and setting DIRS to rest of the list * compile-in-dir-helper runs the make command on the new directory * compile-in-dir runs is the only interactive command and relies on the compilation hook to finish compilation in the rest of the directories I need some kind of conditional in the hook, otherwise an infinite loop condition can occur with an empty directory variable is passed to the helper function indefinitely. I'm not sure why the sentinel is complaining of the condition function, however. ``` (setq DIRS '( "dir1" "dir2" "dir3" )) (defun my-compilation-finish-function (buffer desc) ;;; (message "Buffer %s: %s" buffer desc) ;;; (if (< (length 'DIRS) 0) (cond (> (length DIRS) 0) ( ;;; (cond '(eql 1 0) ( (setq directory (car DIRS)) (compile-in-dir-helper directory) (setq DIRS (cdr DIRS))))) (add-hook 'compilation-finish-functions 'my-compilation-finish-function) (defun compile-in-dir-helper (dir) (setq make_cmd (concatenate 'string "make -j1 -C" dir)) (compile make_cmd)) (defun compile-in-dir () (interactive) (compile "make -j1 -C ~/dir0")) ``` # Answer You're missing parentheses around the interior of your `cond` expression. You also should not have the parentheses around the body forms of the condition (although this part is not what is causing your error). When fixed, your code should read: ``` (defun my-compilation-finish-function (buffer desc) (message "Buffer %s: %s" buffer desc) (cond ((> (length DIRS) 0) (setq directory (car DIRS)) (compile-in-dir-helper directory) (setq DIRS (cdr DIRS))))) ``` This may just be a typo on your part, but in case you'd like an explanation I've included one below. (If you were using `paredit mode` or `lispy mode` while writing your code, this may have been caused by an accidental barf and it can be fixed with a slurp). **Explanation:** As the Emacs manual says, each clause in `cond` has the form `(condition body-forms...)` where `condition` is the value that is evaluated to determine whether the `body-forms` will be evaluated. This means that when Emacs attempts to evaluate this `cond`, it tries to evaluate the leftmost expression in the list for its truthiness. Since that is the `>` symbol, Emacs tries to look it up as a variable. However, by default the `>` symbol is not defined as a variable, so an error is produced. By wrapping the entire expression in parentheses, the condition being evaluated will be `(> (length DIRS))` which is what you want. After making this change, the body of your conditional would still be wrapped in unnecessary parentheses and this would cause a different error. The body forms should not be in a list but should instead be their own terms in the conditional clause. Here's an example conditional clause with 3 body forms: ``` (t (+ 3 2) (setq my-fake-var 9) 99) ``` You may find the fact that Emacs thinks the `>` symbol is an invalid variable surprising, especially if you are used to Scheme or some other Lisp-1, since you know that `>` is bound as a function. However, in Emacs Lisp, functions and variables have different namespaces. Only the the `>` function is bound by default, not the variable. Seeing that Emacs is telling you that a symbol you are trying to use as a function is void as a variable is a good sign that you have made some kind of syntactical error in your code. > 3 votes --- Tags: terminal-emacs, elisp-macros, compilation, compilation-mode ---
thread-59591
https://emacs.stackexchange.com/questions/59591
How can I split a window so that the cursor ends up in the right / lower window?
2020-07-12T11:05:45.120
# Question Title: How can I split a window so that the cursor ends up in the right / lower window? The functions I have found for splitting windows are `(split-window-right)` and `(split-window-below)`. When these are evaluated the cursor ends up in the right window in the case of `(split-window-right)`or the upper window in the case of `(split-window-below)`. I want to have functions that split a window and puts the cursor in the right or lower window. I wrote the following myself, but it unfortunately does not move the cursor as I expected. Instead it just behaves as if `(split-window-right)` was called by itself. ``` (defun olav-split-window-left () (interactive) (split-window-right) (windmove-right)) ``` # Answer Try this: ``` (defun olav-split-window-left () (interactive) (select-window (split-window-right))) ``` > 4 votes --- Tags: window, window-splitting ---
thread-59578
https://emacs.stackexchange.com/questions/59578
How to turn off automatic indenting for Org files in a specific folder?
2020-07-11T15:45:32.977
# Question Title: How to turn off automatic indenting for Org files in a specific folder? I am using Doom Emacs. I like having indentation for most of my org files, but I have one folder where I want to have org files without indenting, to use for writing documents. I have already tested adding `#+STARTUP noindent`, and that works per file, but I'm trying to find a way to make it the default for the folder. I used `add-dir-local-variable`, to set `org-indent-mode` to `nil`, and I can see that was written to a `.dir_locals.el` in the folder I want to make the change for. But when I open an Org file it is still indented. If, after the file is open, I manually toggle `org-indent-mode`, I can turn the indenting on and off. Seems like maybe a matter of the sequence or I'm going about this the wrong way. If it helps, here is the `.dir_locals.el` ``` ;;; Directory Local Variables ;;; For more information see (info "(emacs) Directory Variables") ((org-mode (org-indent-mode nil))) ``` # Answer > 5 votes `C-h v org-indent-mode RET` says (emphasis added): > If called interactively, enable Org-Indent mode if ARG is positive, and disable it if ARG is zero or negative. If called from Lisp, **also enable the mode if ARG is omitted or nil**, and toggle it if ARG is ‘toggle’; disable the mode otherwise. You probably want to say (edited as per the OP's answer to avoid misleading future visitors): ``` ((org-mode . ((eval . (org-indent-mode -1))))) ``` in your `.dir-locals.el` file. # Answer > 3 votes Thank you NickD for your help, it got me to the right answer! Doing exactly what is listed above worked when added to the Doom Emacs `config.el` but not in the `.dir-locals.el`. To make it work as a directory variable, adding an `eval` seems to have done the trick. Here is my updated `.dir-locals.el'` ``` ;;; Directory Local Variables ;;; For more information see (info "(emacs) Directory Variables") ((org-mode . ((eval . (org-indent-mode -1))))) ``` --- Tags: org-mode, indentation ---
thread-59598
https://emacs.stackexchange.com/questions/59598
Re-enable flychecksyntax checker after reported too many errors
2020-07-12T20:46:05.653
# Question Title: Re-enable flychecksyntax checker after reported too many errors I recently ran into this error from flycheck: ``` Warning (flycheck): Syntax checker csharp-omnisharp-codecheck reported too many errors (482) and is disabled. ``` I saw this: Warning (flycheck): Syntax checker javascript-eslint reported too many errors (494) and is disable \- which is great, but it doesn't answer the question "what do I do now?" I got to this point by removing a closing brace, and of course everything broke. I replaced the brace, but now the syntax checker is disabled, and it doesn't show any errors. So, how do I turn it back on? # Answer I think I stumbled on an answer: When I selected the same checker, a buffer opened, and it said "Flycheck Mode is enabled. Use C-u C-c ! x to enable disabled checkers." So: ``` C-u C-c ! x ``` Then enter the name of the checker. I hope someone has a simpler answer! > 1 votes --- Tags: flycheck ---
thread-27581
https://emacs.stackexchange.com/questions/27581
Why do setq and set quote act differently on let-bound variables with lexical scope?
2016-10-05T08:01:35.760
# Question Title: Why do setq and set quote act differently on let-bound variables with lexical scope? I had a bug in one of my extensions that eventually turned out to be caused by `set` not working as I expected: ``` ;; -*- lexical-binding: t -*- (let ((a nil)) (setq a t) (print a)) (let ((a nil)) (set 'a t) (print a)) ``` when run with `emacs -Q --batch -l temp.el` prints: ``` t nil ``` This seems very strange to me. I was under the impression that `(setq a b)` is shorthand for `(set 'a b)`. What's going on? # Answer This is documented behaviour. The (much improved) explanation in the Emacs 25.1 elisp manual is as follows: > Note that unlike dynamic variables which are tied to the symbol object itself, the relationship between lexical variables and symbols is only present in the interpreter (or compiler). Therefore, functions which take a symbol argument (like ‘symbol-value’, ‘boundp’, and ‘set’) can only retrieve or modify a variable’s dynamic binding (i.e., the contents of its symbol’s value cell). `C-h``i``g` `(elisp) Lexical Binding` > 17 votes # Answer BTW, one way to think about why it *can't* work is to remember that lexical scoping enjoys the so-called "α-renaming" property: variable names do not matter, and you (or the compiler) can trivially (i.e. without having to understand what the code does) rename a variable (as long as the new name doesn't collide with some other local variable) without changing the meaning of the code (and hence the result of evaluation). Now how could that work with code like: ``` (let ((a nil) (varname 'a)) (set varname t) (message "%s = %s" varname a)) ``` If you expect this to say `a = t`, then how could the compiler rename the variable to `fresh-a` and still get the same output? > 6 votes --- Tags: lexical-scoping, setq ---
thread-59366
https://emacs.stackexchange.com/questions/59366
Spacemacs gg=G replacing tabs with spaces in org-babel makefile block
2020-06-30T21:08:28.283
# Question Title: Spacemacs gg=G replacing tabs with spaces in org-babel makefile block I'm using Spacemacs, and my org-mode file contains an org-babel block of Makefile code, which I want to "tangle" so it becomes part of the source code while remaining in sync with the documentation. All of this is working, **except** when I auto-indent the org-mode file, the tabs inside my makefile source code block get replaced with spaces. Spaces aren't valid indentation in makefiles, but I may accidentally use `gg=G` at some point, so I would like to tell emacs to not replace those tab characters. This behavior persists when I set `org-src-preserve-indentation` to `t` in the file, so I don't know what else to do. I already found this but my question is about auto-indenting the org-mode file itself, not exporting to another format. ``` # -*- org-src-preserve-indentation: t -*- * some header ** another header #+begin_src makefile :tangle src/Makefile :mkdirp yes :exports code all: people main.o: main.c gcc -g -c -o main.o main.c linked_list.o: linked_list.c gcc -g -c -o linked_list.o linked_list.c clean: rm -f people *.o people: main.o linked_list.o gcc -g -o people linked_list.o main.o test: people ./people #+end_src ``` # Answer Based on suggestions from the spacemacs issue pages \[,\], I arrived at the following configuration that so far solves my issue completely: ``` (setq org-src-fontify-natively t org-src-preserve-indentation t evil-indent-convert-tabs nil org-src-tab-acts-natively nil) ``` > 1 votes --- Tags: spacemacs, org-babel, indentation, literate-programming ---
thread-38472
https://emacs.stackexchange.com/questions/38472
Problem evaluating a `sage-shell-mode` function through `ob-sagemath`
2018-01-30T17:22:11.250
# Question Title: Problem evaluating a `sage-shell-mode` function through `ob-sagemath` I'm trying to use `sage-math` within an `org-mode` file. So far I've been able to configure the `sage-shell-mode` package (I'm impressed that `sagemath` can be installed in Debian using the package manager), my configuration: ``` (setq sage-shell:sage-executable "/usr/bin/sage") (sage-shell:define-alias) ;; Turn on eldoc-mode (add-hook 'sage-shell-mode-hook #'eldoc-mode) (add-hook 'sage-shell:sage-mode-hook #'eldoc-mode) (setq sage-shell:use-prompt-toolkit t) (setq sage-shell:completion-function 'pcomplete) ``` Then, I installed `ob-sagemath` from the MELPA repository and followed the instructions from its github page. Notice that I've added a line requiring the package, that it's not in the instructions... but don't work either! ``` (require 'ob-sagemath) ;; Ob-sagemath supports only evaluating with a session. (setq org-babel-default-header-args:sage '((:session . t) (:results . "output"))) ;; C-c s for asynchronous evaluating (only for SageMath code blocks). (with-eval-after-load "org" (define-key org-mode-map (kbd "C-c s") 'ob-sagemath-execute-async)) ;; Do not confirm before evaluation (setq org-confirm-babel-evaluate nil) ;; Do not evaluate code blocks when exporting. (setq org-export-babel-evaluate nil) ;; Show images when opening a file. (setq org-startup-with-inline-images t) ;; Show images after evaluating code blocks. (add-hook 'org-babel-after-execute-hook 'org-display-inline-images) (eval-after-load "sage-shell-mode" '(sage-shell:define-keys sage-shell-mode-map "C-c C-i" 'helm-sage-complete "C-c C-h" 'helm-sage-describe-object-at-point "M-r" 'helm-sage-command-history "C-c o" 'helm-sage-output-history)) (setq sage-shell:input-history-cache-file "~/.emacs.d/.sage_shell_input_history") (add-hook 'sage-shell-after-prompt-hook #'sage-shell-view-mode) ``` Now, I open an `org-mode` file and try an example: ``` #+begin_src sage :exports both 2+2 #+end_src ``` and I get a comment in the `*Messages*` buffer > executing Sage code block... ob-sagemath--last-res-info: Invalid output: --------------------------------------------------------------------------- NameError Traceback (most recent call last) in () ----\> 1 \_emacs\_ob\_sagemath.read\_file\_and\_run\_cell("/tmp/sage\_shell\_mode7254uF0/sage\_shell\_mode\_temp.sage", filename=None, latex=False, latex\_formatter=None) > > NameError: name ’\_emacs\_ob\_sagemath’ is not defined --- ### Complementary info: From my `.emacs` ``` (org-babel-do-load-languages 'org-babel-load-languages '((C . t) (emacs-lisp . t) (fortran . t) (gnuplot . t) (ipython . t) (latex . t) (ledger . t) (python . t) (mathematica . t) (maxima . t) (octave . t) (org . t) (R . t) (shell . t) )) (setq org-confirm-babel-evaluate nil) ``` --- ## Questions: * What is happening? * How do I solve it? # Answer Probably it is not a problem for you anymore after 2 years, but I had exactly the same problem. I got it working now, and I think the reason was that in my .emacs I was configuring sage-shell-mode (in addition to ob-sagemath), but I didn't have it installed. Installing sage-shell-mode fixed it for me. > 0 votes --- Tags: org-mode, init-file, org-babel ---
thread-59608
https://emacs.stackexchange.com/questions/59608
How to change background of Org-mode's source code block only from the indentation of #+BEGIN_SRC?
2020-07-13T15:01:03.507
# Question Title: How to change background of Org-mode's source code block only from the indentation of #+BEGIN_SRC? In Org-mode, I wonder if the background color of the source code block can be changed only from the indentation of #+BEGIN\_SRC? Here is the current background in my Org-mode: Is it possible to change its background to something like this? Note that the background of the first few columns of the code environment is unchanged. # Answer > 1 votes There's no simple configuration option that you can change to do this; you would need to change the org-mode code. That said, you should be aware that the content of the code block includes the spaces at the beginning of the lines. --- Tags: org-mode ---
thread-51086
https://emacs.stackexchange.com/questions/51086
Can we get inline results with polymode for Rmd files?
2019-06-18T08:10:59.503
# Question Title: Can we get inline results with polymode for Rmd files? As a new Emacs user, I've recently learned how to use `polymode` to handle R code in org-mode. I'm happy with it, since I get the same features than those implemented for example in Rstudio for Rmd files (e.g., facilities to execute code chunks and visualize the results directly in the org file, display inline images, code completion in code chunks, etc.). Even if I prefer now working with org-babel than rmarkdown, I wonder if it is possible to get the same features for Rmd files with `polymode`. With my current settings, when working on an Rmd file, code completion works properly inside R chunks, and R chunks can be executed (i.e., sent to an inferior R process) by `C-c C-c`. Everything is okay for that. But I don't understand how to display/preview/visualize the results and plots produced by R chunks directly within the Rmd file, and I don't even know if it is possible. All the chunks are sent and executed in a separate R buffer, but it would be more convenient to have the results displayed just below the chunks, as with org-babel. All information is welcome :) # Answer > 2 votes Your R output will be put in the file(s) produced by running knitr on your .Rmd file. IMHO, it doesn't make sense to have it inserted in the .Rmd file itself since that's 'input' not 'output'. I don't work in org-mode (yet?), but my understanding is that when working in that mode, it's possible to have the graphics output displayed in an emacs window. See here for more details. I do wish this was possible with poly-r. I have considered trying to output my graphics as a PDF or PNG file, which can be displayed in an emacs' window with the file reloaded each time it changes. However, I haven't done it yet. Finally, I am curious to know what your poly-r settings are since I don't get command completion within my R chunks in my .Rmd files. I'd love to have that ability. --- Tags: ess, r, markdown-mode, polymode ---
thread-59619
https://emacs.stackexchange.com/questions/59619
icicles: Package yow is obsolete
2020-07-14T02:10:07.857
# Question Title: icicles: Package yow is obsolete `GNU Emacs 26.3` I updated all the packages and started to face with following error, I am not sure what is causing it, it wasn't happening before the update: ``` ./icicles/icicles-cmd1.el :512:(eval-when-compile (require 'yow nil t)) ;; (no error if not found) Debugger entered: nil (progn (debug)) (if (equal (car (last (split-string filename "[/\\]") 2)) "obsolete") (progn (debug))) debug-on-load-obsolete("/usr/share/emacs/26.3/lisp/obsolete/yow.elc") run-hook-with-args(debug-on-load-obsolete "/usr/share/emacs/26.3/lisp/obsolete/yow.elc") do-after-load-evaluation("/usr/share/emacs/26.3/lisp/obsolete/yow.elc") require(yow nil t) (progn (require (quote yow) nil t)) eval((progn (require (quote yow) nil t)) nil) #f(compiled-function (&rest body) "Like `progn', but evaluates the body at compile time if you're compiling.\nThus, the result of the body appears to the compiler as a quoted\nconstant. In interpreted code, this is entirely equivalent to\n`progn', except that the value of the expression may be (but is\nnot necessarily) computed at load time if eager macro expansion\nis enabled." #<bytecode 0x1a5c47>)((require (quote yow) nil t)) macroexpand((eval-when-compile (require (quote yow) nil t))) internal-macroexpand-for-load((eval-when-compile (require (quote yow) nil t)) nil) eval-buffer(#<buffer *load*-881575> nil "/home/alper/.emacs.d/lisp/icicles/icicles-cmd1.el" nil t) ; Reading at buffer position 24864 load-with-code-conversion("/home/alper/.emacs.d/lisp/icicles/icicles-cmd1.el" "/home/alper/.emacs.d/lisp/icicles/icicles-cmd1.el" nil t) require(icicles-cmd1) eval-buffer(#<buffer *load*-925687> nil "/home/alper/.emacs.d/lisp/icicles/icicles.el" nil t) ; Reading at buffer position 84684 load-with-code-conversion("/home/alper/.emacs.d/lisp/icicles/icicles.el" "/home/alper/.emacs.d/lisp/icicles/icicles.el" nil t) require(icicles) eval-buffer(#<buffer *load*> nil "/home/alper/.emacs" nil t) ; Reading at buffer position 56616 load-with-code-conversion("/home/alper/.emacs" "/home/alper/.emacs" t t) load("~/.emacs" t t) #f(compiled-function () #<bytecode 0x1e0f5d>)() command-line() normal-top-level() ``` # Answer > 3 votes It's not an error. It's just a silly message from Emacs. You can ignore it. For reasons of copyright, Emacs removed all of the guts from `yow.el` (the Zippy quotes) several years back. But it didn't remove library `yow.el`. That means: 1. You can provide and use your own such guts - Zippyisms, and still take advantage of what `yow.el` does. To provide your own Zippy quotes, put them in the file that's the value of option `yow-file`. Icicles provides a command, `icicle-apropos-zippy`, that, like the more rudimentary command `apropos-zippy`, shows the Zippy quotes that match an apropos pattern you enter. And Icicles soft-requires `yow.el[c]`: `(require 'yow nil t)`, meaning that if the library is available then it gets loaded. If it's not available then nothing happens (no error). 2. `(require 'yow nil t)` will still load file `yow.el[c]` even now, since it's still provided. As long as Emacs provides it, it will be loaded. 3. When it gets loaded (`;-)`), Emacs makes it send you that silly message. You can think of that message as a kind of Zippyism, or meta-Zippyism, if you like. As if Emacs had Zippy's sense of humor. Alas... --- However, it seems that you're getting that message as an *error*, because you have a function called `debug-on-load-obsolete` that's apparently on hook `after-load-functions`. Apparently `debug-on-load-obsolete` raises an error whenever you load an obsolete library. IMO that's a misfeature - obsolete does not mean unsupported. It means it's the thing is no longer in active development. If you want to keep raising an error for loading obsolete libraries, but you don't want to raise an error in this case, then just comment out the `(require 'yow nil t)` in `icicles-cmd1.el`. And then *thank Zippy for the lesson*. --- For more about Zippy, see Zippy the Pinhead. ***Yow!*** --- P.S. Emacs now calls **Yow** a *"package"*. Shame. Shame. Such a step backward... --- Tags: icicles ---
thread-59621
https://emacs.stackexchange.com/questions/59621
How to us a shortcut to add semicolon to end of current line?
2020-07-14T05:22:26.967
# Question Title: How to us a shortcut to add semicolon to end of current line? Is there a shortcut to add a semicolon to the end of the current line of code? For instance, `M-;` inserts a comment at the end of the current line of code. Is there anything like that for a semicolon? Currently, I press `C-e` to move the cursor to the end and type the semicolon `;`. I was wondering if there is a quicker way. # Answer If you ever want to add shortcuts functionality where you have control over the *exact* behavior, it's worth learning a little emacs-lisp. This kind of functionality is trivial to write. ``` (global-set-key (kbd "<f12>") (lambda () (interactive) ;; Keep cursor motion within this block (don't move the users cursor). (save-excursion ;; Typically mapped to the "End" key. (call-interactively 'move-end-of-line) (insert ";")))) ``` > 5 votes --- Tags: c++, c ---
thread-59624
https://emacs.stackexchange.com/questions/59624
How to exit emacs with `q` when man inside emacs is opened
2020-07-14T11:57:09.057
# Question Title: How to exit emacs with `q` when man inside emacs is opened Default behavior of `man <command>` (opens inside `less`) when `q` is pressed it is closed. --- I am using following to open `MANPAGER` with `emacs`: `emacsclient -nw -e "(let ((Man-notify-method 'bully)) (man \"$1\"))"` Here pressing `q` closes buffer but does not close the `emacs` like `Ctrl-x Ctrl-c` does. Is it possible to bind `q` into the same action `Ctrl-x Ctrl-c` to exit the `emacs` and get back to shell. # Answer > 3 votes the incantation you want is ``` (define-key Man-mode-map "q" 'save-buffers-kill-emacs) ``` I am guessing that you can do this inside your let form. ``` emacsclient -nw -e "(let ((Man-notify-method 'bully)) (man \"$1\") (define-key Man-mode-map \"q\" 'save-buffers-kill-emacs))" ``` --- Tags: emacsclient, man ---
thread-59627
https://emacs.stackexchange.com/questions/59627
Custom Keybindings not working
2020-07-14T14:36:58.913
# Question Title: Custom Keybindings not working I had to reinstall emacs and completely redo my config file, but for some reason, some of the custom keybindings that used to work with "move-dup" package from Melpa. Here is what i have: ``` #+begin_src emacs-lisp (require 'move-dup) (global-set-key (kbd "M-<up>") 'md-move-lines-up) (global-set-key (kbd "M-<down>") 'md-move-lines-down) (global-set-key (kbd "C-M-<up>") 'md-duplicate-up) (global-set-key (kbd "C-M-<down>") 'md-duplicate-down) #+end_src> ``` What would stop these from working? EDIT: so this does work, if i enable move-dup-mode, however I can't seem to get it to be enabled on start up, I've tried adding the following but it still doesn't load on startup: ``` (move-dup-mode 1) ``` I've also tried: ``` (global-move-dup-mode 1) ``` and I've also tried replacing the '1' for a 't' in on each one too, but to no avail. How can I get this to load on startup please? # Answer Do you have either a `(require 'move-dup)` or a `use-package` declaration for `move-dup`? If not, that is likely your problem. > 1 votes --- Tags: key-bindings, minor-mode ---
thread-59625
https://emacs.stackexchange.com/questions/59625
How to remove day grouping header for today's date in Agenda View?
2020-07-14T13:06:26.993
# Question Title: How to remove day grouping header for today's date in Agenda View? I have following custom agenda command definition. What I would like to achieve is to group all tasks for today without wrapping them in the current date header. ``` (setq org-agenda-custom-commands '(("o" "Custom Agenda" ((agenda "" ((org-agenda-overriding-header "\n ⚡ Do Today ⚡\n⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺") (org-agenda-remove-tags t) (tags-todo "today") (category-todo "today") (org-agenda-highlight-todo) (org-agenda-span 'day) (org-agenda-skip-deadline-if-done) (org-agenda-time-grid nil) (org-agenda-prefix-format " %-3i %10b %15t%10s"))))))))))))) ``` **TL:DR** How to remove current day header, but still group the tasks by today's date? # Answer You can define `org-agenda-format-date` either as a string or as a function to format the date in the agenda. `C-h v org-agenda-format-date RET` says: > Format string for displaying dates in the agenda. > > Used by the daily/weekly agenda. This should be a format string understood by ‘format-time-string’, or a function returning the formatted date as a string. The function must take a single argument, a calendar-style date list like (month day year). So all you need to do is add a setting for it in your org-agenda-custom-commands: ``` (setq org-agenda-custom-commands '(("o" "Custom Agenda" ((agenda "" ((org-agenda-overriding-header "\n ⚡ Do Today ⚡\n⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺") (org-agenda-remove-tags t) (tags-todo "today") (category-todo "today") (org-agenda-highlight-todo) (org-agenda-span 'day) (org-agenda-skip-deadline-if-done) (org-agenda-time-grid nil) (org-agenda-format-date "") ; <---- HERE (org-agenda-prefix-format " %-3i %10b %15t%10s"))))))) ``` > 3 votes --- Tags: org-mode, org-agenda ---
thread-59628
https://emacs.stackexchange.com/questions/59628
Adding a pattern to compilation-error-regexp-alist
2020-07-14T14:45:53.410
# Question Title: Adding a pattern to compilation-error-regexp-alist I'm using the latest Doom Emacs on Emacs 27 with this config: https://github.com/gregghz/doom-config/tree/d3af4724cb4a5dd379645580698f7d24a5c3922a. I have this code to run a bloop command (like `bloop compile`) and have the results pop up in a `compilation-mode` buffer. My understanding was that adding entries to `compilation-error-regexp-alist` would allow `compilation-mode` to detect and linkify all errors in the output (and jump to the first one). I have this in my config.el: ``` (after! compile (add-to-list 'compilation-error-regexp-alist-alist '(bloop "^\\[E\\] \\([A-Za-z0-9\\._/-]+\\):\\([0-9]+\\):\\([0-9]+\\):.*$" 1 2 3)) (add-to-list 'compilation-error-regexp-alist 'bloop)) ``` Here is some example error output from the buffer: ``` -*- mode: compilation; default-directory: "~/workspace/scratch/scala/" -*- Compilation started at Tue Jul 14 07:32:08 bloop compile --reporter scalac scala Compiling scala (1 Scala source) [E] /Users/gher33/workspace/scratch/scala/src/main/scala/Main.scala:4:34: not found: type Units [E] def main(args: Array[String]): Units = { [E] ^ [E] /Users/gher33/workspace/scratch/scala/src/main/scala/Main.scala:5:17: not found: type Thing [E] val x = new Thing [E] ^ [E] /Users/gher33/workspace/scratch/scala/src/main/scala/Main.scala:8:19: value f is not a member of Int [E] lazy val x = 10 f [E] ^ [E] three errors found Compiled scala (991ms) [E] Failed to compile 'scala' Compilation exited abnormally with code 8 at Tue Jul 14 07:32:10 ``` Testing the regex with `regexp-builder` matches each of the three errors. However in the `compilation-mode` buffer none of the errors are detected or linkified. What am I missing? **=EDIT=** Running `describe-mode` produces this output: ``` Auto-Compression Auto-Encryption Better-Jumper Better-Jumper-Local Clipetty Column-Number Company Company-Prescient Dap Dap-Auto-Configure Dap-Tooltip Dap-Ui Dap-Ui-Controls Dap-Ui-Many-Windows Doom-Modeline Electric-Indent Evil Evil-Escape Evil-Goggles Evil-Local Evil-Snipe Evil-Snipe-Local Evil-Snipe-Override Evil-Snipe-Override-Local Evil-Surround File-Name-Shadow Flyspell-Lazy Font-Lock Gcmh General-Override Global-Clipetty Global-Company Global-Eldoc Global-Evil-Surround Global-Flycheck Global-Font-Lock Global-Git-Commit Global-Magit-File Global-So-Long Global-Undo-Tree Ivy Ivy-Posframe Ivy-Prescient Ivy-Rich Line-Number Mouse-Wheel Ns-Auto-Titlebar Override-Global Persp Prescient-Persist Projectile Recentf Save-Place Savehist Shell-Dirtrack Show-Paren Size-Indication Smartparens-Global Solaire-Global Transient-Mark Treemacs-Filewatch Treemacs-Follow Treemacs-Fringe-Indicator Treemacs-Git Undo-Tree Which-Key Window-Divider Winner Ws-Butler Ws-Butler-Global Xterm-Mouse (Information about these minor modes follows the major mode info.) Compilation mode defined in ‘compile.el’: Major mode for compilation log buffers. To visit the source for a line-numbered error, move point to the error message line and type RET. To kill the compilation, type C-c C-k. ``` If I run `compilation-mode` in that buffer, linkification happens and the links work. The output of `describe-mode` doesn't change. The buffer is created/summoned with this code: ``` (defun bloop-exec (comint root command &rest args) (unless command (error "Missing argument `command'.")) (let* ((buffer-name (bloop-buffer-name root command)) (raw-command (cons bloop-program-name (cons command args))) (full-command (string-join (mapcar 'shell-quote-argument raw-command) " ")) (inhibit-read-only 1)) (when (not (executable-find bloop-program-name)) (error (concat "`%s' not found. Is bloop installed and on PATH? " "See `bloop-program-name' variable.") bloop-program-name)) (if comint (with-current-buffer (get-buffer-create buffer-name) (pop-to-buffer-same-window (current-buffer)) ;; (read-only-mode) (buffer-disable-undo) (if (comint-check-proc (current-buffer)) (error "A bloop command is still running!") ;; TODO: Maybe save buffers? (cd root) (erase-buffer) (insert (concat root "$ " full-command)) (newline 2) (comint-mode) ;; (compilation-shell-minor-mode) (comint-exec (current-buffer) buffer-name bloop-program-name nil (cons command args)) (current-buffer))) (let ((compilation-buffer-name-function (lambda (mode) buffer-name))) (cd root) (compile full-command))))) ``` # Answer Changing `(compile full-command)` to `(compile full-command t)` in `bloop-exec` fixes the issue. > 0 votes --- Tags: compilation, compilation-mode, doom ---
thread-14909
https://emacs.stackexchange.com/questions/14909
How to use Flyspell to efficiently correct previous word?
2015-08-20T19:25:43.577
# Question Title: How to use Flyspell to efficiently correct previous word? From the moment when I started using Flyspell, it always was painful to use. I rarely check entire buffer for misspelled words, usually I type and once I see underlined word I want to correct it instantly and continue typing. This is simply because I fear to forget to correct the word later and because when I start comprehensive checking of buffer, iSpell gives too many false positives. So, almost always I correct words as soon as possible while I type. Here is built-in functions I know about and reasons why they are not efficient (for me): * `flyspell-correct-word` — This is bound to mouse click. Forget it, I'm not going to use mouse. * `flyspell-correct-word-before-point` — I used it for some time. It has two downsides: 1. By default it shows GUI menu that is difficult to operate without mouse and it's really cumbersome when you have list of corrections with more than 10 items. 2. It doesn't work for word *long* before point. I type fast and when I spot misspelled word I typically have one or two words between the misspelled word and point. I need to move point, correct word, return back. Oh. * `flyspell-auto-correct-word` — See point 2 ↑ plus it doesn't work well when you have long list of completions (because of cycling). **Q:** How can I use Flyspell efficiently, with keyboard, being able to choose from list of completions without cycling, and with ability to correct even more or less distant words? Acceptable answers include packages that help to navigate to previous misspelled word, correct it and get back or something like that as well as little snippets, possibly from your own configuration file, since I believe other people figured out their ways to efficiently interact with Flyspell. # Answer The inbuilt `flyspell-auto-correct-previous-word` works like a charm for me. I have bound it to `F12` and I haven't looked back. It has consistently correctly words for me not matter how many words back the incorrect word was. From the function documentation: ``` flyspell-auto-correct-previous-word is an interactive compiled Lisp function in `flyspell.el'. (flyspell-auto-correct-previous-word POSITION) For more information check the manuals. Auto correct the first misspelled word that occurs before point. But don't look beyond what's visible on the screen. ``` In addition, if the first time autocorrect did not give you the right word, keep on hitting your bound key (`F12` in my case) to cycle through all options. *\[My spell check config\]* > 21 votes # Answer I'm pretty sure other people will come up with different solutions that will be useful for future readers. However, here is how I currently handle this. I think `flyspell-correct-word-before-point` is a good place to start, because it at least can be invoked with key pressing and it displays menu of possible corrections. To fix the menu I've written package Ace Popup Menu that uses Avy as backend. This replaces GUI popup menu that `flyspell-correct-word-before-point` uses (the function is called `x-popup-menu`) with textual popup menu that presents labeled menu items: one or two key strokes and you're done. To solve second problem (inability to correct words “at distance”) I've written this helper: ``` (defun flyspell-correct-previous (&optional words) "Correct word before point, reach distant words. WORDS words at maximum are traversed backward until misspelled word is found. If it's not found, give up. If argument WORDS is not specified, traverse 12 words by default. Return T if misspelled word is found and NIL otherwise. Never move point." (interactive "P") (let* ((Δ (- (point-max) (point))) (counter (string-to-number (or words "12"))) (result (catch 'result (while (>= counter 0) (when (cl-some #'flyspell-overlay-p (overlays-at (point))) (flyspell-correct-word-before-point) (throw 'result t)) (backward-word 1) (setq counter (1- counter)) nil)))) (goto-char (- (point-max) Δ)) result)) ``` This seems to work. > 8 votes # Answer With helm-flyspell you can choose from the list of corrections efficiently. I use the following code to jump to the errors and correct them with it, it saves the position of the point to the `mark-ring` so you can jump back to the position where you started or corrected words previously: ``` (defun flyspell-goto-previous-error (arg) "Go to arg previous spelling error." (interactive "p") (while (not (= 0 arg)) (let ((pos (point)) (min (point-min))) (if (and (eq (current-buffer) flyspell-old-buffer-error) (eq pos flyspell-old-pos-error)) (progn (if (= flyspell-old-pos-error min) ;; goto end of buffer (progn (message "Restarting from end of buffer") (goto-char (point-max))) (backward-word 1)) (setq pos (point)))) ;; seek the previous error (while (and (> pos min) (let ((ovs (overlays-at pos)) (r '())) (while (and (not r) (consp ovs)) (if (flyspell-overlay-p (car ovs)) (setq r t) (setq ovs (cdr ovs)))) (not r))) (backward-word 1) (setq pos (point))) ;; save the current location for next invocation (setq arg (1- arg)) (setq flyspell-old-pos-error pos) (setq flyspell-old-buffer-error (current-buffer)) (goto-char pos) (if (= pos min) (progn (message "No more miss-spelled word!") (setq arg 0)))))) (defun check-previous-spelling-error () "Jump to previous spelling error and correct it" (interactive) (push-mark-no-activate) (flyspell-goto-previous-error 1) (call-interactively 'helm-flyspell-correct)) (defun check-next-spelling-error () "Jump to next spelling error and correct it" (interactive) (push-mark-no-activate) (flyspell-goto-next-error) (call-interactively 'helm-flyspell-correct)) (defun push-mark-no-activate () "Pushes `point' to `mark-ring' and does not activate the region Equivalent to \\[set-mark-command] when \\[transient-mark-mode] is disabled" (interactive) (push-mark (point) t nil) (message "Pushed mark to ring")) ``` > 7 votes # Answer Having just discovered the benefit of doing `C-C $` (default binding that triggers the `flyspell-correct-word-before-point` command) I too found annoying the need of the mouse to pick a word from the suggested corrections . But, by pure chance, I saw that those options could be cycled through —within the small windows that pops up—, only by pressing the first letter of the world (and pressing Enter) That was useful to me, and thought of sharing the trick that didn't see written down anywhere. > 0 votes --- Tags: flyspell ---
thread-59636
https://emacs.stackexchange.com/questions/59636
Magit deprecates `magit-popup`. Which of my packages depend on it?
2020-07-15T00:32:19.193
# Question Title: Magit deprecates `magit-popup`. Which of my packages depend on it? How do I get Emacs to report which packages in my running Emacs depend on `magit-popup`? Soon Magit will stop supporting `magit-popup` because it has transitioned to the replacement `transient`. Somehow Magit (in preparation for version 3.0.0) is detecting a dependency on `magit-popup` and warns about this repeatedly, to the point of making Magit unusable. As described in this GitHub issue the message is written considerately and is well intentioned, but does not give any guidance on how to figure out which package has the dependency on `magit-popup`. That GitHub issue resolves when the reporter finds a dependency in their local Emacs configuration. I've searched my local config, and I don't find any dependencies on `magit-popup` so I seem to be stuck. Maybe I need to get Emacs itself to tell me at run-time what's causing this apparent dependency? Assuming I know nothing about debugging Emacs Lisp, **how do I track down exactly what is causing this `magit-popup` dependency** to the precision where I know exactly what to remove and/or file bug reports against? # Answer The function which produces that warning is `magit--magit-popup-warning`. You can use `M-x` `debug-on-entry` `RET` `magit--magit-popup-warning` `RET` to discover what is causing it to be called. See `C-h``i``g` `(elisp)Debugger Commands` for what you can do from inside the debugger, and how to exit it. Use `M-x` `cancel-debug-on-entry` if you don't want that to happen any more. --- Using `M-x` `rgrep` to search in your Emacs config for the following regexp will *probably* produce all of the relevant results, as well: `magit-\(define\|change\|remove\)-popup` You can see the complete list of targeted functions at the end of the `magit-obsolete.el` library, via `M-x` `find-library`. > 4 votes --- Tags: magit, debugging ---
thread-59640
https://emacs.stackexchange.com/questions/59640
How to enable org mode and evil mode for untitled buffer when creating a new frame
2020-07-15T03:14:31.737
# Question Title: How to enable org mode and evil mode for untitled buffer when creating a new frame The code below creates a new frame with an untitled buffer, how to make this buffer default with org-mode and evil-mode? ``` (global-set-key (kbd "s-n") 'new-empty-frame) (defun new-empty-frame () "Create a new frame with a new empty buffer." (interactive) (let ((buffer (generate-new-buffer "untitled"))) (set-buffer-major-mode buffer) (display-buffer buffer '(display-buffer-pop-up-frame . nil)))) ``` 1. `M-x org-mode RET` worked, but how to do it with elisp? 2. `M-x evil-mode RET` didn't even work. The code is from: https://stackoverflow.com/a/25792276/5520270 # Answer > 1 votes All you have to do is replace the `set-buffer-major-mode` call which sets the buffer to a default mode (`fundamental` mode in this case) with a couple of calls to set the modes you want. `org-mode` is a major mode, so you set it by calling the function that implements it, with no arguments, in the buffer whose mode you want to set: ``` (set-buffer <some buffer>) (org-mode) ``` `evil-mode` is a global minor mode, which can be enabled or disabled at will, like all minor modes. To enable it, you have to call its function with a positive argument: ``` (evil-mode 1) ``` To disable it, you call the function with a negative argument. All these things and more can be glimpsed by checking the doc string of the functions: `C-h f org-mode RET` and `C-h f evil-mode RET`. If a function does not behave the way you expect, you probably have a wrong expectation and you can check that by reading its doc string, so `C-h f <function> RET` is something you should do often. Putting it all together, the result is: ``` (defun new-empty-frame () "Create a new frame with a new empty buffer." (interactive) (let ((buffer (generate-new-buffer "untitled"))) (set-buffer buffer) (org-mode) (evil-mode 1) (display-buffer buffer '(display-buffer-pop-up-frame . nil)))) ``` Only partially tested, since I don't have `evil-mode` installed. --- Tags: org-mode, buffers, frames, major-mode, minor-mode ---
thread-59396
https://emacs.stackexchange.com/questions/59396
Archive all marked entries with evil-mode
2020-07-02T05:35:40.050
# Question Title: Archive all marked entries with evil-mode I recently switched to evil mode and cannot figure out how to archive all marked entries at once. The way I did it earlier, when I was in a list seeing the candidate entries for archiving I pressed * to mark them all (this works) and then B $ to archive them in bulk. But now B is a motion command and means bo back a word. Is there an evil-mode equivalent of B $? I know that dA stands for $ but I cannot figure out how to do this for all marked entries. # Answer Presuming this is about bulk changes in org-agenda. For me, the Org-Agenda buffers are in evil-mode's emacs-state, meaning that the default emacs key bindings work as expected. You can check what evil state in the mode line: `<N>` for normal state, `<E>` for emacs state. It might help to put the following into your .emacs: ``` (evil-set-initial-state 'org-agenda-mode 'emacs) ``` > 1 votes --- Tags: org-mode, evil ---
thread-59645
https://emacs.stackexchange.com/questions/59645
How to check if a customize group exists in Emacs Lisp code?
2020-07-15T13:52:14.333
# Question Title: How to check if a customize group exists in Emacs Lisp code? How can I programmatically check if a customize group exists? Interactively I can use `M-x customize-group` and use completion to see if a specific group exists or not. But that's not what I need. If I evaluate: ``` (customize-group "some-invalid-non-existing-group" nil) ``` Emacs will open a `*Customize Group*` buffer stating that the requested group is missing. I'm writing code that programmatically opens a `*Customize Group*` buffer but I'd like to do that only if the group exists. So i'd need to check if a specific group name (held in a string) exists prior to programatically calling the `customize-group` function. How to do that? # Answer Cribbing from `cus-edit.el` gets you this: ``` (let (custom-groups) (mapatoms (lambda (symbol) (when (or (and (get symbol 'custom-loads) (not (get symbol 'custom-autoload))) (get symbol 'custom-group)) (push symbol custom-groups)))) custom-groups) ``` > 3 votes --- Tags: custom ---
thread-59602
https://emacs.stackexchange.com/questions/59602
Process shell exited abnormally with code 53 on windows 10
2020-07-13T10:05:30.237
# Question Title: Process shell exited abnormally with code 53 on windows 10 I'm using emacs 26.2 installed through msys2. Recently starting subprocesses from emacs has stopped working for me. Specifically `M-x shell` and `shell-command-to-string`. I get the feeling this is due to a windows update or something since I didn't update emacs when this problem started occurring. I'm on the Windows 10 beta channel running version 20H2 at the moment. Now when I do `M-x shell` I get this error message: `Process shell exited abnormally with code 53`. If I call `shell-command-to-string` I just get an empty string as a reply. No matter what the argument. Has anyone else seen this problem? # Answer > 2 votes It seems the issue was cmdproxy.exe complaining about not being able to find libssp-0.dll. As a workaround copy libssp-0.dll from mingw64/bin to mingw64/libexec/emacs/26.3/x86\_64-w64-mingw32. --- Tags: microsoft-windows, shell, process ---
thread-59551
https://emacs.stackexchange.com/questions/59551
M-x compile hangs with WARNING: terminal is not fully functional
2020-07-09T14:50:30.843
# Question Title: M-x compile hangs with WARNING: terminal is not fully functional I have been using `M-x compile` for ages. Lately (our sysadmin has updated many things) it hangs after giving this message: `WARNING: terminal is not fully functional - (press RETURN)`. Pressing return does nothing. I have tried changing the terminal to `xterm`, `vt102`, etc. with no change. I get a similar warning with `M-x shell` but I can proceed after hitting return a few times. Need to get this functionality back, thanks! # Answer > 1 votes The problem arises because the `M-x compile` command uses the `dumb` terminal type and invokes `.cshrc` before running the command `make -k`. My `.cshrc` loads modules with the `module` command. The module command uses a pager which does not work properly with the `dumb` terminal type. The solution is to include the following in the `.cshrc` before the `module` command. The `INSIDE_EMACS` environment variable is set by the emacs shell. This also fixes `M-x shell`. ``` if (${?INSIDE_EMACS}) then setenv MODULES_PAGER cat endif ``` --- Tags: shell, term, compile ---