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-62044
https://emacs.stackexchange.com/questions/62044
Can't use eval-replace-last-sexp in multiple-cursors
2020-12-01T18:14:47.973
# Question Title: Can't use eval-replace-last-sexp in multiple-cursors In scratch file I has: ``` (* 60 10) (* 50 100) (* 50 200) ``` I want to use my custom function **replace-last-sexp** (**C-c C-l**) ``` (defun replace-last-sexp () (interactive) (let ((value (eval (preceding-sexp)))) (kill-sexp -1) (insert (format "%S" value)))) ``` To do this I use **multiple-cursors** package - https://github.com/magnars/multiple-cursors.el After I press C-c C-l in **multiple-cursors** mode I get this: ``` 600 (* 50 100) (* 50 200) ``` Why not calculate another lines? # Answer > 2 votes I have the same issue as you. And I'm not asked if I want to apply this function to other cursors ... strange, becuase I did expect this question. Maybe there are some changes in multiple-cursors recently? I also can't answer your "why" question. But here is some source code, to make it do, what you expect. ``` (defun replace-last-sexp--internal () (interactive) (let ((value (eval (preceding-sexp)))) (kill-sexp -1) (insert (format "%S" value)))) (defun replace-last-sexp () (interactive) (if (functionp 'mc/execute-command-for-all-cursors) (mc/execute-command-for-all-cursors #'replace-last-sexp--internal) (replace-last-sexp--internal))) ``` --- Tags: multiple-cursors ---
thread-55004
https://emacs.stackexchange.com/questions/55004
How do I configure first emacs frame position on startup?
2020-01-19T07:38:28.920
# Question Title: How do I configure first emacs frame position on startup? When coding I prefer to have my screen split vertically in two with my editor on the right and reference material or browser opened on the left. This saves me from physically switching workspaces or windows more often than I find necessary. I have therefore configured my emacs frames to take that position on the right when started. I acheive that with this code in my init.el: ``` ; Frame (use-package frame :ensure nil :custom ;(initial-frame-alist (quote ((fullscreen . maximized)))) (initial-frame-alist (quote ((top . 0) (left . 748) (width . 84) (height . 30)))) (default-frame-alist (quote ((top . 0) (left . 748) (width . 84) (height . 30)))) :config (blink-cursor-mode -1) (when (member "OperatorMono NF" (font-family-list)) (set-frame-font "OperatorMono NF-14:weight=regular" t t)) (defun my/disable-scroll-bars (frame) (modify-frame-parameters frame '((vertical-scroll-bars . nil) (horizontal-scroll-bars . nil) (left . 748)))) (add-hook 'after-make-frame-functions 'my/disable-scroll-bars)) ``` When I start emacs for the first time however, I see two different frames flash briefly on the top left of the screen, each with a different size before finaly respecting the settings in my config. Is there a way to set the very first frame that shows up to take up the correct postion on the screen instead of starting from the top left of the screen? # Answer You will have to set these things in `early-init.el` as pointed out by @lawlist. I have following snippet in my settings and it starts really smoothly: ``` (setq default-frame-alist '((height . 55) (width . 174) (left . 613) (top . 391) (vertical-scroll-bars . nil) (horizontal-scroll-bars . nil) (tool-bar-lines . 0))) ``` The parameters names are documented in `(elisp) Window Frame Parameters`. Yes this is in *elisp manual* and *not* in *emacs manual*. > 1 votes --- Tags: frames ---
thread-62034
https://emacs.stackexchange.com/questions/62034
What are the yellow-background items in Ivy?
2020-12-01T10:53:22.483
# Question Title: What are the yellow-background items in Ivy? I'm currently migrating from Helm to ivy+counsel, and I have a problem with the faces ivy applies in the minibuffer for some commands. See this example: Some of the possible selections are highlighted with a yellow background. However, the face for the currently selected item has a yellow foreground, so it can't be read against that background. I could of course just switch the foreground of the selected item (via the face `ivy-current-match`) to have a blue foreground or whatever, but I would also like to know what the difference between the items highlighted via yellow background and the non-highlighted ones is, and what face is used to do that highlighting. Since all of this happens in a minibuffer, I can't just hit `C-u C-x =` to get the faces at point (or rather: I can, but I can't move the point to one of these items). Is there a way to see the faces active in the minibuffer? This does not happen for all selections via ivy. `find-file`, `switch-to-buffer` and `execute-extended-command` seem unaffected (i.e., don't have background-highlighted items), but the help commands (`C-h k`, `C-h v`, `C-h f` etc.) are. # Answer It's `ivy-highlight-face`. According to the source code: > "Forward to \`describe-function'. > > Interactive functions (i.e., commands) are highlighted according to \`ivy-highlight-face'." > 2 votes --- Tags: faces, minibuffer, ivy ---
thread-62049
https://emacs.stackexchange.com/questions/62049
Override the default font for emoji characters
2020-12-02T00:16:49.533
# Question Title: Override the default font for emoji characters My fonts setup is ``` (setq default-frame-alist '((font . "DejaVu Sans Mono-10"))) (defun my-emoji-fonts () (set-fontset-font t 'symbol "Twemoji") (set-fontset-font t 'symbol "Noto Color Emoji" nil 'append) (set-fontset-font t 'symbol "Symbola" nil 'append)) (if (daemonp) (add-hook 'server-after-make-frame-hook #'my-emoji-fonts) (my-emoji-fonts)) ``` With it most emoji display nice and coloured, except those for which DejaVu provides its own glyph, then that overrides the coloured one. How can I avoid that? <sup>U+1F682 and U+2615. They don't let me sleep :/</sup> `describe-char` reports that the train is displayed with `ftcrhb:-GOOG-Twemoji-normal-normal-normal-*-16-*-*-*-m-0-iso10646-1 (#x3C6)`, while the coffee uses `ftcrhb:-PfEd-DejaVu Sans Mono-normal-normal-normal-*-16-*-*-*-m-0-iso10646-1 (#xA6C)`. --- **Solution** Turned out to be more complicated than I had thought. First, I had to turn off `use-default-font-for-symbols` in order to make Emacs honor the fontsets. (I use the first person because I don't feel like saying "do this and that". I got it working by trial and error.) This allows an Emoji font to override the default one when both provide glyphs for the same character: ``` (setq use-default-font-for-symbols nil) ``` Now however all greek letters, mathematical symbols and so on had switched to Twemoji or Symbola. I didn't want that, so I what I had to do was * restore DejaVu Sans Mono as the main symbols font; * make Twemoji override DejaVu for some specified character ranges; * finally, make Symbola act like a font of last resort. The only arrangement of `set-fontset-font` with which I was able to pull it off is this: ``` (defun my-emoji-fonts () (set-fontset-font t 'unicode (face-attribute 'default :family)) (set-fontset-font t '(#x2300 . #x27e7) "Twemoji") (set-fontset-font t '(#x2300 . #x27e7) "Noto Color Emoji" nil 'append) (set-fontset-font t '(#x27F0 . #x1FAFF) "Twemoji") (set-fontset-font t '(#x27F0 . #x1FAFF) "Noto Color Emoji" nil 'append) (set-fontset-font t 'unicode "Symbola" nil 'append)) ``` I chose the range from `#x2300` to `#x1FAFF` but had to break it in correspondence of `#x27e8` and `x27e9` (i.e. ⟨ and ⟩) because I noticed that Symbola was overriding those two specific characters, though they are available in DejaVu Sans Mono. Thanks zzkt and rpluim for helping me out. # Answer > 4 votes You want to set `use-default-font-for-symbols` to `nil` `C-h v use-default-font-for-symbols`: ``` use-default-font-for-symbols is a variable defined in `src/fontset.c'. Its value is t Probably introduced at or before Emacs version 25.2. Documentation: If non-nil, use the default face's font for symbols and punctuation. By default, Emacs will try to use the default face's font for displaying symbol and punctuation characters, disregarding the fontsets, if the default font can display the character. Set this to nil to make Emacs honor the fontsets instead. ``` # Answer > 3 votes You can define the Unicode ranges used for each font if you want more control over how particular glyphs or blocks are displayed. Rather than setting the `default-frame-alist` you could try setting a default font, then adding specific ranges **after** setting it... Depending on your language environment and coding systems (see also `list-character-sets`), you can change the default font in a few different ways... ``` (set-face-font 'default "DejaVu Sans Mono 10") ``` which can then be modified if required... ``` (set-face-attribute 'default nil :family "DejaVu Sans Mono" :weight 'medium :height 100) ``` `set-fontset-font` can be used to override or add extra character sets... ``` (set-fontset-font "fontset-default" nil (font-spec :family "DejaVu Sans Mono 10")) ``` then defining the relevant fonts for specific unicode blocks... ``` (set-fontset-font t #xFE0F spec-1) ;; Variation Selector 16 (set-fontset-font t '(#x1F1E6 . #x1F1FF) spec-2) ;; Regional Indicator Syms (set-fontset-font t '(#x1F3FB . #x1F3FF) spec-3) ;; Emoji Modifiers (set-fontset-font t '(#x1F700 . #x1F77F) spec-4) ;; Alchemical Symbols ``` etc... --- Tags: fonts, unicode ---
thread-62029
https://emacs.stackexchange.com/questions/62029
File mode specification error: (void-variable lsp-csharp--action-client-find-references)
2020-12-01T06:06:23.170
# Question Title: File mode specification error: (void-variable lsp-csharp--action-client-find-references) I'm using doom emacs. my `~/.doom.d/config.el` is - ``` (use-package! lsp-mode :hook (haskell-mode . lsp) :commands lsp) (use-package! lsp-ui :commands lsp-ui-mode) (use-package! lsp-haskell :after haskell-mode :config (setq lsp-haskell-process-path-hie "ghcide") (setq lsp-haskell-process-args-hie '()) (add-hook 'haskell-mode-hook #'lsp) ) (use-package! haskell-mode :mode "\\.hs$" :config (rainbow-delimiters-mode) ;; (setq haskell-font-lock-symbols t) ;;(add-to-list ("<>" . "⊕")) (setq haskell-font-lock-symbols-alist (-reject (lambda (elem) (or)) haskell-font-lock-symbols-alist))) ``` whenever i open haskell file i get error `File mode specification error: (void-variable lsp-csharp--action-client-find-references)` - OS details - ``` $ lsb_release -a LSB Version: :core-4.1-amd64:core-4.1-noarch Distributor ID: Fedora Description: Fedora release 32 (Thirty Two) Release: 32 Codename: ThirtyTwo ``` emacs details - ``` $ emacs -version GNU Emacs 27.1 ``` How can I solve this issue? # Answer I would suggest reinstalling lsp-mode and eventually unpinning the lsp-mode package. If this does not help, can you post the error callstack after M-x toggle-debug-on-error? > 0 votes --- Tags: lsp-mode, doom, haskell-mode, lsp, lsp-ui ---
thread-62054
https://emacs.stackexchange.com/questions/62054
Why advice won't work if the function is called from another compiled function?
2020-12-02T08:22:23.467
# Question Title: Why advice won't work if the function is called from another compiled function? Let's consider a minimal example, I take `org-narrow-to-subtree` as a compiled function, under the hood it calls `narrow-to-region`, I add simple advice to it: ``` (defun bark (START END) (message "Bark!")) (advice-add 'narrow-to-region :before #'bark) ``` If I call `narrow-to-region` interactively, the advice obviously works, but if I call `org-narrow-to-subtree` which in its turn calls `(narrow-to-region)`, it behaves as if there was no advice. If re-eval the function definition (the same source as the original, only defining it again instead of using the compiled version): ``` (defun org-narrow-to-subtree () "Narrow buffer to the current subtree." (interactive) (save-excursion (save-match-data (org-with-limited-levels (narrow-to-region (progn (org-back-to-heading t) (point)) (progn (org-end-of-subtree t t) (when (and (org-at-heading-p) (not (eobp))) (backward-char 1)) (point))))))) ``` and call `org-narrow-to-subtree` again, the advice gets called normally. 1. Why is that? 2. How do I solve my problem then? How do I add an advice? # Answer > 4 votes This (`narrow-to-region`) is the exact example covered by Chris Wellon's article The Limits of Emacs Advice. As @xuchunyang has already pointed out, the issue is that this function has its own byte code value, and hence advice does not work when the code is byte-compiled. You should read the whole article, but I'll quote this: > It turns out narrow-to-region is so special — probably because it’s used very frequently — that it gets its own bytecode. The primitive function call is being compiled away into a single instruction. This means my advice will not be considered in byte-compiled code. Darnit. The same is true for widen (code 126). --- Tags: advice, narrowing, nadvice ---
thread-62063
https://emacs.stackexchange.com/questions/62063
replace-regexp-in-string: How to prepend a string to the entire string matched?
2020-12-02T21:14:51.480
# Question Title: replace-regexp-in-string: How to prepend a string to the entire string matched? I am adding divider lines to certain sections of the reports generated by the binary `ledger` \[ https://www.ledger-cli.org/ \] through the function `ledger-do-report` in the `ledger-mode` Lisp library \[ https://github.com/ledger/ledger-mode\]. To accomplish this goal, I have chosen `replace-regexp-in-string`. I wish to **prepend** the divider line followed by a new line; i.e., `"======\n"`. **Q**: Is there a built-in way to prepend the additional string without the need to create an empty substring at the beginning of the REGEXP; i.e., `\\(\\)`? In the following example, I have begun my REGEXP with `^\\(\\)` so that I can replace that number 1 subsexpression with the new string. However, I have a feeling that there is a more correct approach to simply prepend a string without using an empty placeholder in the REGEXP. NOTE: The `^[` is defined by Emacs as: old-name: ESCAPE; general-category: Cc (Other, Control); decomposition: (27) ('^\[') ``` ;;; $ 98,477.47 ASSETS ;;; => ;;; ;;; $ 98,477.47 ^[[34mASSETS^[[0m ;;; (setq report (replace-regexp-in-string "^\\(\\)[\s]+$[\s]\\([0-9,.]+\\)[\s]+^[\\[34m\\(ASSETS\\)^[\\[0m$" (concat (make-string (- (window-width) 1) ?=)" \n") report nil nil 1)) ``` # Answer If `LITERAL` is `nil` then you can use `"\\&"` in the replacement to represent the entire matched string, and so your replacement text could be `"PREFIX\\&"`. Refer to `C-h f replace-match` for the behaviour of `LITERAL`. (And if you *didn't* want special characters in the replacement text to be processed, you would generally want LITERAL to be non-nil, for safety.) > 2 votes --- Tags: regular-expressions, replace ---
thread-62061
https://emacs.stackexchange.com/questions/62061
counsel-rg how to repeat last search?
2020-12-02T21:02:47.310
# Question Title: counsel-rg how to repeat last search? When repeat invoking counsel-ag, counsel-rg, counsel-projectile-rg etc, how can I quickly bring back the previous search term without retyping the query? # Answer `M-p` will do it. Works like most list commands. > 4 votes # Answer If you didn't use ivy in meantime, you can call `ivy-resume` which will resume your search. > 0 votes --- Tags: projectile, counsel ---
thread-62068
https://emacs.stackexchange.com/questions/62068
Is there any way to search in the current narrowed subtree in org mode?
2020-12-03T03:55:46.437
# Question Title: Is there any way to search in the current narrowed subtree in org mode? I can use `C-x n s (org-narrow-to-subtree)` to narrow the content to the current subtree, which is great. After doing that, I want to search a keyword in the current narrowed subtree(instead of the whole file). I tried opening `org-agenda`, and use the search functionality(`s`) in it. But it didn't work as expected. Org Mode searched the whole file for my keyword. So my question is, how to only search in the current narrowed subtree? # Answer Assuming that `C-c a` brings up the agenda dispatcher, you can restrict the agenda search by saying `C-c a < s` in the narrowed buffer. The dispatcher documentation says: > ‘\<’ Restrict an agenda command to the current buffer. If narrowing is in effect restrict to the narrowed part of the buffer. After pressing ‘\<’, you still need to press the character selecting the command. > 1 votes --- Tags: org-mode, search ---
thread-62045
https://emacs.stackexchange.com/questions/62045
Define new keywords in orgmode
2020-12-01T20:56:20.343
# Question Title: Define new keywords in orgmode I am trying to define new keywords for org-mode in order to highlight text in buffer. I followed this tutorial and this one which leads me to the following code : ``` (defface ex-face '((t (:foreground "red"))) "Face for !") (defface caret-face '((t (:foreground "orange"))) "Face for ^") (defface at-face '((t (:foreground "green"))) "Face for %%") (defvar my-org-custom-keywords '(("!!" . ex-face) ("^^" . caret-face) ("%%" . at-face))) (defun my-org-add-custom-keywords () "Add custom keywords." (loop for (delimiter . face) in my-org-custom-keywords do (add-to-list 'org-font-lock-extra-keywords `(,(concat "\\(" (regexp-quote delimiter) "\\)\\([^\n\r\t]+\\)\\(" (regexp-quote delimiter) "\\)") (1 '(face ,face invisible t)) (2 ',face) (3 '(face ,face invisible t)))))) (add-hook 'org-font-lock-set-keywords-hook #'my-org-add-custom-keywords) ``` I restarted emacs. Unfortunately, when I ask for the value of `org-font-lock-set-keywords-hook` I always get : : GNU Emacs 26.3 (build 2, x86\_64-pc-linux-gnu, GTK+ Version 3.24.14) : of 2020-03-26, modified by Debian : Spacemacs v.0.200.13 # Answer I think you need to `(require 'cl-lib)` \- that will define the `cl-loop` macro and you need to modify the code just a bit to use the `cl-loop` macro: ``` (require 'cl-lib) (defface ex-face '((t (:foreground "red"))) "Face for !") (defface caret-face '((t (:foreground "orange"))) "Face for ^") (defface at-face '((t (:foreground "green"))) "Face for %%") (defvar my-org-custom-keywords '(("!!" . ex-face) ("^^" . caret-face) ("%%" . at-face))) (defun my-org-add-custom-keywords () "Add custom keywords." (cl-loop for (delimiter . face) in my-org-custom-keywords do (add-to-list 'org-font-lock-extra-keywords `(,(concat "\\(" (regexp-quote delimiter) "\\)\\([^\n\r\t]+\\)\\(" (regexp-quote delimiter) "\\)") (1 '(face ,face invisible t)) (2 ',face) (3 '(face ,face invisible t)))))) (add-hook 'org-font-lock-set-keywords-hook #'my-org-add-custom-keywords) ``` Assuming that this code is in your `~/.emacs.d/init.el` file (or some other init file), then restarting emacs and opening an Org mode file should allow you to enter something like `!!exclamation face!!` and get what you expect: invisible `!!` delimiters and a red-foreground `exclamation face`. If you do `C-h v org-font-lock-set-keywords-hook RET` you should get: ``` org-font-lock-set-keywords-hook is a variable defined in ‘org.el’. Its value is (my-org-add-custom-keywords) ... ``` If you do `C-h v org-font-lock-extra-keywords RET` you will see that its value is `nil`: that's OK. This variable is only to be used by functions that are called by the hook (BTW, my first comment to your question was wrong: I did not realize then the special character of this variable). The variable that *really* controls the fontification is `org-font-lock-keywords` and that is set from the temporary value of `org-font-lock-extra-keywords`. If you check that variable with `C-h v org-font-lock-keywords RET` then you should see your entries: ``` org-font-lock-keywords is a variable defined in ‘org.el’. Its value is shown below. This variable may be risky if used as a file-local variable. Documentation: Not documented as a variable. Value: (("\\(%%\\)\\([^ ]+\\)\\(%%\\)" (1 '(face at-face . #1=(invisible t))) (2 'at-face) (3 '(face at-face . #2=(invisible t)))) ("\\(\\^\\^\\)\\([^ ]+\\)\\(\\^\\^\\)" (1 '(face caret-face . #1#)) (2 'caret-face) (3 '(face caret-face . #2#))) ("\\(!!\\)\\([^ ]+\\)\\(!!\\)" (1 '(face ex-face . #1#)) (2 'ex-face) (3 '(face ex-face . #2#))) (org-font-lock-hook) ... ``` Assuming that that is the case, the fontification should work. > 1 votes --- Tags: org-mode ---
thread-59757
https://emacs.stackexchange.com/questions/59757
Bind Meta key to Command on Mac Without Altering its System-wide Behaviour
2020-07-20T20:28:00.203
# Question Title: Bind Meta key to Command on Mac Without Altering its System-wide Behaviour To switch between tasks on an unaltered MacOS Mojave (OS X 10.14.6), one uses command-tab, which is convenient when done with the thumb finger. Now, in order to turn on the meta key inside Terminal (to allow e.g. skipping words with the cursor inside bash backward and forward emacs-style), I can tick the 'use Option as Meta key' in Terminal.app preferences. This setup leaves me with option as meta key inside emacs, which is not ergonomic, as the key is physically too much on the left and my thumb finger needs to bend to get there. I would like to: * leave the command-tab system-wide key unaltered, in order to be able to exit the emacs context into another task * still have the command key to be the meta key in emacs (so that, e.g., meta-f and meta-b hop over words) * all of this while working inside terminal emacs, not emacs with GUI variant Some things I tried: * swapping the command and option buttons in System Preferences/Keyboard/Modifier keys. This results in a need to press option-tab for the task manager * setting the `mac-command-modifier` variable, as explained here, however my emacs 26.3, installed via `brew install emacs`, doesn't seem to know about this variable (ctrl- h-v doesn't recognize it at all and changing the variable doesn't have any effect) Can this be done? In other words, is there a way to have the command key be `meta` in emacs and yet have command-tab still switch between tasks system-wide? # Answer In non-windows mode, changes to `ns-*` variables (such as `ns-alternate-modifier` and `ns-command-modifier`) are ignored. In particular, if the `-nw` option is passed as argument to emacs, the logic that propagates changes to `ns-*` variables (implemented in `src/nsterm.c`) is not evaluated. See the call to `init_display` in the `src/emacs.c` in the Emacs 27.1 source code. Roughly, it'll evaluate stuff from `nsterm.c` only if the window system is not inhibited (controlled by the `inhibit_window_system` variable which is set if the `-nw` flag is passed) and otherwise rely on `src/term.c`. If the window system is inhibited, the `ns-*` variables will still be visible - this is because `syms_of_nsterm` is invoked regardless of the `inhibit_window_system` variable at `emacs.c:1930`. The variables are there but have no bearing on the actual key mappings. As such when windows are inhibited, attempting to resolve this with `ns-*` is a dead end. Iterm2 and its remapping features can be of help here until there's a better way: ..which simply remaps the left command key to left option key. Also, in Preferences -\> Profiles -\> Keys, Left option key needs to be mapped to Esc+. > 1 votes --- Tags: key-bindings, keyboard-layout ---
thread-12927
https://emacs.stackexchange.com/questions/12927
Reading and writing email with emacs
2015-06-05T14:43:34.263
# Question Title: Reading and writing email with emacs **How can we use emacs to read and write email?** This question is intended to provide a canonical landing point for users wanting to deal with email using emacs. Please post only one package/solution per answer, with as much details as you can. Information that may be useful include: * requirements, supported environment * supported methods (read and/or send) * supported protocols (pop, imap, smtp, local mail setup...) * supported authentications * password storage (none, plain-text, access to an external wallet...) * offline support (none, aggressive caching, on-demand...) * how easy is it to use attachements? (adding with drag-and-drop, downloading, opening with emacs or another application...) * setup instructions (the more detailed the better), screenshots... * support for additional email features (archiving, filtering, folders) * support for additional related features (contacts, rss feeds)... no need to be too detailed here, depending on how closely the feature relates to email Solutions requiring an external tool in order to process the mail are welcome, as long as the user does not need to interact directly with the external process. *Examples: a package acting as a front-end for mutt is on-topic, a solution allowing a thunderbird user to write his message using emacs isn't.* Meta post for discussion. **Quick links to answers (alphabetically):** # Answer > 48 votes I use Mu4e. It is well documented (also via Info), and as of this writing, actively developed. Mu4e is shipped as an add-on to mu, *"a set of tools to deal with Maildirs and message files, in particular to index and search e-mail messages"*. It works together with offlineimap or fetchmail. I also use the Emacs package smtpmail-multi so that I can send from different accounts with different settings. For smooth integration with your email provider, you should `apt-get install ca-certificates`. And if you want a package-managed version, you can grab mu itself with `apt-get install maildir-utils`. Several example configurations are supplied, including the following "minimal configuration": ``` (require 'mu4e) (setq message-send-mail-function 'smtpmail-send-it smtpmail-default-smtp-server "smtp.example.com" smtpmail-smtp-server "smtp.example.com" smtpmail-local-domain "example.com") ``` Depinding on the set-up of your mail provider, you will need to do a bit more; and in particular, you will need to configure OfflineIMAP or Fetchmail to actually retrieve the mail. In my configuration, shown below, I set everything up to work with two accounts. If you just need to retrieve from one account, you may want to refer to the sample .offlineimaprc included in the mu4e manual. As for extensions and integration with other Emacs packages: Mu4e integrates conveniently with Org Mode (for capturing links to messages or custom searches, and even for authoring HTML formatted emails using Org syntax, although I don't use that feature) via the included org-mu4e.el. There is a separate helm-mu integration that is usable, but needs some more work IMO. It is themed in solarized.el. There is also a mu4e-maildirs-extension that gives a convenient count of read and unread messages per mail directory, and there is some other stuff I haven't tried. Together with the docs, these sample configs may help a new mu4e user get off the ground. # `.offlineimaprc` ``` [general] accounts = Gmail, Uni maxsyncaccounts = 3 [Account Gmail] localrepository = Local remoterepository = Remote status_backend = sqlite [Repository Local] type = Maildir localfolders = ~/Maildir/google [Repository Remote] type = IMAP remotehost = imap.gmail.com remoteuser = other.e.mail@gmail.com remotepass = TryAndGuess12345 ssl = yes maxconnections = 1 realdelete = no # cert_fingerprint = fa88366ccd90cd02f7a5655800226c43c8044ada # but they change all the time, so... sslcacertfile = /etc/ssl/certs/ca-certificates.crt # Folders to get: # # In Gmail, filter all current mail that isn't *otherwise* # filtered into the folder or folders you want to receive/sync. # Keep that up to date; it will boost efficiency if you would # otherwise be syncing a very large "Inbox" here. folderfilter = lambda foldername: foldername in [ 'JUNE2015', 'Drafts', 'Sent'] [Account Uni] localrepository = UniLocal remoterepository = UniRemote status_backend = sqlite [Repository UniLocal] type = Maildir localfolders = ~/Maildir/uni [Repository UniRemote] type = IMAP remotehost = pod666.outlook.com remoteuser = username@campus.university.ac.uk remotepass = TryAndGuess9876 ssl = yes maxconnections = 1 realdelete = no sslcacertfile = /etc/ssl/certs/ca-certificates.crt ``` # Config for `mu4e` and `smtpmail-multi`: ``` ;;; Replies (setq message-citation-line-function 'message-insert-formatted-citation-line) (setq message-citation-line-format "On %a, %b %d %Y, %f wrote:\n") ;;; smtp (add-to-list 'load-path "~/smtpmail-multi") (require 'smtpmail-multi) (require 'smtpmail) (setq smtpmail-multi-accounts (quote ((uni . ("username@campus.university.ac.uk" "pod666.outlook.com" 587 "e.mail@uni.ac.uk" nil nil nil nil)) (gmail . ("other.e.mail@gmail.com" "smtp.gmail.com" 587 "other.e.mail@gmail.com" starttls nil nil nil))))) (setq smtpmail-multi-associations (quote (("other.e.mail@gmail.com" gmail) ("e.mail@uni.ac.uk" uni)))) (setq smtpmail-multi-default-account (quote gmail)) (setq message-send-mail-function 'smtpmail-multi-send-it) (setq smtpmail-debug-info t) (setq smtpmail-debug-verbose t) ;;; MU4E config (require 'shr) (defun shr-render-current-buffer () (shr-render-region (point-min) (point-max))) (setq mu4e-compose-dont-reply-to-self t) (setq mu4e-compose-signature-auto-include nil) (setq mu4e-html2text-command 'shr-render-current-buffer) (setq mu4e-mu-binary "~/mu/mu/mu") (setq user-full-name "Hello World") (setq user-mail-address "other.e.mail@gmail.com") (setq mu4e-hide-index-messages t) (setq mu4e-maildir "~/Maildir" ;; top-level Maildir mu4e-sent-folder "/sent" ;; folder for sent messages mu4e-drafts-folder "/drafts" ;; unfinished messages mu4e-trash-folder "/trash" ;; trashed messages mu4e-refile-folder "/archive") ;; saved messages (setq mu4e-get-mail-command "offlineimap" ;; -a Uni to just do university acc't mu4e-update-interval nil) ;; 300 to update every 5 minutes (setq mu4e-bookmarks '( ("flag:unread AND NOT flag:trashed" "Unread messages" ?u) ("date:today..now" "Today's messages" ?t) ("date:7d..now" "Last 7 days" ?w) ("date:1d..now AND NOT list:emacs-orgmode.gnu.org" "Last 1 days" ?o) ("date:1d..now AND list:emacs-orgmode.gnu.org" "Last 1 days (org mode)" ?m) ("maildir:/sent" "sent" ?s) ("maildir:/uni/INBOX AND date:7d..now" "University Last 7 days" ?g) ("maildir:/google/JUNE2015 AND date:7d..now" "Gmail Last 7 days" ?c) ("mime:image/*" "Messages with images" ?p))) (setq mu4e-maildir-shortcuts '( ("/google/JUNE2015" . ?c) ("/uni/INBOX" . ?g) ("/sent" . ?s))) (setq mu4e-user-mail-address-list (list "other.e.mail@gmail.com" "e.mail@uni.ac.uk")) (setq message-kill-buffer-on-exit t) (setq mu4e-view-show-images t mu4e-view-image-max-width 800) ;; A little demo function for switching accounts (defun switch () (interactive) (save-excursion (goto-char (point-min)) (forward-char 19) (cond ((looking-at "other.e.mail@gmail.com") (delete-region (match-beginning 0) (match-end 0)) (insert "e.mail@uni.ac.uk") (buffer-face-set 'default)) ((looking-at "e.mail@uni.ac.uk") (delete-region (match-beginning 0) (match-end 0)) (insert "other.e.mail@gmail.com") (buffer-face-set 'bold-italic)) (t nil)))) (add-hook 'mu4e-compose-mode-hook (lambda () (buffer-face-set 'bold-italic))) ;;; Saving outgoing mail ;; Following tip from documentation for `mu4e-sent-messages-behavior' - see also ;; http://www.djcbsoftware.nl/code/mu/mu4e/Saving-outgoing-messages.html ;; for some related points, but not necessary to do things both ways. (setq message-sendmail-envelope-from 'header) (setq mu4e-sent-messages-behavior (lambda () (if (string= (message-sendmail-envelope-from) "other.e.mail@gmail.com") (progn (message "Delete sent mail.") 'delete) (progn (message "Save sent mail.") 'sent)))) ;;; Org mode compatibility ;; Use `org-store-link' to store links, and `org-insert-link' to paste them (require 'org-mu4e) ;;; That's all (provide 'my-mu4e-config) ``` # screenshot: browsing with search term list:emacs-orgmode.gnu.org # Answer > 28 votes If you use Gnus (bundled with Emacs already), check https://github.com/redguardtoo/mastering-emacs-in-one-year-guide/blob/master/gnus-guide-en.org Here is the summary of the guide: * Use minimum setup from EmacsWiki is enough (http://www.emacswiki.org/emacs/GnusGmail). It's setup for any mail service, not only Gmail * You can read/write html mail * You need subscribe mail folders manually * Press `C-u Enter` on any mail folder to see ALL items in that folder, or else, only unread mails are visible * popular protocols and authentication methods are supported out of box * for password storage, I just used easygpg which is bundled with Emacs. easygpg is a general framework. So the password is encrypted and stored offline. * email offline local cache is supported in Gnus ages ago * add/remove/download attachments is easy. I don't know the drag-and-drop thing because I only use keyboard. You need setup 'mailcap-mime-data\` to open attachment with 3rd party applications. * mail searching locally/remotely is supported out of the box * filter/archive is supported. But I suggest popfile which is an independent mail filter software. I use popfile because it's much much better than any other mail filter (Gmail's own filter, for example). * Contacts management is handled by bbdb (another Emacs plugin), it's also easy to import contacts from Gmail by using gmail2bbdb.el (written by me). * For rss reading, you'd better use elfeed (Gnus supports rss by using Gwene service. But elfeed is easier to set up). Gwene is powerful but requires much more knowledge (my Gnus guide, APIs of emacs-w3m, hydra, Lisp programming, Linux cli tools, shell) * Gnus supports all platforms. But on Windows, you need add binary from OpenSSH and GnuTLS to your environment variable PATH. These two packages could be installed through Cygwin. Emacs could be Windows native version. Please note since Emacs 26, all dependencies are packaged into one bundle on Windows. Check my guide for more tips. IMO, you'd better not replace Gmail's web UI (or any other mail service's web UI) with Gnus completely. The best practice to master Gnus is treating Gnus as an enhancement of Gmail. So you won't get frustrated if Gnus can's do certain thing because you always can fallback on web UI. Screenshot: # Answer > 14 votes # Notmuch I use notmuch for my emails in emacs. It does only operate on local mails which needed to be stored one message per file and I use maildir folders to which my smtp-server delivers. It should be able to cope with other solutions syncing mails to maildir folders on your computer. To start using it you install the command-line base and the emacs interface and start configuring via a short text wizard by calling `notmuch`, setup a regular call to a filtering script which calls `notmuch new` and tags other mails from the threads you tagged (for example mailing list threads you wish to ignore) or tag mails sorted by your mail daemon into special maildirs. In emacs you call `M-x notmuch` to see the interface from before. Almost all configuration for the interface can be done via the Customization interface from emacs. As it doesn't download messages from other systems it has no authentication or protocols built-in, apart from using emacs built-in support for sending emails. It doesn't use folders as such, but in practice stored searches feel like them for reading mails. It does list all used tags on the notmuch-hello view, so that when you decide how to tag your mail your lists get automatically updated. It doesn't need archiving as it shouldn't slow down when you have a lot of emails. The elisp part of notmuch brings apart from fast full-text and tagged and scoped searches possibilities to list matches and answer to messages. I don't know how drag and drop would work with notmuch as I use it via terminals and remote shells on my server. more screenshots: https://notmuchmail.org/screenshots/ The most difficult part about it would be having a synchronized tags when you use notmuch on 2 different computers, but people have worked around that, and from what I gathered from the mailing list it probably works now. Or have a look at https://notmuchmail.org/remoteusage/ for a new setup I just stumbled upon. There are packages for most linux distributions and it is developed in a bazaar environment via the mailing list. If you self-compile from tarballs or the git, it uses C code and has a dependencies on Xapian for storing the excerpts from the messages, GMime for decoding MIME emails, Talloc for memory management and zlib (which is also a dependency of Xapian). It would probably function well with rss2email or any solution converting rss feeds into maildirs. It's usable via the command-line and apart from the default emacs elisp interface other people use it with mutt (copies/hardlinks search results to a maildir folder on the disk) or vim. It will probably need some maintenance to keep running if your mail volume exceeds mine (~90k messages, not much mail). # Answer > 7 votes I was a happy user of mew for many years. I haven't used emacs for reading and writing mail for a long time now, so this information may well be outdated. Hopefully, more recent mew users can fill it in. For now, consider this answer a stub. (I'll make it community wiki, so others can edit it more freely.) First and foremost, in my experience, mew was *fast*. I had no difficulty handling mailing lists with enormous traffic using mew. Setting up mew was a bit involved, especially as it uses (used?) `stunnel` for creating encrypted connections to SMTP and IMAP servers. But basically, it just involves editing a file `~/.mew.el` and setting up a directory for mew to keep its data in. Apart from `stunnel` (and emacs, of course), it has no dependencies. The documentation seems adequate, though I often found myself looking in the wrong section. Maintenance seems to have slowed to a trickle, though. There are some bug fixes now and then, but no new features that I have noticed for a while. # Answer > 7 votes **WANDERLUST**: https://github.com/wanderlust/wanderlust FEATURES: * Implementation in elisp only. * Support of IMAP4rev1, NNTP, POP(POP3/APOP), MH and Maildir. * Integrated access to messages based on Folder Specifications like Mew. * Key bindings and mark processing like Mew. * Management of threads and unread messages. * Folder mode to select and edit subscribed folders. * Message cache, Disconnected Operation. * MH-like Fcc (Fcc: %Backup is possible). * Full support of MIME (by SEMI). * Draft editing of mail and news as a same interface. * Icon based interface for the list of Folder (XEmacs and \>= Emacs 21). * Skip fetching of a large message part of MIME(IMAP4). * Server side searching (IMAP4), internationalized searching is available. * Virtual folder, including, but not limited custom searches using Wanderlust, or external utilities such as `mu` and `grep`. * Compressed folder. * Automatic expiration of old messages. * Automatic refiling. * Draft templates. EMACS WIKI: https://www.emacswiki.org/emacs/WanderLust # Answer > 1 votes I use mutt for day-to-day email management. However, when there is a need to leverage the text manipulation functionality that Emacs provides, I *read* email using https://github.com/nicferrier/emacs-maildir . * Requirements, supported environment: Email must be stored in the maildir format. As my email is already in a local maildir (I use `fdm` to fetch), all that is needed is: ``` ;; Specify the location of the maildir directory > (setq maildir-mail-dir "/home/me/mail/my-fdm-maildir/") ``` and `M-x maildir-list`. * How easy is it to use attachments? Use the `>` key from the message-view mode to *view* attachments. * Support for additional email features (archiving, filtering, folders): Unknown. * Support for additional related features (contacts, rss feeds): I don't believe this package provides support for these sorts of things. --- Tags: email ---
thread-55491
https://emacs.stackexchange.com/questions/55491
Org Mode export options: do not export TODO keyword sections
2020-02-13T00:30:57.677
# Question Title: Org Mode export options: do not export TODO keyword sections I read in the manual, and here that ``` #+STARTUP: overview #+TASKS: nil * TODO Config tasks :tasklist: ** TODO todo1 SCHEDULED: <2020-02-16 Sun> ** TODO todo2 SCHEDULED: <2020-02-17 Mon> :LOGBOOK: - State "TODO" from [2020-02-13 Thu 01:26] - State "TODO" from [2020-02-13 Thu 01:26] :END: ``` **#+tasks: nil** should stop the exporting of todo items. It doesn't using the md backend. What am I doing wrong? My org export config is as follows:- ``` ** Self documenting config file #+begin_src emacs-lisp (use-package ox-gfm :defer 3 :after org :config (defun config-export-to-markdown() (interactive) (if (and (eq major-mode 'org-mode) (file-exists-p (concat (file-name-sans-extension (buffer-file-name)) ".md"))) (org-gfm-export-to-markdown))) (add-hook 'after-save-hook 'config-export-to-markdown)) #+end_src ``` # Answer The correct option to exclude task keywords is the following: ``` #+OPTIONS: todo:nil ``` See all export options here: https://orgmode.org/manual/Export-Settings.html > 3 votes --- Tags: org-mode, org-export, tags ---
thread-62067
https://emacs.stackexchange.com/questions/62067
Completing read with must-match and cannot be null
2020-12-03T03:36:39.877
# Question Title: Completing read with must-match and cannot be null The function `completing-read` permits the user to simply press the enter key without selecting a match against the list of valid choices: ``` (let* ((completion-ignore-case t) (client (completing-read "CLIENT: " '("a" "b" "c" "d") nil t))) client) ``` **Q**: Is there a similar completion function that will prevent the user from exiting by simply pressing the enter key without making a valid choice? # Answer I'd do this (similar to @lawlist's answer): ``` (let ((completion-ignore-case t) (client "")) (while (equal client "") (setq client (completing-read "CLIENT: " '("a" "b" "c" "d") nil t))) client) ``` > 1 votes # Answer See the answer by `Stefan` in a similar thread on stackoverflow.com \[ https://stackoverflow.com/a/12824748/2112489 \] that states in relevant part: ``` My guess is that you want to prevent the user from hitting RET with an empty answer. Indeed `completing-read' does not prevent that, even with `require-match' set. The way this is usually handled is by using a non-nil value for the `default' argument, in which case this value is returned when the user just hits RET. If that's not good enough, then you're probably going to have to use `minibiffer-with-setup-hook' and in the hook, setup a special keymap you've created for this purpose where RET is bound to a new function that signals an error if the minibuffer is empty and calls `minibuffer-complete-and-exit' otherwise. ``` Another option is to use a `while` loop: ``` (let ((client (catch 'break (while t (let* ((completion-ignore-case t) (choice (completing-read "CLIENT: " '("a" "b" "c" "d") nil t))) (if (equal choice "") (message "Please select a valid choice!") (throw 'break choice))))))) client) ``` > 0 votes --- Tags: completion, completing-read ---
thread-48294
https://emacs.stackexchange.com/questions/48294
Binding simple keys in spacemacs
2019-03-12T12:12:46.317
# Question Title: Binding simple keys in spacemacs I would like to set a `projectile find file` function to the hotkey `C-e`, and a `elpy-goto-definition` function to the hotkey `F12`, but I'm not sure why spacemacs is not recognizing the config that I'm trying to set. Here's my config: ``` (defun dotspacemacs/user-config () "Configuration function for user code. This function is called at the very end of Spacemacs initialization after layers configuration. This is the place where most of your configurations should be done. Unless it is explicitly specified that a variable should be set before a package is loaded, you should place your code here." (global-set-key "f12" 'elpy-goto-definition) (global-set-key (kbd "C-e") 'projectile-find-file)) ``` I've tried various combinations of these. I've read that global keys have low priority, maybe this is why, but I feel a leader key is not the correct option. # Answer > 0 votes The reason that the global set key was not working for `f12` was because I needed the line to look like ``` (global-set-key [f12] 'elpy-goto-definition) ``` and the other line, configuring projectile's `find-file` function was not working because I simply had to manually enable projectile on startup by running `projectile-mode` # Answer > 0 votes You can define also like that ``` (global-set-key (kbd "<f12>") 'it-works) (defun it-works () (interactive) (message "It works")) ``` If you want to define more specific keys, please, look at the link which is below. https://www.gnu.org/software/emacs/manual/html\_node/elisp/Key-Sequences.html --- Tags: key-bindings, spacemacs ---
thread-26188
https://emacs.stackexchange.com/questions/26188
Override particular range of code points with a non-default font
2016-08-11T00:42:28.613
# Question Title: Override particular range of code points with a non-default font Is it possible to override glyphs at some range of code points, that the default-font already covers, with ones from a non-default font? For instance, I'd like to use *Arial* only except for the uppercase letters, which I want to use *Cooper Black* for. How can I achieve this? I know that I can override some rage of code points whose glyphs are **missing** in the default font, but I'm failing to do the same for the code points whose glyphs exist in the default font. Here's what I tested. ``` (set-face-attribute 'default nil :family "Arial") (let ( (my-upper-case-font "Cooper Black") (font-sets '( "fontset-default" "fontset-standard" "fontset-startup"))) (mapcar (lambda (font-set) (set-fontset-font font-set '(#x00. #x17F) my-upper-case-font) ;I set the range wider for the sake of testing. ;This doesn't work and when I inserted "t" after "font-set", ;a message showed up saying "Wrong type argument: frame-live-p, "Cooper Black"" ) font-sets)) ``` # Answer See this question I asked: Override the default font for emoji characters. The gist of it is that *you have to set* `use-default-font-for-symbols` *to nil to make Emacs honor the fontsets*. Then you can specify the fontsets themselves, which can be simply ``` (set-fontset-font t '(#x00. #x17F) my-upper-case-font) ``` See also the manual and "best practice" for configuring fonts in Emacs today - fontsets, the default face, and ... IDK, like, stabbing things, maybe? on Reddit (Eli Zaretskii, one of Emacs' maintainers, posted some tips there). > 1 votes --- Tags: fonts ---
thread-62059
https://emacs.stackexchange.com/questions/62059
Where is the *meghanada-server-log*
2020-12-02T18:30:15.917
# Question Title: Where is the *meghanada-server-log* I recently installed `meghanada-mode` from melpa to help with some Java I am writing. Mostly I like it. However, it has started showing the following messages (in my `*Messages*` buffer): ``` Error:jetbrains.exodus.ExodusException: . Please check *meghanada-server-log* WARN not match type ``` However, I cannot find a buffer by that name, nor a file (using the find command). Moreover, if I compile my project (with Maven) it gives no errors and runs, but I assume something is not completely correct and would like to fix it. However, I don't know where to look. # Answer > 1 votes The `*meghanada-server-log*` only exists in the Emacs which started the meghanada server (with the `meghanada-server-start` command, which gets implicitly run when you turn on `meghanada-mode`). So, if you start a 2nd Emacs, it will find the server running and not have that buffer. Moreover, if you kill the 1st Emacs (the one that started the server) you can get the error messages I was referring to (because killing that emacs will kill the server), but not have the buffer to look in (because the 2nd Emacs didn't start the server and thus didn't create that buffer). However, the messages will go away if you either: 1. Start another Emacs and have it turn on `meghanada-mode` for some file, whence it will find that the server is not running, because killing the 1st emacs killed it (causing the error message) and restart it. or 2. Explicitly restart the `meghanada-server` with: ``` C-xmeghanada-server-kill C-xmeghanada-server-start ``` --- Tags: java ---
thread-41446
https://emacs.stackexchange.com/questions/41446
Org-Mode repeating task until
2018-05-12T16:47:32.897
# Question Title: Org-Mode repeating task until Simple question here, pretty new to org mode. I have an assignemnt I want to do once a day until a specific date. How can I have it scheduled for every day, but end on a ceratin day? This is what I have right now but it goes forever, and I want it to stop on monday `*** TODO f, f' , f'' sheet :NEXTACTION:MOBILEOFFICE: SCHEDULED: <2018-05-10 Thurs +1d>` # Answer > 6 votes There is an org-mode FAQ here that recommends using a command to generate a separate task for each day. That might seem heavyweight, but the FAQ suggests reading this blog post for the pros of this approach. The folding nature of org makes it easy to hide long lists. If you prefer infinite recurrence, note that there are two kinds. There is an infinite task recurrence, like in the question, which uses SCHEDULED and the plus time increment syntax. This entry only shows up in the agenda once and is regenerated each time you mark it completed, leaving a completion log. A fairly simple solution would be to use this and schedule a task on the day that the recurrence should end, reminding you to end the recurrence. An infinite calendar recurrence would be a case where, instead of a single timestamp, you can use an elisp expression to match multiple dates. These entries show up on the agenda on every matching date. There is an org-mode FAQ about using this, here. The thing about this approach is, you can't combine it with regeneration. I tried inserting one of these expressions into the SCHEDULED: field on a task and it works but still behaves like a recurring calendar entry, not a recurring task. I tried adding increments like +1d before the close angle bracket and it didn't seem to do anything. It's not apparently possible to get a task with this kind of customized scheduling to regenerate when it's marked as done. Even if it has a TODO keyword, it's a single task, that happens to show up multiple times, so if you mark it done it's done everywhere. You could use this method if you don't need to log completion times, or you could, for example, reset from DONE back to TODO when you review your agenda in the morning. Or submit a patch to make TODOs with elisp based recurrences regenerate :) See also the manual node for repeated tasks. # Answer > 0 votes Surprisingly, there is no out-of-the-box, automatic method to stop a recurring task. No option for a `repeat-until` date. @Ratha Grimes points out one option. You could make a separate "reminder-task" that is scheduled to appear on the date you'd like your repeating-task to end. Another option: use a property (e.g., `:UNTIL:`) in the property drawer. Set `:UNITL:` to the date you want the task to stop. Then you'd have to tell Agenda to ignore any tasks with an `:UNTIL:` value preceding Today. I am not sure if someone has already written a little routine for this. `org-super-agenda` might let you filter tasks based on property values. Once in a while, you'd have to go through your org files and clear out halted repeating-tasks... not as tedious as it sounds if you use Agenda to find tasks with `UNTIL` dates preceding Today. --- Tags: org-mode ---
thread-37800
https://emacs.stackexchange.com/questions/37800
How to inherit priority in org-mode?
2017-12-30T06:54:59.380
# Question Title: How to inherit priority in org-mode? I want child org items to inherit priority from their parent. I tried setting `org-use-property-inheritance '("PRIORITY")`, but it did not have any apparent effect. Use case: I often have high priority projects whose tasks are mostly equally important. I don't want to waste time setting priorities for each individual child task unless it differs from the parent (e.g., an optional subtask may have lower priority). Update: I e-mailed the org mailing list. Will report back if I get a useful response. # Answer > 4 votes The mailing list referenced in the first comment of the question states the following: > Note that you can already achieve inheritance by setting \`org-get-priority-function' to a function that searches priority cookies among ancestors of the current headline. I went ahead and implemented that suggestion (note that `org-get-priority-function` is just an alias for `org-priority-get-priority-function`): ``` (defun my/org-inherited-priority (s) (cond ;; Priority cookie in this heading ((string-match org-priority-regexp s) (* 1000 (- org-priority-lowest (org-priority-to-value (match-string 2 s))))) ;; No priority cookie, but already at highest level ((not (org-up-heading-safe)) (* 1000 (- org-priority-lowest org-priority-default))) ;; Look for the parent's priority (t (my/org-inherited-priority (org-get-heading))))) (setq org-priority-get-priority-function #'my/org-inherited-priority) ``` Along with adding `%l` to `org-agenda-prefix-format`, this bit of code gives me an Org Agenda with indented subtasks that immediately follow their parent tasks (why I went down this rabbit hole in the first place). # Answer > 1 votes In the absence of a genuine answer to this at the moment, I'm going to post this partial solution to the problem, if not to the literal question. The second pair of functions here raise and lower the priority of all items in the selected region: ``` (defun my/org-priority-up () (org-priority 'up)) (defun my/org-priority-down () (org-priority 'down)) (defun my/org-priority-up-region () (interactive) (org-map-entries #'my/org-priority-up nil 'region) (setq deactivate-mark nil)) (defun my/org-priority-down-region () (interactive) (org-map-entries #'my/org-priority-down nil 'region) (setq deactivate-mark nil)) ``` You can just bind those last two to keys in the normal way. For spacemacs users, here's a fancier way (`,r.` puts you in a transient state which lets you raise and lower the priorities on all items in the selected region using just the up and down arrow keys -- `q` to escape the transient state): ``` (spacemacs|define-transient-state my/org-region :title "Org region transient state" :bindings ("<up>" my/org-priority-up-region "up") ("<down>" my/org-priority-down-region "down") ("q" (lambda () (interactive) (setq deactivate-mark t)) "quit" :exit t)) (with-eval-after-load 'org (spacemacs/set-leader-keys-for-major-mode 'org-mode "r." 'spacemacs/my/org-region-transient-state/body)) ``` --- Tags: org-mode ---
thread-62058
https://emacs.stackexchange.com/questions/62058
Executing init.el file to load journal
2020-12-02T14:44:19.540
# Question Title: Executing init.el file to load journal I have this configuration init.el file: ``` ;; for org-journal (setq org-journal-dir "~/Desktop/doctorado") (setq org-journal-date-format "%A, %d %B %Y") (setq org-journal-file-type 'yearly) (setq org-file-format "Diary %Y") (require 'org-journal) ;; package manager (require 'package) (add-to-list 'package-archives '("org" . "https://orgmode.org/elpa/") t) ;; package initialization (package-initialize) ``` I want to open my journal with `C-c C-j` when opening emacs. However now I have to open `init.el` and do `M-x ev-b` before it works. Why is this happening? How can I solve it? # Answer > 0 votes A combination of what NickD and phils suggested did the trick. package-initialization should be up in the configuration file. ``` ;; package initialization (package-initialize) ;; for org-journal (setq org-journal-dir "~/Desktop/doctorado") (setq org-journal-date-format "%A, %d %B %Y") (setq org-journal-file-type 'yearly) (setq org-file-format "Diary %Y") (require 'org-journal) ;; package manager (require 'package) (add-to-list 'package-archives '("org" . "https://orgmode.org/elpa/") t) ``` I also wasn't using the init.el configuration file but the .emacs file. I erased one of them and then it worked. --- Tags: org-mode, org-journal ---
thread-62095
https://emacs.stackexchange.com/questions/62095
Treat hyphens as part of a word?
2020-12-04T10:27:39.337
# Question Title: Treat hyphens as part of a word? I use: ``` (global-superword-mode t) ``` in my `init.el` because I don't want Emacs to treat `_` as a word delimiter. How do I do the same thing for `-`? I'd like to enable this globally. # Answer > `(global-superword-mode t)` \[Note that mode functions are not documented as accepting `t` as argument - you should enable modes either as `(mode)` or with a non-zero natural number such as `(mode 1)`.\] > How do I do the same thing for `-`? That depends on the syntax table (see `(info "(elisp) Syntax Tables")`), and thus the modes, in use. AFAICT, `superword-mode` delegates all of its boundary finding to the command `forward-symbol`. So if `forward-symbol` recognises `-` as constituting a symbol, then so will `superword-mode`. In Elisp, `-` already has `symbol` syntax (see `C-u C-x =`, `C-h s`) so `forward-symbol` will skip all of e.g. `global-superword-mode` in one go. This is also the case in e.g. `fundamental-mode` and `text-mode`. For changing the syntax category of `-`, there's the command `modify-syntax-entry`; see `(info "(elisp) Syntax Table Functions")`. For example, you could do `M-x modify-syntax-entry RET - _ RET` to give it `symbol` syntax in the current buffer. > 1 votes --- Tags: syntax-table, words ---
thread-62098
https://emacs.stackexchange.com/questions/62098
Argument to ivy-read action when collection is an alist
2020-12-04T13:35:47.697
# Question Title: Argument to ivy-read action when collection is an alist The documentation of `ivy-read` states that if the collection supplied is an alist, the selected candidate is passed as a cons cell to the function supplied in the `:action` argument. So why does the code snippet below return `"C1"` or `"C2"`, depending on the selection, and not `(1 2 3)` or `(3 4 5)`, respectively? ``` (ivy-read "Choose: " (list (cons "C1" (list 1 2 3)) (cons "C2" (list 3 4 5))) :action (lambda (x) (cdr x))) ``` I can work around this by doing something like the following, but I don't understand why I have to. ``` (let (tmp) (ivy-read "Choose: " (list (cons "C1" (list 1 2 3)) (cons "C2" (list 3 4 5))) :action (lambda (x) (setq tmp (cdr x)))) tmp) ``` # Answer > So why does the code snippet below return `"C1"` or `"C2"`, depending on the selection, and not `(1 2 3)` or `(3 4 5)`, respectively? Because the argument passed to `:action` is not, and is not documented as being, the same thing as the return value of `ivy-read`. The value returned by `ivy-read` is usually, but not always, the same as what `completing-read` would return. This is done to allow `ivy-completing-read` to be used as a `completing-read-function`. Ivy `:action`s, OTOH, are intended for Ivy-specific features like non-exiting completion, multi-actions, etc. > 2 votes --- Tags: ivy, association-lists ---
thread-62090
https://emacs.stackexchange.com/questions/62090
Unable to load color "#FFFFFF" (mouse-face)
2020-12-04T07:44:27.323
# Question Title: Unable to load color "#FFFFFF" (mouse-face) Using Emacs 27.1 (mac port, BigSur), I get a strange behavior when I set the mouse face color using an hexadecimal description. Running `emacs -Q -l show-bug.el`, with `show-bug.el` being: ``` (font-lock-mode 0) (insert (propertize " CLICK " 'face '(:foreground "black" :background "light grey") 'mouse-face '(:foreground "white" :background "orange"))) (insert (propertize " CLICK " 'face '(:foreground "#37474F" :background "#ECEFF1") 'mouse-face '(:foreground "#FFFFFF" :background "#FFAB91"))) (insert "\n") ``` The two texts are properly rendered but when the mouse hovers the second button, it is not highlighted with the specified color (it becomes white instead). In the meantime, in the `*Messages*` buffer, I get: ``` Unable to load color "#FFAB91" Unable to load color "#FFFFFF" ``` However, if I switch to the `*Messages*` before hovering, the text becomes properly highlighted without error reporting. I would like to debug this but I'm not sure where to start. **Update 1** If I call `describe-char` on the second text, hovering works properly. **Update 2** If the mouse pointer is over the position where the button will appear (after starting emacs), it also works. **Update 3** It has been fixed # Answer > 0 votes Looks like a platform-specific bug to me. I don't see it on MS Windows (Emacs 26.3). I see exactly the same behavior for the first and second `CLICK`s - just as you are expecting. Consider reporting this as a bug: `M-x report-emacs-bug`. --- Tags: debugging, faces, colors ---
thread-62091
https://emacs.stackexchange.com/questions/62091
Bind multiple keys to a command using `global-set-key` interactively
2020-12-04T08:20:12.953
# Question Title: Bind multiple keys to a command using `global-set-key` interactively I want to bind multiple keys interactively to a single function using `global-set-key`. For example, let `M-. g` bind to `project-find-file` function. How to achieve this? # Answer `M-x global-set-key`, followed by hitting the key and entering the command to bind to it. Do that twice, once for each key. You ask how to *interactively* bind multiple keys. That's the way. There's no special provision for binding multiple keys to the same command using a single command invocation. But you can use `M-p` to retrieve your command-name input, `project-find-file` for the second binding, so you don't have to type/complete it again. > 1 votes --- Tags: key-bindings ---
thread-38711
https://emacs.stackexchange.com/questions/38711
Encountering `Symbol's value as variable is void: <!DOCTYPE` error while installing Icicles in Emacs on Windows 7
2018-02-09T07:28:56.733
# Question Title: Encountering `Symbol's value as variable is void: <!DOCTYPE` error while installing Icicles in Emacs on Windows 7 I was trying to install the Icicles packages as presented here by following this guide. First I downloaded only the required packages and put them in this directory: ``` C:\Users\Administrator\AppData\Roaming\.emacs.d\icicles ``` Then added this directory to `load-path` by putting this line in `.emacs` file: ``` (add-to-list 'load-path "~/.emacs.d/icicles/") ``` and executing `M-x eval-buffer`, so the directory was put in `load-path` when I checked it by `C-h v load-path`. But when I executed `M-x load-library RET icicles RET` it prompted the error: ``` Symbol's value as variable is void: <!DOCTYPE ``` Is it due to the files `icicles-chg.el, icicles-doc1.el and icicles-doc2.el` being in the load-path? I'm using Emacs 24.5 running on Windows 7. # Answer That `<!DOCTYPE` is your clue that you did not download the Emacs-Lisp files (`*.el`). Instead, you downloaded an HTML file - e.g., an HTML file that describes or displays an Emacs-Lisp file. Try downloading the source files again (`*.el`). Then check their content to see if they look like Lisp code or HTML code. If the latter then you are still downloading incorrectly. When you click the name of an Elisp file in the Emacs-Wiki Elisp Area, you see an HTML display of its code (e.g. the `icicles.el` file. To get the code file itself, right-click the `Download` button on that page (upper left) and choose `Save Link As` (the exact text might depend on your browser). > 4 votes # Answer Easy to have this happen, esp. when using `wget` or something. (Guess how I know.) In particular, **when downloading from Github, make sure you are grabbing the "raw" version** of a file, not the one you get by clicking on it on the main file list. The former has `/raw/` as part of the URL's path; the latter, `/blob/`. Then, eyeball the file, as a sanity check ;-) > 0 votes --- Tags: icicles, emacs-wiki ---
thread-62050
https://emacs.stackexchange.com/questions/62050
Make Evil Mode "s" key behave like Vim
2020-12-02T03:15:03.197
# Question Title: Make Evil Mode "s" key behave like Vim Doom Emacs' `s` key does not behave like Vim's implementation. In Vim, `s` deletes the character under the cursor and puts you into insert mode whereas Evil Mode performs a search, similar to `f` and `t`. 1. Is this something that can be changed? 2. If not, what was the reasoning behind `s` not working like it does in Vim? It seems like most bindings work as expected, except for this one. # Answer > 1 votes Having this is your init file will make `s` function as it does in Vim: `(define-key evil-normal-state-map (kbd "s") 'evil-substitute)` But this will *replace* the current functionality of `s`, so you will have to map its current value (`C-h k s`) to something else. # Answer > 0 votes Running `C-h k` for `s` revealed that evil-snipe was mapped to `s` and `S`. I found a Doom-specific solution, provided by the creator to add to `config.el` which allows for all evil-snipe functionality to remain the same: ``` (after! evil-snipe (evil-snipe-mode -1)) ``` Source: https://github.com/hlissner/doom-emacs/issues/1642#issuecomment-518711170 --- Tags: key-bindings, evil, doom ---
thread-62030
https://emacs.stackexchange.com/questions/62030
Blank menus with Athena / Lucid
2020-12-01T08:04:25.197
# Question Title: Blank menus with Athena / Lucid I compiled Emacs 27.1 with `--with-x-toolkit=lucid`, now the menus are blank. I tried setting the colors in `~/.Xresources`: ``` Emacs.pane.menubar.background: black Emacs.pane.menubar.foreground: white Emacs.pane.menubar.buttonForeground: white ``` But that only turned the menus black, I still see no text. I started Emacs with `xrdb ~/.Xresources && emacs -Q`. GTK and Motif menus work fine. # Answer > 0 votes It is a bug in Emacs 27.1. The problem was that I have “Noto Color Emoji” as my second preferred font in my fontconfig configuration file (`~/.config/fontconfig/fonts.conf`): ``` <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE fontconfig SYSTEM "fonts.dtd"> <fontconfig> <!-- […] --> <alias> <family>sans-serif</family> <prefer> <family>Source Sans Pro</family> <family>Noto Color Emoji</family> </prefer> </alias> </fontconfig> ``` `fc-match -s sans | head -n2` looks like this: ``` SourceSansPro-Regular.otf: "Source Sans Pro" "Regular" NotoColorEmoji.ttf: "Noto Color Emoji" "Regular" ``` ### Workaround Remove “Noto Color Emoji” from your preferred fonts list. You will lose color emojis in a lot of programs. ### Solution Wait for Emacs 27.2 or apply this patch from the emacs-27 branch: ``` diff --git a/lwlib/lwlib-utils.c b/lwlib/lwlib-utils.c index f15cb603a8..2b3aa55c3e 100644 --- a/lwlib/lwlib-utils.c +++ b/lwlib/lwlib-utils.c @@ -148,6 +148,7 @@ XftFont * crxft_font_open_name (Display *dpy, int screen, const char *name) { XftFont *pub = NULL; + FcPattern *match = NULL; FcPattern *pattern = FcNameParse ((FcChar8 *) name); if (pattern) { @@ -162,12 +163,18 @@ crxft_font_open_name (Display *dpy, int screen, const char *name) FcPatternAddDouble (pattern, FC_DPI, dpi); } FcDefaultSubstitute (pattern); + FcResult result; + match = FcFontMatch (NULL, pattern, &result); + FcPatternDestroy (pattern); + } + if (match) + { cairo_font_face_t *font_face - = cairo_ft_font_face_create_for_pattern (pattern); + = cairo_ft_font_face_create_for_pattern (match); if (font_face) { double pixel_size; - if ((FcPatternGetDouble (pattern, FC_PIXEL_SIZE, 0, &pixel_size) + if ((FcPatternGetDouble (match, FC_PIXEL_SIZE, 0, &pixel_size) != FcResultMatch) || pixel_size < 1) pixel_size = 10; @@ -177,7 +184,7 @@ crxft_font_open_name (Display *dpy, int screen, const char *name) cairo_matrix_init_scale (&font_matrix, pixel_size, pixel_size); cairo_matrix_init_identity (&ctm); cairo_font_options_t *options = cairo_font_options_create (); - cairo_ft_font_options_substitute (options, pattern); + cairo_ft_font_options_substitute (options, match); pub->scaled_font = cairo_scaled_font_create (font_face, &font_matrix, &ctm, options); cairo_font_face_destroy (font_face); @@ -190,7 +197,7 @@ crxft_font_open_name (Display *dpy, int screen, const char *name) pub->height = lround (extents.height); pub->max_advance_width = lround (extents.max_x_advance); } - FcPatternDestroy (pattern); + FcPatternDestroy (match); } if (pub && pub->height <= 0) { ``` --- Tags: gui-emacs, menu-bar ---
thread-61682
https://emacs.stackexchange.com/questions/61682
How to use Emacs Application Framework as Default PDF viewer?
2020-11-11T13:45:37.393
# Question Title: How to use Emacs Application Framework as Default PDF viewer? I recently discovered the Emacs Application Framework, which works quite nice for me. The only thing that's bothering me is, that I need to explicitly call `eaf-open` on a file, to open it with the framework. I tried to associate eaf with the file extension via `(add-to-list 'auto-mode-alist '("\\.[pP][dD][fF]\\'" . eaf-mode))` but to no avail. How can I tell Emacs that it should open PDF files with eaf? # Answer You can modify the Emacs file association way by the following code. ``` (defun adviser-find-file (orig-fn file &rest args) (let ((fn (if (commandp 'eaf-open) 'eaf-open orig-fn))) (pcase (file-name-extension file) ("pdf" (apply fn file nil)) ("epub" (apply fn file nil)) (_ (apply orig-fn file args))))) (advice-add #'find-file :around #'adviser-find-file) ``` > 1 votes --- Tags: pdf ---
thread-61848
https://emacs.stackexchange.com/questions/61848
Magit continues despite pre-commit hook failing
2020-11-21T03:26:35.417
# Question Title: Magit continues despite pre-commit hook failing I have a pre-commit hook in git that returns nonzero on some "fatal" QA checks. When using `git commit` on the command line, git bails out. However, when trying the very same commit in Magit, Magit continues on presenting the commit message buffer. I would like Magit to bail like git does. I don't have anything related to Magit in my init file beyond `(use-package magit)`. Magit version: `Magit 20201110.1643, Git 2.26.2, Emacs 27.1, gnu/linux` Magit process buffer (`$`): ``` 1 git … commit --signoff pre-commit running in /home/titan/repos/gentoo Running repoman for: app-office/gnucash digest.unused 3 /home/titan/repos/gentoo/app-office/gnucash::gnucash-3.8b.tar.bz2 /home/titan/repos/gentoo/app-office/gnucash::gnucash-4.0.tar.bz2 /home/titan/repos/gentoo/app-office/gnucash::gnucash-4.1.tar.bz2 Non-Fatal QA errors found pre-commit done in /home/titan/repos/gentoo hint: Waiting for your editor to close the file... Waiting for Emacs... ``` I've programmed the script to consider unused digest items to be an error. So, the script returns 1. Edit: Well, I've done nothing...and now it works as expected. Something must have gotten stuck. # Answer > 1 votes Magit simply runs `git commit ...`, `git` then invokes `$EDITOR`, which Magit has arranged to be `emacsclient ...`, so that ends up calling back into the same Emacs instance. `git commit` may decide that the commit should not be created after all, e.g. because there are no changes that could be committed or because the `pre-commit` hook exits with a non-zero exit status. In that case it needs no commit message, so it simply does not call the `$EDITOR`. This does not appear to be what is happening here; `git commit` does not abort. Looking at the output you provided, we can see that only ***Non-Fatal* QA errors \[were\] found**. Therefore the `pre-commit` hook exits with a zero status, communicating to `git commit` that there is no reason to abort, and that uses `$EDITOR` to have you write the message. Compare the hook output to the output that you get on the command line. Does it here say that the QA errors are fatal? If so, then this difference is probably due to configuration and you then have to figure out why that configuration appears to be ignored when `git commit` is invoked from inside Magit instead of from inside a shell. My guess would be on environment variables that are set in your shell's configuration files, which don't apply to Emacs because you don't start Emacs by typing `emacs` into a terminal. --- Tags: magit ---
thread-62116
https://emacs.stackexchange.com/questions/62116
Use message mode without headers
2020-12-05T10:33:34.367
# Question Title: Use message mode without headers I would like to edit e-mail messages without the header (!) in message mode. If I open a file in message mode and it does not have the usual e-mail headers, then `M-q` filling does not work as I discovered in this question. In that question I learned that the header separator can be customized, but what if there is no header and no header separator at all? I understand that sending the mail will not work without this header, but I send the mail on a different route. Actually, this is part of trying to use Emacs as the external editor for MailMate which works fine, except that I have not found a mode in which I can edit e-mail with font-locking for quote depth etc. Probably this should be a minor mode for editing e-mail which does not exist yet. notmuch-mode, mu4e-mode and org-msg all seem to be based on message mode and behave the same wrt. the header. So is it possible to use message mode without a header? # Answer > So is it possible to use message mode without a header? Would narrowing to the body work in your use case? See `(info "(emacs) Narrowing")`. For example, you could `C-c C-b` (`message-goto-body`), `C-SPC` (`set-mark-command`), `M->` (`end-of-buffer`), `C-x n n` (`narrow-to-region`). To undo the narrowing, you could `C-x n w` (`widen`). Here's a command that does this in one go: ``` (defun my-message-narrow-to-body () "Narrow buffer to Message body." (interactive) (narrow-to-region (save-excursion (message-goto-body) (point)) (point-max))) ``` > 1 votes --- Tags: message-mode ---
thread-62110
https://emacs.stackexchange.com/questions/62110
Rebasing with -X option
2020-12-05T05:01:18.237
# Question Title: Rebasing with -X option This is my scenario: * My branch is rebased against some other branch * that other branch changed and I want to get mine back to sync * I do a rebase and magit makes me go through all commits and merge In terminal I would do this with a `git rebase -X ours root-branch`. Is something like that possible with magit? If that's not possible, is there some alternative for what I'm trying to achieve? # Answer That wasn't available yet, but I've just added it with 46b2f6e3a. Because this should only be used if you know what you are doing, it is hidden by default. To learn how to reveal it, see Enabling and Disabling Suffixes. > 1 votes --- Tags: magit ---
thread-61783
https://emacs.stackexchange.com/questions/61783
Is it possible to apply `smerge-keep-mine` for all the conflicts by using a single keybinding?
2020-11-16T23:07:11.053
# Question Title: Is it possible to apply `smerge-keep-mine` for all the conflicts by using a single keybinding? I am using `smerge` to resolve conflicts in order to apply merge. I am applying one by one for `smerge-keep-mine` to all conflicts, which I belive equivalent for `git merge --strategy-option ours` `[Q]` Is it possible to apply `smerge-keep-mine` for all the conflicts by using a single keybinding? config: ``` (defun smerge-try-smerge () (save-excursion (goto-char (point-min)) (when (re-search-forward "^<<<<<<< " nil t) (require 'smerge-mode) (smerge-mode 1)))) (add-hook 'find-file-hook 'smerge-try-smerge t) (add-hook 'after-revert-hook 'smerge-try-smerge t) (defun smerge-next-safe () "returns t on success, nil otherwise" (condition-case err (not (smerge-next)) ('error nil))) (require 'vc) (defun next-conflict () ;; key-binding (interactive) (let ((buffer (current-buffer))) (when (not (smerge-next-safe)) (vc-find-conflicted-file) (if (eq buffer (current-buffer)) (message "No conflicts found") (goto-char 0) (smerge-next-safe))))) ;; smerge-keep-current bound to smerge-command-prefix (RET) to keep the version the cursor is on. ;; smerge-keep-mine bound to smerge-command-prefix (m) to keep your changes. ;; smerge-keep-other bound to smerge-command-prefix (o) to keep other changes. ``` # Answer > 1 votes As far as I know, no `smerge` does not provide that functionality. --- Tags: smerge ---
thread-61713
https://emacs.stackexchange.com/questions/61713
Force magit to ask for confirmation before deleting a branch
2020-11-13T00:32:36.263
# Question Title: Force magit to ask for confirmation before deleting a branch I would like to have magit ask for confirmation when I've told it to delete a particular branch. Currently it seems that magit considers the selection of a branch to delete to be the confirmation, as the documentation to `magit-no-confirm` says: > The user always has to confirm the deletion of a branch by accepting the default choice (or selecting another branch) This is not enough of a confirmation for me, and I'd like to make magit ask me for confirmation *after* I've selected a branch to delete. Is there any way to do this? # Answer Quoting some more context from the documentation: > \`delete-unmerged-branch' Once a branch has been deleted it can only be restored using low-level recovery tools provided by Git. And even then the reflog is gone. The user always has to confirm the deletion of a branch by accepting the default choice (or selecting another branch), but when a branch has not been merged yet, also make sure the user is aware of that. In other words, if you enable this option, then Magit *will* ask for confirmation before deleting an *unmerged branch*. It won't do so for merged branches, because doing that by accident is much less dangerous. > 1 votes --- Tags: magit, config ---
thread-61710
https://emacs.stackexchange.com/questions/61710
Magit git commit isn't working on spacemacs
2020-11-12T20:36:51.110
# Question Title: Magit git commit isn't working on spacemacs After installing Magit in spacemacs. I used Helm to create a git repository. I added some files to stage then tried to commit. Let me know if I'm doing something wrong or it's just an issue. I get: ``` transient--emergency-exit: Wrong type argument: transient-suffix, [eieio-class-tag--transient-switch 1 nil nil nil nil nil nil nil nil ...] ``` I've also put this question: github gitter reddit Ubuntu 18.04.3 LTS The rest was: * Emacs: 25.2.2 * Spacemacs: 0.300.0 * Spacemacs branch: develop (rev. 76ce0ac) Reinstalled Emacs same version and spacemacs stable Spacemacs v.0.200.13 and I have the same issue. Full trace: ``` Debugger entered--Lisp error: (wrong-type-argument transient-suffix [eieio-class-tag--transient-switch 1 nil nil nil nil nil nil nil nil "-a" transient:magit-commit:--all t " %k %d (%v)" "Stage all modified and deleted files" nil nil nil nil nil nil nil nil nil "--all" "-a" nil unbound nil nil nil nil nil nil nil nil] object) signal(wrong-type-argument (transient-suffix [eieio-class-tag--transient-switch 1 nil nil nil nil nil nil nil nil "-a" transient:magit-commit:--all t " %k %d (%v)" "Stage all modified and deleted files" nil nil nil nil nil nil nil nil nil "--all" "-a" nil unbound nil nil nil nil nil nil nil nil] object)) transient--emergency-exit((wrong-type-argument transient-suffix [eieio-class-tag--transient-switch 1 nil nil nil nil nil nil nil nil "-a" transient:magit-commit:--all t " %k %d (%v)" "Stage all modified and deleted files" nil nil nil nil nil nil nil nil nil "--all" "-a" nil unbound nil nil nil nil nil nil nil nil] object)) transient-setup(magit-commit) magit-commit() funcall-interactively(magit-commit) call-interactively(magit-commit nil nil) command-execute(magit-commit) ``` # Answer > 1 votes Issues like this happen because of one of these reasons: * Some backward incompatible change in Emacs itself that requires that the byte-code is regenerated. If you recently updated Emacs, then that's likely the cause. * Some backward incompatible change in one of the involved libraries itself, which is of a nature that causes the old now invalid incarnation of the thing to leak into the byte-code generated from the new source, if the compilation happens while the old version of the library has already been loaded. This seems to happen a lot when Eieio is involved. `package.el` should really use a separate `emacs` instance to prevent this sort of issue. * If a macro is defined in one package and used in another package, then the package that uses it might have to be recompiled when the definition changes. This could be addressed by dumping dependencies, but it often gets overlooked. --- In this case you should be able to fix it by uninstalling `magit` and `transient`, exiting Emacs (that is very important), restarting Emacs, and then reinstalling. --- Tags: spacemacs, magit, git ---
thread-60915
https://emacs.stackexchange.com/questions/60915
Syntax highlighting for comments in Magit commit buffers with custom core.commentChar
2020-09-30T16:00:08.123
# Question Title: Syntax highlighting for comments in Magit commit buffers with custom core.commentChar I frequently source the body of my GitHub PRs from my commits, and thus is makes sense to consider my commits to be made in Markdown (it is nice to have a markup language for commits anyway). Thus I customized Magit's `git-commit-major-mode` to be `markdown-mode`, but then all the `#` comment lines that Git inserts get formatted like markdown headers---highly undesirable! So I switched away from `#` as Git's comment delimiter. Somewhat randomly, I picked `!`, and added to my `.gitconfig`: ``` [core] commentChar = ! ``` This keeps them from being formatted like headers, but I previously enjoyed the way that Magit had some understanding of these lines and would syntax-highlight them. I was hoping that there was some intelligence in the Git commit mode that would be able to mesh markdown mode with the original abilities of Magit, so that *above* the comment lines would be highlighted with Markdown, and the comment lines themselves would be highlighted by Magit (which is already aware of `core.commentChar`, because when I set commit buffers to have no major mode, it properly highlights the comments that use `!`). My current configuration is usable, but with Emacs (and Magit especially) I always shoot for the stars. How do I achieve this? # Answer This is supposed to already work. Figuring out why it doesn't work for you will require a debugging effort on your part and I am afraid I won't be able to help you any more with that because I do not know enough about Spacemacs to do so. I suggest you ask for help from some other Spacemacs users. > 1 votes --- Tags: magit, git, markdown-mode ---
thread-62124
https://emacs.stackexchange.com/questions/62124
Racket Mode not working, although all requirements has been provided
2020-12-05T13:03:49.920
# Question Title: Racket Mode not working, although all requirements has been provided I wanna do some Scheme. For this, I choose Racket language. And I'm Emacs user about 1-2 months. So I think I did all requirements for writing Racket in Emacs. But still, I can't get `racket-mode` package in list of all packages in Emacs. So firstly, I installed Racket to my computer. It's okay and I can write Racket in `repl mode`(but I want `racket-mode`). After all, I know that I need Melpa for installing packages. But I can't find `racket-mode` in `list-of-packages`. This is image of packages I have. So what's problem. Why I can't find `racket-mode` package **Some Points:** I write this code into `init` file and I have `init` file in `.emacs.d` directory ``` (require 'package) (add-to-list 'package-archives '("melpa-stable" . "https://stable.melpa.org/packages/")) ``` Don't recomment DrRacket I only use Emacs # Answer There is no racket-mode package in MELPA Stable, so it's not listed in the package list. You'll have to add regular MELPA instead and refresh the package archives. > 1 votes --- Tags: package-repositories ---
thread-62114
https://emacs.stackexchange.com/questions/62114
How to find if an Emacs lisp function is setf-able?
2020-12-05T03:27:50.450
# Question Title: How to find if an Emacs lisp function is setf-able? Emacs Lisp setf macro allows you to set generalized variables. You can, for example change the size of the current window with the following form: ``` (setf (window-height) 10) ``` The macro will translate the above code to: ``` (progn (enlarge-window (- 10 (window-height))) 10) ``` **My question:** Is there a way to find out dynamically whether an Emacs function is "*setf-able*" like window-height is? I searched in the GNU EMacs Common Lisp Emulation manual and could not find and answer to my question. # Answer > 4 votes Check the value of symbol's `gv-expander` property, for "setf-able" functions, the value is non-nil (and a function), e.g., ``` (functionp (get 'window-height 'gv-expander)) ;; => t ``` for other functions, the value is nil, e.g., ``` (get 'length 'gv-expander) ;; => nil ``` --- Tags: setf ---
thread-34086
https://emacs.stackexchange.com/questions/34086
How can I install Emacs25.2 on openSuse?
2017-07-11T01:42:03.393
# Question Title: How can I install Emacs25.2 on openSuse? On Ubuntu I would install emacs dependencies with `apt-get build-dep emacs24`, extract the emacs25.2.tar.gz and install but the dependencies don't seem to be on openSuse's zypper (package manager). Atm I'm getting this when trying to install emacs25.2 ``` configure: error: You seem to be running X, but no X development libraries were found. You should install the relevant development files for X and for the toolkit you want, such as Gtk+ or Motif. Also make sure you have development files for image handling, i.e. tiff, gif, jpeg, png and xpm. If you are sure you want Emacs compiled without X window support, pass --without-x ``` How should I go about getting that dependency and other dependencies needed for emacs on openSuse? # Answer > 1 votes emacs 25.2 is already available in the `editors` repo. See these instructions on how to add it. EDIT: Other openSUSE releases are available for the same repo. # Answer > 0 votes The command for installing build dependencies only for emacs is: ``` zypper source-install --build-deps-only emacs ``` NOTE: You may need to enable sources repository in YAST. Shameless self promotion: This script downloads the latest version of emacs, automagically installs dependencies (for Debian and openSUSE), builds it, installs under a folder you can configure and finally creates symbolic links onto your $HOME/bin. --- Tags: install, build ---
thread-19654
https://emacs.stackexchange.com/questions/19654
Org print output in OCaml source blocks
2016-01-18T19:40:43.740
# Question Title: Org print output in OCaml source blocks Using org source blocks with OCaml, I get a blank resulting output with that code : ``` #+BEGIN_SRC ocaml :results output print_string "hello" #+END_SRC #+RESULTS: ``` And without the `:results value` parameter : ``` #+RESULTS: : () ``` How to catch the output of OCaml in org source blocks ? *Edit* : My init parts about ocaml ``` (use-package utop :ensure t) (use-package merlin :ensure :config ;; Add opam emacs directory to the load-path (setq opam-share (substring (shell-command-to-string "opam config var share 2> /dev/null") 0 -1)) (add-to-list 'load-path (concat opam-share "/emacs/site-lisp")) ;; Load merlin-mode (require 'merlin) ;; Start merlin on ocaml files (add-hook 'tuareg-mode-hook 'merlin-mode t) (add-hook 'caml-mode-hook 'merlin-mode t) ;; Make company aware of merlin (with-eval-after-load 'company (add-to-list 'company-backends 'merlin-company-backend)) ;; Enable company on merlin managed buffers (add-hook 'merlin-mode-hook 'company-mode) ;; Or enable it globally: ;(add-hook 'after-init-hook 'global-company-mode) ;; Use opam switch to lookup ocamlmerlin binary (setq merlin-command 'opam) ;; (define-key tuareg-mode-map (kbd "C-c M-s") ') ;;;###autoload (defun tuareg-run-metaocaml () "Run an OCaml toplevel process. I/O via buffer `*ocaml-toplevel*'." (interactive) (tuareg-run-process-if-needed "/usr/bin/opam config exec -- metaocaml") (display-buffer tuareg-interactive-buffer-name)) (add-hook 'tuareg-mode-hook ' (lambda () (define-key tuareg-mode-map (kbd "C-c M-s") 'tuareg-run-metaocaml))) (setq tuareg-interactive-program "/usr/local/bin/opam config -- exec metaocaml") ;;(setq merlin-use-auto-complete-mode t) ;;(setq merlin-error-after-save nil) ) (use-package tuareg :ensure t :config (setq auto-mode-alist (cons '("\\.ml\\w?" . tuareg-mode) auto-mode-alist)) (autoload 'tuareg-mode "tuareg" "Mode majeur pour éditer du code Caml" t) (autoload 'camldebug "camldebug" "Exécuter le débogueur Caml" t) (when (string= (getenv "MY_EMACS_DAEMON") "ocaml") (load-file "~/.emacs.d/elisp/daemon/my-tuareg-daemon.el")) ;; Setup environment variables using opam (dolist (var (car (read-from-string (shell-command-to-string "opam config env --sexp")))) (setenv (car var) (cadr var))) ;; Update the emacs path (setq exec-path (append (parse-colon-path (getenv "PATH")) (list exec-directory))) ;; Update the emacs load path (add-to-list 'load-path (expand-file-name "../../share/emacs/site-lisp" (getenv "OCAML_TOPLEVEL_PATH"))) ;; utop top level (autoload 'utop "utop" "Toplevel for OCaml" t) (autoload 'utop-minor-mode "utop" "Minor mode for utop" t) (add-hook 'tuareg-mode-hook 'utop-minor-mode) ) ``` I tried without utop but output remained the same. # Answer > 2 votes Apparently if a line is not properly (newline-) terminated it is ignored in output. The following example shows it: ``` #+BEGIN_SRC ocaml :results output print_string "hello\nagain" #+END_SRC #+RESULTS: : hello ``` I would tend to call this a bug since the documentation says (emphasis mine): > 14.9.1.2 ‘:results output’ > > The code is passed to the interpreter as an external process, and **the contents of the standard output stream** are returned as text. (In certain languages this also contains the error output stream; this is an area for future work.) However, see an interesting loosely related discussion on unix SE: > A text file, under unix, consists of a series of lines, each of which ends with a newline character (\n). A file that is not empty and does not end with a newline is therefore not a text file. # Answer > 1 votes You can try adding `ocaml` to the list of `org-babel-load-languages` with `M-x customize-variable org-babel-load-languages`, inserting a new value with `INS`, and then selecting `Ocaml` from the list. Or you can define the list in your init file. Here is mine (plus Ocaml just for testing): ``` (org-babel-do-load-languages 'org-babel-load-languages '((python . t) (sh . t) (ocaml . t) )) ``` With this configuration I get the following results when I execute your example block with `C-c C-c` in the block: ``` #+BEGIN_SRC ocaml :results output print_string "hello" #+END_SRC #+RESULTS: : () ``` With `:results value`: ``` #+BEGIN_SRC ocaml :results value print_string "hello" #+END_SRC #+RESULTS: : hello- : unit = () ``` Also, you may find this resource helpful if you haven't seen it already. # Answer > 0 votes I tried `:results verbatim` (interchangeable with `:results raw`) and got this ``` #+begin_src ocaml :results verbatim open List let res = map (fun x -> x+1) [1;2] #+end_src #+RESULTS: : val res : int list = [2; 3] #+begin_src ocaml :results verbatim 1 + 2 * 3 #+end_src #+RESULTS: : - : int = 7 #+begin_src ocaml :results verbatim print_string "hello" #+end_src #+RESULTS: : hello- : unit = () #+begin_src ocaml :results raw 1 + true #+end_src #+RESULTS: Line 1, characters 4-8: 1 | 1 + true;; ^^^^ Error: This expression has type bool but an expression was expected of type int ``` These results are pretty much what my Ocaml 4.11.1 REPL is giving. Also, I'm using the `opam-user-setup.el` and org-mode version 9.4 on Emacs 27.1. Do ``` opam user-setup install ``` and it will append `opam-user-setup.el` to your `.emacs.d/init.el` file. Move to suit. --- Tags: org-mode, org-babel ---
thread-62133
https://emacs.stackexchange.com/questions/62133
Why I can't use `let` in this example?
2020-12-06T07:04:28.407
# Question Title: Why I can't use `let` in this example? I am learning Emacs lisp and wrote a function which takes as input a list of file name, and returns a list of numbers of each defun in a file (introduced in this tutorial) ``` (lengths-list-file "/usr/share/emacs/28.0.50/lisp/simpl.el") => (49, 49, 49, ... ) ``` I tried to write another function, which takes a list of filenames and return an `append`-ed list of return values of `lengths-list-file` of each element in the list. ``` (defun lengths-list-files2 (list-of-files) "Return list of lengths of defuns in LIST-OF-FILES." (let (lengths-list) (dolist (filename list-of-files lengths-list) (let (cur-lengths-list (lengths-list-file filename)) (message "%d" (length cur-lengths-list)) (setq lengths-list (append lengths-list cur-lengths-list)))) lengths-list)) ``` Here I first used `let` to bind `(lengths-list-file filename)` to a symbol `cur-length-list`, however, I found out that `cur-lengths-list` was always `nil`. Instead, I removed `let` expression, and I found that it started to work as I expected: ``` (defun lengths-list-files (list-of-files) "Return list of lengths of defuns in LIST-OF-FILES." (let (lengths-list) (dolist (filename list-of-files lengths-list) (setq lengths-list (append lengths-list (lengths-list-file filename)))) lengths-list)) ``` What is the reason that the function with `let` within the `dolist` block failed to produce correct result? (i.e., why `cur-lengths-list` is always `nil`?) # Answer > 3 votes ``` (let (cur-lengths-list (lengths-list-file filename)) ``` > Here I first used `let` to bind `(lengths-list-file filename)` to a symbol `cur-lengths-list` No, you bound `cur-lengths-list` to `nil` (hence "I found out that cur-lengths-list was always nil"), and then you bound `lengths-list-file` to the value of the variable `filename`. You wanted this: ``` (let ((cur-lengths-list (lengths-list-file filename))) ``` See `C-h f let` for details. --- Tags: let-binding, parentheses ---
thread-62138
https://emacs.stackexchange.com/questions/62138
Make `re-search-forward` return string with Korean characters
2020-12-06T11:57:01.700
# Question Title: Make `re-search-forward` return string with Korean characters I am trying to implement a web scraper that does the following: 1. Make a request to https://m.weather.naver.com/, 2. Get interesting pieces of information (regarding today's weather), then 3. Organize them nicely into a new org-buffer. So far, I have this piece of code (credit: http://teaching.sociology.ul.ie/bhalpin/wordpress/?p=580): ``` ;;; scrape_weather.el --- -*- lexical-binding: t; -*- (defun get-weather-page () "get the title text of Naver Weather" (set-buffer (url-retrieve-synchronously "https://m.weather.naver.com")) ; set this buffer to current buffer (re-search-forward "<title>\\(.+\\)</title>") ; re-search for pattern (match-string 1)) ; return the first parens in regexp (defvar *str* (get-weather-page)) ;; *str* evals to "\263\327\300\314\271\366 \263\257\276\276".. is there any way I can encode it back to Korean? ;;; scrape_weather.el ends here ``` For debugging purposes, I evaluated the variable `*str*` and got weird sequences of hex codes. That must be `네이버 날씨`, but I'm sure that the decoding of Korean characters got broken after the execution of `re-search-forward`. Is there any way I can correct the decoding? # Answer > 5 votes In order to handle non-ASCII characters, you need turn on multibyte via `(set-buffer-multibyte t)` (see also (elisp) Selecting a Representation), e.g., ``` (with-current-buffer (url-retrieve-synchronously "https://m.weather.naver.com") (set-buffer-multibyte t) (goto-char (point-min)) (re-search-forward "<title>\\(.+\\)</title>") (match-string 1)) ;; => "네이버 날씨" ``` Emacs uses multibyte mode by default, e.g., ``` (with-temp-buffer enable-multibyte-characters) ;; => t ``` however `url-retrieve-synchronously` turns it off, hence you need to turn it on according to you needs. > For debugging purposes here is another way to debug which is more intuitive, eval this code ``` (display-buffer (url-retrieve-synchronously "https://m.weather.naver.com")) ``` you will see some characters in octal format, and after `M-x toggle-enable-multibyte-characters`, you'll see the actual characters. --- Tags: character-encoding ---
thread-62142
https://emacs.stackexchange.com/questions/62142
Access strange list data
2020-12-06T20:27:00.950
# Question Title: Access strange list data I'm trying to parse the output of `ledger-context-at-point` for the account name. The output looks something like: ``` (acct-transaction account ((indent " " 238117) (status nil nil) (account "asset:checking" 238121))) ``` I want `"asset:checking"`. I can get it by ``` (cadr (assq 'account (nth 2 ;; (ledger-context-at-point) (quote (acct-transaction account ((indent " " 238117) (status nil nil) (account "asset:checking" 238121))) )))) ``` or by ``` (cadadr (cdaddr ;; (ledger-context-at-point) (quote (acct-transaction account ((indent " " 238117) (status nil nil) (account "asset:checking" 238121))) ))) ``` I would have expected a simple structure, like an alist or plist. Does this data structure follow a different idiom? Is there a conventional way to get at the list elements like these? # Answer > 1 votes Per @Drew's prompting and some poking around, I see within `ledger-context.el` the following definitions: ``` (defun ledger-context-field-info (context-info field-name) (assoc field-name (nth 2 context-info))) (defun ledger-context-field-value (context-info field-name) (nth 1 (ledger-context-field-info context-info field-name))) ``` This corresponds, more or less, to the approaches given in the question (with the exception of `assoc` instead of `assq`). The idiom, if it can be called that, is to compose simpler components into an expressive language tailored to the problem domain. The list accessor functions `assoc`, `assq`, `nth`, `car`, etc., are building blocks. As a developer, defining a function such as `ledger-context-field-value` may carry more meaning for users than `(cadadr (cdaddr .. ))`. To wit, which do you prefer, ``` (ledger-context-field-value (ledger-context-at-point) 'account) ;; vs (cadadr (cdaddr (ledger-context-at-point))) ``` The `ledger` developers have decided the former to be the "conventional" way to get at the list elements like these. You can decide which you prefer (or find another). If you encounter an unusual data structure, search for accessors defined elsewhere. There may not be a clear reason *why* data is the way it is, but such accessors can give you confidence in *how* to use it. --- Tags: list ---
thread-62150
https://emacs.stackexchange.com/questions/62150
How to write a portion of text from current file to the beginning of another file?
2020-12-07T14:22:54.507
# Question Title: How to write a portion of text from current file to the beginning of another file? I have written a function that extracts a portion of text from current file and writes it in another one: ``` (defun foobar () (interactive) ;; re-search "beg" point ;; re-search "end" point ;; define markers (let* ((beg (copy-marker ...)) (end (copy-marker ...))) (write-region beg end filename t))) ``` Now I would like that all the text between `beg` and `end` is added at the beginning of `filename`. How can I do this? # Answer > 1 votes The doc string of `write-region` says: > Optional fourth argument APPEND if non-nil means append to existing file contents (if any). If it is a number, seek to that offset in the file before writing. So call it like this: ``` (write-region beg end filename 0) ``` but as you found out that overwrites the beginning of the file with the contents of the region. To *insert* the contents of the region, you can do something like this: ``` ... (let ((s (buffer-substring beg end))) (with-current-buffer (find-file-noselect filename) (goto-char (point-min)) (insert s) (save-buffer))) ``` --- Tags: files, region ---
thread-62153
https://emacs.stackexchange.com/questions/62153
Is there a way to call M-x my-org-babel-block?
2020-12-07T16:09:13.640
# Question Title: Is there a way to call M-x my-org-babel-block? I have a named org-babel source block like this: ``` #+NAME: my-org-babel-block #+BEGIN_SRC elisp :results output (print org-babel-load-languages) #+END_SRC ``` **Is there any way to call this block with `M-x my-org-babel-block`?** # Answer No, but you can do something like this: ``` #+begin_src emacs-lisp (defun my-org-babel-block () (interactive) (org-sbe "my-org-babel-block")) #+end_src ``` defining a *command* (i.e. a function with an `interactive` spec) that executes the block with the given name. You can now call the command with `M-x my-org-babel-block` which will use `org-sbe` to execute the block. The doc string of `org-sbe` (which you can get with `C-h f org-sbe RET`) says in part: > org-sbe is a Lisp macro in ‘ob-table.el’. > > (org-sbe SOURCE-BLOCK &rest VARIABLES) > > Return the results of calling SOURCE-BLOCK with VARIABLES. > > Each element of VARIABLES should be a list of two elements: the first element is the name of the variable and second element is a string of its value. > 1 votes --- Tags: org-mode, org-babel ---
thread-62158
https://emacs.stackexchange.com/questions/62158
org-babel: define commands for all named source blocks in given set of files
2020-12-07T22:42:46.193
# Question Title: org-babel: define commands for all named source blocks in given set of files This answer shows how to define a command that executes a named org-babel source block. If you want to do this for all named source blocks in a file, you could define one command per block. That's cumbersome. **I'm looking for a function that defines commands for *all* named blocks in a given set of files**. * the function should be placed in `init.el` to define commands for all named source blocks in a set of files * the command names should prefix something like 'my-org-babel-' to all block names * in case of duplicate block names, the latest one encountered can be retained # Answer Here is some code to do almost (but not quite) everything you want. The following two functions are to be added to your init file: ``` (defun my-org-babel-make-func (name) "Construct a string defining the function, then parse the string into a Lisp s-expression and eval that to actually define the function." (let ((s (format "(defun my-org-babel-%s () (interactive) (org-sbe \"%s\"))" name name))) (eval (read s)))) (defun my-org-babel-function-maker(filename) "Map the form over all the code blocks in the file. The form gets the name of the block and if non-nil, calls the make-func function to define the function for that name." (org-babel-map-src-blocks filename (let ((name (plist-get (cadr (org-element-at-point)) :name))) (when name (my-org-babel-make-func name)))) nil) ``` I hope the comments are enough to convey what the functions are doing. Then if you have an Org mode file `foo.org` with named code blocks like this: ``` * foo #+name: hello #+begin_src emacs-lisp "Hello" #+end_src #+name: good-bye #+begin_src emacs-lisp "Good Bye" #+end_src ``` you can execute `(my-org-babel-function-maker "foo.org")` and then you should have commands `my-org-babel-hello` and `my-org-babel-good-bye` that you can execute with `M-x my-org-babel-hello` or `M-x my-org-babel-good-bye`. If you want this to be done when you open the file you can use a file local variables block to execute the function maker when the file is opened: ``` ... named code blocks as above ... * COMMENT Local variables # Local variables: # eval: (my-org-babel-function-maker (buffer-file-name)) # End: ``` Caveats: * no error checking * blocks with duplicate names are not handled the way you want: `org-sbe` will execute the named code block - if there is more than one code block with that name, it will run whichever one *it* wants: which one that is depends on the implementation of `org-sbe` and is outside the scope of this answer. I would suggest you avoid blocks with the same name in the file. * it would be nice if these functions were defined locally for this file only, but that's not the way it works: functions are global in scope in Emacs Lisp, so `my-org-babel-hello` will exist everywhere. If you execute it in a different file that has a code block named `hello`, it will happily run that code block; and if there is no such code block, it will complain. > 2 votes --- Tags: org-mode, org-babel ---
thread-62165
https://emacs.stackexchange.com/questions/62165
Any way to invoke vim from within an org file and on closing vim, the result is copied back at parent org file cursor?
2020-12-08T16:07:28.100
# Question Title: Any way to invoke vim from within an org file and on closing vim, the result is copied back at parent org file cursor? This is a specific use case and I understand that not a lot of folks will have use (or prefer) this. But I'd still like to understand whether this is possible. While editing an org file, I want to open a temp file in my vim (with my plugins as I would from a terminal) and by the end of the edit, on close, I want to get the contents of the file into the org file at the cursor. Deleting the temp file would be a plus but not really needed. Maybe I can reuse the same file again. This is what I have tried: ``` (defun vim-insert-here () (interactive) (shell-command (format "gvim temp")) (insert-file-contents "temp")) ``` This works well enough for simply copying the contents. But I need help adding functionality such as: * Not inserting the vim file text when vim is exited with `q!` * Selecting an existing piece of text in the org file and opening that in vim, and the resulting changes are overwritten in the org file # Answer `suspend-emacs` works for me using Emacs inside a terminal (it does not work for GUI Emacs on macOS), e.g., here a simple example ``` (defun foo () (interactive) (suspend-emacs "vim /tmp/x; fg") (insert-file-contents "/tmp/x")) ``` the following tries to do what yout want, (1. use the contents of the region as initial text; 2. replace the region with new text; 3. delete the temp file) ``` (defun bar (beg end) (interactive "*r") (let ((tmpfile (make-temp-file ""))) (write-region beg end tmpfile) (suspend-emacs (format "vim %s; fg" (shell-quote-argument tmpfile))) (goto-char beg) (delete-region beg end) (insert-file-contents tmpfile) (delete-file tmpfile))) ``` > 1 votes --- Tags: org-mode ---
thread-9621
https://emacs.stackexchange.com/questions/9621
How to find what causes ESS to run very slow?
2015-02-26T22:31:26.807
# Question Title: How to find what causes ESS to run very slow? When working with an iESS session of R and an R file open side-by-side, I noticed extremely slow performance when typing indetifiers. Typing braces and operators is fine, however, when an identifier is typed, there is very significant input lag (typed letters are appearing several second late). During this period, the the status of the iESS buffer flashes between `run` and `no process`. This happens most often when I am typing inside a function argument list and with a subordinate R process that consumes a sizeable chunk of memory (around 3G, a couple of big data frames and sparse matrices). I have disabled `eldoc-mode` and `company-mode`, but ESS still seems to do something to the background R process synchronously. *What causes this? How can I profile ESS to find out how it spends time communicating with R?* I tried `profiler-start` and its friends, which show that Emacs spends 45% of its time in `term-emulate-terminal` (I ran `htop` in an ansi-term buffer to see the CPU usage of emacs and R) and 16% in the Automatic GC. That's hardly suspicious. I guess the time spent waiting for the subordinate process is considered idle time by the profiler. # Answer > 2 votes I know this is 5, almost 6, years late. The last response is from January of this year though. There's been a recent development that might solve the issue for people in the future. It turns out that the contextual help at the bottom in the minibuffer that appears when you're getting autocomplete is massively inefficient. This seems to be an isolated issue when `company-mode` is on. The current "fix" is a flag someone put into a very recent version of ESS. You can enable it by setting `(setq ess-r--no-company-meta t)`. You'll still get completion from `company-mode`. The only difference is that the sometimes helpful, sometimes not, line in the minibuffer that will say `plot(x, y, main="", etc., ...)` will not appear. See the discussion on GitHub. # Answer > 1 votes Try turning off these: ``` (setq ess-use-flymake nil) (setq ess-eval-visibly-p nil) ``` Flymake is on by default. Turning it off can speed things up. Also long lines in ess-eval-visibly-p can slow or stall emacs. --- Tags: performance, ess, r ---
thread-61370
https://emacs.stackexchange.com/questions/61370
Prevent ESS from opening an R console
2020-10-22T14:47:59.573
# Question Title: Prevent ESS from opening an R console Say I want to create and edit a new R file using emacs/ESS. I type `emacs myfile.R` at my shell prompt and an empty file opens. Hurray! I start typing my code: `library(da` at which point I am interrupted and prompted with, `R starting project directory? ~/Desktop/` I think I have two options: 1) `Ctrl+g` to ignore the prompt and keep on working or 2) specify a project directory. If I do the former, I will keep getting the same prompt until I specify a project directory. If I specify a project directory, an R console will automatically open. The problem is that I don't *want* an R console: I just want to create and edit an R file using ESS so that I have syntax highlighting. **Q:** Is there a way to prevent the R console from opening? # Answer This is happening because `ESS` uses an active `R` process to find completion targets. If you customize the variable `ess-use-R-completion` to the value `nil`, you won't be prompted to start an R process anymore. You also won't get tab completion of variable names, function arguments, etc. > 1 votes # Answer It was recently discovered that this is actually being caused by the search for the signature hints in the minibuffer, not the completion itself. You can disable the hint in the minibuffer and keep completion by running: ``` (setq ess-r--no-company-meta t) ``` This was only recently "fixed" about 20 days ago. This is just a temporary stopgap, hopefully. It seems actually solving the problem is a bit more involved. See the discussion here for more details. > 0 votes --- Tags: ess ---
thread-54220
https://emacs.stackexchange.com/questions/54220
Company-mode slow in ESS
2019-12-07T12:50:43.680
# Question Title: Company-mode slow in ESS When using (i)ESS, I would like to function/variable/argument/filename completion on demand using the minibuffer, without triggering the company pseudotooltip front end. I have tried the following: ``` (setq company-begin-commands nil) company-idle-delay nil) ``` This seems to work fine for all sorts of completion. Except, that when I call a function that has a lot of arguments, emacs becomes very unresponsive. For example, if I type: ``` print( ``` and press `TAB` after the parenthesis, the minibuffer will show, but typing will become nearly impossible (i.e. delay of 2 or 3 seconds between each typed character). Even if I disable `company-mode` the completion is sluggish so I wonder if this is an issue of ESS? How to solve this? # Answer > 1 votes There's been a recent development that might solve the issue for people in the future. It turns out that the contextual help at the bottom in the minibuffer that appears when you're getting autocomplete is massively inefficient. This seems to be an isolated issue when `company-mode` is on. The current "fix" is a flag someone put into a very recent version of ESS. You can enable it by setting `(setq ess-r--no-company-meta t)`. You'll still get completion from `company-mode`. The only difference is that the sometimes helpful, sometimes not, line in the minibuffer that will say `plot(x, y, main="", etc., ...)` will not appear. See the discussion on GitHub. --- Tags: company-mode, ess ---
thread-62130
https://emacs.stackexchange.com/questions/62130
How to prevent M-x package-install from editing my ~/.emacs file?
2020-12-06T05:01:58.707
# Question Title: How to prevent M-x package-install from editing my ~/.emacs file? When I install packages with `M-x package-install`, it edits the `~/.emacs` file and adds the following content: ``` (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 '(paredit slime))) (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. ) ``` Is there a way to prevent `package-install` from editing my `~/.emacs` file. I write `~/.emacs` by hand and keep it neat, so it is quite disconcerting when `package-install` inserts this big blob of code in between. If `package-install` really needs to maintain this code somewhere, can I not make it put this code in another file that I can load into `~/.emacs`? # Answer I think you are looking that: ``` (setq custom-file (concat user-emacs-directory "custom.el")) (when (file-exists-p custom-file) (load custom-file)) ``` Another way to get rid of the customization discussed here: https://www.reddit.com/r/emacs/comments/9rrhy8/emacsers\_with\_beautiful\_initel\_files\_what\_about/ > 3 votes # Answer If you have a file named `custom-file`, which you load from your init file, then Customize will save such customizations in that file. I recommend doing that, to keep your hand-written Emacs-Lisp code separate (in your init file) from the file that Customize uses to write the code it uses to save your customizations. I'm assuming that `package-install` does the same as Customize - it uses the file that's the value of variable `custom-file`, not your init file. But I don't know that for a fact. I don't see that mentioned in the doc string or in the manual. If it doesn't then maybe it would be good to send an enhancement request for that: `M-x report-emacs-bug`. Really, there's no good reason that either the package system or Customize should fiddle with your init file. That's what `custom-file` is for: to tell Customize "Hands off my init file!" > 1 votes # Answer `custom-file` is all you need, as the other answers say, but you might also be interested in a more general approach. You can "split" your customizations into as many files as you like, not just the one named by `custom-file`, if you use the package `initsplit`, available on MELPA. From the package description: > This file allows you to split Emacs customizations (set via M-x customize) into different files, based on the names of the variables. It uses a regexp to match against each face and variable name, and associates with a file that the variable should be stored in. It is then up to you to load each file, as in the answer @kadircancetin gave. While the description mentions only `M-x customize`, the splitting takes place automatically whenever *any* customization is saved, including when `package-install` saves `package-selected-packages`. > 0 votes --- Tags: init-file, customize, custom-file ---
thread-61082
https://emacs.stackexchange.com/questions/61082
How can I enable lsp-headerline-breadcrumb-mode in lsp-mode?
2020-10-09T07:13:47.510
# Question Title: How can I enable lsp-headerline-breadcrumb-mode in lsp-mode? I would like to enable lsp-headerline-breadcrumb-mode in every buffer where lsp-mode is active. I'd know how to do it for every mode, for example ``` (use-package go-mode :ensure t :config (add-hook 'go-mode-hook (lambda () ;; other stuff (lsp-headerline-breadcrumb-mode t) ) ) ) ``` But I fail to do it for every buffer with `lsp-mode` ... With this, lsp-mode doesn't work at all: ``` (use-package lsp-mode :ensure t :commands (lsp lsp-deferred) :hook (go-mode . lsp-deferred) (python-mode . (lambda () (require 'lsp-python-ms) (lsp-deferred))) :config (setq lsp-diagnostic-package :auto ;; stuff deleted lsp-print-performance nil ) (add-hook 'lsp-mode-hook (lambda () ((lsp-headerline-breadcrumb-mode t)) ) ) ) ``` # Answer There is a variable you can customize that automatically enables the headerline breadcrumb mode whenever `lsp-mode` is active. Try something like: ``` (use-package lsp-mode :custom (lsp-headerline-breadcrumb-enable t)) ``` > 2 votes # Answer The following snippet works for me, it enables breadcrumbs in all modes where `lsp` is active. ``` (require 'package) (setq package-user-dir (expand-file-name "~/.emacs.d/elpa/") package-enable-at-startup nil) (add-to-list 'package-archives '("melpa" . "https://melpa.org/packages/") t) (package-initialize) (unless (package-installed-p 'use-package) (package-refresh-contents) (package-install 'use-package)) (eval-when-compile (require 'use-package)) (add-hook 'c++-mode-hook #'lsp) (add-hook 'python-mode-hook #'lsp) (use-package lsp-mode :ensure t :commands (lsp lsp-deferred) :hook ((lsp-mode . lsp-enable-which-key-integration) (lsp-managed-mode . lsp-modeline-diagnostics-mode) (lsp-mode . lsp-headerline-breadcrumb-mode) (lsp-mode . lsp-modeline-code-actions-mode))) ``` Here I have only included `c++-mode` and `python-mode`. I usually prefer to enable `lsp` from the corresponding major mode `use-package` declarations. > 1 votes --- Tags: lsp-mode ---
thread-44244
https://emacs.stackexchange.com/questions/44244
Assign TAB in markdown mode
2018-08-22T05:16:04.410
# Question Title: Assign TAB in markdown mode Running emacs 25.2.2, general, evil and markdown-mode installed from MELPA. The problem is when I hit `TAB` on a heading in a markdown file, it does not cycle visibility of content. `C-h k TAB` shows it is assigned to `evil-jump-forward`. So, in my `init.el`, I added: ``` (general-def 'markdown-mode-map "TAB" 'markdown-cycle) ``` But still `TAB` is assigned to `evil-jump-forward`. How do I assign `TAB` to `markdown-cycle` in `markdown-mode`? Moreover, can I assign it such that only when the cursor is on a heading, it is assigned to `markdown-cycle` but at other locations, it is assigned to `evil-jump-forward`? # Answer I've been looking into this as well. The reason your attempt isn't working, is because of `evil` and the way it binds keys to a higher level keymap (as far as I understand the matter). Anyways, you can bind directly to the corresponding `evil` state you want to use the key in. The following should do the trick: ``` (evil-define-key 'normal markdown-mode-map (kbd "<tab>") 'markdown-cycle) ``` (You might need to hit `tab` twice if there are no subheadings.) The package `evil-markdown` provides much more complete integration with `evil`. Not on MELPA, unfortunately, so you'll have to install it manually. Check it out on https://github.com/Somelauw/evil-markdown. > 1 votes # Answer Supporting the previous answer, I think `<tab>` needs to be replaced with `TAB`. For me, snippet in above answer didn't work but the following snippet worked: ``` (evil-define-key 'normal markdown-mode-map (kbd "TAB") 'markdown-cycle) ``` All the change is that I have used `TAB` instead of `<tab>`. > 0 votes --- Tags: key-bindings, evil, markdown, markdown-mode ---
thread-55889
https://emacs.stackexchange.com/questions/55889
Passing arguments to dap-mode (c++)
2020-03-03T14:48:46.297
# Question Title: Passing arguments to dap-mode (c++) everyone. I am new to debugging with dap-mode and i can't figure out how to pass arguments. I tried by creating a template ``` (dap-register-debug-template "GDB::Mine" (list :type "gdb" :request "launch" :args "/home/george/Documents/Repos/pop/encoder/OBJs/Buddha.obj" :name "GDB::Mine" :target nil :program "/home/george/Documents/Repos/pop/encoder/build/addon" :cwd "/home/george/Documents/Repos/pop/encoder/")) ``` but it doesn't work. It gives me ``` No source file named /home/george/Documents/Repos/olive/app/main.cpp. Program exited with code 0377 undefinedPlease give path to .obj file. ``` I actually don't know why it tells that there isn't an olive/app/main.cpp file since that's not the project i'm trying to debug. What am i supposed to do? # Answer Arguments are specified with `:arguments` instead of `:args` like the VSCode configuration. Reference: https://github.com/emacs-lsp/dap-mode/issues/247 > 1 votes --- Tags: debugging, c++ ---
thread-62186
https://emacs.stackexchange.com/questions/62186
Can Emacs be set to auto-stage (preferably with --intent-to-add) new files?
2020-12-09T10:02:19.093
# Question Title: Can Emacs be set to auto-stage (preferably with --intent-to-add) new files? I often add a new file to a repo, make some other changes, then stage all, and commit all, forgetting that the new file is not yet tracked, so is not included in the stage all step. At least one editor (IntelliJ) has an option to auto-stage new files, which would be very helpful to me in Emacs. I guess this would be particularly helpful if it invoked --intent-to-add. Is this feature present in magit or built-in in Emacs? If not, I'd be interested in writing some elisp. Is there a hook run when magit sees a new untracked file, or would I have to add to the after-save-hook and query the git status? # Answer Magit does not implement this and as far as I know VC/Emacs does not do so either. Magit also does not provide a hook that is run "when it sees a new untracked" file but you could use `find-file-hook`, which is run when *you* see a untracked file. ;D You probably want to use `magit-file-tracked-p` in your hook function. > 0 votes --- Tags: magit, git, vc ---
thread-60957
https://emacs.stackexchange.com/questions/60957
Separate Bibliography from Last Heading
2020-10-02T17:19:35.487
# Question Title: Separate Bibliography from Last Heading I'm trying to use org-ref and I'm doing pretty well. There is one thing bothering me, though. The bibliography gets attached to the last heading (in the org file), where-as I would like it to be separate. ``` #+TITLE: Title #+LATEX_HEADER: \usepackage{natbib} * Section 1 * Section 2 ** Subsection 2.1 ** Subsection 2.2 # Maybe add a * Bibliography heading here? But how to hide it? bibliographystyle:unsrt # These get attached to subsection 2.2 bibliography:project.bib ``` Thank you in advance for your answers. # Answer That bothered me too. My solution was to add `#+LATEX_HEADER: \renewcommand{\bibsection}{}` and keep those `bibliography:` and `bibliographystyle:` links under a References (or whatever you like) heading. So, you are not hiding the heading in .org, but the one that is generated by the link, in order to avoid a duplicate. So, in your case you can do: ``` #+TITLE: Title #+LATEX_HEADER: \usepackage{natbib} #+LATEX_HEADER: \renewcommand{\bibsection}{} * Section 1 * Section 2 ** Subsection 2.1 ** Subsection 2.2 * Bibliography bibliographystyle:unsrt bibliography:project.bib ``` > 1 votes --- Tags: org-mode, org-ref ---
thread-62196
https://emacs.stackexchange.com/questions/62196
How to find all lines in a buffer that match string 1 but do not match string 2?
2020-12-10T01:17:44.063
# Question Title: How to find all lines in a buffer that match string 1 but do not match string 2? I have a build log file that includes information on issues reported by clang-tidy. Each of the lines in the log file that reference an issue identified by clang-tidy contain the string "warning G". The problem is that the vast majority of the issues are not in my code and most of those that are not in my code are in Boost. Each of the lines in the log file that reference an issue identified by clang-tidy in Boost also contain the string "\include\boost/". So what I need is a way to list all the lines in the buffer that contain the string "warning G" and do not contain the string "\include\boost/". Occur gets me half way there, it allows me to list all lines that match "warning G" but I do not know how to filter out the lines that match "\include\boost/". # Answer You can use `M-x` `flush-lines` in the occur buffer to perform the second half. You may have to toggle the read-only state first. > 1 votes --- Tags: occur ---
thread-62192
https://emacs.stackexchange.com/questions/62192
Emacs not indenting enum / enum class contents
2020-12-09T18:41:05.733
# Question Title: Emacs not indenting enum / enum class contents I've got a small problem to do with Doom Emacs / Emacs. Enum contents are not indented at all... Here's what I would like: ``` enum class RandomEnum { A, B, C, D }; ``` Here's what I get: ``` enum class RandomEnum { A, B, C, D }; ``` How can I go about fixing this? I'm sure that there a simple option I can put in my config? Thank you in advance. # Answer > 1 votes Emacs comes with some preconfigured C/C++ Styles. You can change the indentation style of the current buffer with `C-c .` When you have chosen a style and only want to temporary/test adjust a few offsets `C-c C-o` helps. Emacs indentation styles can be modified very fine grained. You can also set a default style by changing the alist `c-default-style` --- Given the above information, the elisp code following will set the indentation style "stroustrup" as default style for c++ source code. Then it modifies this style to give the indentation for your example: ``` (defun change-c-style (c-style-name option-section add-options) "function to easily change a predefined indentation style." (let ((tmp (assoc option-section (assoc c-style-name c-style-alist)))) (when tmp (setf (cdr tmp) (append (cdr tmp) add-options)))) ) (require 'cc-mode) ;; load up c++-mode environment (push '(c++-mode . "stroustrup") c-default-style) ;; make "stroustrup" the default style for c++ files (change-c-style "stroustrup" 'c-offsets-alist '((brace-list-open . 0) (brace-list-intro . ++))) ;; modify the "stroustrup" style with above defined function ``` Evaling above elisp code and then opening a c++-file will give you the wanted indentation by pressing `tab` Above code is meant as a working example, because your question did not deliver enough information about your current environment. --- Tags: indentation, c++, c, doom ---
thread-62202
https://emacs.stackexchange.com/questions/62202
Context-aware username (e.g., git username instead of login name) in time-stamp
2020-12-10T12:54:12.900
# Question Title: Context-aware username (e.g., git username instead of login name) in time-stamp I am a total emacs/elisp newbie and I can't figure out how to do this. * I have `time-stamp-active t` with a pretty standard format: `time-stamp-format "Last modified %Y-%02m-%02d %02H:%02M:%02S MyUser")`. * I have different git repos where I use other nicknames. How can I write a function which checks if the file-in-buffer belongs to a git repository, if yes, substitute 'MyUser' with the local git user name, and if not revert to the default? I googled around and I did not find anything useful to me... # Answer > 1 votes You can configure *per-repo* options following this magit manual page, but what you want is just git. Then if you want to get your configured `user.name` or `user.email` from your elisp code, this should work: ``` (shell-command-to-string "git config user.name") ``` Note that you're launching a short-living process for each call to obtain a parameter that probably you can call once and keep. --- Tags: magit ---
thread-61997
https://emacs.stackexchange.com/questions/61997
How do I fix "incomprehensible buffer" error when running list-packages?
2020-11-29T11:33:34.117
# Question Title: How do I fix "incomprehensible buffer" error when running list-packages? When running list-packages in emacs on an up-to-date Debian Buster (10.6) I get the following error: `error in process sentinel: Error retrieving: https://stable.melpa.org/packages/archive-contents "incomprehensible buffer"` The exact version of the emacs package is 1:26.1+1-3.2+deb10u1. When using wget on that URL and looking at the downloaded file it looks like a valid e-lisp data structure to me. This has been working in the past and works fine in the MacPorts emacs package version 27.1\_5. # Answer I had the same problem. Solved it by adding the following to `init.el` ``` (setq gnutls-algorithm-priority "NORMAL:-VERS-TLS1.3") ``` > 14 votes --- Tags: package-repositories ---
thread-62209
https://emacs.stackexchange.com/questions/62209
Switch desktops hotkey on Windows is not ignored by Emacs
2020-12-10T21:59:14.807
# Question Title: Switch desktops hotkey on Windows is not ignored by Emacs The following keys: * `Ctrl-Win-Left` * `Ctrl-Win-Right` are used to switch desktops on Windows. If Emacs is the active window when you use either of these keys, you get the following in the minibuffer: If you're using `emacsclient`, you may also have the taskbar icon flashing until you switch to that window: One approach that seems to work to resolve this is adding the following to the init file: ``` (if (eq system-type 'windows-nt) (global-set-key (kbd "<C-lwindow>") 'ignore)) ``` Is that the recommended approach for resolving this? Is this issue considered a bug for Emacs on Windows? Should the above ignore-behaviour be the default? # Answer > 1 votes Do you see this if you start Emacs using `emacs -Q` (no init file)? (I don't.) If not, bisect your init file to find the culprit. With `emacs -Q` on MS Windows 10, `Control`+`Alt`+`->` (right arrow) is `<C-M-right>`, and it can be bound or unbound normally. It's bound by default to command `forward-sexp`. And with `emacs -Q`, `<C-lwindow>` is available and unbound by default. --- **UPDATED after your edit:** Try putting this in your init file: ``` (w32-register-hot-key (kbd "<C-lwindow>")) (w32-register-hot-key (kbd "<C-rwindow>")) ``` Or maybe something like this (see doc below), to be able to bind only the left window key for Emacs: ``` (setq w32-lwindow-modifier 'super) (register-hot-key [s-]) ``` `C-h f w32-register-hot-key` tells us: > **`w32-register-hot-key`** is a built-in function in ‘C source code’. > > `(w32-register-hot-key KEY)` > > Register `KEY` as a hot-key combination. > > Certain key combinations like `Alt-Tab` and `Win-R` are reserved for system use on Windows, and therefore are normally intercepted by the system. These key combinations can be received by registering them as hot-keys, except for `Win-L` which always locks the computer. > > On Windows 98 and ME, `KEY` must be a one element key definition in vector form that would be acceptable to `define-key` (e.g. `[A-tab]` for `Alt-Tab`). The meta modifier is interpreted as `Alt` if `w32-alt-is-meta` is `t`, and `hyper` is always interpreted as the Windows modifier keys. The return value is the hotkey-id if registered, otherwise `nil`. > > On Windows versions since NT, `KEY` can also be specified as `[M-]`, `[s-]` or `[h-]` to indicate that all combinations of that key should be processed by Emacs instead of the operating system. The `super` and `hyper` modifiers are interpreted according to the current values of `w32-lwindow-modifier` and `w32-rwindow-modifier`. For instance, setting `w32-lwindow-modifier` to `super` and then calling `(register-hot-key [s-])` grabs all combinations of the left Windows key to Emacs, but leaves the right Windows key free for the operating system keyboard shortcuts. The return value is `t` if the call affected any key combinations, otherwise `nil`. --- Tags: key-bindings, microsoft-windows ---
thread-16822
https://emacs.stackexchange.com/questions/16822
How can I use the PROPERTIES drawer with a TAGS property and asign multiple values to it
2015-09-21T22:50:15.903
# Question Title: How can I use the PROPERTIES drawer with a TAGS property and asign multiple values to it In org-mode long header line and multiple tags sometimes makes the overview unreadable. *My question is:* Can I use the `TAGS` property in the `PROPERTIES` drawer to list tags as values rather then having them in the header line. Alternatively but less desirable assign multiple `custom_ids` or equivalent, with a list of values. The goal is to hide the tags from the overview but still have them searchable. What I have tried: I was naively thinking that the tags property could substitute the header line tags and to list tags here instead. The result of using `C-c C-x p` and trying to input TAGS value pair results in an error `org-entry-put: The TAGS property cannot be set with`org-entry-put'\`. Manually trying to input a TAGS entry with a value works but the tag is not searchable by the two methods I tried, `C-c /` and `C-c \ p`. # Answer > 4 votes After your comment below, I did some experimentation. I am guessing, after you move all the tags to the `TAGS` property, you are expecting to continue to use the normal tag related interfaces to continue working. This does not look possible. The tags are provided as properties in the property API, but that does not mean they are like real properties. They are a bit "special". In short: I do not think what you are looking for is possible. That said, I believe there is a workaround that will get you half-way. You could use a custom property, and use the `:prop+:` syntax to add to the property value to represent multiple tags. It might get very clumsy if you have too many values for each headline. You will of course lose all the normal tag related conveniencs, except for inheritance, which is still possible. ``` * Headline :PROPERTIES: :MYTAGS: tag1 :MYTAGS+: tag2 :MYTAGS+: tag3 :END: This headline has the tags: tag1, tag2, tag3 ** Sub-headline :PROPERTIES: :MYTAGS+: tag4 :END: This one inherits all the above, and adds tag4 ``` Essentially this way you will be using a custom property as a tag, just for yourself. That said, I don't think this is worth it, if not having them on the headline is just a matter of aesthetics for you. Tags are rather deep-seated in how Org works. Many important functionality like: export, filtering, search, sparse tree uses it heavily. You will have to miss out on all that. # Answer > 1 votes Try `*-multivalued-property` in org mode Property API. More here. --- Tags: org-mode, header-line, org-tags ---
thread-62207
https://emacs.stackexchange.com/questions/62207
Is it possible to ignore paste operation during `C-x C-x` to jump back?
2020-12-10T19:58:05.650
# Question Title: Is it possible to ignore paste operation during `C-x C-x` to jump back? This question is related to Is it possible to bind `C-u C-x C-x`s behavior into `C-x C-x`. My main goal is to jump top of the file, type `import` and paste a package name and jump back where I was. **Scenario:** I am on the line 10 and copied a word. Than I press `M-<`to jump top of the file, move down to line 1 and typed `import` and pasted the copied word. Now when I press `C-x C-x`, it jumps to the starting point of the pasted word and if I press again it jumps to end of the paster word in the line 1. ``` 0 | <= jumped here and go one line below 1 | import hello_world # (2) type import and 2 | paste hello_world \ 3 | | 4 | | 5 | | 6 | | 7 | | 8 | | 9 | | 10 hello_world() # (1)cursor is here | <= (3) I want to jump back here <-------- ``` At this point, I just want to jump pack to point where I was (which is line 10), how can I acheive it? # Answer > 4 votes Each command that sets the mark pushes the previous mark onto a stack. More precisely, the previous position is added to the mark ring (the difference between a mark and a ring is that accessing the front of the ring doesn't remove the element, but pushes it to the other side of the ring). To get to the next-to-last position, use `C-1 C-SPC` or `C-u C-SPC`. Repeat to get to the previous position, etc. Or use directly `C-2 C-SPC` to go two positions back, and so on. `C-SPC` (`set-mark-command`) is the command to set the mark, but with a numeric argument or a `C-u` prefix, it jumps back to a previous mark instead of setting the mark. In your case, both `M-<` and pasting set a mark, so you want to go two marks back, hence `C-2 C-SPC` or `C-u C-SPC C-u C-SPC`. If Emacs is running in a terminal, you may need to use `C-u 2` or `M-2` or `ESC 2` instead of `C-2`. # Answer > 3 votes As you're not going to use the region between point and mark, consider another approach using `save-excursion`, like this one: ``` (defun auto-import-word-at-point() "Autoimport word at point." (interactive) (let ((word-at-point (thing-at-point 'word))) (save-excursion (goto-line 2) (insert (concat "import " word-at-point)) (newline)))) ``` It will copy the thing at point, goto line 2, insert it there and restore things. Bind to whatever you want and it's ready to go, `thing-at-point` is just a way to obtain data, but can use anything else that you may prefer. `thing-at-point` will automagically get the specified kind of thing around point; as `save-excursion` will save point, it'll return to it after executing its body, but saved point may not be the end of word, so you may want to `forward-word` (`M-f`) which was left out for clarity. --- Tags: key-bindings, motion ---
thread-61415
https://emacs.stackexchange.com/questions/61415
How can I stop iso-transl running
2020-10-25T15:12:22.877
# Question Title: How can I stop iso-transl running I have run the macport emacs 27 on macOS. The bindings of my keys as as per mac-keys-mode (and aquamacs) and have Command key acting as alt. Thus all my key bindings are A-key This normally works. However (iso-transl-ctl-x-8-map) copies the ctl-x-8-map into alt key bindings thus wiping out my bindings. How do I stop iso-transl being run. On the latest time this happend the debug stack shows ``` Debugger entered--entering a function: * iso-transl-define-keys((("* " . [160]) (" " . [160]) ("*!" . [161]) ("!" . [161]) ("\"\"" . [168]) ("\"A" . [196]) ("\"E" . [203]) ("\"I" . [207]) ("\"O" . [214]) ("\"U" . [220]) ("\"a" . [228]) ("\"e" . [235]) ("\"i" . [239]) ("\"o" . [246]) ("\"s" . [223]) ("\"u" . [252]) ("\"y" . [255]) ("''" . [180]) ("'A" . [193]) ("'E" . [201]) ("'I" . [205]) ("'O" . [211]) ("'U" . [218]) ("'Y" . [221]) ("'a" . [225]) ("'e" . [233]) ("'i" . [237]) ("'o" . [243]) ("'u" . [250]) ("'y" . [253]) ("*$" . [164]) ("$" . [164]) ("*+" . [177]) ("+" . [177]) (",," . [184]) (",C" . [199]) (",c" . [231]) ("*-" . [173]) ("-" . [173]) ("*." . [183]) ("." . [183]) ("//" . [247]) ("/A" . [197]) ("/E" . [198]) ("/O" . [216]) ("/a" . [229]) ("/e" . [230]) ("/o" . [248]) ("1/2" . [189]) ("1/4" . [188]) ...)) byte-code("\301\10!\210\302\303!\207" [iso-transl-char-map iso-transl-define-keys provide iso-transl] 2) map-keymap(#f(compiled-function (key item) #<bytecode 0x1fe107d7ed09>) iso-transl-ctl-x-8-map) keymap-canonicalize(iso-transl-ctl-x-8-map) describe-buffer-bindings(#<buffer file-management.org> [24]) which-key--get-current-bindings([24]) which-key--get-bindings([24] nil nil) which-key--create-buffer-and-show([24]) which-key--update() ``` SO in this case which-key called describe-buffer-bindings but it could be something else. I do not need or want these extra key bindings # Answer I was using Aquamacs as my main emacs which uses Alt as the Apple command key (A PC keyboard has Alt written on that key). Aquamacs had found this or a similar problem and so had patched iso-transl.el to alther its behaviour - it made it a mode so could set or unset the Alt key bindings. A comment in Aquamacs source code gives more information > Note that C-h b will autoload this package, which is one reason why the more destructive key sequences (without C-x 8 prefix) are only defined in \`iso-transl-mode', and are thus reversible. So for more normal emacs Alt key bindings include these keys (which I think is wrong as they are an arbitrary list especially as you can change the keyboard mapping in the OS to other languages on the fly). For simplicity bind the Apple command key to hyper or super and don't bind anything to Alt. > 0 votes --- Tags: key-bindings, debugging ---
thread-62223
https://emacs.stackexchange.com/questions/62223
Org-mode set a global configuration variable for `#+OPTIONS: ^:{}`
2020-12-11T17:53:51.740
# Question Title: Org-mode set a global configuration variable for `#+OPTIONS: ^:{}` I add `#+OPTIONS: ^:{}` to all of my org-mode documents so `_` is not interpreted and displayed directly as a LaTeX subscript unless I use write `thing_{subscript}`. How do I set this globally in my emacs config? I can't find the variable in the documentation and this answer https://emacs.stackexchange.com/a/59135/16023 does not seem to work for me. Would love a link to the spot in the documentation that explains this as well. # Answer > 1 votes Check Export Settings in the manual for the variables corresponding to these in-file options. In this particular case, you will find: > ^ > > Toggle TeX-like syntax for sub- and superscripts. If you write ‘^:{}’, ‘a\_{b}’ is interpreted, but the simple ‘a\_b’ is left as it is (`org-export-with-sub-superscripts`). (emphasis added) So the variable you need to set is `org-export-with-sub-superscripts`. The doc string of the variable (`C-h v org-export-with-sub-superscripts`) says: > ... > > Still, ambiguity is possible. So when in doubt, use {} to enclose the sub/superscript. If you set this variable to the symbol ‘{}’, the braces are *required* in order to trigger interpretations as sub/superscript. This can be helpful in documents that need "\_" frequently in plain text. For display, the appropriate variable is `org-use-sub-superscripts`: it takes the same values as `org-export-with-sub-superscripts`. The doc string for `org-export-with-sub-superscripts` says: > If you want to control how Org displays those characters, see `org-use-sub-superscripts`. `org-export-with-sub-superscripts` used to be an alias for `org-use-sub-superscripts` in Org \<8.0, it is not anymore. So you can add the following to your init file: ``` (setq org-export-with-sub-superscripts '{}) (setq org-use-sub-superscripts '{}) ``` to enable the feature globally both for display and for export. As the OP points out in a comment, the doc for `org-use-sub-superscripts` is in the Subscripts and Superscripts section of the manual. --- Tags: org-mode ---
thread-62222
https://emacs.stackexchange.com/questions/62222
How do I stop Prolog mode from jumping to the Prolog REPL when consulting the buffer?
2020-12-11T16:53:13.660
# Question Title: How do I stop Prolog mode from jumping to the Prolog REPL when consulting the buffer? Suppose I am using Prolog mode with the Prolog REPL started as an inferior process using `Ctrl``c``Enter`. Whenever I "consult" (i.e. evaluate) the Prolog mode buffer using `Ctrl``c``Ctrl``b` (`(prolog-consult-buffer)`), I will end up in the Prolog REPL. Is there a way to prevent this? I want to stay in the source code when I "consult" the buffer; I don't want to go to the REPL. # Answer Unfortunately, it seems that this behavior is hardcoded into prolog.el. The function responsible for moving to the REPL is `prolog-goto-prolog-process-buffer`. For the moment, I will be adding this hack into `~/.emacs` as a stopgap solution: ``` (eval-after-load "prolog" (advice-add 'prolog-consult-buffer :around (lambda (f &rest args) (cl-letf (((symbol-function 'prolog-goto-prolog-process-buffer) (lambda () nil))) (apply f args))))) ``` This effectively disables the call to `prolog-goto-prolog-process-buffer` in `prolog-consult-buffer` by redefining `prolog-goto-prolog-process-buffer` to do nothing (`(lambda () nil)`) when it is used by `prolog-consult-buffer`. > 0 votes --- Tags: major-mode, repl ---
thread-62219
https://emacs.stackexchange.com/questions/62219
How do I get colour emoji to display in Emacs
2020-12-11T15:02:21.780
# Question Title: How do I get colour emoji to display in Emacs Emacs 27 gained support for Cairo for font rendering and this is supposed to let me render emojis but I can't find out how to make it work. I just about managed to set up some fontsets but the emoji which are made out of multiple characters don't work. Is it possible to make them work? # Answer > 5 votes You need to use a font with support for that. This is what I do: ``` (if (>= emacs-major-version 27) (set-fontset-font t '(#x1f000 . #x1faff) (font-spec :family "Noto Color Emoji"))) ``` # Answer > 4 votes Step 1 is to make sure that you have Cairo and Harfbuzz enabled. You can run this elisp and check the results to test this: ``` (featurep 'cairo) ; should evaluate to t (frame-parameter (selected-frame) 'font-backend) ; should be a list starting with ftcrhb ``` I'm not sure about Windows or MacOS support. I think for Windows, you possibly need `harfbuzz` as the font backend and for MacOS you don't get any choice and I think things may work automatically. Step 2 is to ensure you have a font which supports emoji, and that font is used for emoji by your fontset. I did this with an Emacs lisp function: ``` (defun init-my-font () (set-face-font 'default (font-spec :family "<your default font>" :size 10.3 :weight 'normal :width 'normal :slant 'normal)) (set-face-attribute 'default nil :height 103) ;; emoji font (set-fontset-font t 'symbol (font-spec :family "Noto Color Emoji" :size 10.3 :weight 'normal :width 'normal :slant 'normal)) ;; fallback font (set-fontset-font t nil (font-spec :family "DejaVu Sans Mono" :size 10.3 :weight 'normal :width 'normal :slant 'normal))) ``` If you use Emacs without a daemon, I think it is sufficient to call this function in your init file by writing `(init-my-font)`. But I use a daemon and it seems to require that you wait until you have a gui frame before setting up the fonts. I have this hook for that: ``` (add-hook 'server-after-make-frame-hook (let (done) (lambda () (unless done ;; still set done to true even if we hit a bug (otherwise we ;; can never open a frame to see the problem) (setq done t) (init-my-font))))) ``` Note that this snippet requires lexical scoping in your init file. This should cause some emoji to be displayed but not the “ligatures” made of multiple emoji, for example country flags, skin tone modifiers, or family emoji. To support them, we need to specify what the sequences start with, a regex for the rest of the sequence, and an instruction for how Emacs should figure out which glyphs to draw. For the instruction we use `font-shape-gstring`, which tells Emacs to ask the font how to combine things (but the problem is knowing how Emacs decides which font from the fontset to use. I'm not really sure but I think it picks the font for the first character.) This config catches some things that won't form ligatures however that isn't a problem—they just get shaped into multiple glyphs as they normally would. ``` (require 'cl) ;; setting up composition functions for emoji modifiers (dolist (items `(((? . ?) [".[-]+" 0 font-shape-gstring]) ((? . ?) [".[️‍⚧☠-]*" 0 font-shape-gstring]) (?⃣ ["[#*0-9]️⃣" 2 font-shape-gstring]) ;; TODO: I can't make keycap sequences work because I ;; think they're trying to shape with the wrong font. ,@(mapcar (lambda (range) (list range [".‍?[-]?[‍️♂♀]*️?" 0 font-shape-gstring])) (concatenate 'list "☝❤" '((?⛹ . ?✍) (? . ?) (? . ?) (? . ?) (? . ?) (? . ?) (? . ?) (? . ?) (? . ?) (? . ?) (? . ?) (? . ?) (? . ?) (? . ?) (? . ?) (? . ?))) ) (? [".‍?[-]?[‍⚕⚖✈❤️--]*" 0 font-shape-gstring]) ((? . ?) [".‍?[-]?[‍⚕⚖✈❤️--]*" 0 font-shape-gstring]) ,@(mapcar (lambda (str) (list (elt str 0) (vector str 0 'font-shape-gstring))) '("‍️" "‍⬛" "‍" "‍❄️" "️‍️" "‍" "‍")))) (set-char-table-range composition-function-table (car items) (list (cadr items)))) ``` Possibly, the above snippet will not survive StackExchange’s formatting, so here it is in base64 of UTF-8: ``` Ozsgc2V0dGluZyB1cCBjb21wb3NpdGlvbiBmdW5jdGlvbnMgZm9yIGVtb2ppIG1vZGlmaWVycwooZG9saXN0IChpdGVtcyBgKCgoP/Cfh6YgLiA/8J+HvykgWyIuW/Cfh6Yt8J+Hv10rIiAwIGZvbnQtc2hhcGUtZ3N0cmluZ10pCiAgICAgICAgICAgICAgICAgKCg/8J+PsyAuID/wn4+0KSBbIi5b77iP4oCN8J+MiOKap+KYoPOggKAt86CBv10qIiAwIGZvbnQtc2hhcGUtZ3N0cmluZ10pCiAgICAgICAgICAgICAgICAgKD/ig6MgWyJbIyowLTld77iP4oOjIiAyIGZvbnQtc2hhcGUtZ3N0cmluZ10pCiAgICAgICAgICAgICAgICAgOzsgVE9ETzogSSBjYW4ndCBtYWtlIGtleWNhcCBzZXF1ZW5jZXMgd29yayBiZWNhdXNlIEkKICAgICAgICAgICAgICAgICA7OyB0aGluayB0aGV5J3JlIHRyeWluZyB0byBzaGFwZSB3aXRoIHRoZSB3cm9uZyBmb250LgogICAgICAgICAgICAgICAgICxAKG1hcGNhciAobGFtYmRhIChyYW5nZSkgKGxpc3QgcmFuZ2UgWyIu4oCNP1vwn4+7LfCfj79dP1vigI3vuI/imYLimYBdKu+4jz8iIDAgZm9udC1zaGFwZS1nc3RyaW5nXSkpCiAgICAgICAgICAgICAgICAgICAgICAgICAgIChjb25jYXRlbmF0ZSAnbGlzdCAi4pid8J+OhfCfj4fwn5GC8J+Rg/Cfkabwn5Gn8J+RvPCfko/wn5KR8J+SqvCflbTwn5W18J+VuvCflpDwn5aV8J+WlvCfmYfwn5qj8J+bgPCfm4zwn6SP8J+knvCfpJ/wn6Sm8J+kvfCfpL7wn6W38J+mu/Cfka/inaQiCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAnKCg/4pu5IC4gP+KcjSkgKD/wn4+CIC4gP/Cfj4QpICg/8J+PiiAuID/wn4+MKSAoP/CfkYYgLiA/8J+RkCkKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgKD/wn5GrIC4gP/Cfka4pICg/8J+RsCAuID/wn5G4KSAoP/CfkoEgLiA/8J+ShykgKD/wn5mFIC4gP/CfmYcpICg/8J+ZiyAuID/wn5mPKQogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAoP/CfmrQgLiA/8J+atikgKD/wn6SYIC4gP/CfpJwpICg/8J+ksCAuID/wn6S5KSAoP/CfpLwgLiA/8J+kvikgKD/wn6a1IC4gP/CfprkpCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICg/8J+njSAuID/wn6ePKSAoP/Cfp5IgLiA/8J+nnykpKSApCiAgICAgICAgICAgICAgICAgKD/wn6eRIFsiLuKAjT9b8J+Puy3wn4+/XT9b4oCN4pqV4pqW4pyI4p2k77iP8J+MvvCfjbPwn4288J+OhPCfjpPwn46k8J+OqPCfj6vwn4+t8J+Rpi3wn5Gp8J+Si/Cfkrvwn5K88J+Up/CflKzwn5qA8J+akvCfpJ3wn6av8J+msC3wn6az8J+mvPCfpr3wn6eRXSoiIDAgZm9udC1zaGFwZS1nc3RyaW5nXSkKICAgICAgICAgICAgICAgICAoKD/wn5GoIC4gP/CfkakpIFsiLuKAjT9b8J+Puy3wn4+/XT9b4oCN4pqV4pqW4pyI4p2k77iP8J+MvvCfjbPwn4288J+OhPCfjpPwn46k8J+OqPCfj6vwn4+t8J+Rpi3wn5Gp8J+Si/Cfkrvwn5K88J+Up/CflKzwn5qA8J+akvCfpJ3wn6av8J+msC3wn6az8J+mvPCfpr3wn6eRXSoiIDAgZm9udC1zaGFwZS1nc3RyaW5nXSkKICAgICAgICAgICAgICAgICAsQChtYXBjYXIgKGxhbWJkYSAoc3RyKSAobGlzdCAoZWx0IHN0ciAwKSAodmVjdG9yIHN0ciAwICdmb250LXNoYXBlLWdzdHJpbmcpKSkKICAgICAgICAgICAgICAgICAgICAgICAgICAgJygi8J+YtuKAjfCfjKvvuI8iICLwn5CI4oCN4qybIiAi8J+QleKAjfCfproiICLwn5C74oCN4p2E77iPIiAi8J+Rge+4j+KAjfCfl6jvuI8iICLwn5iu4oCN8J+SqCIgIvCfmLXigI3wn5KrIikpKSkKICAoc2V0LWNoYXItdGFibGUtcmFuZ2UKICAgY29tcG9zaXRpb24tZnVuY3Rpb24tdGFibGUKICAgKGNhciBpdGVtcykKICAgKGxpc3QgKGNhZHIgaXRlbXMpKSkpCg== ``` You can decode it with the command `base64 -d`. --- Tags: fonts, linux, emacs27 ---
thread-62227
https://emacs.stackexchange.com/questions/62227
Enable OS X keys in Emacs
2020-12-11T19:40:21.060
# Question Title: Enable OS X keys in Emacs I installed Emacs via homebrew using this Emacs bundle, https://github.com/railwaycat/homebrew-emacsmacport This bundle has some nice OS X features but it doesn't have the OS X keyboard shortcuts enabled by default (e.g., command + c for copy and command + v for paste). How can I enable this? I would have thought a Google search would find the answer but all I found was this https://www.emacswiki.org/emacs/MacKeyMode but I am not sure if that's still relevant. Any pointers would be welcomed and sorry if I missed something obvious. # Answer > 6 votes You could add any (or all) of the following key bindings to your `init.el` to have most of the key commands working as a macOS user would expect... ``` (setq mac-option-modifier 'meta mac-command-modifier 'super mac-right-option-modifier 'none)) (global-set-key (kbd "s-c") 'kill-ring-save) (global-set-key (kbd "s-v") 'yank) (global-set-key (kbd "s-x") 'kill-region) (global-set-key (kbd "s-a") 'mark-whole-buffer) (global-set-key (kbd "s-z") 'undo) (global-set-key (kbd "s-f") 'isearch-forward) (global-set-key (kbd "s-g") 'isearch-repeat-forward) (global-set-key (kbd "s-o") 'find-file) (global-set-key (kbd "s-o") 'mac-open-file) (global-set-key (kbd "s-n") 'find-file) (global-set-key (kbd "s-s") 'save-buffer) (global-set-key (kbd "s-S") 'mac-save-file-as) (global-set-key (kbd "s-p") 'mac-preview) ; requires mac-preview (global-set-key (kbd "s-w") 'kill-buffer) (global-set-key (kbd "s-m") 'iconify-frame) (global-set-key (kbd "s-q") 'save-buffers-kill-emacs) (global-set-key (kbd "s-.") 'keyboard-quit) (global-set-key (kbd "s-l") 'goto-line) (global-set-key (kbd "s-k") 'kill-buffer) (global-set-key (kbd "s-<up>") 'beginning-of-buffer) (global-set-key (kbd "s-<down>") 'end-of-buffer) (global-set-key (kbd "s-<left>") 'beginning-of-line) (global-set-key (kbd "s-<right>") 'end-of-line) (global-set-key [(meta down)] 'forward-paragraph) (global-set-key [(meta up)] 'backward-paragraph) ``` For a mac like open & save interface you might also need these applescript wrappers... ``` (defun mac-open-file () (interactive) (let ((file (do-applescript "POSIX path of (choose file)"))) (if (> (length file) 3) (setq file (substring file 1 (- (length file) 1)))) (if (and (not (equal file "")) (file-readable-p file)) (find-file file)))) (defun mac-save-file-as () (interactive) (let ((file (do-applescript "POSIX path of (choose file name with prompt \"Save As...\")"))) (if (> (length file) 3) (setq file (substring file 1 (- (length file) 1)))) (if (not (equal file "")) (write-file file)))) ``` the key map is based on the following... ``` ⌘ + O — Open an existing file into an Emacs buffer ⌘ + W — Discard (kill) current buffer ⌘ + S — Save current buffer into its file ⌘ + ⇧ (Shift) + S — Write current buffer into another file ⌘ + I — Display current file/directory in a Finder window ⌘ + P — Print current buffer ⌘ + Q — Quit ⌘ + Z — Undo ⌘ + ⇧ (Shift) + Z — Redo ⌘ + X — Cut ⌘ + C — Copy ⌘ + V — Paste ⌘ + A — Select All ⌘ + F — Search for a string ⌘ + ⌥ (Option) + F — Advanced Search (M-x occur) ⌘ + G — Search forward for a string ⌘ + ⇧ (Shift) + G — Search backward for a string ⌘ + L — Go to Line ⌘ + T — Show/Hide the font panel ⌘ + M — Minimize the window ⌘ + ` — Move to a different visible window (frame) ⌘ + ⇧ (Shift) + N — Make a new window (frame) ⌘ + ⇧ (Shift) + W — Close window (frame) ⌘ + ? — Show help files (M-x info) ⌘ + / — Same as ⌘ + ? ⌘ + . — Interrupt operation ⌘ + ↑ — Move point to the beginning of the buffer ⌘ + ↓ — Move point to the end of the buffer ⌘ + ← — Move point to beginning of current line ⌘ + → — Move point to end of current line ⌘ + Click — Open URL with a browser ⌃ (Control) + Click — Show contextual menu ⇧ (Shift) + Click — Select region ``` --- Tags: key-bindings, osx ---
thread-17095
https://emacs.stackexchange.com/questions/17095
How supress Dired confirmation of large file for specific extensions?
2015-10-03T10:50:34.810
# Question Title: How supress Dired confirmation of large file for specific extensions? I started to use Dired. The movie files will be opened by another external application (VLC) with the help of the package `openwith`. So I would like to supress the confirmation `File foobar.avi is too large, really open? (y or n)` for movie files. When exploring this feature, I found the variable `large-file-warning-thresold`, the docstring is: ``` The variable is large-file-warning-threshold. Documentation: large-file-warning-threshold is a variable defined in `files.el'. Its value is 10000000 Documentation: Maximum size of file above which a confirmation is requested. When nil, never request confirmation. You can customize this variable. This variable was introduced, or its default value was changed, in version 22.1 of Emacs. ``` So I would like to disable this thresold for only specific extensions like `.mp4` or `.mkv`, but don't change it for another extensions. By reading the source, look at the function to open files: C-h k C-x C-f (or C-h f find-file RET). Click on files.el to browse the source file (you must have the Lisp sources installed). Don't read the code — it's pretty big — but search for parts of the message in that file. You'll find ``` (defun abort-if-file-too-large (size op-type filename) "If file SIZE larger than `large-file-warning-threshold', allow user to abort. OP-TYPE specifies the file operation being performed (for message to user)." (when (and large-file-warning-threshold size (> size large-file-warning-threshold) (not (y-or-n-p (format "File %s is large (%dMB), really %s? " (file-name-nondirectory filename) (/ size 1048576) op-type)))) (error "Aborted"))) ``` The message is only displayed when some conditions are met. The first condition is large-file-warning-threshold (interpreted as a boolean), i.e. large-file-warning-threshold must be non-nil. So you can disable the message by setting that variable to nil. (You can confirm that it's a global variable by looking at its definition in the same file — it's a customizable item, and the documentation explains how it's used if you aren't familiar enough with Lisp and only figured out that the variable mattered in some way.) So I would add the condition for `.mp4` and `.mkv4` files. Any idea how I could achieve that, without fiddling with the source code for Dired? I could use `defadvice`, but it's currently unclear to me how I could apply extra conditional for confirmation messages. # Answer You're on the right track. This should do the trick: ``` (defvar my-ok-large-file-types (rx "." (or "mp4" "mkv") string-end) "Regexp matching filenames which are definitely ok to visit, even when the file is larger than `large-file-warning-threshold'.") (defadvice abort-if-file-too-large (around my-check-ok-large-file-types) "If FILENAME matches `my-ok-large-file-types', do not abort." (unless (string-match-p my-ok-large-file-types (ad-get-arg 2)) ad-do-it)) (ad-activate 'abort-if-file-too-large) ``` > 7 votes # Answer This is an elaboration of phils' answer that sets `my-ok-large-file-types` automatically using the value of `openwith-associations`: ``` (define-advice abort-if-file-too-large (:around (orig-fn size op-type filename &optional offer-raw) unless-openwith-handles-it) "Do not abort if FILENAME is handled by Openwith." (let ((my-ok-large-file-types (mapconcat 'car openwith-associations "\\|"))) (unless (string-match-p my-ok-large-file-types filename) (funcall orig-fn size op-type filename offer-raw)))) ``` The setting of `my-ok-large-file-types` works like this: `my-ok-large-file-types` is a list of lists with a structure like `((<regexp> <application> <file>) (<regexp> <application> <file>) …)`. You can make a big regexp that matches any file handled by Openwith by combining all the `<regexp>` elements using `or` operators. In code, that's `(mapconcat 'car openwith-associations "\\|")`: `car` returns the first element of a list, `mapconcat` applies `car` to all elements of `openwith-associations` and concatenates the results separating them with `\\|`, the `or` operator (see (elisp)Mapping Functions). Another difference is that this advice is written using `nadvice.el`, which is the newer advice library. I don't know much about its technical advantages, for those I refer you to Practical benefits of new advice system in Emacs 24.4. Here, notice that all the arguments of `abort-if-file-too-large` are declared in the lambda list. That's what allows calling the original function's argument `filename` by name in `(string-match-p my-ok-large-file-types filename)`, instead of having to use `ad-get-arg` as with the old `advice.el` library. Advices with the `:around` combinator additionally take the advised function's name as an argument. When you call the original function in your advice, you do it by invoking `funcall` or `apply` with that argument, in place of `ad-do-it`. > 1 votes # Answer To suppress the question altogether, I followed your thought pattern above with this line: (setq large-file-warning-threshold nil) > 0 votes --- Tags: dired, openwith ---
thread-58073
https://emacs.stackexchange.com/questions/58073
How to find inheritance of modes?
2020-04-26T15:37:10.157
# Question Title: How to find inheritance of modes? As an example, let's use `latex-mode`, that inherits from `tex-mode`, that inherits from `text-mode`. Is there a command, that would take as input `latex-mode` and give me parent and grand-parent? Or, other way around, is there a command that would take `text-mode` as input, and give me children and grand-children? # Answer > 4 votes Property `derived-mode-parent` of a mode symbol gives you the parent mode it is derived from. ``` (get 'latex-mode 'derived-mode-parent) (get 'tex-mode 'derived-mode-parent) ``` This will give you a list of the hierarchy: ``` (defun derived-modes (mode) "Return a list of the ancestor modes that MODE is derived from." (let ((modes ()) (parent nil)) (while (setq parent (get mode 'derived-mode-parent)) (push parent modes) (setq mode parent)) (setq modes (nreverse modes)))) ``` # Answer > 0 votes I have a version based on recursion ``` (defun my/derived-modes (mode) (interactive (list major-mode)) (defun iter (mode) (and mode (cons mode (iter (get mode 'derived-mode-parent))))) (message "%s" (iter mode))) ``` --- Tags: major-mode, derived-mode ---
thread-62236
https://emacs.stackexchange.com/questions/62236
Org-ref, Exporting org file to HTML with its style exactly same as a specific scientific journal
2020-12-12T12:31:49.243
# Question Title: Org-ref, Exporting org file to HTML with its style exactly same as a specific scientific journal I've been writing articles with Google Docs and Zotero. Recently, I tried Org-mode with Org-ref package, but the output was not so good. My Problems: * The citation is verbose without any rule. I expected it will be concisely expressed in numbers, etc., following some rule or style of a certain scientific journals, but it was not. * The bibliography is not numbered. It is difficult to find out which part of the text the reference is cited. I don't use LaTex. What I want is only HTML output following some style of a specific scientific journal. Question: Can my problems be fixed by some advanced configuration of Org-ref? If possible, how can it be fixed? Many Thanks. --- My "~/.emacs" configuration (Windows 10 pro 64bits) ``` (use-package org-ref :after org :init (setq reftex-default-bibliography '("C:/Users/k/Documents/emacs_practice/news.bib")) (setq org-ref-bibliography-notes "C:/Users/k/Documents/emacs_practice/notes.org" org-ref-default-bibliography '("C:/Users/k/Documents/emacs_practice/news.bib") org-ref-pdf-directory "C:/Users/k/Documents/emacs_practice/pdf/") (setq helm-bibtex-bibliography "C:/Users/k/Documents/emacs_practice/news.bib") (setq helm-bibtex-library-path "C:/Users/k/Documents/emacs_practice/pdf/") (setq helm-bibtex-pdf-open-function (lambda (fpath) (start-process "open" "*open*" "open" fpath))) (setq helm-bibtex-notes-path "C:/Users/k/Documents/emacs_practice/notes.org") :config (key-chord-define-global "uu" 'org-ref-cite-hydra/body) ;; variables that control bibtex key format for auto-generation ;; I want firstauthor-year-title-words ;; this usually makes a legitimate filename to store pdfs under. (setq bibtex-autokey-year-length 4 bibtex-autokey-name-year-separator "-" bibtex-autokey-year-title-separator "-" bibtex-autokey-titleword-separator "-" bibtex-autokey-titlewords 2 bibtex-autokey-titlewords-stretch 1 bibtex-autokey-titleword-length 5)) ``` Emacs captured HTML output # Answer > 3 votes `org-ref` does not play well (natively) with docx, odt or html export. Its creator (J. Kitchin) explains why in several blog posts. I don't know if this is the canonical (or even a good) way to proceed, but here is the workaround I use when I want clean references for an html export. 1. Install `ox-bibtex` (i.e., put it your load-path and add `(require 'ox-bibtex)` into your .emacs file) if you still don't have it. You can find it here for example. (Let's take a look at its embedded documentation.) 2. As explained in the documentation of `ox-bibtex`, you'll also need to install the external software `bibtex2html`. It seems that there is a Windows binary available on its web page. 3. This is almost done! Let's consider the following org file: ``` #+TITLE: My html output #+AUTHOR: Philopolis * Headline cite:tao2016_Analysis is a great book about analysis. #+BIBLIOGRAPHY: biblio plain limit:t option:-nobibsource * Biblio :noexport: bibliography:biblio.bib ``` You'll note that here, we'll need a `#+BIBLIOGRAPHY` keyword, where you must at least indicate your bib file, your desired style (here, "plain" style). Some other options (such as `limit:t` which I use here) are described within the documentation. Finally, I place the `bibliography:biblio.bib` statement within an Org section which is not exported (you still need that for `org-ref` to work). Here is my output: --- Tags: org-ref, style ---
thread-14952
https://emacs.stackexchange.com/questions/14952
How do I set up hunspell on a Windows PC?
2015-08-22T11:10:15.930
# Question Title: How do I set up hunspell on a Windows PC? I have my hunspell dictionaries at `C:\hunspell\`. It contains `.dic` and `.aff` files for three languages: `en_GB`, `en_US`, and `nb_NO`. The descriptions I find on the web about how to make hunspell work in Emacs make me confused. What is the minimum code I need in my init file to be able to use these three hunspell dictionaries in Emacs? I have tried the following code suggested by one web site: ``` (add-to-list 'exec-path "C:/hunspell/bin/") (setq ispell-program-name (locate-file "hunspell" exec-path exec-suffixes 'file-executable-p)) ``` But when wanting to change dictionary by `M-x ispell-change-dictionary`, I get the following message: > ispell-phaf: No matching entry for nil. # Answer > 7 votes Emacs setup: ``` (setq ispell-program-name "c:/what-ever-path/hunspell") ;; "en_US" is key to lookup in `ispell-local-dictionary-alist'. ;; Please note it will be passed as default value to hunspell CLI `-d` option ;; if you don't manually setup `-d` in `ispell-local-dictionary-alist` (setq ispell-local-dictionary "en_US") (setq ispell-local-dictionary-alist '(("en_US" "[[:alpha:]]" "[^[:alpha:]]" "[']" nil ("-d" "en_US") nil utf-8))) ;; new variable `ispell-hunspell-dictionary-alist' is defined in Emacs ;; If it's nil, Emacs tries to automatically set up the dictionaries. (when (boundp 'ispell-hunspell-dictionary-alist) (setq ispell-hunspell-dictionary-alist ispell-local-dictionary-alist)) ;; With Emacs 28.2 may also need to set hunspell-default-dict (setq hunspell-default-dict "en_US") ``` Hunspell dictionary setup: Run `hunspell -D` in dos window which will list the directories hunspell searching for dictionaries. Copy your dictionaries to that directory. This is the minimum setup you need. See http://blog.binchen.org/posts/what-s-the-best-spell-check-set-up-in-emacs.html for more technical details. # Answer > 4 votes I ran into this problem myself a while back. If I recall correctly, the reason you get that error message is because `hunspell` is unable to configure itself based on the current environment. So to fix it, you need to configure the `hunspell` specific `ispell` variables. The following code *should* be enough to setup hunspell for english dictionaries: ``` (require 'flyspell) (setq ispell-dictionary "english") (add-to-list 'ispell-local-dictionary-alist '(("english" "[[:alpha:]]" "[^[:alpha:]]" "[']" t ("-d" "en_US") nil utf-8))) (setq ispell-hunspell-dictionary-alist ispell-local-dictionary-alist) ``` The important part is the `ispell-hunspell-dictionary-alist`, it has to be populated with a proper dictionary list, such as the one given in `ispell-local-dictionary-alist`. There's quite a bit of details surrounding this list though. If you want to know more about it, feel free to read up with `M-x describe-variable` `ispell-local-dictionary-alist`. # Answer > 1 votes Install all the dictionaries you want in the location that hunspell searches in; find this with `hunspell -D`. Once installed, this command should show them. In the init file, add just add one of them E.g. I have `en_GB` and `en_US` dictionaries installed. I've, in my init file, this: ``` (setenv "DICTIONARY" "en_GB") ``` Upon opening Emacs, just enable `flyspell-mode`. Emacs should say that it is started ispell with default dictionary. This means `en_GB` is in action, for our example. Now if you want to switch, just do `M-x ispell-change-dictionary` and give the new dictionary name E.g. `en_US`. Now the other dictionary should be in action. This, again, will be notified by Emacs saying it started ispell but this time with the `en_US` dictionary. # Answer > 1 votes Assuming you're using a recent version of Emacs (24.4 or above, as I recall) then all you need to do is make sure you're using the correct dictionary name, and Emacs will do the rest automatically. The main problem is that Windows uses a different language description format, for example British English is called **ENG**, and US English is **ENU**. This means your dictionary files should be called *ENU.dic* and *ENU.aff* for US English, and *ENG.dic* and *ENG.aff* for British English. It may also be necessary to have a "default" dictionary or hunspell may not be too happy. You can also set the *DICTIONARY* environment variable to force a default. Unfortunately I can't work out what your Norwegian dictionary should be called. If you're using the Norwegian locale in Windows, you should be able to check within Emacs by evaluating: ``` (getenv "LANG") ``` Which will show you the setting that Emacs is using. # Answer > 1 votes chen bin and serghei's answer worked for me on Emacs 26.x, but not with Emacs 27.1, which seems to have an updated ispell.el file. In Emacs 27.1, I would get: ``` Can’t find Hunspell dictionary with a .aff affix file ``` To "fix", I overwrote ./share/emacs/27.1/lisp/textmodes/ispell.el with a version from 26.x. # Answer > 0 votes This is just a guess, but maybe you need to tell which language you would like to use as the “default”: ``` (setq ispell-dictionary "en") ; default dictionary ``` Default value of `ispell-dictionary` is `nil`, so may be this is the cause of your problem. --- Tags: microsoft-windows, hunspell ---
thread-62243
https://emacs.stackexchange.com/questions/62243
How to identify the file of an already loaded feature, independently on how the file was loaded?
2020-12-12T21:31:16.190
# Question Title: How to identify the file of an already loaded feature, independently on how the file was loaded? Normally to find which file corresponds to a loaded feature, one could use the `(locate-library LIBRARY &optional NOSUFFIX PATH INTERACTIVE-CALL)` function. However, if the user used the function `(load-file FILE)` a file that is not located in a directory listed in load-path can be loaded. A call to locate-library will not find it. Also, lets say that there are several files that provide the same FEATURE because they have the same `(provide FEATURE)` form in them, and they are all stored in a directory listed in the load-path and one of them is loaded, `locate-library` will always report the file it finds with what is the content of the load-path at the moment of the execution of locate-library. This may happen in the following scenarioS: * while developing where several copies of the file exists in various directories or, * on projects that create the final distributed file from a set of smaller files. I am trying to find a way to identify the path of the file that was originally used to load the existing feature, regardless of any modification that might have occurred to load-path after the file was loaded and even if the file was loaded from a `load-file` call. Is this feasible? # Answer > 1 votes Global variable `load-history` records the files you've loaded (no matter how), and the definitions they contain. Assuming you know the file name of the file that provides the feature, you can use this, where `FILENAME` is the file name as a string. ``` (load-history-filename-element (load-history-regexp FILENAME)) ``` `C-h f load-history-regexp`: > **`load-history-regexp`** is a compiled Lisp function in `subr.el`. > > `(load-history-regexp FILE)` > > Form a regexp to find `FILE` in `load-history`. > > `FILE`, a string, is described in the function `eval-after-load`. `C-h f load-history-filename-element`: > **`load-history-filename-element`** is a compiled Lisp function in `subr.el`. > > `(load-history-filename-element FILE-REGEXP)` > > Get the first elt of `load-history` whose car matches `FILE-REGEXP`. > > Return `nil` if there isn't one. --- Tags: load-path ---
thread-62242
https://emacs.stackexchange.com/questions/62242
How to ensure that gnus only check for new messages in my subscribed groups
2020-12-12T21:30:37.043
# Question Title: How to ensure that gnus only check for new messages in my subscribed groups Gnus scans thousands of groups on the news server upon startup. How do I restrict it to only my subscribed groups? **Edit**: This happens despite having set gnus-default-subscribed-newsgroups to true in my .gnus.el file. I have also set gnus-check-new-newsgroups to nil to no avail. I am using Emacs 27.1. # Answer > 2 votes Gnus scans only subscribed groups on startup. To find new groups you will have to explicitly invoke `gnus-group-find-new-groups` which has a keybinding `F` in the Group-buffer. --- Tags: gnus ---
thread-62245
https://emacs.stackexchange.com/questions/62245
does advice :around always have to pass a list of args?
2020-12-13T03:22:05.873
# Question Title: does advice :around always have to pass a list of args? I'm new to elisp, and I'm struggling to figure out how to do advice. I got my code working, but I'm not sure why. This is from a real problem that I had digging into markdown mode to add an extra exclusion to spellchecking to its implementation of `flyspell-generic-word-predicate`---but the details don't matter, so I'll just reduce it to an abstract form to start with, and see if there's an easy explanation... but then I'll provide the full details later, in case my abstract theory of what's going on is wrong. Consider a predicate function `is-foo` that takes *zero* arguments and runs a test against the word at point. Suppose I decide that the implementation of some library function `is-foo` is deficient for my purposes, because there's a small, easily testable, class of words for which `is-foo` returns `t` but I'd prefer it returns `nil`. So I write a predicate function of my own, which also takes no arguments---call it `is-bar`---which correctly handles the case that `is-foo` screws up. And then I decide that the best way to handle matters is to just use advice to wrap `is-bar` around `is-foo` such that if `is-bar` returns `nil`, the whole function just returns `nil`; otherwise, it returns whatever `is-foo` would return. So here's my first try: ``` (defun do-better-advice (orig) (if (is-bar) (orig) nil)) (advice-add 'is-foo :around #'do-better-advice) ``` When I try to actually run the underlying code, what I get is an error about `(void-function orig)` However, with the following small change, my code runs correctly: ``` (defun do-better-advice (orig &rest args) (if (is-bar) (apply orig args))) ``` What I don't understand is why calling `apply` makes this work? The documentation for apply says that "apply calls function with arguments" and that "apply returns the result of calling function." But if that's true, then when `f` takes no arguments, and is passed none (i.e. `args` above is an empty list), then `(f)` and `(apply f args)` ought to evaluate to exactly the same thing. So why don't they? **nitty-gritty details** In real life, this was an attempt to get flyspell to stop marking pandoc citation references (which begin with an ampersand) as spelling errors in markdown-mode. The source of the function I was advising, `markdown-flyspell-check-word-p` is here; as you can see, it is a predicate that takes no arguments. Ultimately, the markdown-mode library just takes `markdown-flyspell-check-word-p` and binds it to `flyspell-generic-check-word-predicate`. My code that failed was: ``` (defun is-ampersand (s) (string= "@" s)) (defun not-cite () (save-excursion (forward-word -1) (let ((result (is-ampersand (string (preceding-char))))) (not result)))) (defun not-cite-advice (orig) (if (not-cite) (orig) nil)) (advice-add 'markdown-flyspell-check-word-p :around #'not-cite-advice) ``` And the specific error I got when I turned on flyspell was `Error in post-command-hook (flyspell-post-command-hook): (void-function orig)` But when I simply rewrote to use apply and to pass it a presumably empty list of args, it worked exactly as intended: ``` (defun not-cite-advice (orig &rest args) (if (not-cite) (apply orig args))) ``` The only reason I actually knew to try `apply` was because I saw a couple examples of using `:around` in advice, and they all used `apply`. The documentation for around just says "Call function instead of the old function, but provide the old function as an extra argument to function" --- it doesn't say anything like "and also pass around a list of the arguments" or anything like that. Although the quoted bit below I guess means that you *can* give it a list of args (?). # Answer > 2 votes > When I try to actually run the underlying code, what I get is an error about (void-function orig) The error message says `orig` is not a function. In your code, `orig` is a variable, not a function. In Emacs Lisp, a symbol can be a variable and a function at the same time without conflict, Which one will be used depends on their location in the function call `(func arg1 arg2 ...)`, e.g., ``` (defun foo () 1) (defvar foo 2) ;; use the function foo (foo) ;; => 1 ;; use the variable foo (identity foo) ;; => 2 ``` Sometimes, the value of a variable is a function object, and you want to call the function, you use `funcall` or `apply`, e.g., ``` (defun foo () 1) (setq foo (lambda () 123)) ;; use the function foo (foo) ;; => 1 ;; use the variable foo (funcall foo) ;; => 123 ``` `funcall` is simpler and `apply` is more generic, e.g., ``` (+ 1 2 3) ;; => 6 ;; there is only one way to use funcall (funcall '+ 1 2 3) ;; => 6 ;; there are many ways to use apply (apply '+ '(1 2 3)) ;; => 6 (apply '+ 1 '(2 3)) ;; => 6 (apply '+ 1 2 '(3)) ;; => 6 (apply '+ 1 2 3 ()) ;; => 6 ``` and when the function accepts zero arguments ``` (defun foo () 1) (foo) (funcall 'foo) ;; => 1 ;; the function arguments is always a list, it's empty list for zero arguments function (apply 'foo ()) ;; => 1 ``` > Consider a predicate function is-foo that takes zero arguments > > (apply orig args) It's `(apply orig ())` since `args` is always `()` (or `nil`: `nil` and `()` are `eq` hence the same thing), but `(funcall orig)` is easier to read. --- There are more than one ways to write the advice function (that's `do-better-advice` in this case), e.g., ``` (defun foo (a b) (+ a b)) (advice-add 'foo :around (lambda (orig a b))) (advice-add 'foo :around (lambda (orig a &rest r))) (advice-add 'foo :around (lambda (orig &rest r))) (advice-add 'foo :around (lambda (orig &optional a b))) ``` it's because the advice function will be called with `apply`, in the following `FUNCTION` is `do-better-advice`, `OLDFUN` is `is-foo` ``` ;; C-h f add-function `:around' (lambda (&rest r) (apply FUNCTION OLDFUN r)) ``` --- Tags: advice, symbols ---
thread-34170
https://emacs.stackexchange.com/questions/34170
reload bookmarks file without restarting Emacs?
2017-07-14T05:49:25.660
# Question Title: reload bookmarks file without restarting Emacs? I'm using Emacs (latest master branch as of June,2017) and I'm using Syncthing (like Dropbox) to store my emacs-bookmark file which I load in my configuration using ``` '(bookmark-default-file "~/Sync/emacs-bookmarks") ``` On one computer I have to do a `bookmark-save` command to output my current bookmarks to the `~/Sync/emacs-bookmarks` file. On the other computer this file is updated but when I do a list of bookmarks using `C-x r l` the listing is not refreshed it's showing the old bookmarks. Is there a way without restarting emacs to reload the bookmarks file? # Answer > 0 votes You want to call `bookmark-load`. You don't need Bookmark+. # Answer > 0 votes Take a look at bookmark+. There are a lot of things in that package but this is very handy: ``` bookmark-load is an interactive compiled Lisp function in bookmark+-1.el . It is bound to C-x p l, <menu-bar> <edit> <bookmark> <load>. (bookmark-load FILE &optional OVERWRITE BATCHP) Load bookmarks from FILE (which must be in the standard format). Without a prefix argument (argument OVERWRITE is nil), add the newly loaded bookmarks to those already current. They are saved to the current bookmark file when bookmarks are saved. ``` I also set this in my init file: ``` (setq bmkp-last-as-first-bookmark-file nil) ;; always uses the value of bookmark-default-file as the initial bookmark file ``` --- Tags: bookmarks ---
thread-50153
https://emacs.stackexchange.com/questions/50153
Indentation with reader macros: common lisp in emacs
2019-04-25T17:41:28.390
# Question Title: Indentation with reader macros: common lisp in emacs Okay, I'm not sure whether this question is more relevant to Common Lisp, or to Emacs. I have reader macros in Common Lisp (found them here), that allow the declaration of hash-tables by: ``` #{'a 'b, 'c 'd} ``` I'd like it to be indented as (both in emacs, and REPL - slime / portacle in particular): ``` #{'a 'b, 'c 'd} ``` And I'd like some guidance. I looked at the top of this, but I don't quite understand how to do it for reader macros as well. My current (relevant) code is as follows: ``` (defun read-left-brace (stream char n) (declare (ignore char)) (let ((*readtable* (copy-readtable))) (set-macro-character +comma+ 'read-separator) (loop for key = (read-next-object-for-hash-table +right-brace+ +comma+ stream) while key for value = (read-next-object-for-hash-table +right-brace+ +comma+ stream) collect (list (eval key) (eval value)) into pairs finally (return (make-hash pairs))))) ``` # Answer > 0 votes The closest thing would be putting this in .emacs ``` (use-package lisp-mode :config (modify-syntax-entry ?\[ "(]" lisp-mode-syntax-table) (modify-syntax-entry ?\] ")[" lisp-mode-syntax-table) (modify-syntax-entry ?\{ "(}" lisp-mode-syntax-table) (modify-syntax-entry ?\} "){" lisp-mode-syntax-table)) ``` Post that, the documentation for `modify-syntax-entry` should be helpful. --- Tags: indentation ---
thread-30307
https://emacs.stackexchange.com/questions/30307
How to restore window layout on `org-agenda-switch-to`?
2017-01-30T18:10:09.853
# Question Title: How to restore window layout on `org-agenda-switch-to`? Pressing `q` in an agenda view restores the window layout if `org-agenda-restore-windows-after-quit` is non-nil. Is there a way to do the same on `RET` (`org-agenda-switch-to`)? # Answer > 1 votes Define the function `my-org-agenda-switch-to`: ``` (defun my-org-agenda-switch-to (&optional delete-other-windows) "Go to the Org mode file which contains the item at point. When optional argument DELETE-OTHER-WINDOWS is non-nil, the displayed Org file fills the frame. Like `org-agenda-switch-to', but respects the value of the variable `org-agenda-restore-windows-after-quit'. It is recommended to replace `org-agenda-switch-to' by this function (using advice)." (interactive) (if (and org-return-follows-link (not (org-get-at-bol 'org-marker)) (org-in-regexp org-link-bracket-re)) (org-link-open-from-string (match-string 0)) (let* ((marker (or (org-get-at-bol 'org-marker) (org-agenda-error))) (buffer (marker-buffer marker)) (pos (marker-position marker))) (unless buffer (user-error "Trying to switch to non-existent buffer")) (when org-agenda-restore-windows-after-quit (org-agenda-quit)) (switch-to-buffer-other-window buffer) (when delete-other-windows (delete-other-windows)) (widen) (goto-char pos) (when (derived-mode-p 'org-mode) (org-show-context 'agenda) (run-hooks 'org-agenda-after-show-hook))))) ``` This is a slight modification of the source code of `org-agenda-switch-to`. It will restore the window configuration if `org-agenda-restore-windows-after-quit` is non-nil. Then use advice to overwrite the original function: ``` (advice-add #'org-agenda-switch-to :override #'my-org-agenda-switch-to) ``` If you want to open the file in the same window instead of "other window", replace `(switch-to-buffer-other-window buffer)` by `(pop-to-buffer-same-window buffer)`. # Answer > 1 votes I think he means after selecting an entry, it splits the frame in two pieces. After some debugging, I found out the org-agenda-switch-to can be called with an "optional" argument, which instructs the function to close all other windows. ``` (add-hook 'org-agenda-mode-hook (lambda() (define-key org-agenda-mode-map (kbd "RET") (lambda () (interactive) (org-agenda-switch-to t))))) ``` Note: I'm not an emacs expert. --- Tags: org-mode ---
thread-62251
https://emacs.stackexchange.com/questions/62251
Running code after org-deadline
2020-12-13T10:49:21.840
# Question Title: Running code after org-deadline I want to run code after adding a deadline, for example to move it forward by one day in case the deadline is early in the day, or by a few hours in case it's on a different time zone. This attempt with a hook and a function is not called upon setting a deadline with `C-d`: ``` (defun my-org-deadline(&rest ignore) (interactive) (message "Called!!!!!") (let ((todo (org-get-todo-state)) (deadline (org-entry-get nil "DEADLINE")) ) ;; move deadline ahead by 1 day, to avoid missing it. (when (and todo deadline) (org-back-to-heading) (search-forward "DEADLINE: ") (org-timestamp-change -1 'day) ))) (add-hook 'org-deadline #'my-org-deadline) ``` The function works properly if I call it, but it is not called after setting a deadline. What is the proper way to make code run after setting a deadline? # Answer There is no hook called `org-deadline`. Most hooks are called `<mumble>-hook` so when you are looking for one, try `C-h v org--hook` and press TAB: that should give you a completion buffer with all the available hooks whose names start with `org-`. Unfortunately, there is no hook defined to allow you to call a function after you set a deadline. But you can still use an advice: define your function to do what you want, and then add it as an `after` advice to `org-deadline`. Something like this should work with your `my-org-deadline` function: ``` (advice-add 'org-deadline :after #'my-org-deadline) ``` `C-h f org-deadline` will then tell you that this function has been advised. You can remove the advice with ``` (advice-remove 'org-deadline #'my-org-deadline) ``` --- NOTE: This *SHOULD* work I think, but it doesn't for me: I get a `wrong-number-of-arguments` error when `org-deadline` gets called. The error happens in various functions and I have not had time to debug the problem yet. OTOH, I tried it on a different machine with slightly more recent emacs and it works fine: GNU Emacs 28.0.50 (build 3, x86\_64-pc-linux-gnu, GTK+ Version 3.24.13, cairo version 1.16.0) of 2020-10-30 Org mode version 9.4 (release\_9.4-53-g23f941) so I suspect the solution is fine in general: there must be something wrong with the emacs/org version on the other machine. > 1 votes --- Tags: org-mode, hooks ---
thread-58994
https://emacs.stackexchange.com/questions/58994
"Symbol’s value as variable is void: org-priority-highest" using org-agenda
2020-06-09T16:10:30.140
# Question Title: "Symbol’s value as variable is void: org-priority-highest" using org-agenda While I'm trying to access any of the org-agenda options or commands! I always get this error `Symbol’s value as variable is void: org-priority-highest` and the list shows nothing even though I've set `org-agenda-files` correctly # Answer The current name for the highest priority value is `org-highest-priority` instead of `org-priority-highest`. They changed the names in January 2020 in this commit. An alias was added for the old name, but there was a bug in the way it was done. This bug appears to be in 9.3.6 and fixed in 9.3.7. Try updating your `org-mode`. > 2 votes # Answer It's an problem of `straight.el` see here. I solved using a solution given by one user in the github isssue. Thanks for answering and helping me! > 2 votes # Answer This error occurred for me when using `straight.el` to load various `org` packages. Org being a dependency leads straight to cloning a current version of it into its local repo. Using agenda then created the same error message of `Symbol’s value as variable is void: org-priority-highest`. In my case(Emacs 27.1, Org 9.3), a simple solution was to tell `straight.el` to use Emacs' standard built-in `org` version instead by using the `:type built-in` directive. I placed the following before declaring any other org-related packages: ``` (straight-use-package '(org :type built-in)) ``` > 2 votes --- Tags: org-mode, org-agenda, debugging ---
thread-62258
https://emacs.stackexchange.com/questions/62258
Undecorated Frame with header line as titlebar
2020-12-13T17:14:09.303
# Question Title: Undecorated Frame with header line as titlebar I am trying to remove all window manager decorations from emacs. This works well using: ``` (set-frame-parameter nil 'undecorated t) ``` But now what I want to have is a one line (global) header line (which spans across the entire frame) which acts like a title bar. Where I can drag the frame and resize it and so on. ``` (set-frame-parameter nil 'drag-with-header-line t) ``` Works to make the header line draggable. But I so far was only able to get a separate header line for each window. But I want one global one. Also I did not find out a way to resize the frame. Any way to do this? # Answer As far as I know, a header-line, like a mode-line, is specific to a particular buffer, which means a window showing that buffer. So I believe the answer is that you can't do what you want, without having just one window in the frame. > 1 votes # Answer I don't know how to make a titlebar that works as you want, but you can drag the window around by clicking anywhere on it and holding down the `Super` key (this works on Linux). As for resizing the frame, you need to set the frame parameters `drag-internal-border` and `internal-border-width`, for instance ``` (setq default-frame-alist (append ; Note: if there are any conflicting settings in ‘default-frame-alist’, it is the one that comes first that gets applied. '((undecorated . t) (drag-internal-border . t) (internal-border-width . 4)) default-frame-alist)) ``` Or, interactively, you can use the commands `set-frame-height` and `set-frame-width` (assuming you're on Emacs 27). > 0 votes --- Tags: frames, header-line ---
thread-59433
https://emacs.stackexchange.com/questions/59433
Pandas data frame as table
2020-07-03T17:36:30.017
# Question Title: Pandas data frame as table I'm enjoying learning org-babel to write literate documents and am trying to include summary tables produced by Pandas `describe()`. I found an old thread with some answers but none of the provided solutions seemed to satisfy the aim of the original poster and they seem quite clunky so I thought I'd try playing around. Starting with the working solution I have ``` #+BEGIN_SRC python :exports results :results value table :return summary import pandas as pd import numpy as np n = 1000 low = 0 high = 100 df = pd.DataFrame({'x': np.random.random_integers(low, high, size=n), 'y': np.random.random_integers(low, high, size=n)}) summary = df.describe() summary = [list(summary)] + [None] + summary.values.tolist() #+END_SRC #+RESULTS: | x | y | |--------------------+--------------------| | 1000.0 | 1000.0 | | 49.743 | 49.326 | | 29.186517500445365 | 29.128580435685468 | | 0.0 | 0.0 | | 26.0 | 24.0 | | 49.0 | 48.0 | | 76.0 | 75.0 | | 100.0 | 100.0 | ``` And the table renders, however it has lost the index which defines what the rows are (`count`, `mean`, `sd`, `min`, `25%`, `50%`, `75%`, `max`). Pandas DataFrames have a `to_html()` method so I figured that might be a viable option to return that, and it works... ``` #+BEGIN_SRC python :exports results :results html import pandas as pd import numpy as np n = 1000 low = 0 high = 100 df = pd.DataFrame({'x': np.random.random_integers(low, high, size=n), 'y': np.random.random_integers(low, high, size=n)}) summary = df.describe() return(summary.to_html()) #+END_SRC #+RESULTS: #+begin_export html <table border="1" class="dataframe"> <thead> <tr style="text-align: right;"> <th></th> <th>x</th> <th>y</th> </tr> </thead> <tbody> <tr> <th>count</th> <td>1000.00000</td> <td>1000.00000</td> </tr> <tr> <th>mean</th> <td>51.51800</td> <td>49.76100</td> </tr> <tr> <th>std</th> <td>29.75643</td> <td>28.97149</td> </tr> <tr> <th>min</th> <td>0.00000</td> <td>0.00000</td> </tr> <tr> <th>25%</th> <td>26.00000</td> <td>25.00000</td> </tr> <tr> <th>50%</th> <td>52.00000</td> <td>48.00000</td> </tr> <tr> <th>75%</th> <td>78.00000</td> <td>76.00000</td> </tr> <tr> <th>max</th> <td>100.00000</td> <td>100.00000</td> </tr> </tbody> </table> #+end_export ``` But, what if I wanted to compile the document to LaTeX? HTML tables wouldn't be rendered correctly and I'd need to leverage the `to_latex()` method instead... ``` #+BEGIN_SRC python :exports results :results latex import pandas as pd import numpy as np n = 1000 low = 0 high = 100 df = pd.DataFrame({'x': np.random.random_integers(low, high, size=n), 'y': np.random.random_integers(low, high, size=n)}) summary = df.describe() return(summary.to_latex()) #+END_SRC #+RESULTS: #+begin_export latex \begin{tabular}{lrr} \toprule {} & x & y \\ \midrule count & 1000.000000 & 1000.000000 \\ mean & 48.942000 & 50.595000 \\ std & 28.681026 & 28.868848 \\ min & 0.000000 & 0.000000 \\ 25\% & 24.000000 & 25.000000 \\ 50\% & 48.000000 & 50.000000 \\ 75\% & 73.000000 & 76.000000 \\ max & 100.000000 & 100.000000 \\ \bottomrule \end{tabular} #+end_export ``` One of the appealing aspects, to me at least, of literate programming and org-babel is the ability to have one source file that can be output to multiple different formats on execution/compilation, but I can't work out (mainly through lack of knowledge/understanding) how to include Pandas DataFrames in a generic manner in the resulting documents. Is it possible to have a block of code return a generic table that is rendered depending on the target output? # Answer It depends on what you want to do with the tables of course, but assuming that you want to produce generic Org mode tables that can be exported in the standard way, you will have to make the python block produce the structure that Org Babel expects in order to produce the generic Org mode table. That structure is a list of lists: first a list for the headers, then a list like this: `[None]` in order to produce the hline and then a list of lists for the rows. So the header list should be: ``` [ ' ', 'x', 'y'] ``` We have to add an empty entry since `pandas` does not label the index column. To get the rows, we'll get the index column and the values columns and knit them together appropriately: we zip them together and then use a list comprehension to construct each row. Most of this is just pythonisms to get the lists correct: ``` desc = df.describe() summary = [list(' ') + list(desc)] + [None] + [ [x[0]] + x[1] for x in zip(desc.index.array, desc.values.tolist())] ``` Here's what it looks like when you put it all together: ``` #+BEGIN_SRC python :exports results :results value table :return summary import pandas as pd import numpy as np n = 1000 low = 0 high = 100 df = pd.DataFrame({'x': np.random.random_integers(low, high, size=n), 'y': np.random.random_integers(low, high, size=n)}) desc = df.describe() summary = [list(' ') + list(desc)] + [None] + [ [x[0]]+x[1] for x in zip(desc.index.array, desc.values.tolist())] #+END_SRC #+RESULTS: | | x | y | |-------+--------------------+-------------------| | count | 1000.0 | 1000.0 | | mean | 50.384 | 50.238 | | std | 28.442354183708364 | 29.16724334050244 | | min | 0.0 | 0.0 | | 25% | 26.0 | 24.75 | | 50% | 51.0 | 50.0 | | 75% | 74.0 | 76.0 | | max | 100.0 | 100.0 | ``` EDIT: Just to clarify: this has nothing much to do with Pandas (or Python or elisp or ...); it has more to do with what Org Babel expects in order to produce a table. So here are two small examples with constant tables, one in python and one in elisp. I hope that clarifies what the result should be in each case in order to satisfy Org Babel's requirements. It is then up to you to arrange your program to produce a result of the proper form: ``` #+begin_src python :results value table :return summary summary = [ ['x', 'y'], None, [1,1], [2,4], [3, 9] ] #+end_src #+RESULTS: | x | y | |---+---| | 1 | 1 | | 2 | 4 | | 3 | 9 | #+begin_src emacs-lisp :results value table (setq summary '(("x" "y") hline (1 1) (2 4) (3 9))) #+end_src #+RESULTS: | x | y | |---+---| | 1 | 1 | | 2 | 4 | | 3 | 9 | ``` > 2 votes # Answer First install jupyter package from emacs and add these two lines to your init: ``` (add-to-list 'load-path "~/path/to/jupyter") (require 'jupyter) ``` Then, when you need to see a Pandas dataframe just add `:display plain` to your source block. Example: ``` #+begin_src jupyter-python :session py :display plain import pandas as pd pd.read_csv("https://raw.githubusercontent.com/cs109/2014_data/master/countries.csv") #+end_src #+RESULTS: #+begin_example Country Region 0 Algeria AFRICA 1 Angola AFRICA 2 Benin AFRICA 3 Botswana AFRICA 4 Burkina AFRICA .. ... ... 189 Paraguay SOUTH AMERICA 190 Peru SOUTH AMERICA 191 Suriname SOUTH AMERICA 192 Uruguay SOUTH AMERICA 193 Venezuela SOUTH AMERICA [194 rows x 2 columns] #+end_example ``` > 0 votes --- Tags: latex, org-babel, python, html ---
thread-62266
https://emacs.stackexchange.com/questions/62266
Find org babel header arguments documentation for shell language
2020-12-14T10:44:30.923
# Question Title: Find org babel header arguments documentation for shell language The org manual specifies in the this link: https://orgmode.org/manual/Languages.html#Languages the language it supports (including shell). It mentions this: > Additional documentation for some languages is at https://orgmode.org/worg/org-contrib/babel/languages.html The above link points further this page: https://orgmode.org/worg/org-contrib/babel/languages/index.html But unfortunately it doesn't have any documentation for the `shell` language. What I'm looking is to see if I can change the working directory where it is executed. Something like this: ``` #+begin_src sh working-dir:/home/some_dir #working-dir doesn't work obviously. ls #+end_src ``` But I'm not able to find documentation on where to find the header arguments for a specific language. # Answer > 3 votes What you are looking for is the `:dir` header argument: ``` #+begin_src shell :dir /home/nick/src pwd #+end_src #+RESULTS: : /home/nick/src #+begin_src shell :dir /home/nick/src/github pwd #+end_src #+RESULTS: : /home/nick/src/github/pbench #+begin_src python :dir /home/nick/src/ import os pwd = os.getcwd() return pwd #+end_src #+RESULTS: : /home/nick/src ``` Note that it is a language-independent header argument, so you won't find it documented under a specific language: look in the Org mode manual for it: ``` +begin_src emacs-lisp (info "(org) Environment of a code block") #+end_src ``` and search for the "Choosing a working directory" subsection (or look for the same thing in the online manual.) Note also that you can use a remote host spec for it, in which case babel will use Tramp to execute the block on the remote host: ``` #+begin_src shell :dir /scp:foo.bar.org:/home/nick/src :results drawer hostname pwd #+end_src #+RESULTS: :results: foo.bar.org /home/nick/src :end: #+begin_src python :dir /scp:foo.bar.org:/home/nick/src/ :results drawer import os import socket pwd = os.getcwd() return (socket.gethostname(), pwd) #+end_src #+RESULTS: :results: ('foo.bar.org', '/home/nick/src') :end: ``` --- Tags: org-mode, org-babel ---
thread-62276
https://emacs.stackexchange.com/questions/62276
Idiomatic way to prevent a function calling itself in elisp?
2020-12-15T00:27:04.220
# Question Title: Idiomatic way to prevent a function calling itself in elisp? If I have a function which needs to know if it's calling itself, what is an idiomatic way to check for this situation? While I can always bind a symbol (with a name that's highly likely to be unique) with `let`, then check if it's declared in the outer scope, I'm not sure if this is the best way. Is there a common convention for handling this case? # Answer > 2 votes One common way to detect recursion without using a global variable is the use of an optional argument: ``` (defun foo (x &optional recursed) "Frobnicate X." (unless recursed (foo x t))) ``` You could even hide the optional argument from the function's API: ``` (defun foo (x &optional recursed) "Frobnicate X." (declare (advertised-calling-convention (x) "1.0.0")) (unless recursed (foo x t))) ``` or: ``` (defun foo (x &optional recursed) "Frobnicate X. \n(fn X)" (unless recursed (foo x t))) ``` (See `(info "(elisp) Function Documentation")`.) Another way is to create a closure: ``` (defalias 'foo (let (recursed) (lambda (x) (unless recursed (setq recursed t) (foo x)))) "Frobnicate X.") ``` Of course, there's nothing wrong with using a dynamic variable instead, depending on your needs. For example, the built-in `lisp/net/shr.el` HTML renderer uses a counter variable that it increments with each recursive call to `shr-descend`. If you're looking for something more complicated than just guarding against recursion, then you may want to look at how `called-interactively-p` uses `backtrace-frame`, or `mapbacktrace`. --- Tags: functions ---
thread-62278
https://emacs.stackexchange.com/questions/62278
Is there any difference between '(let (var) ...)' and '(let ((var nil)) ...)'?
2020-12-15T02:27:17.173
# Question Title: Is there any difference between '(let (var) ...)' and '(let ((var nil)) ...)'? I've seen both `(let (var) ...)` and `(let ((var nil)) ...)` is there any difference between these statements? # Answer > 13 votes The documentation for `let` says: ``` Each element of VARLIST is a symbol (which is bound to nil) or a list (SYMBOL VALUEFORM) (which binds SYMBOL to the value of VALUEFORM). ``` The `let (var)` variant matches the first line — `var` is a symbol, bound to nil. The `let ((var nil))` variant matches the second line — `(var nil)` where `var` is the symbol and the initial value is nil. They do the same thing in this case. # Answer > 13 votes @amitp provided the answer. They do have the same behavior. --- However, IMO they can indicate something slightly different to a human reader of the code -- at least according to an informal convention. That is, they can convey a different connotation. I use `(let (foo) ...)` only when the initial value is intentionally set in the `let` body, e.g., in a conditional way. It tells me, as a (later) reader of my own code, that an initial value of `nil`, which is what it provides, isn't used - makes no difference. I use `let ((foo nil)) ...)` to indicate that the `nil` binding matters -- it really is an intentional initialization. I do it to make the value more obvious. I do the latter also in the case of binding a global variable for which I know that a `nil` value has a particular behavior. Using that form, with the explicit `nil`, points out to me clearly that I'm imposing that `nil` behavior there. IOW, it just makes the binding more obvious. --- Tags: let-binding ---
thread-62281
https://emacs.stackexchange.com/questions/62281
Defining minor-mode buffer-local variables
2020-12-15T07:33:22.663
# Question Title: Defining minor-mode buffer-local variables I want to do something VERY simple. I want to create a minor mode, which when enabled sets a buffer-local variable (say `left-margin-width`, for instance) with a specific value. I can do this: ``` (define-minor-mode margin-mode (setq left-margin-width 3)) ``` Now, I want the variable to take back it's global value when `margin-mode` is disabled. To me this seems like a very natural use-case, but apparently I can't find a simple and easy way to do his yet! Once enabled, the variable retains it's value until the buffer is closed. Which is very undesirable. Help! # Answer > 1 votes Minor modes are toggles. Defining a minor mode also creates a variabel with the same name. This variable is toggled when enabling/disabling the minor mode. So following code works: ``` (define-minor-mode margin-mode (if (not margin-mode) (setq left-margin-width 3) (setq left-margin-width (default-value 'left-margin-width)))) ``` Elisp is a Lisp-n type language. This means there exist separate namespaces for function names and variable names. You can have a variable and a function with the same name. This is used here. (instead of resetting the local variable with `(setq left-margin-width (default-value 'left-margin-width))` you could also use `(kill-local-variable 'left-margin-width)`. --- To get more info on how to define minor modes, read the documentation. you can access the documentation with `C-h f define-minor-mode <RET>` # Answer > 1 votes See `C-h``f` `kill-local-variable` for reverting a buffer-local variable to the global state. If you just set the buffer-local value to the variable's current default value, then it's still a buffer-local value (i.e. it won't reflect future changes to the default). --- Tags: minor-mode, buffer-local ---
thread-52965
https://emacs.stackexchange.com/questions/52965
How to activate leuven-dark-theme?
2019-10-04T14:14:07.007
# Question Title: How to activate leuven-dark-theme? I have installed leuven with melpa a while ago and updated it as of 31st of August 2019. I found out there is a dark version. How do I activate it at loading of Emacs? I have tried: ``` (add-to-list 'custom-theme-load-path " ~/.emacs.d/elpa/leuven-theme-20190831.1008/") (load-theme 'leuven-dark t) ``` Note that (load-theme 'leuven t) works for the light version. I have tried comparing leuven-theme.el and leuven-dark-theme.el but could not find a clue about what I am doing wrong. # Answer > 1 votes Add MELPA to your .emacs file ``` (require 'package) (add-to-list 'package-archives '("melpa" . "https://melpa.org/packages/") t) ;; Comment/uncomment this line to enable MELPA Stable if desired. See `package-archive-priorities` ;; and `package-pinned-packages`. Most users will not need or want to do this. ;;(add-to-list 'package-archives '("melpa-stable" . "https://stable.melpa.org/packages/") t) (package-initialize) ``` Restart Emacs. Refresh package database and install the leuven theme: ``` M-x package-refresh-contents M-x package-install leuven-theme ``` Add this startup hook to your .emacs file ``` (add-hook 'emacs-startup-hook (lambda () (load-theme 'leuven-dark) )) ``` Restart Emacs again. Confirm that you want to run this theme ( asked only at the first start ). # Answer > 0 votes It seems you have to load leuven first and then switch to leuven-dark.So first do ``` (load-theme 'leuven t) ``` Then load leuven-dark via ``` M-x load-theme <RET> leuven-dark <RET> ``` Doing `M-x describe-variable <RET> custom-enabled-themes <RET>` shows that 'leuven-dark' is now installed. My installation is via ``` git clone git://github.com/fniessen/emacs-leuven-theme.git ``` I assume the same applies if you use the package manager. --- Tags: themes ---
thread-62290
https://emacs.stackexchange.com/questions/62290
Cua-mode commands broken at launch (when using evil), until the mode is manually toggled
2020-12-15T14:32:46.957
# Question Title: Cua-mode commands broken at launch (when using evil), until the mode is manually toggled I'm very new to emacs, and can't seem to get cua-mode to work by default. I'm using emacs 26.3 with spacemacs 0.300 on Kubuntu 20.04.1 I have set `(cua-mode t)` in my `.spacemacs`, and cua-mode shows up as active when I check the `M-x menu`, but the cua commands won't work *until* I toggle cua-mode in the `M-x menu` (i.e. turn it off, and then on again), then they work perfectly. This gets old, and I would really like to have those commands working by default. I've tried adjusting a few settings to no avail, here are the related lines in my `.spacemacs` now: ``` (cua-mode t) (setq cua-auto-tabify-rectangles nil) ;; Don't tabify after rectangle commands (transient-mark-mode 1) ;; No region when it is not highlighted (setq cua-keep-region-after-copy t) ;; Standard behaviour (setq org-CUA-compatible t) ``` Thanks for reading, any help you can offer would be greatly appreciated! # Answer > 1 votes So, fwiw, I belatedly discovered that I can remap the commands to accomplish the same effect, as described here, by adding the following to my `init.el`: ``` (define-key evil-insert-state-map (kbd "C-c") 'cua-copy-region) (define-key evil-insert-state-map (kbd "C-v") 'cua-paste) (define-key evil-insert-state-map (kbd "C-x") 'cua-cut-region) (define-key evil-insert-state-map (kbd "C-z") 'undo-tree-undo) (define-key evil-insert-state-map (kbd "C-y") 'undo-tree-redo) ``` --- Tags: evil, cua-mode ---
thread-62224
https://emacs.stackexchange.com/questions/62224
How can I automatically rename buffers created with `async-shell-command` to the shell command that was called?
2020-12-11T18:04:48.983
# Question Title: How can I automatically rename buffers created with `async-shell-command` to the shell command that was called? I am often opening exwm buffers by running `async-shell-command` but unfortunately these buffers always get named `*EXWM*`. It would be great if when I ran `async-shell-command 'firefox` the buffer that gets created would be named firefox. # Answer something like this could work... ``` (defun async-shell-to-buffer (cmd) (interactive "sCall command: ") (let ((output-buffer (generate-new-buffer (format "*async:%s*" cmd))) (error-buffer (generate-new-buffer (format "*error:%s*" cmd)))) (async-shell-command cmd output-buffer error-buffer))) ``` then it's possible to call `(async-shell-to-buffer "firefox")` > 0 votes --- Tags: shell-command, async ---
thread-62298
https://emacs.stackexchange.com/questions/62298
How to use face-remap-set-base to substitute a face for another?
2020-12-15T22:02:59.167
# Question Title: How to use face-remap-set-base to substitute a face for another? I'd like to locally remap a face to other custom face. The docstring reads: > `(face-remap-set-base FACE &rest SPECS)` > > Set the base remapping of `FACE` in the current buffer to `SPECS`. This causes the remappings specified by ‘`face-remap-add-relative`’ to apply on top of the face specification given by `SPECS`. > > The remaining arguments, `SPECS`, should form a list of faces. Each list element should be either a face name or a property list of face attribute/value pairs, like in a ‘face’ text property. Armed with this knowledge, I tried: ``` (defface my/exceptional-face '((t (:background "red"))) "My exceptional face.") (face-remap-set-base 'font-lock-keyword-face '(my/exceptional-face)) ``` In a Lisp buffer, `M-x eval-buffer RET`, I'd expect the keywords to show up with a red background. However, this fails with: ``` (wrong-type-argument listp my/exceptional-face) ``` Indeed, the `face-remap-set-base` function reads: ``` (defun face-remap-set-base (face &rest specs) (while (and (consp specs) (not (null (car specs))) (null (cdr specs))) (setq specs (car specs))) (if (or (null specs) (and (eq (car specs) face) (null (cdr specs)))) ; Error raised here ;; Set entry back to default (face-remap-reset-base face) ;; Set the base remapping ...snip...)) ``` It thus seems that there's no way I can pass a single face to this function. Using: ``` (face-remap-set-base 'font-lock-keyword-face '(my/exceptional-face nil)) ``` …seems to work though. Is that the expected behavior, or is this a bug? # Answer > 1 votes Remove the quoted list from around its elements. Just provide the elements (as an implicit list) as additional args to `face-remap-set-base`: ``` (face-remap-set-base 'font-lock-keyword-face 'my/exceptional-face) ``` The code defining function `face-remap-set-base` binds its single `&rest` parameter `SPECS` to the *list* `(my/exceptional-face)`. The doc says: > The remaining arguments, `SPECS`, should **form a list of faces**. What that means is what **`&rest`** means: provide faces individually as separate additional arguments. Don't provide an explicit *list* of faces as a single argument. You provide any number of faces as additional actual arguments, and the function *receives*, as its single `&rest` argument `SPECS`, a *list* of those actual args that you passed. See the Elisp manual, node Argument List, for an explanation of `&rest`. In the code you provided the list `(my/exceptional-face)` that you passed resulted in the `&rest` parameter `SPECS` being bound to this list: `((my/exceptional-face))`. Function `face-remap-set-base` figured that this was a list of one face, that face (or face spec) being the *list* `(my/exceptional-face)`. A face spec that's a list needs a certain form, and `(my/exceptional-face)` doesn't have that form -- hence the error: ``` (wrong-type-argument listp my/exceptional-face) ``` See node Defining Faces of the Elisp manual for the proper list form of a face spec. --- Oddly enough, I don't find anywhere in the Elisp manual or the Eintr manual (An Introduction to Programming in Emacs Lisp) where it is explained that passing multiple optional args to a function results in a single `&rest` list argument being received. But it's fundamental to Lisp (pretty much any Lisp, not just Elisp). The Common Lisp doc tells you this about a `&rest` parameter: > all remaining arguments are **made into a list** for the `&rest` parameter --- **However**, though all I said is I think true, the code I suggested that you use also fails. I think there's a bug in the code of `face-remap-set-base`. I submitted bug report #45264. We'll find out.... I note that there are zero uses of `face-remap-set-base` in the Emacs Lisp code. Perhaps it was never tested... (Or perhaps I'm mistaken, and someone else will provide a correct answer.) --- Tags: elisp, faces, functions ---
thread-61770
https://emacs.stackexchange.com/questions/61770
whitespace-style "face" activates highlighting of quoted string in fundamental mode
2020-11-16T11:51:16.680
# Question Title: whitespace-style "face" activates highlighting of quoted string in fundamental mode After putting `face` to `whitespace-style`: ``` (setq whitespace-style '(trailing tabs empty face)) (global-whitespace-mode 1) ``` string enclosed in a double quote started to be highlighted by `font-lock-string-face` in fundamental-mode. As workaround I disabled `global-whitespace-mode` and switched to old good v21.1 style: ``` (setq-default show-trailing-whitespace t) (set-face-attribute 'trailing-whitespace nil :background "magenta") ``` Still I like `whitespace-mode` goodies. It is a bug? How can I debug an issue with double quotation highlighting? **EXTRA** When problem is here `font-lock-keywords` has value: ``` (t ((whitespace-point--flush-used) (#1="\\( +\\)" . #2=(1 whitespace-tab t)) (whitespace-trailing-regexp . #3=(1 whitespace-trailing t)) (whitespace-empty-at-bob-regexp . #4=(1 whitespace-empty t)) (whitespace-empty-at-eob-regexp . #5=(1 whitespace-empty t))) (whitespace-point--flush-used (0 nil)) (#1# #2#) (whitespace-trailing-regexp #3#) (whitespace-empty-at-bob-regexp #4#) (whitespace-empty-at-eob-regexp #5#)) ``` # Answer The following will do it. It's source is from `font-lock.el` which is included in emacs. ``` (setq font-lock-string-face nil) ``` > 1 votes --- Tags: whitespace, whitespace-mode ---
thread-46259
https://emacs.stackexchange.com/questions/46259
Force new window to open to the left or right
2018-11-27T17:11:06.093
# Question Title: Force new window to open to the left or right I have two frames open with the following window splits: ``` Frame 1 Frame 2 |---+---+ |------| |a |b | |d | | | | | | |---+---+ | | |c | | | |---+---+ |------| ``` Say that I am in window `"a"` or `"b"`. Sometimes when I call a function that needs a window, a new, tiny one `"e"` will be created instead of using a current one. This new window is often too small to be of use. ``` Frame 1 Frame 2 |---+---+ |------| |a |b | |d | | | | | | |---+---+ | | |c |e | | | |---+---+ |------| ``` **How could I open new windows in one of the currently existing vertical windows, `"a"`, `"b"`, or `"d"`?** I have experienced this issue with at least `occur` and `xref-find-definitions-other-window`. --- The crux of the issue seems to be with the `display-buffer` function. At first glance it seemed like I could use `display-buffer-in-side-window` to get the behavior I want. In the case of `occur`, I came up with ``` (setq display-buffer-alist `(("\\*Occur\\*" display-buffer-in-side-window (side . right) (slot . 0) (window-width . fit-window-to-buffer)))) ``` This has two problems. First, it turns out that a side window isn't a window like `"b"` is to `"a"`. Instead, it is a 'hidden' window that can be toggled. For instance, the above code does the following when in window `"a"`, `"b"`, or `"c"` ``` Frame 1 Frame 2 |---+---+---| |---| |a |b |e | |d | | | | | | | |---+---+ | | | |c | | | | |---+---+---| |---| ``` and does the following when in `"d"` ``` Frame 1 Frame 2 |---+---+ |---|---| |a |b | |d |e | | | | | | | |---+---+ | | | |c | | | | |---+---+ |---|---| ``` Unfortunately, Frame 2 lives on a vertically aligned monitor and the windows `"d"` and `"e"` are too narrow to be convenient. It's the same kind of problem as before! The second problem is that it relies on an explicit buffer name. When using `xref-find-definitions-other-window`, the buffer name varies. # Answer > 3 votes You can invoke `windmove-display-up`/`-down`/`-left`/`-right`, `windmove-display-same-window` (`C-M-S-0`) or `windmove-display-new-tab` (`C-M-S-t`) right before making a new buffer to specify where to put it. The function `windmove-display-default-keybindings` sets up key bindings for the directional `windmove-display-*` commands. Withouth arguments, it sets `S-M-<arrow key>` as the key bindings, so that, for instance, `S-M-right` followed by `C-x` `4` `b` tells Emacs to display the next buffer in the window at the right (creating it if necessary). `windmove-display-default-keybindings` can take as argument a list of modifiers that it will use in place of the default ones. For example, `(windmove-display-default-keybindings '(control meta shift))` sets the key bindings to `C-M-S-<arrow keys>`. So, say you have evaluated `(windmove-display-default-keybindings '(control meta shift))`, you're in window `a` and you want to use `xref-find-definitions-other-window` (plain `xref-find-definitions` doesn't obey `windmove-*` functions). You can open the buffer with the definition * in the current window with `C-M-S-0` `M-x` `xref-find-definitions-other-window` `RET`; * in window `b` with `C-M-S-→` `M-x` `xref-find-definitions-other-window` `RET`; * in window `c` with `C-M-S-↓` `M-x` `xref-find-definitions-other-window` `RET`; * in another tab with `C-M-S-t` `M-x` `xref-find-definitions-other-window` `RET`; Same for `occur`: `C-M-S-0` `M-s` `o` *`REGEXP`* `RET`, and so on. `windmove-*` functions also work on clickable text with `C-M-S-0` `mouse-2` (middle click) etc.. I don't know how to open the buffer in another frame (window `d`). --- Tags: buffers, window-splitting, occur ---
thread-16548
https://emacs.stackexchange.com/questions/16548
extraneous stars when using org-indent-mode
2015-09-11T20:01:30.883
# Question Title: extraneous stars when using org-indent-mode Since a recent update from the org-mode repository, if I turn on `org-indent-mode`, all lines show up indented with stars rather than spaces. Here's an example of how it looks: Here's the file without indenting: I am using Emacs 24.4.1 on Linux. Do you know what may be causing this? # Answer > 2 votes I was able to fix this by setting the `org-indent` font to have the same foreground and background color. To do this, in my `custom-set-faces`, I included the following line: ``` '(org-indent ((t (:background "#181818" :foreground "#181818")))) ``` # Answer > 1 votes A theme tweak may fix the problem: you can adapt the following .emacs excerpt code for your case: ``` (let ((class '((class color)))) (custom-theme-set-faces 'leuven `(org-hide ((,class (:foreground "#000000")))))) ``` My theme is `leuven`. I tried to change the color `#000000` which changed the color oh the "hidden" stars. # Answer > 0 votes The thing that helped me was to delete the older theme packages that I was using. --- Tags: org-mode, indentation ---
thread-62162
https://emacs.stackexchange.com/questions/62162
Dead keys suddenly not working in Emacs
2020-12-08T10:30:27.030
# Question Title: Dead keys suddenly not working in Emacs I'm using the emacs package on debian 10 and the dead keys for typing accents on characters (for instance, á) are no longer working. WHen I type the dead key, some kind of tiny window or artifact gets displayed, and then when I type the character itself the artifact disappears but nothing gets typed. I think I must have unwittingly toggled some option, because I haven't changed anything in locale,etc and all other applications except emacs work well re typing of accents. What can I do to get dead keys working again? Thanks # Answer > 1 votes I have the same problem. Reproduced with `emacs -Q`, version `GNU Emacs 27.1 (build 1, x86_64-pc-linux-gnu, GTK+ Version 3.24.23, cairo version 1.16.0)` A workaround is disabling the input methods, as described in https://www.emacswiki.org/emacs/DeadKeys. Namely the option of unsetting the `XMODIFIERS` environment variable works for me: `env XMODIFIERS= emacs`. Launching emacs like this, the pop-up does not show and the XKB-defined dead keys produced the combined characters. I believe that this means giving up on all the fancy input method facilities provided by emacs, but I don't use those anyways. The first workaround described in the Emacs Wiki, `(require 'iso-transl)`, does not do anything for me. --- Tags: prefix-keys ---
thread-62318
https://emacs.stackexchange.com/questions/62318
storing string in variable fails to work in `early-init.el`
2020-12-17T01:30:56.123
# Question Title: storing string in variable fails to work in `early-init.el` Putting the following code in my `early-init.el` causes my emacs not to startup. ``` (require 'cl-lib) (defvar void-initial-frame-font (cl-find-if (lambda (font) (find-font (font-spec :name font))) (list "Victor Mono-19" "Anonymous-Pro-19")) "Font for initial frame.") (push (cons 'font void-initial-frame-font) default-frame-alist) ``` The form `(cl-find-if ...)` evaluates to "Victor Mono-19". Thus `void-initial-frame-font` is "Victor Mono-19". When I replace the variable `void-initial-frame-font` in the push form with what it should evaluate to, my emacs config starts up successfully with the frame font being "Victor Mono-19" as I would expect. ``` (require 'cl-lib) (defvar void-initial-frame-font (cl-find-if (lambda (font) (find-font (font-spec :name font))) (list "Victor Mono-19" "Anonymous-Pro-19")) "Font for initial frame.") ;; replaced `void-initial-frame-font` with what it should evaluate to (push (cons 'font "Victor Mono-19") default-frame-alist) ``` For fun, I tried to see if let binding the variable font would work, but it did not. The following form also causes my emacs to fail to start. ``` (require 'cl-lib) (let ((font (cl-find-if (lambda (font) (find-font (font-spec :name font))) (list "Victor Mono-19" "Anonymous-Pro-19")))) (push (cons 'font font) default-frame-alist)) ``` Why can't I store the result of evaluating the `(cl-find-if ...)` form `early-init.el`? # Answer ``` find-font is a built-in function in ‘C source code’. (find-font FONT-SPEC &optional FRAME) Probably introduced at or before Emacs version 23.1. Return a font-entity matching with FONT-SPEC on the current frame. Optional 2nd argument FRAME, if non-nil, specifies the target frame. ``` I think you'll find that either there is no "current frame" during early init, or else that it's not a frame which is useful for this purpose. > 1 votes --- Tags: init-file, variables ---
thread-60560
https://emacs.stackexchange.com/questions/60560
Error retrieving: https://elpa.gnu.org/packages/archive-contents (error http 400)
2020-09-08T14:28:48.217
# Question Title: Error retrieving: https://elpa.gnu.org/packages/archive-contents (error http 400) I am on this version of GNU Emacs on a Windows 10 computer: GNU Emacs 26.3 (build 1, x86\_64-w64-mingw32) of 2019-08-29 For the past many weeks, Emacs report this error accessing GNU Elpa when I run "list-packages": Importing package-keyring.gpg...done error in process filter: Error retrieving: https://elpa.gnu.org/packages/archive-contents (error http 400) \[2 times\] Package refresh done In a browser, I can access the URI just fine. This happens on two Windows 10 boxes I have. A Google shows complaints about such errors as recently as a year ago, though I've not found any with "http 400 (Bad Request)". In addition, I don't have errors for melpa stable, the other repository in my package-archives list: ``` '(package-archives (quote (("gnu" . "https://elpa.gnu.org/packages/") ("melpa-stable" . "https://stable.melpa.org/packages/")))) ``` Does one of you have suggestions on what else I might try? Thanks, Mario # Answer > 14 votes try this out : (setq gnutls-algorithm-priority "NORMAL:-VERS-TLS1.3") reference: https://www.reddit.com/r/emacs/comments/cdei4p/failed\_to\_download\_gnu\_archive\_bad\_request/etw48ux/?utm\_source=share&utm\_medium=web2x Explanation: It is a race bug int Emacs and newer versions of GNU TLS that showed up in Emacs v26.1 but is fixed in Emacs v27. A simple temporary fix is just to turn of TLS 1.3 support in Emacs v26.1 and the race conditions goes away. It is not a good solution, as we need TLS 3.1, but it will do until the propper sollution is implemented. As discussed in the original bug report. See https://debbugs.gnu.org/cgi/bugreport.cgi?bug=34341#19 # Answer > 2 votes This is most likely your Emacs not having working TLS support. Make sure your Emacs has been built with GnuTLS support (this should be on by default, check with `M-: (string-match-p "GNUTLS" system-configuration-features)`) and that the GnuTLS libraries are available in the expected location. The easiest way of doing the latter on Windows is installing a version that includes the dependencies, check https://ftp.gnu.org/gnu/emacs/windows/ for the relevant downloads. --- Tags: package-repositories, list-packages ---
thread-62324
https://emacs.stackexchange.com/questions/62324
Is there a convenient way to swap two words that aren't adjacent?
2020-12-17T09:07:35.580
# Question Title: Is there a convenient way to swap two words that aren't adjacent? I've recently been editing some source code where I often want to swap elements in an array that spans multiple lines. Doing this manually is quite tedious, moving the cursor between both locations and copy-pasting twice. It's possible to write a utility that does this - which would be much faster than copy-pasting between two locations (either with a single mouse drag, or marking two locations with the cursor). However for all I know this may already exist. Does Emacs provide a convenient way to do this, or is there a package this supports this feature? # Answer > 11 votes Function transpose-words can do that. * Set a mark at one word (C-SPC). * Move the cursor to the other word. * C-0 M-t Enjoy! --- Tags: text-editing, selection ---
thread-61501
https://emacs.stackexchange.com/questions/61501
Make mark color overlap highlight symbol at point
2020-10-31T16:45:38.210
# Question Title: Make mark color overlap highlight symbol at point I use auto-highlight-symbol-mode package to auto highlight symbol on point. I found it annoying when I mark a text because the symbol highlight overlaps on my marked text, so I don't see if I marked what I want to mark already. I have no attachment to `auto-highlight-symbol-mode` package or anything else, I just looking for a way to have a auto highlight symbol functionality overlapped by text mark background color. Any solution? # Answer The solution I ended up with is symbol-overlay package with `(setq symbol-overlay-idle-time 0.1)` which makes highlighting instant. > 1 votes --- Tags: syntax-highlighting, colors, highlighting ---
thread-62307
https://emacs.stackexchange.com/questions/62307
Cannot evaluate matplotlib in Python code block
2020-12-16T13:24:33.677
# Question Title: Cannot evaluate matplotlib in Python code block These are my first attempts to plot graph in Python. Following this example , I tried a very simple graph ``` import matplotlib.pyplot as plt import matplotlib as mpl import numpy as np x = np.linspace(0, 20, 100) plt.plot(x, np.sin(x)) plt.show() plt.savefig('python-matplot-fig.png') return 'python-matplot-fig.png' # return filename to org-mode ``` I got an error : ``` Traceback (most recent call last): File "<stdin>", line 13, in <module> File "<stdin>", line 3, in main ImportError: No module named matplotlib.pyplot ``` Whereas I have the python installed and running on my system. On VsCode, it is calculated I use spacemacs python layer ``` dotspacemacs-configuration-layers '( (python :variables python-backend 'anaconda python-format-on-save t python-sort-imports-on-save t) ``` # Answer The python version used by org-babel was 2.7.8 To use the "last" version of Python on my system, I used in my init.el file ``` (setq org-babel-python-command "python3") ``` then all librairies installed by `pip` in my terminal were usable > 1 votes --- Tags: org-mode, spacemacs, org-babel, python ---
thread-62319
https://emacs.stackexchange.com/questions/62319
The `org-set-effort` fn has changed behavior on Emacs 28? How to select an effort by index typing 1, 2, 3 etc.? instead type the entire value?
2020-12-17T01:40:13.090
# Question Title: The `org-set-effort` fn has changed behavior on Emacs 28? How to select an effort by index typing 1, 2, 3 etc.? instead type the entire value? I was using Emacs 26 and put this line on top of my org-mode file: ``` #+PROPERTY: Effort_ALL 0:25 0:50 1:15 1:40 2:05 2:30 2:55 3:20 3:45 4:10 4:35 5:00 5:25 5:50 6:15 6:40 7:05 7:30 7:55 8:20 ``` This means how much "pomodoros" (25 min each) I'd like to make as an effort prediction. When I pressed `C-c C-x e` (aka `M-x org-set-effort`) I could type like `1`, `2`, `3`, `4`... until `9` to say that I want like "1 pomodoro", "2 pomodoros", "3 pomodoros" and so on. After upgrade my Emacs to version 28 now I cannot type the number as index. I should type the entire value, like `0:50`, for example. I could not type 1, 2 etc. anymore. Why not? What have changed and what can I do to back the previous behavior? Thank you. # Answer The signature of `org-set-effort` changed with this commit and does not allow using an index into the allowed values any longer. There is no option to restore the previous behavior. This change went in to Org mode with version 9.2. See also ORG-NEWS and the description of `org-set-effort` in the manual. The new version allows completion so you can select by typing a prefix or by selecting from a completion buffer. That said however, it seems to me that what you should be doing is to use a function that uses the units that you prefer in this case: `pomodoros`, not minutes. So instead of specifying that number indirectly (by pre-calculating a list of values and then using a number as an index into that list, something which is error-prone for an arbitrary list, since you have to count to figure out which value you want), specify instead the value of a `pomodoro` in conventional units and then use the number of `pomodoros` as a multiplier. For example, let's say you want 1 pomodoro = 25 minutes. Here is an implementation for that: ``` * effort :PROPERTIES: :Effort: 1:15 :END: * Code :noexport: #+begin_src emacs-lisp (defun ndk/org-set-effort-in-pomodoros (n) (interactive "nHow many pomodoros: ") (let ((mins-per-pomodoro 25)) (org-set-effort nil (org-duration-from-minutes (* n mins-per-pomodoro))))) ;; redefine the key binding `C-c C-x e' which was originally bound to `org-set-effort' ;; to the pomodoro function (define-key org-mode-map (kbd "C-c C-x e") #'ndk/org-set-effort-in-pomodoros) #+end_src ``` Note that I rebind the `C-c C-x e` key, which was originally bound to `org-set-effort`, to the new function, assuming that that's going to be your main interface to set the effort (you can always call `org-set-effort` with `M-x org-set-effort RET` anyway, but you might want to bind the new function to some other key and leave the existing binding alone. If so, change the key(s) you specify in the `define-key` above to suit your taste, but in the following I've assumed that the original key combo has been redefined.) If you say `C-c C-x e` now, you will call the `ndk/org-set-effort-in-pomodoros` function, which will ask you how many pomodoros this effort is worth. I answered `3` and it calculated the duration as `3*25 = 75 minutes` or as a duration `1:15`. There is no need to pre-calculate the list or use an index. You might want to specify the `pomodoro` duration to be something other than 25 minutes. Let's imagine that you do that by defining a property `MINUTES_PER_POMODORO`: if that's defined, we use the property value, otherwise we use 25. The implementation is now a bit more complicated, but not by much: ``` #+PROPERTY: MINUTES_PER_POMODORO 9 * effort :PROPERTIES: :Effort: 0:27 :END: * Code :noexport: #+begin_src emacs-lisp (defun ndk/org-set-effort-in-pomodoros (n) (interactive "nHow many pomodoros: ") (let* ((mins-per-pomodoro-prop (org-entry-get (point) "MINUTES_PER_POMODORO" t)) (mins-per-pomodoro (if mins-per-pomodoro-prop (string-to-number mins-per-pomodoro-prop) 25))) (org-set-effort nil (org-duration-from-minutes (* n mins-per-pomodoro))))) ;; redefine the key binding `C-c C-x e' which was originally bound to `org-set-effort' ;; to the pomodoro function (define-key org-mode-map (kbd "C-c C-x e") #'ndk/org-set-effort-in-pomodoros) #+end_src ``` You might also want to be able to specify the number of pomodoros as a prefix argument, so you can say `M-3 C-c C-x e` to specify 3 pomodoros. The question is what to do when you call the function without a prefix argument; the following implements a default value of 1 pomodoro in that case: ``` (defun ndk/org-set-effort-in-pomodoros (&optional n) (interactive "p") (setq n (or n 1)) ; if prefix arg is nil, then use the default setting of 1 (let* ((mins-per-pomodoro-prop (org-entry-get (point) "MINUTES_PER_POMODORO" t)) (mins-per-pomodoro (if mins-per-pomodoro-prop (string-to-number mins-per-pomodoro-prop) 25))) (org-set-effort nil (org-duration-from-minutes (* n mins-per-pomodoro))))) ``` Or you might want to use the prefix argument if specified, but instead of using the default of 1 if not, force the user to enter a value in the minibuffer (as was done in the first two implementations): ``` (defun ndk/org-set-effort-in-pomodoros (&optional n) (interactive "P") (setq n (or n (string-to-number (read-from-minibuffer "How many pomodoros: " nil nil nil nil "1" nil)))) (let* ((mins-per-pomodoro-prop (org-entry-get (point) "MINUTES_PER_POMODORO" t)) (mins-per-pomodoro (if mins-per-pomodoro-prop (string-to-number mins-per-pomodoro-prop) 25))) (org-set-effort nil (org-duration-from-minutes (* n mins-per-pomodoro))))) ;; redefine the key binding `C-c C-x e' which was originally bound to `org-set-effort' ;; to the pomodoro function (define-key org-mode-map (kbd "C-c C-x e") #'ndk/org-set-effort-in-pomodoros) ``` Hope this helps. > 1 votes --- Tags: org-mode, key-bindings ---
thread-62336
https://emacs.stackexchange.com/questions/62336
Do not colour "word" colours in rainbow-mode
2020-12-17T18:45:40.113
# Question Title: Do not colour "word" colours in rainbow-mode In `rainbow-mode`, is it possible to toggle colouring only "words" or only "hexadicimals"? I don't see a variable I could set. # Answer > 1 votes The code is in the library `rainbow-mode.el`, particularly the functions `rainbow-turn-on` and `rainbow-turn-off`. You can make copies of these functions that include or omit the appropriate sets of commands to get the result you want. A quick and dirty example: ``` (defun rainbow-turn-off-hexadecimal () "Turn off hexadecimal colours in rainbow-mode." (interactive) (font-lock-remove-keywords nil `(,@rainbow-hexadecimal-colors-font-lock-keywords))) (defun rainbow-turn-off-words () "Turn off word colours in rainbow-mode." (interactive) (font-lock-remove-keywords nil `(,@rainbow-x-colors-font-lock-keywords ,@rainbow-latex-rgb-colors-font-lock-keywords ,@rainbow-r-colors-font-lock-keywords ,@rainbow-html-colors-font-lock-keywords ,@rainbow-html-rgb-colors-font-lock-keywords))) ``` With these functions defined, call `rainbow-mode`, and then `M-x rainbow-turn-off-words` to remove the highlighting from words, and leave it for the hexadecimals. Note that the colours won't change immediately, it will happen next time the buffer is 're-fontified'. You can force this by calling `font-lock-fontify-buffer`. You can reset your colors by turning rainbow mode off and on again. --- Tags: colors ---