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-55216
https://emacs.stackexchange.com/questions/55216
The dirtree mode not present installed using melpa
2020-01-31T11:59:49.890
# Question Title: The dirtree mode not present installed using melpa My Emacs version is 25.2.2. I installed dirtree using melpa. But `M-x dirtree` is not there. # Answer Command `dirtree` is not marked for autoloading so you need do `(require 'dirtree)` first. Or follow instructions provided in `dirtree` commentary section: > Put the following into your ~/.emacs: > > `(autoload 'dirtree "dirtree" "Add directory to tree view" t)` > 1 votes --- Tags: require, load ---
thread-55197
https://emacs.stackexchange.com/questions/55197
Call mode-specific backspace from "smart-backspace" function
2020-01-30T14:27:42.823
# Question Title: Call mode-specific backspace from "smart-backspace" function I'm writing an IntelliJ-style "smart backspace" function which does the following: * If the whole of the line up to the point is whitespace + Join the line to the previous line, killing that whitespace + Indent the line * Otherwise, just delete a char **as normal** I've got the smart backspace working, but the **as normal** part is proving difficult. ``` (defun smart-backspace () (interactive) (if (beginning-of-line-text-p) (progn (join-line) (indent-according-to-mode)) (delete-backward-char 1))) ``` The problem is most language modes provide their own version of `delete-backward-char`, so overriding backspace like this doesn't do handy (or crucial!) stuff such as `paredit`/`smartparens`' `sp-backward-delete-char`, which keeps the sexp tree intact when you backspace over a closing delimiter. What I'm asking is: is there a way to call the "default" binding for a key or mode from inside a function such as mine? # Answer > 0 votes The answer is "yes". As usual, I suspect that's not the answer you were looking for, tho. How to do that depends on how you bind your backspace key to your `smart-backspace` command. One way to do it is to bind it as part of a minor mode: ``` (defvar smart-backspace-mode-map (let ((map (make-sparse-keymap))) (define-key map (kbd "DEL") 'smart-backspace) map)) (define-minor-mode smart-backspace-mode "Be smart." :global t) ``` in which case you can call the "default" binding with something like: ``` (let ((smart-backspace-mode nil)) (command-execute (key-binding (this-single-command-keys)))) ``` # Answer > 1 votes Stefan's solution is almost perfect, but it required the following modifications: * Use `command-execute` instead of `execute-command` * Provide a fallback to backspace when no key binding is defined, via `or`: ``` (defun smart-backspace () (interactive) (if (beginning-of-line-text-p) (progn (join-line) (indent-according-to-mode)) (let ((smart-backspace-mode nil)) (command-execute (or (key-binding (this-single-command-keys)) 'evil-delete-backward-char-and-join))))) ``` --- Tags: key-bindings, major-mode ---
thread-55221
https://emacs.stackexchange.com/questions/55221
HTML export with Org mode : all CSS specifications in one external file
2020-01-31T15:49:00.510
# Question Title: HTML export with Org mode : all CSS specifications in one external file I am using org mode to write my personnal website. I use the workflow described in the documentation (cf. https://orgmode.org/worg/org-tutorials/org-publish-html-tutorial.html) and I therefore have a `converter.el` file consisting, as in the link given above, of the definition of `org-publish-project-alist` with the *notes* and *static* components. I evaluate the whole buffer and run `org-publish-project "org"` everytime I want to export my files to HTML. However, I use my own CSS files to style my webpage. For the moment, my files all have a variant of `#+HTML_HEAD: <link rel="stylesheet" href="./css/style.css"/>` in their first lines. This is totally functionnal and gives the expected graphical result as it allows me to use my own options. `#+STYLE: ...` is great too. However, what I'm looking for is the following : I would like to have simple .org files with only the markup part and a unique "switch file" specifying for each of the .org file what style should be assigned, or more generally what are its options. This way, I would have a total separation between my writings (the .org files) and the configuration (this "switch file" plus the CSS files). I guess this file would have some kind of switch-loop structure (hence its name here) and should be used in `convert.el`, but I have no idea how to code it. Anyone have any idea how to program it ? I've tried myself but I'm not really good at elisp. I've also searched the web for similar questions, but all the examples I've found always specify the style in the preamble of .org files... Any advice is welcome ! # Answer > 2 votes A useful option is to put ``` #+SETUPFILE: mysetup.org ``` at the top of each `.org` file and then place your common heading commands such as ``` #+HTML_HEAD: <link rel="stylesheet" type="text/css" href="mystyle.css" /> ``` in the file `mysetup.org`. Note that `mysetup.org` can contain further `#+SETUPFILE:` lines, reading in other files. --- Tags: org-mode, org-export, html, css ---
thread-55224
https://emacs.stackexchange.com/questions/55224
How could I change the font color on the popped out window (jedi)?
2020-01-31T18:59:39.697
# Question Title: How could I change the font color on the popped out window (jedi)? I am using `python-mode` and `jedi` for autocompletion. ``` (add-hook 'python-mode-hook 'jedi:setup) (add-hook 'python-mode-hook 'jedi:ac-setup) (require 'auto-complete-config) (ac-config-default) (set-face-background 'ac-completion-face "black") (set-face-underline 'ac-completion-face "black") (set-face-underline 'ac-selection-face "black") ``` The font color show up as yellow on top of a gray background, which is unreadable. Also for the selected line, gray font on top of blue is unreadable. I want to change the font color or the background color, if its possible. --- **\[Q\]** How could I change the font color or the background color on the popped out window that show up on jedi usage? # Answer It's auto-complete package. Completion candidates colors can be changed by customizing `ac-completion-face`, `ac-candidate-face`, `ac-candidate-mouse-face` and `ac-selection-face`. That window with additional candidate info can be changed by customizing `popup-tip-face`. > 1 votes --- Tags: coloring, jedi ---
thread-55226
https://emacs.stackexchange.com/questions/55226
How do I prevent `M-x` then `C-g` from entering the debugger?
2020-01-31T20:14:05.183
# Question Title: How do I prevent `M-x` then `C-g` from entering the debugger? `M-x version` gives: ``` GNU Emacs 26.3 (build 1, x86_64-pc-linux-gnu, GTK+ Version 3.22.30) of 2019-12-02 ``` Quitting the minibuffer in general, or (e.g.,) pressing `M-x` -\> `C-g` in particular opens a `*Backtrace*` buffer with this in it: ``` Debugger entered--Lisp error: (quit) read-from-minibuffer("M-x " nil (keymap (7 . minibuffer-keyboard-quit) (10 . minibuffer-complete-and-exit) (13 . minibuffer-complete-and-exit) keymap (7 . minibuffer-keyboard-quit) (menu-bar keymap (minibuf "Minibuf" keymap (tab menu-item "Complete" minibuffer-complete :help "Complete as far as possible") (space menu-item "Complete Word" minibuffer-complete-word :help "Complete at most one word") (63 menu-item "List Completions" minibuffer-completion-help :help "Display all possible completions") "Minibuf")) (27 keymap (118 . switch-to-completions)) (prior . switch-to-completions) (63 . minibuffer-completion-help) (32 . minibuffer-complete-word) (9 . minibuffer-complete) keymap (menu-bar keymap (minibuf "Minibuf" keymap (previous menu-item "Previous History Item" previous-history-element :help "Put previous minibuffer history element in the minibuffer") (next menu-item "Next History Item" next-history-element :help "Put next minibuffer history element in the minibuffer") (isearch-backward menu-item "Isearch History Backward" isearch-backward :help "Incrementally search minibuffer history backward") (isearch-forward menu-item "Isearch History Forward" isearch-forward :help "Incrementally search minibuffer history forward") (return menu-item "Enter" exit-minibuffer :key-sequence "\015" :help "Terminate input and exit minibuffer") (quit menu-item "Quit" abort-recursive-edit :help "Abort input and exit minibuffer") "Minibuf")) (10 . exit-minibuffer) (13 . exit-minibuffer) (7 . minibuffer-keyboard-quit) (C-tab . file-cache-minibuffer-complete) (9 . self-insert-command) (XF86Back . previous-history-element) (up . previous-line-or-history-element) (prior . previous-history-element) (XF86Forward . next-history-element) (down . next-line-or-history-element) (next . next-history-element) (27 keymap (114 . previous-matching-history-element) (115 . next-matching-history-element) (112 . previous-history-element) (110 . next-history-element))) nil extended-command-history nil nil) completing-read-default("M-x " #f(compiled-function (string pred action) #<bytecode 0x2859eb>) commandp t nil extended-command-history nil nil) completing-read("M-x " #f(compiled-function (string pred action) #<bytecode 0x2859eb>) commandp t nil extended-command-history) read-extended-command() byte-code("\302\030\011\303 \010E)\207" [execute-extended-command--last-typed current-prefix-arg nil read-extended-command] 3) call-interactively(execute-extended-command nil nil) command-execute(execute-extended-command) ``` I've google'd a bit, and not found anything similar. I suspect something like out of date packages on my install, but any hints would be appreciated. # Answer > 2 votes To reproduce exactly the same behavior in `emacs -Q`: 1. `M-x toggle-debug-on-quit` 2. `M-x C-g` Looks like you have the `debug-on-quit` variable set to non-nil. Either directly or by `toggle-debug-on-quit` command or my menu `Options->Enter Debugger on Quit`. --- Tags: minibuffer, quitting ---
thread-55227
https://emacs.stackexchange.com/questions/55227
How do I change the highlight color for selected texts on isearch?
2020-01-31T20:56:56.623
# Question Title: How do I change the highlight color for selected texts on isearch? When I search a text on `isearch` due highlighed color it is not readable. Following line does not have any affect on the main selected word on the `isearch`: ``` (set-face-attribute 'lazy-highlight nil :foreground "black" :background "green") ``` Example: **\[Q\]** How do I change the highlight color for selected text on isearch? # Answer See these faces: * `isearch` > Face for highlighting Isearch matches. * `isearch-fail` > Face for highlighting failed part in Isearch echo-area message. * `lazy-highlight` > Face for lazy highlighting of matches other than the current one. > 4 votes --- Tags: faces, isearch ---
thread-55232
https://emacs.stackexchange.com/questions/55232
Apply different function to each element in list?
2020-02-01T02:08:43.097
# Question Title: Apply different function to each element in list? I have a time-stamp of a video formatted as "00:00:00,000" such that "%H:%M:%s,%3N". I am want to eventually use this timestamp as part of an `in-interval-p` function where I take two timestamps and a current timestamp and check if I'm currently between the two. The best idea I have is to convert these timestamps to cumulative seconds. I'm not sure if this is the best way to do it, but here is what I currently have ``` (require 'dash) (require 's) (defvar time-stamp "00:00:52,010") (s-split "[:|,]" time-stamp) ;; ("00" "00" "52" "010") ``` What I would like to do, but not sure how, is something like ``` (map '((lambda (x) (* x 3600.0)) (lambda (x) (* x 60.0)) (lambda (x) (x)) (lambda (x) (/ (float x) 1000.0))) (s-split "[:|,]" time-stamp)) ;; (0.0 0.0 52 0.01) ``` Is it possible to apply a different function at each index of a list? I would then sum the list to get `52.01` seconds. # Answer > 2 votes There is a function in the "dash" library you are using. ``` (-zip-with #'funcall '((lambda (x) (* x 3600.0)) (lambda (x) (* x 60.0)) (lambda (x) x) (lambda (x) (/ (float x) 1000.0))) (mapcar #'string-to-number (s-split "[:|,]" time-stamp))) ``` Note that `s-split` returns *strings* but you want to work with *numbers*, so you can use `string-to-number` for that. # Answer > 4 votes I think you've overcomplicated the problem. You're obtaining a list comprising hours, minutes, seconds, and microseconds, so I think your code would be simpler and more readable if you expressed that explicitly: ``` (require 'cl-lib) (defvar time-stamp "00:00:52,010") (cl-destructuring-bind (hours minutes seconds microseconds) (mapcar #'string-to-number (split-string time-stamp "[:,]")) (+ (* hours 3600) (* minutes 60) seconds (/ (float microseconds) 1000.0))) ``` --- Tags: list, time-date, mapping ---
thread-55147
https://emacs.stackexchange.com/questions/55147
Enabling minor modes via customize
2020-01-27T14:37:01.227
# Question Title: Enabling minor modes via customize I see that minor modes defined via `define-minor-mode` have a variable that has the same name as the function and the following documentation: > Setting this variable directly does not take effect; either customize it (see the info node β€˜Easy Customization’) or call the function β€˜editorconfig-mode’. However, customizing doesn't seem to work for me. The value of the variable ends up as `nill`, β€œCHANGED outside Customize”, and the minor mode is not enabled unless I additionally add the following to my `.emacs`: ``` (editorconfig-mode 1) ``` In this example I'm using `editorconfig-mode`, but I have the issue with other modes too. What am I missing? Do I need to do something extra or in a different order to get these customized variable to take effect? # Answer `(package-initialize)` must appear before `(custom-set-variables …)` in the initialisation file. The next major release of GNU Emacs, version 27, will initialise packages before loading the init file, so this will no-longer be an issue. > 1 votes # Answer This is a feature of global minor modes. `define-minor-mode` declares a *default* custom<sup>1</sup> `:set` value for the mode variable like so: ``` (unless set (setq set '(:set #'custom-set-minor-mode))) ``` That function is: ``` (defun custom-set-minor-mode (variable value) ":set function for minor mode variables. Normally, this sets the default value of VARIABLE to nil if VALUE is nil and to t otherwise, but if `custom-local-buffer' is non-nil, this sets the local binding in that buffer instead." (if custom-local-buffer (with-current-buffer custom-local-buffer (funcall variable (if value 1 0))) (funcall variable (if value 1 0)))) ``` So this facility ought to be working generally, unless the mode in question has clobbered that default without replicating the behaviour. --- <sup>1</sup> The variable is only defined with `defcustom` if the mode is global, so this has no effect for buffer-local minor modes. > 0 votes --- Tags: customize, minor-mode ---
thread-55235
https://emacs.stackexchange.com/questions/55235
How to overwrite a package major mode?
2020-02-01T12:33:37.760
# Question Title: How to overwrite a package major mode? I'm a newcomer to Emacs from Vim, I use `rsjx-mode` for react files. Its major mode calls itself `RJSX`, but I would like to call it `React`, so how can I overwrite the rjsx package major mode name? # Answer If you don't want to use the `delight` package, you can also just do it by hand: ``` (add-hook 'rsjx-mode-hook (lambda () (setq mode-name "React"))) ``` > 0 votes # Answer If you install the `delight` package: `M-x` `package-install` `RET` `delight` `RET` You can then add this configuration to your init file: ``` (delight 'rsjx-mode "React" :major) ``` in order to change the name displayed in the mode line. > 1 votes --- Tags: major-mode ---
thread-55241
https://emacs.stackexchange.com/questions/55241
How to avoid export org-mode header title
2020-02-01T19:30:32.820
# Question Title: How to avoid export org-mode header title I am translating a quite flat document (only has a title as a level 1 heading). I am using org-mode and I am creating a level 2 heading for each page to easily find the content when I am reviewing the translation which makes the process easier. I wonder if there is a way to export the full document to PDF/HTML and not include the level 2 headings TITLE but indeed include the full content within the level 2 heading. I need to ingore only level 2 heading titles. Thanks. Herewith an example: ``` * The document title ** DONE Pag 1 bla bla... ** TODO Pag 2 ...more bla bla... ``` Desired output: ``` * The document title bla bla... (new page) ...more bla bla... ``` # Answer Set `ignore` tag and `clearpage` property to `t`. ``` ** Heading :ignore: :PROPERTIES: :clearpage: t :END: This will be exported on new page w/o heading. ``` The `:ignore:` tag is enabled with: ``` (require 'ox-extra) (ox-extras-activate '(ignore-headlines)) ``` Source: Is it possible to export content of subtrees without their headings? > 2 votes --- Tags: org-mode, org-export, pdf ---
thread-38198
https://emacs.stackexchange.com/questions/38198
Automatically preview Latex in org-mode as soon as I finish typing
2018-01-19T16:15:03.293
# Question Title: Automatically preview Latex in org-mode as soon as I finish typing I'm using org-mode in Spacemacs (0.200.10.x). To preview Latex when I open a file, I understand that I can either set the variable `org-startup-latex-with-latex-preview` to `t` in my `init.el`, or set the local `#+STARTUP: latexpreview` option. However, I want org-mode to preview Latex fragment as soon as a finish typing it. Is that possible? If possible, I'd love a solution that's already included in Spacemacs so I can keep my `init.el` clean. # Answer > 12 votes I wrote a plugin that does this. You can install the plugin, then add ``` (add-hook 'org-mode-hook 'org-fragtog-mode) ``` to your config. The plugin enables latex previews when your cursor leaves the fragment, and disables them again when the cursor enters, for further editing. https://github.com/io12/org-fragtog # Answer > 6 votes While I do not know how to do it realtime, I know it is possible to do after each save. You can use emacs local variables to do the trick. https://www.gnu.org/software/emacs/manual/html\_node/emacs/Specifying-File-Variables.html#Specifying-File-Variables . This will generate all latex fragments whenever you save the file. Just append this to the end each file where you want this. ``` # Local variables: # after-save-hook: org-preview-latex-fragment # end: ``` If you would like to apply it to all org mode files you will need to use hooks. See this reference for how to apply a hook in only one mode https://stackoverflow.com/questions/6138029/how-to-add-a-hook-to-only-run-in-a-particular-mode#6141681. This hook will only be active when you are in org mode. ``` (add-hook 'org-mode-hook (lambda () (add-hook 'after-save-hook 'org-preview-latex-fragment nil 'make-it-local))) ``` **Note** After reading the `org.el` definitions for `org-preview-latex-fragment` it is obsolete past org-mode \> 8.3. It looks like you need to toggle the latex fragment display. What the following code does is check if the latex fragments are currently rendered if so toggle twice if not toggle once on save) ``` (defun my/org-render-latex-fragments () (if (org--list-latex-overlays) (progn (org-toggle-latex-fragment) (org-toggle-latex-fragment)) (org-toggle-latex-fragment))) (add-hook 'org-mode-hook (lambda () (add-hook 'after-save-hook 'my/org-render-latex-fragments nil 'make-the-hook-local))) ``` --- Tags: org-mode, spacemacs, preview-latex ---
thread-55210
https://emacs.stackexchange.com/questions/55210
using display-frame-alist to force switch to buffer
2020-01-31T06:59:49.867
# Question Title: using display-frame-alist to force switch to buffer Could someone please explain how to use default-frame-alist to make list-buffers switch to the resulting results buffer? list-buffers uses display-buffer so I am thinking that display-buffer-alist is the object I should be tweaking to ensure that the buffer "\*Buffer List\*" gets focus via switch-to-buffer. # Answer In the end the answer was straightforward enough: create my own function to do just that with the correct calling interface: ``` (defun my-switch-to-buffer-list (buffer alist) (select-window (display-buffer-use-some-window buffer alist))) ``` The custom addition for display-frame-alist: ``` '(display-buffer-alist '(("\\*Buffer List\\*" (my-switch-to-buffer-list)))) ``` I don't think there is a way to attach a lambda in the custom interface so this seems a reasonable solution. Something like help-window-select would seem helpful. > 0 votes --- Tags: frames, focus, display-buffer-alist ---
thread-55240
https://emacs.stackexchange.com/questions/55240
Org-mode table recalculation with a remote() formula using calc?
2020-02-01T18:38:21.643
# Question Title: Org-mode table recalculation with a remote() formula using calc? Can I make table2 automatically recalculate a remote() formula when I modify data in table1? I have the below tables and the first table is automatically recalculated when I press TAB (thanks to the "#" in the first column), but the second one it's only recalculated when move my cursor over it and press TAB in there as well. I would like to have it recalculated when I change (TAB) the first table. ``` #+NAME: table1 | # | + Units | value | value2 | |---+---------+-------+--------| | # | unit1 | 3110 | 295 | | # | unit2 | | | | # | unit3 | | | |---+---------+-------+--------| | # | - Units | value | value2 | |---+---------+-------+--------| | # | unit1 | -40 | | | # | unit2 | -105 | | | # | unit3 | -26 | | |---+---------+-------+--------| | * | TOTAL: | 2939 | 295 | |---+---------+-------+--------| #+TBLFM: @9$3=vsum(@-1..@1);EN::@9$4=vsum(@-1..@1);EN #+NAME: table2 | # | TOTAL + | 3405 | | # | TOTAL - | -171 | #+TBLFM: @1$3=vsum(remote(table1,@I$3..@II$3))+vsum(remote(table1,@I$4..@II$4));EN::@2$3=vsum(remote(table1,@III$3..@IIII$3))+vsum(remote(table1,@III$4..@IIII$4));EN ``` I am aware that it might be possible using elisp code but would like to have it work with calc syntax, if possible. # Answer > 1 votes Not sure if this is the correct solution, or if I'll have trouble when the file gets bigger, with more tables, but it seems to work for the moment. Solution: I have used a lambda function to bind both "org-cycle" and "org-table-recalculate-buffer-tables" to key and both tables are recalculated when I press it. ``` (add-hook 'org-mode-hook (lambda() (local-set-key (kbd "<tab>") (lambda () (interactive) (org-cycle) (org-table-recalculate-buffer-tables))))) ``` --- Tags: org-table, remote ---
thread-55212
https://emacs.stackexchange.com/questions/55212
Git Texinfo indices missing
2020-01-31T07:42:44.227
# Question Title: Git Texinfo indices missing I have installed the official Git documentation in Texinfo format on my computer and for Emacs. But when I try to search for something with `I` in the info buffer (`C-h-i d m git`) it reports no indices. I'm new to Texinfo and is it because the official documentation doesn't include indexing facilities or because I didn't do something right? I need this feature because I find it quite useful. Here's how I build the official doc: 1. Install `asciidoc` and `docbook2X`. ``` $ sudo dnf install asciidoc docbook2X ``` 2. Download the Git repository. These instructions assume that you want the latest, bleeding edge. Replace β€œmaster” with an appropriate tag like β€œv2.20.1”. ``` $ wget https://github.com/git/git/archive/master.tar.gz $ tar xf master.tar.gz $ cd git-master/Documentation ``` 3. Build the info files. ``` $ make git.info gitman.info ``` * Error: docbook2x-texi: command not found ``` SUBDIR ../ make[1]: 'GIT-VERSION-FILE' is up to date. DB2TEXI user-manual.texi /bin/sh: line 1: docbook2x-texi: command not found make: *** [Makefile:413: user-manual.texi] Error 127 ``` This is the docbook to texi converter from the docbook2X package (which has not been updated since 2007). For Red Hat and Fedora, the EPEL package repo provides docbook2X. However, the name of the script is changed because there is a newer docbook package. So, in the git source directory, edit the file "Documentation/Makefile" and change one line: ``` DOCBOOK2X_TEXI = db2x_docbook2texi ``` 4. Install the info files into "~/.local/share/info". ``` $ mv git.info gitman.info ~/.local/share/info $ cd ~/.local/share/info $ install-info git.info dir $ install-info gitman.info dir ``` 5. Add "~/.local/share/info" to the variable "Info-additional-directory-list" to make the directory acessible to Emacs. ``` (add-to-list 'Info-additional-directory-list "~/.local/share/info") ``` 6. Restart Emacs to initialize the info files. # Answer The issue is caused by the git documentation not being indexed (which needs to be done manually β€” adding good index terms is not entirely trivial). In principle, asciidoc, which is what git uses, supports having an index. So does DocBook β€” the intermediate format (the full pipeline for the main manual, is `user-manual.txt` (asciidoc) β†’ `user-manual.xml` (DocBook) β†’ `user-manual.texi` (Texinfo) β†’ `git.info`, and similarly for `gitman.info`). In case you want to be convinced that an index could be added (though in itself, this is obviously completely useless), add (as a "dummy" indexed term): ``` indexterm:[knight, Knight of the Round Table, Lancelot] ``` somewhere in the middle of `user-manual.txt` (the exact location is unimportant; the text is taken from the asciidoctor documentation (asciidoctor is mostly compatible with asciidoc)). Also add: ``` [index] = Index ``` at the very end of `user-manual.txt` (this is needed for an index to be actually created). Now re-generate `git.info` and open in Emacs (you can open it in Emacs as an Info manual, without "installing" it, by using `C-u C-h i path/to/the/manual/git.info`). > is it because the official documentation doesn't include indexing facilities or because I didn't do something right Technically, from a tooling point of view, the source documentation does support indexing, but the git project simply doesn't use it, possibly because they've decided it's not worth the effort. (You didn't do anything wrong.) ### Answer to comment (for better readability) > What do you mean when you say "though in itself, this is obviously completely useless"? I just wanted to emphasise the fact that the example was purely for illustrative purposes, and wasn't a solution to your problem (sorry for belabouring the obvious!). > Are your referring to indexing being useless? If so then why? No, I agree with you that indices are useful. > Are there better ways to list the search results of keywords other than indexing in Emacs? Not that I'm aware of. As a very partial workaround, in case you weren't aware, you could use `g` to easily navigate to a node, but that's extremely coarse-grained. Unfortunately, occur (`M-s o`) doesn't work well with info, as it searches only in the current node, not the entire manual. > Do I need to add the indexing tags (in asciidoc format) one by one manually in the source documentation to generate the indices? Or are they already present? Yes, you would need to add the indexing tags manually, one-by-one, to the source documentation in asciidoc format, so it's not really a feasible solution. (I'm not aware of any way of automating the generation of the indexing tags themselves.) > 1 votes --- Tags: git, texinfo ---
thread-55249
https://emacs.stackexchange.com/questions/55249
built-in function to return the argument itself
2020-02-02T15:06:35.490
# Question Title: built-in function to return the argument itself The line below shows the first element which is not `nil`. ``` (message "%s" (cl-some #'(lambda (x) x) '(nil nil "hello" nil))) ;; Output: hello ``` Is there a built-in function which is equivalent to `(lambda (x) x)`? # Answer `identity` is a built-in function that returns its argument unchanged: ``` (identity ARG) ``` > 4 votes --- Tags: functions ---
thread-55230
https://emacs.stackexchange.com/questions/55230
Help setting up company mode. Autocompletion of HTML CSS files
2020-01-31T23:27:33.120
# Question Title: Help setting up company mode. Autocompletion of HTML CSS files Autocompletion of HTML file by company-mode is not working except when `M-x company-web-html` is explicitly called. I'm expecting, for example, type 'di' in an html file, and get suggested 'div' for instance. Here's my `.emacs`: ``` ;; web stuff ;; automatically load web-mode when opening web-related files (add-to-list 'auto-mode-alist '("\\.ts\\'" . web-mode)) (add-to-list 'auto-mode-alist '("\\.html?\\'" . web-mode)) (add-to-list 'auto-mode-alist '("\\.css?\\'" . web-mode)) (add-to-list 'auto-mode-alist '("\\.js\\'" . web-mode)) (add-to-list 'auto-mode-alist '("\\.scss\\'" . web-mode)) ;; company-web configuration ;(add-to-list 'company-backends 'company-web-html) ;(add-to-list 'company-backends 'company-web-jade) ;(add-to-list 'company-backends 'company-web-slim) ;; set indentations (defun my-web-mode-hook () "Hooks for Web mode." (setq web-mode-markup-indent-offset 2) (setq web-mode-code-indent-offset 2) (setq web-mode-css-indent-offset 2) ) (add-hook 'web-mode-hook 'my-web-mode-hook) (setq tab-width 2) ;; highlight of columns (setq web-mode-enable-current-column-highlight t) (setq web-mode-enable-current-element-highlight t) ;; set the company completition vocabulary to css and html when in web-mode (defun my-web-mode-hook () (set (make-local-variable 'company-backends) '(company-css company-web-html company-yasnippet company-files)) ) ;; emmet settings ;; turn on emmet in web-mode (add-hook 'web-mode-hook 'emmet-mode) ;; emmet to switch between html and css properly in the same document (add-hook 'web-mode-before-auto-complete-hooks (lambda () (let ((web-mode-cur-language (web-mode-language-at-pos))) (if (string= web-mode-cur-language "php") (yas-activate-extra-mode 'php-mode) (yas-deactivate-extra-mode 'php-mode)) (setq emmet-use-css-transform (string= web-mode-cur-language "css"))))) ;; use company-mode in all buffers (add-hook 'after-init-hook 'global-company-mode) ``` When I do `M-x company-web-html` it autocompletes. # Answer > 2 votes company-capf is the backend which should interface to mode's completion support in emacs versions \>= 26 In addtion, look into using lsp and using the company-lsp backend. Instructions for installing css helpers are here: https://github.com/emacs-lsp/lsp-mode Specifically:- ``` npm install -g vscode-css-languageserver-bin ``` --- Tags: company ---
thread-55253
https://emacs.stackexchange.com/questions/55253
pdf-tools auctex question with split buffers
2020-02-02T19:11:12.877
# Question Title: pdf-tools auctex question with split buffers I run auctex with the latex source on the left half buffer and corresponding pdf on the right half (using C-x 3 to split the buffer). I then split the left half buffer into 2 so as two work on different parts of the latex source file. Similarly I split the right hand buffer into two so as to view the two corresponding pdf parts. **Is there some way of doing forward/reverse search between the top left latex source and top right pdf; and a forward/reverse search between the bottom left latex source and bottom right pdf?** This would help a lot when working on a large latex document. Right now, the top left and bottom left latex source do forward/backward search with the top right pdf; the bottom right pdf seems to be ignored. # Answer > 3 votes The solution at the bottom of this answer does not work anymore after https://github.com/emacs-mirror/emacs/commit/f646675cd1637948b2df2351a9666792ea8251ea The extra argument `DEDICATE` of `window--display-buffer` has been removed by that commit. Since `window--display-buffer` does consider `display-buffer-mark-dedicated` anyway maybe Emacs does like the OP wanted out-of-the-box. Otherwise you can use the following modified code: ``` (defun display-buffer-beside-selected (buffer alist) "Try displaying BUFFER in a window beside the selected window. If there is a window below the selected one and that window already displays BUFFER, use that window. If that attempt fails and there is a non-dedicated window beside the selected one, use that window. The left or right hand side is chosen if ALIST contains the cons (side . left) or (side . right), respectively." (let (window) (or (and (setq window (window-in-direction (cdr (assq 'side alist)))) (eq buffer (window-buffer window)) (window--display-buffer buffer window 'reuse alist)) (and (setq window (window-in-direction (cdr (assq 'side alist)))) (not (window-dedicated-p window)) (window--display-buffer buffer window 'reuse alist))))) (defun my-display-buffer-right (fun &rest args) "Use `display-buffer-in-side-window' as `display-buffer-overriding-action'. Then run FUN with ARGS." (let ((display-buffer-overriding-action '(display-buffer-beside-selected (side . right)))) (apply fun args))) (defun my-display-buffer-left (fun &rest args) "Use `display-buffer-in-side-window' as `display-buffer-overriding-action'. Then run FUN with ARGS." (let ((display-buffer-overriding-action '(display-buffer-beside-selected (side . left)))) (apply fun args))) (advice-add 'TeX-pdf-tools-sync-view :around #'my-display-buffer-right) (advice-add 'pdf-sync-backward-search-mouse :around #'my-display-buffer-left) ``` --- You can set the preferred window via the `ACTION` for `display-buffer`, which see. That also works for commands that use `display-buffer`. From all the possibilities for setting the `ACTION` the variable `display-buffer-overriding-action` has the highest priority. The following code shows how to define the action you want and how to set `display-buffer-overriding-action` for the commands you need. ``` (defun display-buffer-beside-selected (buffer alist) "Try displaying BUFFER in a window beside the selected window. If there is a window below the selected one and that window already displays BUFFER, use that window. If that attempt fails and there is a non-dedicated window beside the selected one, use that window. The left or right hand side is chosen if ALIST contains the cons (side . left) or (side . right), respectively." (let (window) (or (and (setq window (window-in-direction (cdr (assq 'side alist)))) (eq buffer (window-buffer window)) (window--display-buffer buffer window 'reuse alist)) (and (setq window (window-in-direction (cdr (assq 'side alist)))) (not (window-dedicated-p window)) (window--display-buffer buffer window 'reuse alist display-buffer-mark-dedicated))))) (defun my-display-buffer-right (fun &rest args) "Use `display-buffer-in-side-window' as `display-buffer-overriding-action'. Then run FUN with ARGS." (let ((display-buffer-overriding-action '(display-buffer-beside-selected (side . right)))) (apply fun args))) (defun my-display-buffer-left (fun &rest args) "Use `display-buffer-in-side-window' as `display-buffer-overriding-action'. Then run FUN with ARGS." (let ((display-buffer-overriding-action '(display-buffer-beside-selected (side . left)))) (apply fun args))) (advice-add 'TeX-pdf-tools-sync-view :around #'my-display-buffer-right) (advice-add 'pdf-sync-backward-search-mouse :around #'my-display-buffer-left) ``` --- Tags: auctex, pdf-tools ---
thread-55251
https://emacs.stackexchange.com/questions/55251
How to disable hints for certain keywords in python elpy
2020-02-02T17:31:48.100
# Question Title: How to disable hints for certain keywords in python elpy I enabled elpy mode for python and I get hints when I type a keyword. Also I have yasnippets. Unfortunately, when I type "for" keyword, elpy gives me a useless hint, blocking `<tab>` key for yasnippet expansion. I have to click left - right to get rid of it. How can I disable hints for "for" keyword? # Answer If you type for\[tab\] very fast, it should work and expand your yasnippet. You can set `company-idle-delay` to a longer time, like 1 (sec) to have more time for this; the default is quite short at 0.1 sec. If you want the tip and it is not showing, I think you can get it with `M-x company-complete`. If the tip shows, I think you can type C-g to get rid of the hint, then press tab to activate the yasnippet. Alternatively, type `M-x yas-expand`. I am not sure you can get it to ignore for otherwise, or if you really want to. What would you do if you wanted completion on something that started with for, e.g. a variable name, other function, etc.? > 0 votes --- Tags: python, elpy ---
thread-55252
https://emacs.stackexchange.com/questions/55252
How to set minor mode variables in dir-locals?
2020-02-02T19:07:36.410
# Question Title: How to set minor mode variables in dir-locals? Im writing an lsp-mode purescript client and couldn't figure out how to override the default config options using a .dir-locals file. For example, I have a defcustom : ``` defcustom lsp-purescript-use-npx t "Whether to execute using npx or a globally installed version. Defaults to Npx" :type '(choice (const :tag "Npx" t) (const :tag "Global" nil)) :group 'lsp-purescript) ``` The problem I'm essentially trying to solve is how to set a variable for a minor mode. I'd like to set the value of `lsp-purescript-use-npx` within dir-locals but the docs ive seen only show how to set major mode variables Any help and/or urls for documentation? # Answer The custom variables defined by major and minor modes are all available for setting within dir-locals. You could set `lsp-purescript-use-npx` to `nil` like so: ``` ((purescript-mode (lsp-purescript-use-npx))) ``` Line 1 `((purescript-mode` says - Only set the following variables for the major mode "purescript-mode". The 2nd line sets the custom variable `lsp-purescript-use-npx` to `nil`. You don't need to reference the minor mode in any way to set this, and you don't need to use any major mode in particular either. To do this using the `add-dir-local-variable` command, it would look like this: 1. `M-x add-dir-local-variable` 2. Type the major mode you want this to apply to (or enter `nil` to apply to all major modes) 3. Type the variable you want to set (from whatever major or minor mode you want) 4. Type the value you want it to have (or leave blank for `nil`) > 1 votes # Answer As @phils suggested you should be able to run `M-x add-dir-local-variable`. You will be prompted for a mode, and you could type/select lsp-mode (I am guessing that is the mode name). Then, you will be prompted for a variable, and you could type/select lsp-purescript-use-npx. Finally, you should be prompted for the value. Depending on your setup, you may or may not get completion, and you may need to press tab to see completion. Alternatively, type this command in a file that is in the directory you want to set the dir-local variable: `(add-dir-local-variable 'lsp-mode 'lsp-purescript-use-npx "Global")` then highlight the code and run `M-x eval-region`. You can delete this line after you run it. That should create a .dir-locals.el file with these contents: ``` ;;; Directory Local Variables ;;; For more information see (info "(emacs) Directory Variables") ((lsp-mode (lsp-purescript-use-npx . "Global"))) ``` You can also create .dir-locals.el directly, and copy that content into it. > 5 votes --- Tags: minor-mode, directory-local-variables, lsp-mode ---
thread-55254
https://emacs.stackexchange.com/questions/55254
How do I open a .gpg file from the command line?
2020-02-02T19:17:58.340
# Question Title: How do I open a .gpg file from the command line? I have a file located in the directory `~/myfiles/list.txt.gpg`. In the terminal, I type `emacs ~/myfiles/list.txt.gpg` and I get something that looks like this, which I'm guessing is the still encrypted form of the file. In order to get it to display properly, I have to `M-x revert-buffer`, then it will prompt me for the password and load it the file properly. My question is: How can I get Emacs to recognize it is encrypted and prompt me for the password immediately instead of having to go through the trouble of pressing `M-x` and selecting `revert-buffer`? # Answer Did you load epa as documented in the wiki? emacswiki.org/emacs/EasyPG . Specifically:- ``` (require 'epa-file) (epa-file-enable) ``` After that evaluate the code or restart. Refer to the emacs documentation for details on how to evaluate the code "in buffer". > 0 votes --- Tags: term, gpg, revert-buffer ---
thread-50469
https://emacs.stackexchange.com/questions/50469
Rebinding smartparens keys using Evil
2019-05-12T19:26:02.397
# Question Title: Rebinding smartparens keys using Evil I use vanilla Emacs with `evil`. I did not install `smartparens` but it is present and enabled on my system as a dependency of something. I need to rebind the `M-s` keys to something other than the default `sp-splice-sexp`. The output of `describe-key` for `M-s` is currently: ``` M-s runs the command sp-splice-sexp, which is an interactive compiled Lisp function in β€˜smartparens.el’. It is bound to M-s, <normal-state> M-s. ``` Going into `smartparens.el`, I am able to see that a `smartparens-mode-map` is defined and `M-s` belongs to it. I have tried in vain to do: ``` (define-key smartparens-mode-map (kbd "M-s") nil) ``` or ``` (evil-define-key 'normal smartparens-mode-map (kbd "M-s") nil) ``` or ``` (define-key evil-normal-state-map (kbd "M-s") nil) ``` The list of the MELPA packages I use is: ``` auto-package-update atom-one-dark-theme slime company evil column-enforce-mode paredit evil-cleverparens highlight-parentheses key-chord ``` One of these packages must be loading `smartparens` and defining the keymap but I can't find which one. Is there a way perhaps to see which keymap or evil keymap to change? # Answer > 0 votes Smartparens doesn't add any key bindings by default as `sp-base-key-bindings` is set to `nil`. Evil-cleverparens has Smartparens as dependency. And evil-cleverparens adds some additional keybindings by default. This includes setting `M-s` to `sp-splice-sexp`. So you have to unbind `M-s` in `evil-cleverparens-mode-map`: ``` (with-eval-after-load 'evil-cleverparens (evil-define-key 'normal evil-cleverparens-mode-map (kbd "M-s") nil)) ``` Or change `evil-cleverparens-use-additional-bindings` to not use those bindings before loading `evil-cleverparens`: ``` (setq evil-cleverparens-use-additional-bindings nil) ``` # Answer > 0 votes Similar to How do I turn-off smartparens when using prelude?, the following might do it: ``` (defun rebind-keys () (define-key smartparens-mode-map (kbd "M-s") nil) ) (add-hook 'smartparens-enabled-hook 'rebind-keys t) ``` --- Tags: key-bindings, evil, smartparens ---
thread-55267
https://emacs.stackexchange.com/questions/55267
Include elisp function in org-capture template
2020-02-03T08:40:40.550
# Question Title: Include elisp function in org-capture template I've tried following some of the other answered questions here regarding this topic but can't seem to get my head around this particular part of the problem. I have the following function, which returns the value of a key `:PROPERTIES:` pair when a cursor is under an org header: ``` (defun capture-noter-link () "insert PROPERTY value of pdftools link" ;; (interactive) (let ((linkStr (save-excursion (save-window-excursion (switch-to-buffer (plist-get org-capture-plist :original-buffer)) (org-entry-get nil "NOTER_PAGE")) ))) (insert linkStr))) ``` Calling this function interactively while in the source org file gives me the desired result. I then tried to implement this in `org-capture` by using the following template: ``` ("ai" "Anki IR" entry (file+headline org-my-anki-file "Incremental Reading Cards") "* %<%H:%M> %^g\n:PROPERTIES:\n:ANKI_NOTE_TYPE: Cloze\n:ANKI_DECK: MegaDeck\n:END:\n** Text\n%x\n** Extra\n %(capture-noter-link)\n") ``` However the desired link isn't inserted into the capture buffer. What could I be doing wrong? # Answer > 3 votes ``` (defun insert-property(&optional p) "insert PROPERTY value of pdftools link" (unless p (setq p "TEST")) (message "property passed is: %s" p) (let ((pvalue (save-window-excursion (message "%s" (org-capture-get :original-buffer)) (switch-to-buffer (org-capture-get :original-buffer)) (message "retrieved property is: %s" (org-entry-get (point) p)) (org-entry-get (point) p) ))) pvalue)) ``` I don't think you need any `(insert x)` call for a start: the function itself should not insert the string - it should just return it. I had a fiddle and came up with the above function, just to satisfy my own curiosity. I hope it helps. I used `org-capture-get` and also `(point)` but maybe that's an alternative way. Just add `%(insert-property "TEST")%` in my capture template. Test data:- ``` *** scratchpad :tangle no:noexport: :PROPERTIES: :TEST: HELLO WORLD :END: ``` My template:- ``` ("t" "Todo" entry (file+headline "refile.org" "Tasks To Refile") "* TODO %? %(insert-property "TEST")% :PROPERTIES: :DateCreated: %T :END: ") ``` --- Tags: org-mode, org-capture ---
thread-55269
https://emacs.stackexchange.com/questions/55269
What is the difference between #+TBLNAME and #+NAME in org-mode
2020-02-03T09:53:09.560
# Question Title: What is the difference between #+TBLNAME and #+NAME in org-mode What is the difference between giving a table a name using `#+TBLNAME` and `#+NAME` in org-mode? # Answer > 1 votes Org mode 8.2.10 is very old. If you can, you should upgrade. `TBLNAME` is deprecated (since version 8.3.4) : you should not use it any longer. It is still (in version 9.3) recognized for backward compatibility but it is likely to go away at some point. As for the link behavior mentioned in your answer, in recent versions of Org mode, `[[a and b]]` still results in the `No match` question, but `[[c and d]]` is a fully functioning link to the corresponding table. # Answer > 0 votes Given two tables below only the one named using `NAME` can be referenced in prose with a navigable link. ``` #+TBLNAME: a and b | a | b | | 1 | 2 | #+NAME: c and d | c | d | | 1 | 2 | ``` The link `[[c and d]]` will not be navigable with `C-c C-o` while attempting the same with the link `[[a and b]]` will result in the user being asked: > No match - create this as a new heading? (y or n) But this is only part of the answer, there surely are more differences than this. This is with org-mode 8.2.10 released with Emacs 25.2.2. --- Tags: org-mode ---
thread-55272
https://emacs.stackexchange.com/questions/55272
Emacs Magit not working after OSX Catalina upgrade
2020-02-03T13:54:03.863
# Question Title: Emacs Magit not working after OSX Catalina upgrade Since upgrading my mac to Catalina yesterday, I managed to get Emacs working again after allowing Ruby access to all files in the settings, and most of it works fine, but I can't get Magit to recognise the repo that it is in. `C-x g` simply does not work, so I tried `M-x magit-status` in the minibuffer and it asks if I want to create a repo, but I'm already in the the right place, still working on the same things I was working on last week. The only change is the Mac OSX upgrade (work machine so enforced). # Answer SOLVED: thanks to all who commented here it helped me find a solution. So first thing to do with Catalina is to give full file access to emacs, this is done in settings - Security & Privacy - /Full Disk Access. Then install this at the start of your settings: https://github.com/purcell/exec-path-from-shell. Apparently this is a common mac issue, but I've not had it till now and it is actually a FAQ in the Magit docs which is where I got the Purcell package tip from. > 3 votes --- Tags: magit, osx ---
thread-54852
https://emacs.stackexchange.com/questions/54852
pdf-tools Emacs with auctex
2020-01-11T14:27:03.260
# Question Title: pdf-tools Emacs with auctex I have setup Emacs pdf-tools with auctex on ubuntu and the forward and reverse search work fine. But in the forward search (latex file to corresponding position in pdf document), it is difficult to find the precise spot in the pdf file. Is it possible to have some sort of highlight color (or box or colored dot) in the pdf file which marks the point. For example, forward search with auctex and evince draws a red box around the corresponding portion in the pdf file. Something similar with pdf-tools would be great. Another way of posing this question: forward search only jumps to the relevant page in the pdf file, not the precise location in the pdf file. Is there way of jumping to the precise location and marking this location in the pdf file? # Answer > Unfortunately for a two column format pdf file, forward search only jumps to the corresponding left hand column line; even though the relevant latex text appears on the right hand column. Is there a way to fix this? I think that this would be better as a separate question (for organisational purposes), but here's a hacky solution. I'm going to override the definition of `TeX-pdf-tools-sync-view`, with an "advice", to avoid having to play around with customizing `TeX-view-program-list` and `TeX-view-program-selection`. Since it's not used elsewhere, this should be harmless. I'm not going to override `pdf-util-tooltip-arrow` or `pdf-sync-forward-search` (and will instead define `pdf-util-tooltip-arrow-custom` and `pdf-sync-forward-search-custom`, based on them), in case they're referred to somewhere else. ``` (defun TeX-pdf-tools-sync-view-custom () "Focus the focused page/paragraph in `pdf-view-mode'. If `TeX-source-correlate-mode' is disabled, only find and pop to the output PDF file. Used by default for the PDF Tools viewer entry in `TeX-view-program-list-builtin'." ;; Make sure `pdf-tools' is at least in the `load-path', but the user must ;; take care of properly loading and installing the package. We used to test ;; "(featurep 'pdf-tools)", but that doesn't play well with deferred loading. (unless (fboundp 'pdf-tools-install) (error "PDF Tools are not available")) (unless TeX-PDF-mode (error "PDF Tools only work with PDF output")) (add-hook 'pdf-sync-backward-redirect-functions #'TeX-source-correlate-handle-TeX-region) (if (and TeX-source-correlate-mode (fboundp 'pdf-sync-forward-search)) (with-current-buffer (or (when TeX-current-process-region-p (get-file-buffer (TeX-region-file t))) (current-buffer)) (pdf-sync-forward-search-custom)) (let ((pdf (concat file "." (TeX-output-extension)))) (pop-to-buffer (or (find-buffer-visiting pdf) (find-file-noselect pdf)))))) (advice-add 'TeX-pdf-tools-sync-view :override #'TeX-pdf-tools-sync-view-custom) (defun pdf-sync-forward-search-custom (&optional line column) "Display the PDF location corresponding to LINE, COLUMN." (interactive) (cl-destructuring-bind (pdf page x1 y1 _x2 _y2) (pdf-sync-forward-correlate line column) (let ((buffer (or (find-buffer-visiting pdf) (find-file-noselect pdf)))) (with-selected-window (display-buffer buffer pdf-sync-forward-display-action) (pdf-util-assert-pdf-window) (when page (pdf-view-goto-page page) (when (and y1 x1) (let ((top (* y1 (cdr (pdf-view-image-size)))) (right (* x1 (car (pdf-view-image-size))))) (pdf-util-tooltip-arrow-custom (round top) (round right)))))) (with-current-buffer buffer (run-hooks 'pdf-sync-forward-hook))))) (defun pdf-util-tooltip-arrow-custom (image-top image-right &optional timeout) (pdf-util-assert-pdf-window) (when (floatp image-top) (setq image-top (round (* image-top (cdr (pdf-view-image-size)))))) (when (floatp image-right) (setq image-right (round (* image-right (car (pdf-view-image-size)))))) (let* (x-gtk-use-system-tooltips ;allow for display property in tooltip (dx image-right) (dy image-top) (pos (list dx dy dx (+ dy (* 2 (frame-char-height))))) (vscroll (pdf-util-required-vscroll pos)) (tooltip-frame-parameters `((border-width . 0) (internal-border-width . 0) ,@tooltip-frame-parameters)) (tooltip-hide-delay (or timeout 3))) (when vscroll (image-set-window-vscroll vscroll)) (setq dy (max 0 (- dy (cdr (pdf-view-image-offset)) (window-vscroll nil t) (frame-char-height)))) (when (overlay-get (pdf-view-current-overlay) 'before-string) (let* ((e (window-inside-pixel-edges)) (xw (pdf-util-with-edges (e) e-width))) (cl-incf dx (/ (- xw (car (pdf-view-image-size t))) 2)))) (pdf-util-tooltip-in-window (propertize " " 'display (propertize "\u2192" ;;right arrow 'display '(height 2) 'face `(:foreground "orange red" :background ,(if (bound-and-true-p pdf-view-midnight-minor-mode) (cdr pdf-view-midnight-colors) "white")))) dx dy))) ``` You can also obviously play around with these definitions to better suit you (the original code is quite comprehensible). Here are the original definitions of the functions, for comparison (the changes I've made are minor): pdf-util-tooltip-arrow, pdf-sync-forward-search, TeX-pdf-tools-sync-view. You can disable the new behaviour by removing the "advice": ``` (advice-remove 'TeX-pdf-tools-sync-view 'TeX-pdf-tools-sync-view-custom) ``` > 1 votes --- Tags: auctex, pdf-tools ---
thread-55231
https://emacs.stackexchange.com/questions/55231
org-mode export-html add name attirbute to checkbox input
2020-02-01T00:24:13.383
# Question Title: org-mode export-html add name attirbute to checkbox input I'm trying to make the **HTML form** for MCQ question via `org-html-export-as-html`. ``` #+BEGIN_EXPORT html <form action="/save" method="POST"> #+END_EXPORT 1. What is your question #+NAME: field-name - [ ] option1 - [ ] option2 - [ ] option3 - [ ] option4 #+BEGIN_EXPORT html <button type="submit">Submit</button> <button type="reset">Reset</button> </form> #+END_EXPORT ``` I have set the `(setq org-html-checkbox-type 'html)` which convert each option to `<input type="checkbox">` but how to add *name* attribute currently I'm exporting option manually. ``` #+BEGIN_EXPORT html <input requried type="checkbox" name="Q1" value="option1"/> option1 <br/> <input requried type="checkbox" name="Q1" value="option2"/> option2 <br/> <input requried type="checkbox" name="Q1" value="option3"/> option3 <br/> <input requried type="checkbox" name="Q1" value="option4"/> option4 <br/> #+END_EXPORT ``` hackish back-end in https://gist.github.com/rhoit/a213d4574a406f094b7d881db8510bcf # Answer I think the best thing to do here is make a custom exporter. Here is an example that treats checkbox items specially. Note this does not work as expected with a nested checkbox list, but I think it handles your specific example. ``` (setq org-html-checkbox-type 'html) (require 'ox) (org-export-define-derived-backend 'my-html 'html :translate-alist '((item . my-item-translator))) (defun my-item-translator (item c info) ;; figure out what kind of item we have (let* ((parent (org-element-property :parent item)) (type (org-element-property :type parent)) (name (org-element-property :name parent)) (value (string-trim (buffer-substring (org-element-property :contents-begin item) (org-element-property :contents-end item))))) (cond ;; Treat checkboxes specially ((org-element-property :checkbox item) (message "%s" item) (format "<input required type=%S name=\"%s\" value=\"%s\"/> %s <br/>" (if (string-match "radio\\'" name) "radio" "checkbox") name value value)) (t (org-html-item item c info))))) (browse-url (org-export-to-file 'my-html "custom.html")) ``` To try this code, make a new heading in the org file you want to export, and tag it with :noexport: then put the code above in an emacs-lisp src block and run it. It should create and open a file called custom.html. > 3 votes # Answer A different approach is to temporarily redefine one of the export functions in the usual html exporter: ``` (cl-letf (((symbol-function 'org-html-item) (lambda (item contents info) (let* ((plain-list (org-export-get-parent item)) (name (org-element-property :name plain-list)) (type (org-element-property :type plain-list)) (counter (org-element-property :counter item)) (checkbox (org-element-property :checkbox item)) (tag (let ((tag (org-element-property :tag item))) (and tag (org-export-data tag info))))) (if (and checkbox name) (format "<input required type=\"checkbox\" name=\"%s\" value=\"%s\"/> %s <br/>" name contents contents) ;; The usual case (org-html-format-list-item contents type checkbox info (or tag counter))))))) (browse-url (org-export-to-file 'html "cl-letf.html"))) ``` as before you put this in an emacs-lisp src block in a section tagged :noexport: and run it. The idea is to use cl-letf to temporarily redefine `org-html-item` which is responsible for generating the html. Here I just duplicated the code in the body of the letf statement, and added a line to capture the case for when there is a checkbox and name. If not, the usual export is done in the else clause. I find this cleaner than the answer above, but it does not work better on nested items. > 2 votes --- Tags: org-mode, org-export ---
thread-55103
https://emacs.stackexchange.com/questions/55103
Regular template
2020-01-24T11:48:49.373
# Question Title: Regular template On a near weekly basis, I need to create an org entry that looks something like ``` * <TODAYS DATE> - <Person 1> - What this person did - <Person 2> - What this person did - <Person 3> - What this person did - <Person 4> - What this person did ``` Is there an idiomatic way to generate this structure with org-mode? My naive idea would be to just define a function in my `init.el` that does ``` (defun some-useful-function-name () (insert "* <TODAYS DATE> - Person 1 - FILL ME IN - Person 2 - FILL ME IN - Person 3 - FILL ME IN - Person 4 - FILL ME IN")) ``` # Answer > 1 votes Thanks for NickD for pointing me towards the capture templates! I've now set up a capture template that does this. The custom-set-variables call looks something like: ``` '(org-capture-templates (quote (("B" "Weekly report" entry (file "~/org/file-to-store-it-in.org") "* %u - Person 1 -%^{PROMPT} - Person 2 -%^{PROMPT} - Person 3 -%^{PROMPT} - Person 4 -%^{PROMPT}")))) ``` --- Tags: org-mode ---
thread-55281
https://emacs.stackexchange.com/questions/55281
Change major mode for buffer without a corresponding file
2020-02-03T17:36:04.537
# Question Title: Change major mode for buffer without a corresponding file I want to change the major mode from `fundamental-mode` to `compilation-mode` for a buffer which contains some generated output named for eg. `*results*`. I've tried to add an entry to `auto-mode-alist` but if i understand correctly this works only with buffers which have a corresponding filename. I've tried to add it in the list like this but this is not working. ``` (add-to-list 'auto-mode-alist '("\\*result\\*" . compilation-mode)) ``` > UPDATE: After some digging in I found that this particular lisp snippet is filling the buffer with data. ``` (start-process "result" "*result*" "some_unix_command") ``` > UPDATE: This buffer is generated from a 3rd party plugin so i'd rather not start and change the src lisp code. I'd like to handle this on a different level. I've already checked if I can attach a hook somewhere where the buffer is created and the answer is negative. Anyone with some ideas on how I can do this? # Answer The general answer to problems of this kind is given by user Lawlist. I consider in the following your special situation. You stated in a comment that you want to use `compilation-mode` for `cmake-ide`. The following code advises that package for that purpose probably with minimal impact on the package: ``` (defcustom my-cide-callback-functions '(my-cide-compilation-mode-activate) "Special hook for cide. Each function registered here is run like a process sentinel for the cmake process after cmake has finished." :type 'hook :group 'cmake-ide) (defun my-cide-compilation-mode-activate (process _event) "Activate `compilation-mode' in PROCESS buffer after compilation. This function can be used in `my-cide-callback-functions'." (let ((buf (process-buffer process))) (when (and (null (process-live-p process)) (buffer-live-p buf)) (with-current-buffer buf (compilation-mode))))) (defun my-cide--register-a-callback (callback) "Register CALLBACK to be called when CMake finishes running." (set-process-sentinel (get-process "cmake") `(lambda (process event) (funcall ,callback process event) (run-hook-with-args 'my-cide-callback-functions process event)))) (advice-add 'cide--register-a-callback :override #'my-cide--register-a-callback) ``` Disclaimer: I do not have `cmake-ide` and do not want to install it if it is not necessary for debugging. Please test the code and report back whether it works or not. > 1 votes # Answer Instead of running `start-process` and then calling `compilation-mode` on the output: ``` (start-process "result" "*result*" "some_unix_command") ``` ... another option is to use the `compile` command, which automatically generates the output buffer in `compilation-mode`: ``` (compile "some_unix_command") ``` Alternatively, consider invoking `compilation-mode` *after* the process finishes running when using `start-process` by using a process-sentinel: https://www.gnu.org/software/emacs/manual/html\_node/elisp/Sentinels.html This following linked thread contains a few examples of using a process sentinel: https://stackoverflow.com/questions/24548536/penetrating-the-set-process-sentinel-hierarchy-with-let-bound-variables > 2 votes --- Tags: init-file, buffers, major-mode ---
thread-47782
https://emacs.stackexchange.com/questions/47782
Is there a way Emacs can infer is running on WSL (Windows Subsystem for Linux)?
2019-02-12T21:17:51.750
# Question Title: Is there a way Emacs can infer is running on WSL (Windows Subsystem for Linux)? I would like to identify when Emacs is running on WSL (Windows Subsystem for Linux). Normally I use `system-type` variable to check if Emacs is on Linux, Windows or MacOS X. Though in this case it returns `gnu/linux`: ``` system-type is a variable defined in β€˜C source code’. Its value is β€˜gnu/linux’ Documentation: The value is a symbol indicating the type of operating system you are using. Special values: β€˜gnu’ compiled for a GNU Hurd system. β€˜gnu/linux’ compiled for a GNU/Linux system. β€˜gnu/kfreebsd’ compiled for a GNU system with a FreeBSD kernel. β€˜darwin’ compiled for Darwin (GNU-Darwin, macOS, ...). β€˜ms-dos’ compiled as an MS-DOS application. β€˜windows-nt’ compiled as a native W32 application. β€˜cygwin’ compiled using the Cygwin library. Anything else (in Emacs 26, the possibilities are: aix, berkeley-unix, hpux, usg-unix-v) indicates some sort of Unix system. ``` Which is what it is expected, though... I want to add a specific check to use the Windows native browser, not the one on WSL. I currently do that setting: ``` (setq browse-url-browser-function 'my-browse-url-function) ``` But I only want to do this in WSL, not in real Linux. Is there a way to do it? # Answer You could also do `(string-match-p "Microsoft" (shell-command-to-string "uname -a"))` Likely in your `my-browse-url-function` you're probably depending on a Windows specific path to exist. You could just check that it exists and is executable with `file-executable-p` like the following code does. However, this may not be enough if you dual boot and mount the windows `C:` drive to the same mount point. ``` ;; setup browser function when running in WSL (defconst powershell-exe "/mnt/c/Windows/System32/WindowsPowerShell/v1.0/powershell.exe") (when (file-executable-p powershell-exe) (defun my\wsl-browse-url (url &optional _new-window) "Opens link via powershell.exe" (interactive (browse-url-interactive-arg "URL: ")) (let ((quotedUrl (format "start '%s'" url))) (apply 'call-process powershell-exe nil 0 nil (list "-Command" quotedUrl)))) (setq-default browse-url-browser-function 'my\wsl-browse-url)) ``` > 4 votes # Answer I just happened to notice this while looking for a an already implemented `wsl-browse-url` (thanks!), so will offer one other option: ``` (when (string-match "-[Mm]icrosoft" operating-system-release) ;; WSL: WSL1 has "-Microsoft", WSL2 has "-microsoft-standard" ) ``` It looks like that works on both my Debian WLinux WSL 2 environments. > 4 votes # Answer I would check for an environment variable using `getenv`. You may want to check what variables are available in your typical WSL shell, but one option would be to check for a Windows-specific PATH entry, perhaps: ``` (string-match-p "Windows" (getenv "PATH")) ``` > 3 votes --- Tags: conditionals, system-environment, wsl ---
thread-55292
https://emacs.stackexchange.com/questions/55292
The call stack result of profile-report doesn't match the real function codes
2020-02-04T14:21:08.750
# Question Title: The call stack result of profile-report doesn't match the real function codes I'm trying to figure out why my emacs was slow tonight and found: ``` - command-execute 82796 87% - call-interactively 82792 87% - funcall-interactively 82792 87% - evil-ex-search-forward 42805 45% - apply 42805 45% - #<compiled 0x1891b35> 42805 45% - apply 42805 45% - #<compiled 0x17e0a1d> 42802 45% - evil-ex-start-search 42802 45% - read-string 42783 45% - redisplay_internal (C function) 42587 45% - eval 42567 45% - awesome-tab-line 42557 45% - cond 42557 45% - or 42550 45% - awesome-tab-line-format 42550 45% - let* 42544 45% - while 42540 45% - setq 42540 45% - cons 42540 45% - awesome-tab-line-tab 42540 45% - propertize 42540 45% - awesome-tab-buffer-tab-label 42540 45% - let* 42540 45% - concat 42540 45% - if 42522 45% - awesome-tab-icon-for-tab 42522 45% - if 42522 45% - and 42380 45% - condition-case 42374 45% progn 42374 45% + progn 142 0% ``` As the result shows, `awesome-tab-icon-for-tab` is the root cause. Here is the definition of `awesome-tab-icon-for-tab`: ``` (defun awesome-tab-icon-for-tab (tab face) "When tab buffer's file is exists, use `all-the-icons-icon-for-file' to fetch file icon. Otherwise use `all-the-icons-icon-for-buffer' to fetch icon for buffer." (when (and awesome-tab-display-icon (ignore-errors (require 'all-the-icons))) (let* ((tab-buffer (car tab)) (tab-file (buffer-file-name tab-buffer)) (background (face-background face)) (icon (cond ;; Use `all-the-icons-icon-for-file' if current file is exists. ((and tab-file (file-exists-p tab-file)) (all-the-icons-icon-for-file tab-file :v-adjust awesome-tab-icon-v-adjust :height awesome-tab-icon-height)) ;; Use `all-the-icons-icon-for-mode' for current tab buffer at last. (t (with-current-buffer tab-buffer (all-the-icons-icon-for-mode major-mode :v-adjust awesome-tab-icon-v-adjust :height awesome-tab-icon-height) ))))) (when (and icon ;; `get-text-property' need icon is string type. (stringp icon)) ;; Thanks ema2159 for code block ;) (propertize icon 'face `(:inherit ,(get-text-property 0 'face icon) :background ,background )))))) ``` the profile tells me that ``` - awesome-tab-icon-for-tab 42522 45% - if 42522 45% - and 42380 45% - condition-case 42374 45% progn 42374 45% ``` But the definition of `awesome-tab-icon-for-tab` contain none of `if`, `and`, `condition-case` and `prog`. What happened? # Answer > 1 votes Let's have a look at ``` (when (and awesome-tab-display-icon (ignore-errors (require 'all-the-icons))) ``` `when` is a macro defined in `subr.el`: ``` (defmacro when (cond &rest body) "If COND yields non-nil, do BODY, else return nil. When COND yields non-nil, eval BODY forms sequentially and return value of last one, or nil if there are none. \(fn COND BODY...)" (declare (indent 1) (debug t)) (list 'if cond (cons 'progn body))) ``` There you have `if`. The `and` is present in the original code. `ignore-errors` is also a macro defined in `subr.el`: ``` (defmacro ignore-errors (&rest body) "Execute BODY; if an error occurs, return nil. Otherwise, return result of last form in BODY. See also `with-demoted-errors' that does something similar without silencing all errors." (declare (debug t) (indent 0)) `(condition-case nil (progn ,@body) (error nil))) ``` There you have `condition-case` and `progn`. The macros are expanded in the compiled code. Therefore, you get their expansions in the profiler output instead of their names. --- Tags: debugging, profiler, macroexpansion ---
thread-55276
https://emacs.stackexchange.com/questions/55276
Issues With org-ql and Searching Based On Property Inheritence
2020-02-03T15:30:23.170
# Question Title: Issues With org-ql and Searching Based On Property Inheritence I would like to be able to search for all TODO's with a property of `FEATURE_NUM`, and that property is inherited in my TODO's. Here's what I have in my `init.el` to make that property inheritable: ``` (setq org-use-property-inheritance (list "FEATURE_NUM")) ``` I then have a TODO tree that looks like thes: ``` * Task List :PROPERTIES: :FEATURE_NUM: 12345 :END: ** TODO Go over the API design docs :c_coding: ``` When I search using `org-sparse-tree` for an element with that property name and value, that TODO is returned. I then looked in the `org-ql` docs regarding property searches and saw that I need to use a custom predicate if I want to search for properties using inheritance. I therefore created a query like this: ``` (org-ql-block '(and (todo) (property "FEATURE_NUM") (> 0 (string-to-number (org-entry-get (point) "FEATURE_NUM" 'inherit))) )) ``` I'm trying to evaluate each TODO and see if it has that property name and the value is \> 0. However, this query always returns `nil`. Can anyone see what I'm missing? According to the docs this seems to be the right way to do things. # Answer Oh duh, I guess I was trying to make things too complicated. This ended up working: ``` (org-ql-block '(and (todo) (org-entry-get (point) "FEATURE_NUM" 'inherit))) ``` Since I'm using the `org-entry-get` function I don't need the `property` predicate. > 1 votes --- Tags: org-mode, search, org-ql ---
thread-55299
https://emacs.stackexchange.com/questions/55299
Invoke emacsclient with a smaller font
2020-02-04T16:38:09.820
# Question Title: Invoke emacsclient with a smaller font For a certain application, I would like to start up emacsclient, but with a slightly smaller font. I can do it for a running emacs by eval'ing: ``` (set-face-attribute 'default nil :height 90) ``` But how to do it with command-line arguments just for the frame opened by emacsclient? The -F flag looks promising, but I'm not sure of the syntax. # Answer > 3 votes The `-F` flag takes an alist (short for association list), which is a list where each element is a cons cell of the form `(parameter . value)`. One of the available parameters is `font`, so to specify e.g. "Consolas 12", you'd say ``` emacsclient -F '((font . "Consolas 12"))' ``` --- Tags: emacsclient, fonts, command-line-arguments ---
thread-55308
https://emacs.stackexchange.com/questions/55308
How to do date calculations in org-mode tables
2020-02-04T23:44:24.097
# Question Title: How to do date calculations in org-mode tables I would like to enter a date (as active or inactive timestamps) in column 1 ( eg \[2020-02-02 Sun\] ) and a number of days in column 2 ( eg as 5d for 5 days) and then let something like: ``` #+TBLFM: $3=$1+$2 ``` calculate the resulting date after adding the days of column 2 to the date in column one. What I get as a result in column 3 is ``` [2020-02-02 Sun] + 5 d ``` Any idea how I can get instead someting like ``` [2020-02-07 Fri] ``` # Answer Sorry I found my mistake. Just putting 5 instead of 5d into column 2 does the trick. Please delete my question if you like. > 0 votes --- Tags: org-mode, org-table ---
thread-50378
https://emacs.stackexchange.com/questions/50378
How to suppress output of link with elisp function in org-mode?
2019-05-07T18:09:33.527
# Question Title: How to suppress output of link with elisp function in org-mode? When using elisp function in the link in org-mode, like ``` [[elisp:(func)][text]] ``` after clicking the link, the function itself will be printed in \*Message\* buffer. How should I prevent it from being printed? I've tried ``` (let ((inhibit-output t)) (...)) ``` but it doesn't work. # Answer \[Editorial comment: I'm not convinced this is a good idea - what difference does it make if the `*Messages*` buffer has an extra line in it? Despite my misgivings, I provide an answer below.\] The relevant function is `org-link--open-elisp`. If you check its implementation, you will see that it uses `message` to print the result of the evaluation to the echo area. But `message` also copies whatever it prints to the echo area, to the `*Messages*` buffer. A quick perusal of the doc string for `message` shows that you can avoid copying to the `*Messages*` buffer if you set `message-log-max` to `nil`. Unfortunately, that is going to turn off *all* output to the *Messages* buffer which is a bad thing. One way to accomplish what you want is to patch the `org-link--open-elisp` function to bind `message-log-max` to nil temporarily (as Marco Wahl suggests in his answer), but my suggestion would be to write a new function for this, which is an exact copy of `org-link--open-elisp` except that it binds `message-log-max` to `nil` before calling `message`: ``` (defun org-link--open-elisp-silent (path) "Open a \"elisp-silent\" type link. PATH is the sexp to evaluate, as a string." (if (or (and (org-string-nw-p org-link-elisp-skip-confirm-regexp) (string-match-p org-link-elisp-skip-confirm-regexp path)) (not org-link-elisp-confirm-function) (funcall org-link-elisp-confirm-function (format "Execute %S as Elisp? " (org-add-props path nil 'face 'org-warning)))) (let ((message-log-max nil)) (message "%s => %s" path (if (eq ?\( (string-to-char path)) (eval (read path)) (call-interactively (read path))))) (user-error "Abort"))) ``` You can then add a new link type "elisp-silent" that is handled by this function: ``` (org-link-set-parameters "elisp-silent" :follow #'org-link--open-elisp-silent) ``` Now `[[elisp:(func)][verbose]]` works as before and `[[elisp-silent:(func)][silent]]` works the same way but avoids writing to the `*Messages*` buffer. This technique of binding a variable around a function call is general and well-worth understanding if you are going to be doing elisp programming. > 1 votes # Answer A shorter way to accomplish this is by Advising Emacs Lisp Functions. You can use `:around` advice to let-bind the variable and then call the original function with its arguments like this: ``` (defun silence (orig-func &rest args) (let ((message-log-max nil)) (apply orig-func args))) (advice-add 'org-link--open-elisp :around 'silence) ``` Later you can remove the advice like this: ``` (advice-remove 'org-link--open-elisp 'silence) ``` > 1 votes # Answer Since the message comes from the respective org mode function you need to somehow circumvent that function. You could patch that function. Actually I think it's a good idea to see the message since this gives transparency to the evaluation. Note that the code evaluation could bring irritation and even harm. > 0 votes --- Tags: org-mode, org-link ---
thread-55283
https://emacs.stackexchange.com/questions/55283
Helm Find Files: prefer certain extensions
2020-02-03T18:23:49.767
# Question Title: Helm Find Files: prefer certain extensions Helm find files lists files of the same name alphabetically. ``` a.aux a.log a.tex b.aux b.log b.tex ``` This is annoying as I want the `.tex` file 99% of the time. Is it possible to prefer certain extensions (by white- or blacklist) to either change the order for extensions only: ``` a.tex (prefered) a.aux a.log b.tex (prefered) b.aux b.log ``` , or even "surpassing" filename priority, like so: ``` a.tex (prefered) b.tex (prefered) a.aux a.log b.aux b.log ``` # Answer This is not possible with the current code AFAIK (see `helm-ff-initial-sort-method`). One solution that doesn't require using a sorting algorithm is to append two lists, one containing the tex files and the other one containing the non-tex files so that the tex files are always on top. ``` (advice-add 'helm-list-directory :filter-return (lambda (files) (let ((tex-files (cl-remove-if-not (lambda (f) (string= (file-name-extension f) "tex")) files)) (non-tex-files (cl-remove-if (lambda (f) (string= (file-name-extension f) "tex")) files))) (append tex-files non-tex-files)))) ``` > 1 votes # Answer When using something like helm-projectile-find-file-dwim I would just add .tex as another search seed. In Helm FF, type the ext after the trailing eg "x/y/.tex" Not quite what you want but close. > 0 votes --- Tags: helm, find-file ---
thread-55298
https://emacs.stackexchange.com/questions/55298
Org-mode, collapse/expand section on click
2020-02-04T16:31:17.890
# Question Title: Org-mode, collapse/expand section on click Hi I'm on Linux and Emacs version is 26.3. I would like to expand or collapse a block by mouse click, instead of moving the cursor to the header and press tab. I actually have a windows computer does so, but do not work on my Linux one. I’ve tried to copy relevant files, however doesn’t work. I also googled, but to be honest, cannot find where to start. So if anyone can help? Thanks a lot!! # Answer > 5 votes You can **use the built-in org-mouse** which adds support for subtree expansion/collapsing (org-cycle) with the left mouse button. To use it either * add `(require 'org-mouse)` to your init file * or activate it in the current session with `M-: (require 'org-mouse) RET M-x org-mode-restart RET`. Org mouse implements the following features (taken from the package commentary): ``` ;; * following links with the left mouse button ;; * subtree expansion/collapse (org-cycle) with the left mouse button ;; * several context menus on the right mouse button: ;; + general text ;; + headlines ;; + timestamps ;; + priorities ;; + links ;; + tags ;; * promoting/demoting/moving subtrees with mouse-3 ;; + if the drag starts and ends in the same line then promote/demote ;; + otherwise move the subtree ``` --- Tags: org-mode ---
thread-55307
https://emacs.stackexchange.com/questions/55307
Recomposing a decomposed character
2020-02-04T22:33:36.763
# Question Title: Recomposing a decomposed character `(get-char-code-property ?αΌ€ 'decomposition)` returns a list of two characters into which the given character is decomposed. Is it possible, given these characters, to recompose the original? Is there a function for that? # Answer > 4 votes I don't think Emacs has a mapping from the decomposed form back to the original character. You can look it up using `ucs-names` though: ``` (defun lookup-composed (decomp) (let (composed) (maphash (lambda (key val) (when (equal decomp (get-char-code-property val 'decomposition)) (push val composed))) (ucs-names)) composed)) ``` --- Tags: character-composition ---
thread-55318
https://emacs.stackexchange.com/questions/55318
Automatic "push-mark" when navigating with xref, find-grep, etc?
2020-02-05T13:01:32.387
# Question Title: Automatic "push-mark" when navigating with xref, find-grep, etc? There seem to be a lot of situations, where a command changes the cursor location (point), but no mark is pushed, making navigating back by popping the mark with `C-u SPC` impossible. For isolated use-cases, I can fix this with e.g. `advice-add` on the affected command, or other ad-hoc fixes (see e.g. Set mark when jumping from emacsclient). I have however found, that it affects just *too many* situations to manually track down where to put the advice, and maintain that advice as the functions change -- quite often the suitable function is a package-private function like `xref--show-pos-in-buf`. Examples, where this makes issues, include: * `M-x xref-...` commands<sup>\[1\]</sup> * `M-x occur` * `M-x grep` * Latex forward/inverse search * ... Is there some better, cleaner way to achieve more comprehensive "mark-pushing"? # Workflow and Workarounds Given a setup ``` +--EmacsFrame----------------------+ | | | | FileBuffer | NavigationBuffer | | FileWindow | NavigationWindow | | | | | | | +----------------------------------+ ``` Where *NavigationBuffer* is associated e.g. with the `xref`, `diff`, `find-grep`, or `occur` feature, I may either: 1. Switch to *NavigationWindow* with a keyboard command, and activate a command, that causes the point in `FileBuffer` to change, or 2. Click somewhere in *NavigationWindow* to the same effect. Case (2) can be covered the same way for left-click and right-click events. Many modes however default to reacting only to middle-button clicks; In this case, `selected-window` and `current-buffer` remain the same before and after the command. While I can probably find a workaround for the middle-click case, the solution seems like a messy workaround at this point; A cleaner solution would be preferable. # Footnotes <sup>\[1\]</sup> RichieHH's Answer: In this case, there is `M-,` aka `xref-pop-marker-stack`, but setting the mark would still be nice for consistency. # Answer Certaily with xref, Use revert: `M-,` is the default. xref-pop-marker-stack > `M-,` (translated from `<escape> ,`) runs the command `xref-pop-marker-stack` (found in `global-map`), which is an interactive compiled Lisp function in `xref.el`. > > It is bound to `M-,`, `<menu-bar> <edit> <goto> <xref-pop>`. > > `(xref-pop-marker-stack)` > > Probably introduced at or before Emacs version 25.1. > > Pop back to where `M-.` was last invoked. > 2 votes --- Tags: motion, mark, navigation, grep, xref ---
thread-55306
https://emacs.stackexchange.com/questions/55306
How do I add a keybinding to use during an interactive isearch, `C-s ...`
2020-02-04T21:22:28.543
# Question Title: How do I add a keybinding to use during an interactive isearch, `C-s ...` Can I assign a key binding starting with `C-s` such as: ``` (global-set-key (kbd "C-s C-w") 'isearch-forward-symbol-at-point) ``` but I want to keep `(kbd "C-s")` for `i-search`. --- I am having following error: ``` error: Key sequence C-s C-w starts with non-prefix key C-s To ensure normal operation, you should investigate and remove the cause of the error in your initialization file. Start Emacs with the β€˜--debug-init’ option to view a complete error backtrace. ``` # Answer As I understand your question, you want `C-s` to start an interactive search, as it normally does, but if you press `C-w` after you've started that search, you want it to switch to `isearch-symbol-at-point`. First off, the feature you're after is almost the same as the default behaviour bound to `C-s C-M-w`. That will call `isearch-yank-symbol-or-char`, which is close, but not identical to `isearch-symbol-at-point`. Maybe that's close enough. If you really want to call `isearch-forward-symbol-at-point`, *without* overwriting the default behaviour of `C-s`, you'll need to add the new binding to the `isearch-mode-map`: ``` (define-key isearch-mode-map (kbd "C-w") 'isearch-forward-symbol-at-point) ``` Note that this will overwrite the default definition of `C-s C-w`, which is to call the function `isearch-yank-word-or-char`. The default options to `isearch` are described in the manual (info "(emacs) Isearch Yank") > 4 votes # Answer The C-s needs to be assigned as a prefix command. eg ``` (define-prefix-command 'myprefix) (global-set-key (kbd "C-s") 'myprefix) (global-set-key (kbd "C-s C-s") 'helm-occur) ``` > 0 votes --- Tags: key-bindings, prefix-keys ---
thread-55314
https://emacs.stackexchange.com/questions/55314
is any way to show empty paths in Dired like com/domain/example/database as single item?
2020-02-05T06:41:28.873
# Question Title: is any way to show empty paths in Dired like com/domain/example/database as single item? for example, Java/Scala sources have a convention that packages like `com.domain.example.database` should be represented as `com/domain/example/database` folder structure (and all dirs are empty except last one the `database`). So I wish to show deep paths like this as a single item as Github does. The `com/domain/example/database` should be shown as a single folder item at Dired. As an example on Github see https://github.com/elastic/elasticsearch/tree/master/modules/analysis-common/src/main \- that folder has a `java/org/elasticsearch/analysis/common` and if you click on it, the `common` be opened. # Answer There is dired-collapse https://github.com/Fuco1/dired-hacks#dired-collapse which looks like the feature you search for. > 3 votes --- Tags: dired ---
thread-55203
https://emacs.stackexchange.com/questions/55203
How to create a function that have the functionality of helm-projectile-switch-to-buffer but with added opened org files?
2020-01-30T23:58:17.610
# Question Title: How to create a function that have the functionality of helm-projectile-switch-to-buffer but with added opened org files? I really like helm-projectile-switch-to-buffer as it shows buffers for the specific project I am working in (i have multiple projects open at the same time). But I also rely on org files for notes and debug information. How is it possible to create a function that performs the exact same functionality of helm-projectile-switch-to-buffer but add to the possible buffers to switch to the opened org files as well? # Answer > 1 votes One way is to define a class that inherits from the `helm-source-buffers` class. You can use the candidate-transformer slot to remove non-Org buffers from the list. Then add the new source to the list of sources in your custom command. ``` (defclass helm-source-org-buffers (helm-source-buffers) ((candidate-transformer :initform (lambda (buffers) (cl-loop for b in buffers when (eq (with-current-buffer b major-mode) 'org-mode) collect b))))) (defvar helm-source-org-buffers-list nil) (defun your-helm-projectile-switch-to-buffer () (interactive) (unless helm-source-org-buffers-list (setq helm-source-org-buffers-list (helm-make-source "Org Buffers" 'helm-source-org-buffers))) (helm :sources '(helm-source-projectile-buffers-list helm-source-org-buffers-list))) ``` --- Tags: org-mode, buffers, helm, projectile ---
thread-55325
https://emacs.stackexchange.com/questions/55325
Dired; Is it possible, to show video duration as column in dired view?
2020-02-05T18:50:56.983
# Question Title: Dired; Is it possible, to show video duration as column in dired view? i want to let dired show the duration of multimedia files as a column inside the dired buffer detail view. Is it possible? Any third-party extensions for dired? Currently i use `exiftool -T -ImageSize -XResolution -YResolution -VideoFrameRate -AvgBitRate -Duration` as shell command run on marked files. But this produce only output. I don't know how to insert this result as columns. # Answer > 0 votes My short answer is no. Depending on what you really want, it's not possible - not without more or less redesigning Dired. Dired is essentially about `ls` listings. But you might try setting variable `insert-directory-program` to a program that produces the kind of listing you want - that should be possible. But you might not then be able to use some Dired features. Worth a try anyway. And you might find some Dired 3rd-party library that tries to add additional, arbitrary columns, so you could make use of that. Perhaps someone else will let you know here about such a library. --- Tags: dired ---
thread-10029
https://emacs.stackexchange.com/questions/10029
Org-Mode: How to create an "org mode markup" keybinding?
2015-03-15T07:34:15.370
# Question Title: Org-Mode: How to create an "org mode markup" keybinding? I know I can use `*bold*`, `/italic/`, `_underline_`, `=verbatim=`, `~code~`, and `+strike-through+` to apply markup to text in `org-mode`. But how do I create key bindings for applying these changes to a region of text? For example, if I want to make some text bold, is there an easier way than 1. navigating to the front of the text 2. prefixing it with a `*` 3. navigating to the end of the text 4. appending a `*`? I can't seem to find any command that "bolds" a stretch of text, such as `org-make-region-bold`. Is there such a command? # Answer > 16 votes 1. Mark you region 2. Click `C-c C-x C-f *` for **bold**, `C-c C-x C-f /` for *italic* etc. > `org-emphasize` is an interactive compiled Lisp function in `org.el`. > > ``` > (org-emphasize &optional CHAR) > > ``` > > Insert or change an emphasis, i.e. a font like bold or italic. If there is an active region, change that region to a new emphasis. If there is no region, just insert the marker characters and position the cursor between them. CHAR should be the marker character. If it is a space, it means to remove the emphasis of the selected region. If CHAR is not given (for example in an interactive call) it will be prompted for. # Answer > 8 votes You can make use of `electric-pair-mode`<sup>1</sup> to facilitate insertion of mark-up characters in `org-mode`. Add the following code to your init-file: ``` (electric-pair-mode 1) (defvar org-electric-pairs '((?\* . ?\*) (?/ . ?/) (?= . ?=) (?\_ . ?\_) (?~ . ?~) (?+ . ?+)) "Electric pairs for org-mode.") (defun org-add-electric-pairs () (setq-local electric-pair-pairs (append electric-pair-pairs org-electric-pairs)) (setq-local electric-pair-text-pairs electric-pair-pairs)) (add-hook 'org-mode-hook 'org-add-electric-pairs) ``` With this in place, all you need to do to wrap a region with mark-up characters is press the corresponding character (`*`, `/`, `=`, `_`, `~`, or `+`) once. As an additional benefit, Emacs will automatically insert matching pairs of mark-up characters at point if there is no region. For example, pressing `*` will insert `**` and leave point between the two chars so you can continue typing without having to move point. --- <sup>1</sup> This mode is built-in; there's no need to install any third-party packages to use it. # Answer > 8 votes You can use the `wrap-region` package (also available on Melpa) to wrap a region with any character of your choice. This of course can be configured per major mode. ``` (require 'wrap-region) (add-hook 'org-mode-hook #'wrap-region-mode) (wrap-region-add-wrapper "=" "=" nil 'org-mode) ; select region, hit = then region -> =region= in org-mode (wrap-region-add-wrapper "*" "*" nil 'org-mode) ; select region, hit * then region -> *region* in org-mode (wrap-region-add-wrapper "/" "/" nil 'org-mode) ; select region, hit / then region -> /region/ in org-mode (wrap-region-add-wrapper "_" "_" nil 'org-mode) ; select region, hit _ then region -> _region_ in org-mode (wrap-region-add-wrapper "+" "+" nil 'org-mode) ; select region, hit + then region -> +region+ in org-mode ``` The `expand-region` package complements this package very well (also available in Melpa). ### Usage * You select the word or phrase using the key binding you chose for `er/expand-region`. * Hit `*` to emphasize that region as bold (in `org-mode`). # Answer > 0 votes Users of Evil can employ the evil-surround minor mode to deal with various kinds of markup. You can either add markup to visual selection with `S` (by default) or to text objects in normal mode with `ys`. You can also change or delete some markers. But, to change or delete markers that aren't known to evil-surround by default, you'll need to add them to Evil as text objects. --- Tags: org-mode, key-bindings ---
thread-55330
https://emacs.stackexchange.com/questions/55330
How do I capitalize the first words of sentences in some buffer text?
2020-02-06T00:59:46.127
# Question Title: How do I capitalize the first words of sentences in some buffer text? I know how to convert a string to upper case, to lower case, or to title case. But the operation I do most frequently writing English text is to fix up capitalization so a sentence or group of sentences is in title case. That is, the first letter is capitalized and usually nothing else is, like the sentence you’re reading right now. Is there an Emacs command or package to reformat a sentence in sentence case? # Answer > 1 votes This is a rough start but seems to work: ``` (defun recapitalize-sentence () "Recapitalizes current sentence as a sentence. Relies on the function sentence-end to find the end of a sentence, which by default relies on two spaces before starting the next sentence." (interactive) (save-excursion (let ((next-sentence-start (progn (forward-sentence) (point)))) (backward-sentence) (capitalize-word 1) (while (< (point) next-sentence-start) (downcase-word 1))))) ``` # Answer > 5 votes (I assume you meant text in a buffer, and not a string (as the original question said). `M-e M-c` (press and hold `Meta` while hitting `e`, then `c`. The `M-e` moves `forward-sentence`. The `M-c` does `capitalize-word`. See the Emacs manual, nodes: You can of course write a simple command that does that, and bind that to a single key. But is it worth it? ``` (defun sentence-case (&optional n) "..." (interactive "p") (dotimes (ii n) (forward-sentence) (capitalize-word 1))) ``` (You can first make it go back to the beginning of the current sentence, with `backward-sentence`, if you want. And you can make other changes, e.g. to act on the sentences in the region. And you can reverse the order, to first capitalize then move to the sentence end. It all depends on what you really want.) --- Tags: motion, capitalization ---
thread-55329
https://emacs.stackexchange.com/questions/55329
TTY allocation in *Compilation* buffer
2020-02-05T21:55:37.177
# Question Title: TTY allocation in *Compilation* buffer I am using some complicated combination of Cygwin (for emacs) and Docker (for Linux environment) for C++ development on my laptop. Recently I noticed that Docker dumps lots of ANSI and XTERM sequences into my `*Compilation*` buffer. Using redirection solved the problem: ``` docker run .... 2>&1 | cat ``` This tells me that somewhere between the latest Cygwin, Emacs and Docker the Docker now thinks it's running in a proper interactive terminal. I'd rather the Docker behaved as if it's redirecting to a file and not do things like clear screen and colorize the output. So the question is: Is there any way to run the compilation command in Emacs without allocating a TTY? P.S. I considered the ANSI filter on compilation output as described here. It does not quite work, as the Docker uses cursor positioning and other XTerm escape sequences that ANSI library in Emacs does not understand, plus it inserts newlines to clear screen and limit lines to 80 characters. # Answer After a kind hint from @rpluim, I wrote this in my `.emacs` : ``` (defun plain-pipe-for-process () (setq-local process-connection-type nil)) (add-hook 'compilation-mode-hook 'plain-pipe-for-process) ``` It does exactly what I need. Docker is no longer spamming me with ANSI codes. > 4 votes --- Tags: compilation-mode ---
thread-55337
https://emacs.stackexchange.com/questions/55337
How to activate diff-mode from command line?
2020-02-06T10:45:28.607
# Question Title: How to activate diff-mode from command line? Git's editor config is set to launch emacs in *no-window mode* and to execute lisp function `diff-mode`: ``` git config --global core.editor "emacs -nw -f diff-mode" ``` However, when I execute `git commit -v` to edit a commit message (the `-v` flag provides the diff to the editor), `diff-mode` is not activated: Manually activating the mode by executing the function (`Mod`+`X` `diff-mode`) *does* work at this point: Why does the mode not get activated when I supply `-f diff-mode` on the command line? # Answer > 4 votes Command line arguments are processed in-order. So your `-f diff-mode` will put into `diff-mode` whichever buffer happens to be current right after Emacs has started (most likely it will be the `*scratch*` buffer). The next argument will probbaly look like `/.../COMMIT_EDITMSG` and will cause Emacs to load that file into some new buffer using some other major mode, determined by `auto-mode-alist`. So your better option is probably to add to your `~/.emacs` a rule ``` (add-to-list 'auto-mode-alist '("/COMMIT_EDITMSG\\'" . diff-mode)) ``` where `/COMMIT_EDITMSG\'` is a regexp which recognizes specifically the name of the temp files used by `git commit`. --- Tags: major-mode, git, start-up, diff, command-line-arguments ---
thread-55344
https://emacs.stackexchange.com/questions/55344
How can I sum (multiply ...) all elements on the calc stack?
2020-02-06T14:41:57.540
# Question Title: How can I sum (multiply ...) all elements on the calc stack? Sometimes I just want to sum a bunch of numbers in calc. Right now I press `+` until the stack is empty. Is there a shorthand for this? # Answer Another solution, if you know from the beginning that you want a sum, is use a vector. Prefix your list of numbers with `[`, finish with `]`, and sum using `calc-reduce` with the `+` operator (`v R +`): ``` [ 1 2 ... ] v R + ``` > 3 votes # Answer Summing the whole stack of calc can be achieved using a keyboard macro. * Define the macro (which does just the `+` operation): `C-x ( + C-x )`. + BTW this definition already sums two elements of the stack as a side effect. * Then run the macro until an error occurs with `C-0 X`. * That's it! The error is expected to occur when one element remains on the stack. If you know the stack size you possibly better use the suggestion of swedgin. > 3 votes --- Tags: calc ---
thread-55336
https://emacs.stackexchange.com/questions/55336
How to copy the symbol name at point?
2020-02-06T10:29:59.063
# Question Title: How to copy the symbol name at point? I want to copy the name of the symbol at point, without using the mouse. ``` (global-set-key (kbd "C-s C-c") '<copy_word>) ``` --- Possible word marking as `i-search` does on the following example usage (https://emacs.stackexchange.com/a/55321/18414) For example: `[_id_hello_world]` and if cursor is in between `hello` and `world` I want to copy complete `_id_hello_world`. # Answer What you want is something like `(kill-new (thing-at-point 'symbol))`. When run, it first extracts the symbol at point and then adds it to the `kill-ring`, i.e. copies it. One caveat you have to keep in mind is that you need an interactive function/lambda in order to be able to invoke it with a keybinding. So actually you can have a binding of the form: ``` (global-set-key (kbd "C-s C-c") (lambda () (interactive) (kill-new (thing-at-point 'symbol)))) ``` > 3 votes # Answer While not strictly answering your question regarding one key copy symbol/word at point I like to use expand-region since frequently I want to copy a lot at point without needing to move to the start, mark, move to end and copy. It might be of use. For example, here are bindings to expand and contract the active region (and of course I then need to `M-w` to copy but it's still reasonably efficient: ``` (use-package expand-region :config (defun er/select-call-f (arg) (setq current-prefix-arg arg) (call-interactively 'er/expand-region) (exchange-point-and-mark)) (defun selectFunctionCall() (interactive) (er/select-call-f 3)) :bind ("<C-return>" . selectFunctionCall) ("M-a" . er/expand-region) ("M-s" . er/contract-region)) ``` > 1 votes --- Tags: copy-paste, symbols, thing-at-point ---
thread-54124
https://emacs.stackexchange.com/questions/54124
Can emacsclient focus an existing frame?
2019-12-03T03:34:58.730
# Question Title: Can emacsclient focus an existing frame? When `emacsclient` is invoked with the option `-c` it creates a new frame. In both Windows and Linux, this frame is a window at the top of the Z-stack and has input focus. With option `-n` (non-blocking) the command window in which `emacsclient` is invoked regains this position but the new Emacs frame only takes one step down the Z-order. I can put the focus back on the Emacs frame just by closing the command window. Is there any way to get this behavior with an existing frame, i.e. without `-c`? The focus question has been asked many times without being clear about whether a new or existing frame is involved. The generally accepted answers seem to revolve around the elisp functions `select-frame-set-input-focus` and `server-raise-frame`. I find that these do nothing with existing frame (no `-c`) and are not needed otherwise. I'm wondering if a viable but ugly solution would be to always invoke `emacsclient` with `-c` and in the command line `eval` an expression that detects the previous frame and deletes it but I don't know how to do this. Windows 10 and 7; `emacsclient` version 26.1 Linux Ubuntu-Mate version 18.04; `emacsclient` version 25.2 # Answer > 2 votes In both Linux and Windows a separate program must be invoked after emacsclient (if it succeeds) to find and elevate the frame window. This is pretty simple in Linux because most of the work can be done by wmctrl, a general-purpose X window control program. This is not included in the Ubuntu distro but is listed in the repository, making installation easy (`sudo apt-get install wmctrl`). There are similar programs for Windows but virus scanners call them out as PUP (Potentially Unwanted Program) because they do too many things that can be exploited (wmctrl is more limited and safer). I wrote a Win32 console program to do what I want wmctrl to do in Linux. wmctrl (and my Windows program) find the requested window by its title. The Emacs default title tells the Emacs version and computer name. This is a lousy title in general so I was happy to change it to something the programs can find. I put `(setq frame-title-format "Emacs>%b")` in .emacs, making every frame window title still tell the program but also the name of the file (buffer). In Linux all the rest can be done by a simple Bash script. The heart of this is the command `wmctrl -a "${1##*/}"` which tells wmctrl to "activate" (bring forward and give focus) to the file name parsed from the path+name given by command parameter 1. The Windows program invokes the OS function EnumWindows, which iterates over all windows, invoking my callback, which looks for the file name in the title bar and calls OS function SetForegroundWindow on match. Since this is not a forum about Bash or Windows programming I won't include code unless requested but I will mention that both of my programs do more than elevate the window. They try emacsclient and, if it fails, invoke emacs including the command argument `--eval "(server-start)"`. They also optionally search for a string. Nevertheless, they are not very complicated. # Answer > 1 votes I use xdotool. This won't work on Wayland. It does on Gnome with Xorg. I have a shell script:- ``` #!/bin/bash WID=`xdotool search --name "OneEmacs"|head -1` if [[ -z ${WID} ]]; then notify-send "Starting Emacs daemon..." emacsclient --alternate-editor='' -c else notify-send "restoring Emacs instance..." xdotool windowactivate $WID fi ``` This looks for a frame with the title "OneEmacs" and restores it if it's there. I call this from a desktop key binding. In my init.el (or command line magic is another way) ``` (setq frame-title-format "OneEmacs") ``` You could only do this if daemon mode maybe if you prefer:- ``` (if daemonp (...)) ``` The notify-send functionality comes from libnotify # Answer > 0 votes I use the following command to create a new Emacs server (Ubuntu 19.10): ``` emacs --eval '(progn (setq server-name "foo-server")(server-start))' & ``` After that I can focus it by running: ``` emacsclient -s foo-server --eval "(progn (select-frame-set-input-focus (selected-frame)))" ``` from the terminal window.. --- Tags: emacsclient, focus ---
thread-34977
https://emacs.stackexchange.com/questions/34977
Any science book written in org-mode?
2017-08-18T09:30:45.947
# Question Title: Any science book written in org-mode? I am thinking to write a physics book in org-mode. Although there are many open-source science books written in LaTeX to figure out its work-flow (and its source) I couldn't find any science book written in org-mode. It is better alternative writing than in LaTeX for science books? # Answer > 4 votes I wrote an academic paper mostly in org-mode. The published paper is here https://pubs.acs.org/doi/abs/10.1021/jacs.7b08572. And the repo I used to make it is hosted here with the main org-mode source here: https://gitlab.com/salotz/Lotz2017sEHTPPUUnbinding/blob/master/paper/paper.org As others have commented you will likely have to export to LaTeX to do some tweaks for the particular journal. But I drafted the entire contents of the paper using org-mode. I think the main advantage in writing in org-mode is that you can be more focused on generating the content instead of typography, which I feel is the case with LaTeX. The nesting/folding implementation of headings in org-mode is really good and allows you to work on large documents (anything larger than can fit on your screen at once) very easily. That said if you are collaborating or requesting edits from others most people will not know org-mode (or use emacs) and be instantly annoyed that you aren't using LaTeX. If you are very good at LaTeX and not distracted by all the extra verbose markup then I don't know that org-mode is right for you. Or if your document relies heavily on advanced typographic formatting In addition to org-mode I used a number of emacs extensions that made adding citations a breeze: * helm-bibtex * org-ref (particularly the `org-ref-extract-bibtex-*` commands to generate a bibtex file) Although, LaTeX modes in emacs have basically the same functionality. I would also suggest a few conventions and tricks that helped along the way, that probably help with LaTeX as well. When drafting I wrote each sentence on a single line separated by a blank line and paragraphs separated by two lines. This makes your `diff`s focused without flagging a whole big paragraph as a change (since source code diffs are line-based and not sentence based). Normally when I am writing prose (or code with support for this function) I compulsively use `M-q` to keep the lines within the fill column limit (80 characters usually), however this breaks the sentence per line convention and makes diffs almost useless. To solve this use `visual-fill-column-mode` (to set number of columns to show text in) and `visual-line-mode` (to stop line breaks within words) when editing. Also I don't see `pandoc` mentioned here but it is definitely worth a mention. As it might be better at outputting LaTeX or PDFs in different situations than the builtin org-mode functions. # Answer > 7 votes The book 'Modeling materials using density functional' by John Kitchin is written in orgmode: http://kitchingroup.cheme.cmu.edu/dft-book/dft.html # Answer > 3 votes This is an example of book written in Org-mode, with a comprehensive tutorial: https://procomun.wordpress.com/2014/03/10/book-available-for-preorder/ --- Tags: org-mode, latex ---
thread-55338
https://emacs.stackexchange.com/questions/55338
How to make emacs show correct hex color on background?
2020-02-06T12:11:35.937
# Question Title: How to make emacs show correct hex color on background? The way I run `emacs`: `TERM=xterm-256color emacs -nw <my_file>` --- I am trying to have background on `dracula-theme` (https://github.com/dracula/dracula-theme). --- I have added following line into `.emacs`: `(add-to-list 'default-frame-alist '(background-color . "#282a36"))` Expected color: but some blue color show up instead: --- I have also installed the draculate them but similiar problem occurs. (add-to-list 'custom-theme-load-path "~/.emacs.d/themes") (load-theme 'dracula t) Possible bug: https://github.com/dracula/emacs/issues/32 # Answer > 1 votes Have you applied a theme? In which case M-x: describe-face type "default" See what that is. Also, remember that terminals have pallettes. This stack exchange article will get you going. --- Tags: terminal-emacs, colors ---
thread-55352
https://emacs.stackexchange.com/questions/55352
How to unconditionally toggle parent checkbox
2020-02-07T03:20:06.327
# Question Title: How to unconditionally toggle parent checkbox In the following example Org mode buffer, I cannot check the `Parent` checkbox without first checking the `Child` checkbox: ``` - [ ] Parent - [ ] Child ``` Is there some way to loosen this restriction? There is a user option called `org-enforce-todo-dependencies` that bypasses such dependency-checking for `TODO` entries, but I cannot find such an option for checkboxes. I'm using version 9.1.14 of `org.el`. # Answer > 2 votes You can literally write an X into the box. It's just text! You could give that scene some meaning and take care. AFAICS Org is quite rigid to only allow the transition to \[X\] via `C-c C-c` or `C-c C-x C-b` when all the children are already in state \[X\]. To set \[X\] to a bunch of items, e.g. in the whole subtree of plain items below the item you want to \[X\], you could define a region around that items before the `C-c C-c`. --- Tags: org-mode ---
thread-54833
https://emacs.stackexchange.com/questions/54833
helm-M-x fuzzy not working (only match if provide proper prefix)
2020-01-10T15:56:39.237
# Question Title: helm-M-x fuzzy not working (only match if provide proper prefix) I set helm-M-x-fuzzy-match to true, but it is not working as I want. For example, if I type `log`: I expect it to show `clm/toggle-command-log-buffer` as well. # Answer > 4 votes Check out https://github.com/syl20bnr/spacemacs/issues/13100. There was a breaking change in Helm which removed the `fuzzy-` variables you defined. In place, you have to set the following variables in your init.el: For emacs27: ``` (setq helm-completion-style 'emacs) (setq completion-styles '(flex)) ``` For emacs26: ``` (setq helm-completion-style 'emacs) (setq completion-styles '(helm-flex)) ``` Hope that helps anyone else with the same issue. --- Tags: helm, helm-sources, m-x ---
thread-55367
https://emacs.stackexchange.com/questions/55367
How to render html in web-mode?
2020-02-07T18:10:40.207
# Question Title: How to render html in web-mode? I'm using web-mode within emacs to edit an html file, in html-mode I can use `C-c C-v` to render html, it opens the file straight to Firefox. How I do that with web-mode? Thanks a lot, P.S : Using emacs 26.3 # Answer > 5 votes You can find out what `C-c C-v` does by pressing `F1 k C-c C-v` in a `html-mode` buffer: > C-c C-v runs the command browse-url-of-buffer (found in html-mode-map), which is an interactive autoloaded compiled Lisp function in β€˜browse-url.el’. That command can be bound in the appropriate `web-mode` keymap, aptly named `web-mode-map`: ``` (with-eval-after-load 'web-mode (define-key web-mode-map (kbd "C-c C-v") 'browse-url-of-buffer)) ``` --- Tags: html, web-mode ---
thread-52603
https://emacs.stackexchange.com/questions/52603
Any date entry in the text will be captured in agenda view
2019-09-10T10:10:07.027
# Question Title: Any date entry in the text will be captured in agenda view I guess this is best explained by screenshots. I have one entry like this: then I run `M-x org-agenda RET a RET` and I get something like this: Problem is, I do not want this timestamp to show up in my agenda as it's the content under the heading **Problems and solutions**, instead of a Deadline or Scheduled time. I've googled for a few hours but amazingly couldn't get any helpful information. thanks in advance. **Edit** I found this and tried the solution (set `org-agenda-search-headline-for-time` provided anyway but had no luck. Also tried searching for something like **-for-time** as suggested but it didn't give me any more than `org-agenda-search-headline-for-time`. # Answer > 1 votes You should be using `inactive` timestamps, delineated with `[]` rather than `<>`: `[2020-02-08]` instead of `<2020-02-08>`. See the Timestamps section of the Dates and Times chapter in the manual. # Answer > 0 votes Just when I was going to give up, I came across this option in the source code: `org-agenda-skip-additional-timestamps-same-entry nil` > "When nil, multiple same-day timestamps in entry make multiple agenda lines. When non-nil, after the search for timestamps has matched once in an entry, the rest of the entry will not be searched." :group 'org-agenda-skip :type 'boolean) This should roughly solve the problem but I'm looking for something that will only include Deadline and Scheduled times. --- Tags: org-mode ---
thread-55342
https://emacs.stackexchange.com/questions/55342
Spacemacs evil-mode : How to toggle off visual mode in interactive function call?
2020-02-06T12:55:54.380
# Question Title: Spacemacs evil-mode : How to toggle off visual mode in interactive function call? ``` ;; .spacemacs file (defun my/function (beg end) ;; To work with visual selection: (interactive "r") ;; Displays visual selection in message buffer: (message (buffer-substring-no-properties beg end)) ;; Now I want to toggle off visual selection in buffer ;; But I do not know how to do it? ) ``` Any ideas? # Answer > 1 votes I have found a way after exploring all `evil-` functions: ``` (evil-normal-state 1) ``` My first idea was to use: ``` (evil-visual-state -1) ``` But it leaves the buffer in `insert mode` with no possibility to go back to `normal mode`. --- **Edit:** I have come to another way of doing it: ``` ;; .spacemacs file (defun my/function (beg end) ;; To work with visual selection: (interactive "r") ;; checking: <----------- section added (unless (evil-visual-state-p) (error "Not in visual mode...")) ;; Displays visual selection in message buffer: (message (buffer-substring-no-properties beg end)) ;; Eventually the function I have been looking for: (evil-exit-visual-state) ) ``` # Answer > 0 votes I think this is what you are looking for `evil-magit-maybe-deactivate-mark` ``` evil-magit-maybe-deactivate-mark is an interactive and compiled function defined in evil-magit.el. Documentation Deactivate mark if region is active. Used for ESC binding. ``` --- Tags: spacemacs, evil, visual-line-mode ---
thread-55375
https://emacs.stackexchange.com/questions/55375
Remove image & link related keybindings in eww
2020-02-08T08:18:18.670
# Question Title: Remove image & link related keybindings in eww I'm using `xah-fly-keys` which provides a few custom keys for easy navigation. ``` u = backward-word o = forward-word i = previous-line ... ``` Unfortunately, my keybindings are overshadowed when point is on a visible/hidden link and sometimes even text. Is there a simple way to force my keybinds over others (`shr-probe-link/save-image`, etc) in eww? Using `bind-keys`, only `forward-word` works, `i` and `u` fail. Even `v` which normally runs `eww-view-source` switches to `shr-browse-url` when point is on a link. This is the webpage, it has nested paragraphs inside a tags which highlights the issue: http://www.ultratechnology.com/blog.htm Below is the code i tried. ``` (bind-keys :map image-map ("i" . previous-line) ("u" . backward-word) ("o" . forward-word) ("v" . eww-view-source) ) (bind-keys :map shr-map ("i" . previous-line) ("o" . forward-word) ("u" . backward-word) ("v" . eww-view-source) ) (bind-keys :map shr-image-map ("i" . previous-line) ("o" . forward-word) ("u" . backward-word) ("v" . eww-view-source) ) ``` # Answer When over links/regions where your bindings do not work do the following:- ``` C-h k ``` and then press the key whose binding you want to replace. The buffer that appears will show you the existing binding and map and you are then good to go with what you already now. > 0 votes --- Tags: key-bindings, keymap, eww, shr ---
thread-36795
https://emacs.stackexchange.com/questions/36795
Auctex imenu add frames to list?
2017-11-11T07:37:45.430
# Question Title: Auctex imenu add frames to list? I use imenu in auctex. For beamer slides, it only offers me the `\section`-commands as entry points. How can I teach imenu to also offer all frames? (Which is an environment: `\begin{frame}....\end{frame}`? # Answer You need to make AUCTeX aware of the frame environment, i.e., `\frametitle`: ``` (add-to-list 'TeX-outline-extra '("\\\\frametitle\\b" 4)) ``` From the documentation on `Tex-outline-extra`: > List of extra TeX outline levels. > > Each element is a list with two entries. The first entry is the regular expression matching a header, and the second is the level of the header. See β€˜LaTeX-section-list’ for existing header levels. Similarly, you need to explicitely tell reftex to show `\frametitle` in its TOC: ``` (setq reftex-section-levels '(("part" . 0) ("chapter" . 1) ("section" . 2) ("subsection" . 3) ("subsubsection" . 4) ("frametitle" . -3) ("paragraph" . 5) ("subparagraph" . 6) ("addchap" . -1) ("addsec" . -2))) ``` > 3 votes # Answer I use some dummy commands to mark my outline. The solution is not perfect, but it is usable. I configure `TeX-outline-extra` this way: ``` (add-to-list 'TeX-outline-extra '("imenu" 1)) (add-to-list 'TeX-outline-extra '("imenuOne" 1)) (add-to-list 'TeX-outline-extra '("imenuTwo" 2)) (add-to-list 'TeX-outline-extra '("imenuThree" 3)) (add-to-list 'TeX-outline-extra '("imenuFour" 4)) ``` In my `tex` file I add: ``` \newcommand{\imenu}[1]{#1} \newcommand{\imenuOne}[1]{#1} \newcommand{\imenuTwo}[1]{#1} \newcommand{\imenuThree}[1]{#1} \newcommand{\imenuFour}[1]{#1} ``` Now I can add an outline level anywhere, like this: ``` \begin{homeworkProblem}[\imenu{The first problem}] ``` > 0 votes # Answer I know this question is more than 2 years old, but I had the same question myself, and none of the above answers worked for me. Here's the workaround I used. I think auctex sets `imenu-create-index-function` to `LaTeX-imenu-create-index-function`. In my LaTeX-mode-hook, I reset it as shown below and use a variant of the regexps given in the answers above. ``` (setq-local imenu-create-index-function 'imenu-default-create-index-function) (setq-local imenu-generic-expression '((nil ; put in top-level menu "^\\\\begin{frame}\\(\\[[a-z,]+\\]\\)?{\\(.+\\)}" 2 ; which bracketed expression goes in title ))) ``` Now my imenu shows the frame titles as entries. > 0 votes --- Tags: auctex, beamer, imenu ---
thread-55379
https://emacs.stackexchange.com/questions/55379
Emacs startup and the elisp environment
2020-02-08T16:31:36.413
# Question Title: Emacs startup and the elisp environment Can anyone tell me what is going on when Emacs starts up? As I understand, Emacs has a "base," a "foundation" of code written in C, but then supposedly a great Lisp "program" takes flight. And from then on you are interacting with one big live Lisp "program," which is supposedly different than running a regular compiled C/C++ program. But then I've never really fully understood what that really means, i.e., what the difference is between a compiled program running in live memory and a Lisp program running in, what?, a Lisp virtual world, perhaps? One specific question would be, when the elisp part of Emacs starts up, is it just like a huge tree of one initial function calling other functions that in turn call other functions? I also understand that the `*scratch*` and the ielm REPL allow you not only to do calculator stuff, but to actually change the running instance of Emacs, at least the running elisp code. Some explanation of this process would be illuminating. # Answer > 3 votes I'm not sure what a good answer could be, but you can see how the Elisp part of Emacs starts by looking at the function `normal-top-level` which is the Elisp function called by the C code once the C side's initialisation is done. So try: ``` C-h o normal-top-level RET ``` and then click on the link to see its source code. # Answer > 2 votes At startup Emacs runs an initialization file `.emacs` or `.emacs.d/init.el`. When Emacs starts from a unix shell, it loads environment variables. Emacs uses Elisp (Emacs lisp) as a command language. You don't need to know Lisp to use Emacs, except for writing the init file but you can even avoid this by using `M-x customize` and never look at `.emacs` (and the initial dot means "hidden"). You will use Lisp to automate complex Emacs tasks and ultimately to improve or adapt Emacs to your special needs (develop custom mode). You can use Emacs to run any Lisp code. According to Wikipedia > GNU Emacs is written in C and provides Emacs Lisp, also implemented in C, as an extension language. But this depends on implementation and may change without you being aware of, except for performance or arithmetic limits. GNU Emacs is built with GNU software like `gcc`. XEmacs is another built. Emacs special keys derive from historical Lisp machines. --- Tags: start-up ---
thread-55372
https://emacs.stackexchange.com/questions/55372
How can I replace all instances of a mispelled word during ispell?
2020-02-08T00:24:54.430
# Question Title: How can I replace all instances of a mispelled word during ispell? I can be remarkably consistent with my misspellings some times; in these instances while running `ispell`, I'd like to be able to hit something like `C-u <correction number>` (for instance) to replace *all* instances of the mispelling at once. Is there a way to tell ispell to not only replace the current word with a suggestion, but all future instances of that word with the same correction? (As if I were to exit, then run `query-replace` and then hit `!` to replace all occurrences.) Thanks in advance. # Answer > 4 votes If you switch on `ispell-query-replace-choices` by `M-x` `customize-option` ispell uses `query-replace` if it finds multiple occurrences of the miss-spelled word after you choose a replacement. After the first correction it will go to the next occurrence and query you with the menu of `query-replace-regexp`. The most important menu choices are: * `!` replace all occurrences of the miss-spelled word with the chosen correction * `y` replace this occurrence and go to the next occurrence * `q` continue with the normal Ispell command loop # Answer > 1 votes Using ispell-buffer, after replacing the first instance you can press "R" - which... yup, gives you query and replace. Not quite as convenient as what you're looking for but almost... --- Tags: ispell ---
thread-47451
https://emacs.stackexchange.com/questions/47451
Definitive answer to org-mode export HTML versus LaTeX
2019-01-28T03:58:02.260
# Question Title: Definitive answer to org-mode export HTML versus LaTeX I keep being stymied by the apparent incompatibility of HTML and LaTeX export. Here's what I have in my .org file header: ``` #+LATEX_CLASS: article #+LATEX_CLASS_OPTIONS: [american] #+LATEX_HEADER: \usepackage{tikz} #+LATEX_HEADER: \usepackage{commath} #+LATEX_HEADER: \usepackage{stackengine} #+LaTeX_HEADER: \usepackage{pgfplots} #+LaTeX_HEADER: \usepackage{sansmath} #+LATEX_HEADER: \usepackage{mathtools} #+LaTeX_HEADER: \usepackage{amsmath} ``` In reality, I don't know if this gets seen by orgmode export to HTML, perhaps by export to LaTeX? So to start, here is working piece of markup that displays great in both HTML and LaTeX: ``` #+begin_src latex :packages '(("" "tikz")) :exports results :results output raw :file other12.png :imagemagick yes :iminoptions -density 600 :imoutoptions -geometry 500 \usetikzlibrary{decorations.pathreplacing} \begin{tikzpicture}[scale=1] \draw[step=1cm,thin,gray!60] (-6,-6) grid (6,6); \draw[<->] (-6,0)--(6,0) node[right]{$x$}; \draw[<->] (0,-6)--(0,6) node[above]{$y$}; \draw[line width=2pt,blue,-stealth](0,0)--(4,-3) node[anchor=south west]{$\boldsymbol{(4,-3)}$}; \draw[line width=2pt,gray,-stealth](2,3)--(6,0) node[anchor=south west]; \draw[line width=2pt,gray,-stealth](-5,4)--(-1,1) node[anchor=south west]; \draw[line width=2pt,gray,-stealth](-3,-1)--(1,-4) node[anchor=south west]; \draw [decorate,color=red,decoration={brace,amplitude=10pt},xshift=-0pt,yshift=0pt] (-5.0,1.0) -- (-5.0,4.0) node [red,midway,xshift=-0.65cm] {\footnotesize $-3$}; \draw [decorate,color=red,decoration={brace,amplitude=10pt,mirror,raise=1pt},xshift=-0pt,yshift=0pt] (-5,1) -- (-1,1) node [red,midway,yshift=-0.6cm] {\footnotesize $4$}; \end{tikzpicture} #+end_src ``` This also displays in both HTML and LaTeX correctly: ``` \begin{align*} \|x\|&=\sqrt{4^2+(-3)^2} \\ &= \sqrt{25} \\ &= 5 \end{align*} ``` as well as this: ``` \begin{equation*} x = \begin{pmatrix} \phantom{-} 4 \\ -3 \\ \end{pmatrix} \end{equation*} ``` but this on the HTML side ``` \setstackEOL{\\} \begin{equation*} x=\parenVectorstack[r]{4\\-3\\2} \end{equation*} ``` doesn't know what `\setstackEOL{\\}` is, nor `\parenVectorstack[r]` and displays mangled. The LaTeX export looks fine, though. And if I put it in a LaTeX babel code block, it disappears from the HTML entirely, while, again, the LaTeX export displays just fine. Confusing is how the Tikz code block is displayed in both HTML and LaTeX, but any other attempt at a LaTeX code block is ignored and left completely out of the HTML export. My educated guess is that the org-mode HTML export processes is handled by MathJax, which is a subset of LaTeX. But then I'd like to know definitively what can be done and what cannot be done LaTeX-wise for the HTML export. # Answer > 2 votes As I've researched this issue, it seems like a very big, complicated, outwardly-billowing, crawling-across-broken-glass trial-and-error slugfest that will take a serious sorting out. The "documentation" at orgmode.org here is hardly better than a reference dump, i.e., it will require painstaking, meticulous trial-and-error to sort out what exactly can and cannot be done, culminating in a user/beginner-friendly tutorial write-up. Hence, I absolve the community of answering this. Till then, I lay this on ice.. . . . . # Answer > 2 votes You already discovered yourself that MathJax does not offer all the finesses of LaTeX. That is the main reason why you can use another LaTeX-backend for HTML export with the help of the `tex` option of the `html` exporter. Example: ``` #+OPTIONS: tex:dvipng ``` Choosing `dvipng` as LaTeX backend, your document is exported fine to HTML. --- Tags: org-mode, org-export, latex, html ---
thread-55386
https://emacs.stackexchange.com/questions/55386
How to automate user-testing with elisp?
2020-02-09T02:25:35.993
# Question Title: How to automate user-testing with elisp? Is it possible to automate testing user input? An example of this could be multiple editing operations, undo, saving, reverting the buffer etc. Then checking the buffer contents is what the test expects. The user input could be keyboard shortcuts or (preferably) commands run as if they were bound to keys. Hooks should run as would typically happen when running interactive commands, so the `last-command`, variable should be set, `post-command-hook` should run. etc. --- To make this question concrete, is it possible to type 5 lines, undo 4, redo 2 times, then ensure 3 of the 5 lines were entered? # Answer > 3 votes I don't think there's a very satisfactory answer, but here's what I used today for testing the new `undo-redo` command I installed into `master`: ``` (defun simple-tests--exec (cmds) (dolist (cmd cmds) (setq last-command this-command) (setq this-command cmd) (run-hooks 'pre-command-hook) (command-execute cmd) (run-hooks 'post-command-hook) (undo-boundary))) ``` Another approach I used (in `mule-cmds--test-universal-coding-system-argument`): ``` (let ((enable-recursive-minibuffers t) (unread-command-events (append (kbd "C-x RET c u t f - 8 RET C-u C-u c a b RET") nil))) (read-string "prompt:"))))) ``` --- Tags: testing, elisp-conventions ---
thread-54817
https://emacs.stackexchange.com/questions/54817
Remove dollar sign at beginning of line
2020-01-09T22:35:11.833
# Question Title: Remove dollar sign at beginning of line In emacs when I scroll right and beginning of lines are truncated emacs inserts dollar sign same as it insert \ at the end of truncated line. I wish it would not insert these two signs. Can I disable this behavior? # Answer Are you asking how to turn off such line truncation? If so, the answer is `M-x toggle-truncate-lines`. You can also set variable `truncate-lines` to `nil` in any given buffer. And you can set its default, global value using `setq-default`. See the Emacs manual, node Line Truncation. See also user option `truncate-partial-width-windows`. --- You could discover this using command `apropos-command` or `apropos` with keyword `truncate`. --- If you instead are asking how to change the chars used, `$` and `\`, or how to have no chars indicate that truncation is in effect, I think the answer is that you cannot - that's coded in C source code. > 1 votes # Answer What you're referring to is described in the manual: > As an alternative to continuation (\*note Continuation Lines::), Emacs can display long lines by β€œtruncation”. This means that all the characters that do not fit in the width of the screen or window do not appear at all. On graphical displays, a small straight arrow in the fringe indicates truncation at either end of the line. On text terminals, this is indicated with β€˜$’ signs in the rightmost and/or leftmost columns. It turns out this can be customized through the use of variable `buffer-display-table` whose docstring includes: > Display table that controls display of the contents of current buffer. > > ... > > If this variable is nil, the value of β€˜standard-display-table’ is used. > > ... > > In addition, a char-table has six extra slots to control the display of: > > the end of a truncated screen line (extra-slot 0, a single character); > > the end of a continued line (extra-slot 1, a single character); > > the escape character used to display character codes in octal (extra-slot 2, a single character); > > ... > > See also the functions β€˜display-table-slot’ and β€˜set-display-table-slot’. We follow the trail to the docstring of `set-display-table-slot`: > (set-display-table-slot DISPLAY-TABLE SLOT VALUE) > > Set the value of the extra slot in DISPLAY-TABLE named SLOT to VALUE. SLOT may be a number from 0 to 5 inclusive, or a name (symbol). Valid symbols are β€˜truncation’, β€˜wrap’, β€˜escape’, β€˜control’, β€˜selective-display’, and β€˜vertical-border’. So finally... If you haven't defined `buffer-display-table` you should set the `truncation` slot of `standard-display-table` to the wanted char, eg 32 for a space. To do so, you can add the following to your init file: ``` (set-display-table-slot standard-display-table 'truncation 32) ``` > 0 votes --- Tags: display, line-truncation ---
thread-55390
https://emacs.stackexchange.com/questions/55390
Infinite repetition (iteration) in Elisp code
2020-02-09T15:02:41.110
# Question Title: Infinite repetition (iteration) in Elisp code There is an option to > repeat a macro an infinite number of times until the function quits (for example, by reaching the end of the buffer) or if the user cancels the command in keyboard macros by using `C-u``0` as prefix to `C-x``e`. How can we mimic this behavior in Elisp code with the loop? For example, I would like to write a code that brings point to the outermost bracket to check if it is of a certain value: ``` (defun outer-paren() (interactive) (while condition (up-list))) ``` What should `condition` be to mimic keyboard macro infinite argument behavior? > ((some (|text) embedded) within brackets) --\> |((some (text) embedded) within brackets) # Answer You really ask two questions: 1. **How to iterate forever?** `(while t ...)` See the Elisp manual, node Iteration. The first argument of `while` is a sexp. It is evaluated to see if the body needs to be evaluated again. The sexp `t` always evaluates to itself, a non-`nil` value, so the body is always reevaluated. 2. **How to get the outermost list?** ``` (defun outer-paren () "Return the outermost list." (interactive) (let ((xs nil)) (while (setq xs (list-at-point)) (up-list)) xs)) ``` But I recommend using `tap-list-at-point` (or `tap-unquoted-list-at-point`), from library Thing-At-Point-Plus, rather than the vanilla `list-at-point`. > 1 votes --- Tags: iteration ---
thread-36390
https://emacs.stackexchange.com/questions/36390
Add original location of refiled entries to LOGBOOK after org-refile
2017-10-24T15:54:09.087
# Question Title: Add original location of refiled entries to LOGBOOK after org-refile With this setup `(setq org-log-refile 'time)` I have the following notes added to my TODO entry that I refiled (already twice and it is ended up in long someday-maybe): ``` * TASK Note on where the entry was refiled from :LOGBOOK: - Refiled on [2016-04-04 Mon 00:57] - Refiled on [2015-05-15 Fri 13:53] - State "TASK" from "" [2015-05-15 Fri 13:53] :END: ``` What I would also like to have is the note about the place where it was refiled from. Like so: ``` * TASK Note on where the entry was refiled from :LOGBOOK: - Refiled on [2016-04-04 Mon 00:57] from ~/emacs-tasks.org::*Tasks%20workflow - Refiled on [2015-05-15 Fri 13:53] from ~/stuff.org - State "TASK" from "" [2015-05-15 Fri 13:53] :END: ``` The problem is that the templates for adding notes `org-log-note-headings` do not support a proper placeholder (something like `%F` used in `org-capture-templates`). Moreover, it is explicitly not recommended to change these templates. Any suggestions how to achieve desired result? # Answer For now I came up with the following work around: ``` ;; do not use default refile logging (setq org-log-refile nil) ;; add custom logging instead (add-hook 'org-after-refile-insert-hook #'clavis-org-refile-add-refiled-from-note) (advice-add 'org-refile :before #'clavis-org-save-source-id-and-header) (defvar clavis-org-refile-refiled-from-id nil) (defvar clavis-org-refile-refiled-from-header nil) (defun clavis-org-save-source-id-and-header () "Saves refile's source entry's id and header name to `clavis-org-refile-refiled-from-id' and `clavis-org-refile-refiled-from-header'. If refiling entry is first level entry then it stores file path and buffer name respectively." (interactive) (save-excursion (if (org-up-heading-safe) (progn (setq clavis-org-refile-refiled-from-id (org-id-get nil t)) (setq clavis-org-refile-refiled-from-header (org-get-heading 'no-tags 'no-todo 'no-priority 'no-comment))) (setq clavis-org-refile-refiled-from-id (buffer-file-name)) (setq clavis-org-refile-refiled-from-header (buffer-name))))) (defun clavis-org-refile-add-refiled-from-note () "Adds a note to entry at point on where the entry was refiled from using the org ID from `clavis-org-refile-refiled-from-id' and `clavis-org-refile-refiled-from-header' variables." (interactive) (when (and clavis-org-refile-refiled-from-id clavis-org-refile-refiled-from-header) (save-excursion (let* ((note-format "- Refiled on [%s] from [[id:%s][%s]]\n") (time-format (substring (cdr org-time-stamp-formats) 1 -1)) (time-stamp (format-time-string time-format (current-time)))) (goto-char (org-log-beginning t)) (insert (format note-format time-stamp clavis-org-refile-refiled-from-id clavis-org-refile-refiled-from-header)))) (setq clavis-org-refile-refiled-from-id nil) (setq clavis-org-refile-refiled-from-header nil))) ``` > 1 votes --- Tags: org-mode ---
thread-47344
https://emacs.stackexchange.com/questions/47344
Ispell not working with Hunspell
2019-01-22T23:10:46.920
# Question Title: Ispell not working with Hunspell I am unable to use Ispell, after the upgrade to Hunspell 1.7.0. It seems that the "-D" option does not return the loaded dictionary, therefore the function `ispell-find-hunspell-dictionaries` fails. Calling a fake file (null device) seems to return the proper values. I am using therefore this workaround: ``` ;; Work around for Hunspell 1.7.0 (defun manage-hunspell-1.7 (old-function-ispell &rest arguments) "Add null-device when calling \"hunspell -D\"." (if (equal "-D" (nth 4 arguments)) (funcall old-function-ispell "hunspell" null-device t nil "-D" null-device) (apply old-function-ispell arguments))) (advice-add 'ispell-call-process :around #'manage-hunspell-1.7)) ``` What is the official way to use Hunspell 1.7.0? # Answer > 0 votes The `null-device` workaround(\*) is now part of the official `ispell-find-hunspell-dictionaries`. (\*) `hunspell -D /dev/null` or the platform equivalent is necessary to print the `LOADED DICTIONARY` section after the available dictionaries. --- Tags: ispell, hunspell ---
thread-55396
https://emacs.stackexchange.com/questions/55396
Org Mode: reference an org tree for input in code block
2020-02-09T20:28:04.740
# Question Title: Org Mode: reference an org tree for input in code block I want to use a (sub)tree of my org file as an imput to a python babel source block to parse it and to stuff with it (in my case generate a folder structure based on the headlines of that tree). I know I can reference a table and the output of another code block but I didn't find anything to reference a tree. Is there a way? Is there probably a hack to explicitely declare a string and reference that? Thanks for any tipps. # Answer You can use `org-link-search` to find the subtree and `org-element-parse-headline` to parse the subtree for headlines. If you do that in a named Elisp source block you can use the output of that source block as input to another source block. You can use the full heading text for the link search. But, I usually don't do that. I rather mark the heading by a target, e.g., `<<mySubtree>>` and search for the target label `mySubtree`. There follows an example: ``` * Main Heading ** <<mySubtree>> Marked Subtree *** Some subsection *** Next subsection * Other heading #+NAME: mySubtreeSearch #+BEGIN_SRC emacs-lisp (let ((hl (save-excursion ;; syntax tree of the headline (org-link-search "mySubtree") (org-element-parse-headline 'headline)))) (cdr (org-element-map hl 'headline (lambda (el) (org-element-property :title el))))) #+END_SRC #+RESULTS: mySubtreeSearch | Some subsection | Next subsection | #+BEGIN_SRC emacs-lisp :var tree=mySubtreeSearch ;; Here we just use the variable tree tree #+END_SRC #+RESULTS: | Some subsection | Next subsection | ``` > 3 votes --- Tags: org-mode, org-babel ---
thread-55397
https://emacs.stackexchange.com/questions/55397
Adjust columns in Hexl-Mode?
2020-02-09T22:45:48.883
# Question Title: Adjust columns in Hexl-Mode? By default, it looks like hexl-mode shows 16-bytes per row as the column numbers range from 0x0 - 0xf. Is there a way to adjust how many byte are displayed per row? E.g. 8-byes per row. # Answer > 1 votes I don't see such an option in `hexl.el`, no. You can do that in nhexl-mode, OTOH: just set the `nhexl-line-width` variable accordingly (or set it to `t` which lets it adjust to your window width). --- Tags: hexl-mode ---
thread-27561
https://emacs.stackexchange.com/questions/27561
Replace selected text on [shift insert] is broken in emacs 25.1
2016-10-04T15:00:27.547
# Question Title: Replace selected text on [shift insert] is broken in emacs 25.1 I updated to 25.1 and found that copy/paste works differently. For example when I select a word "**visit**" and try to replace this word with \[shift insert\], **text** in clipboard is inserted in the beginning of the selection, instead of replacing it. When I select **visit** and type text, **visit** is replaced as expected. I have enabled delete selection and transient mark modes, it worked well in 24.5. Do you know how to fix it? # Answer Finally I found a fix for the problem on emacswiki ``` (setq x-select-enable-primary t) (setq select-enable-primary t) (setq mouse-drag-copy-region t) ``` > **Quick tip**: if you’re here looking to fix the fact that in Emacs shift-insert no longer pastes that text you highlighted with the mouse in your browser, the 2014 answer is to set **x-select-enable-primary** to true, and set **mouse-drag-copy-region** to true to go the other way - I can’t imagine why this excellent default was changed but it’s very hard to find the answer in the verbiage below. But this works only for emacs installed from sources github/emacs-mirror, not 25.1 I also found that it depends on terminal. xterm fails, while vt100 works good > 3 votes # Answer I had the same problem, and found `(setq select-enable-primary t)` makes the situation. I have sent it to `M-x report-emacs-bug`. > 0 votes # Answer I just put `(delete-selection-mode 1)` in my .spacemacs file but I'm sure you can also put it in init.el Source: https://www.emacswiki.org/emacs/DeleteSelectionMode Then saved `C-x` `C-s` and reloaded/refreshed, on spacemacs that's `SPC f e R` there are many other ways to do it: https://stackoverflow.com/questions/2580650/how-can-i-reload-emacs-after-changing-it has a long and interesting (to me) discussion, I think `M-:` would be my favorite answer however it wasn't working for me so I went with my tried and true `SPC f e R` Interesting fact: with this delete-selection-mode, to undo, takes 2 actions! I have to `C-/` twice to get my original text back. Very interesting: once you set `(delete-selection-mode 1)` if you just delete that line in the config and reload, the setting will still be there, you have to `(delete-selection-mode 0)` to recreate the original behavior. > 0 votes --- Tags: terminal-emacs, delete-selection-mode ---
thread-55395
https://emacs.stackexchange.com/questions/55395
auctex and pdf-tools in 2 separate frames for dual monitor setup
2020-02-09T19:42:03.700
# Question Title: auctex and pdf-tools in 2 separate frames for dual monitor setup For auctex with pdftools it is convenient for me (eyesight problems) to have the emacs latex frame on my laptop close to my eyes, and the corresponding pdf (in pdftools) on a separate frame on the dual monitor. How can this be implemented? i.e., emacs latex source in one frame and corresponding pdftools pdf in a separate frame. (Typically latex and pdftools exist in the same frame with two different buffers e.g. with C-x 2; but I want two different frames so that I can drag these frames independently to different monitors) # Answer > 4 votes This is a variation of the question about preview the pdf in a split buffer beside the source. You can use the following Elisp code in your init file. If you do not have already two frames. The pdf view will open in a window beside the window with the LaTeX source. Select that window and type `C-x 5 2` for `make-frame-command`. There will be a new frame showing the pdf. You can delete the original window showing the pdf now. If you call `TeX-View` the window in the other frame is used. ``` (defun framesMenus-display-buffer-use-some-frame (fun &rest args) "Use `display-buffer-use-some-frame' as `display-buffer-overriding-action'. Then run FUN with ARGS." (let ((display-buffer-overriding-action '(display-buffer-use-some-frame))) (apply fun args))) (advice-add 'TeX-pdf-tools-sync-view :around #'framesMenus-display-buffer-use-some-frame) (advice-add 'pdf-sync-backward-search-mouse :around #'framesMenus-display-buffer-use-some-frame) ``` --- Tags: auctex, pdf-tools ---
thread-55401
https://emacs.stackexchange.com/questions/55401
Move point inwards while counting number of nested parentheses without throwing an error
2020-02-10T06:13:54.403
# Question Title: Move point inwards while counting number of nested parentheses without throwing an error I would like to write a function that counts the number of nested parentheses while moving the cursor to the innermost bracket without throwing an error. ``` (defun count-and-move () (interactive) (setq c 0) (while t (down-list) (incf c))) ``` If we run this code, the cursor would eventually reach the innermost bracket. > |γ€Œγ€Œγ€Œγ€Œγ€γ€γ€γ€ --\> γ€Œγ€Œγ€Œγ€Œ|」」」」 After which it throws an error: > down-list: Scan error: "Containing expression ends prematurely", 254, 255 What should the condition for `while` be so that the movement stops automatically when the cursor has reached the innermost point? In human language, it would be something like: "Keep running `(down-list)` and increase counter by 1 until the cursor is stuck." OR "Break out of loop if `(down-list)` is going to throw an error!" # Answer For `down-list` and its worker `scan-lists` there doesn't appear to be an option to *prevent* the error, so we would need to handle it somehow. In some instances, a simplistic use of `ignore-errors` is fine. E.g.: ``` (ignore-errors (down-list)) ``` In this instance that's problematic, because `down-list` will return `nil` even when it works, so we probably want to handle the error; although you *could* use the non-movement of point instead: ``` (if (eql (point) (progn (ignore-errors (down-list)) (point))) didn't move moved) ``` If we want to handle the error explicitly, we can use `M-x` `toggle-debug-on-error` to find out what we're dealing with. Here we learn: ``` Debugger entered--Lisp error: (scan-error "Containing expression ends prematurely" 359 360) (scan-lists 359 1 -1) (down-list 1) (funcall-interactively down-list 1) (call-interactively down-list) (repeat nil) (funcall-interactively repeat nil) (call-interactively repeat nil nil) (command-execute repeat) ``` So the error to handle is `scan-error`. We can handle errors using `condition-case`, like so: ``` (condition-case err (down-list) (scan-error (message "Scan error: %S" err))) ``` See `C-h``i``g` `(elisp)Handling Errors` for details. > 3 votes # Answer You can use `ignore-errors`. You should also use `let` instead of `setq` for `c` to keep the scope of `c` local. ``` (defun count-and-move () (interactive) (let ((c 0)) (ignore-errors (while t (down-list) (incf c))) c)) ``` > 3 votes # Answer I'd probably just use this. But all of the answers provided so far are pretty much the same. The idea is, in each iteration, to increment and return the counter but "handle" a `down-list` error by returning `nil`. `ignore-errors` returns `nil` for an error or whatever evaluating its arg returns - in this case, the counter value, `c`. ``` (defun count-and-move () (interactive) (let ((c 0)) (while (ignore-errors (progn (down-list) (incf c)))))) ``` The `ignore-errors` returns the result of the `progn`, which returns the result of `incf`, which is non-`nil`. But if `down-list` raises an error then `ignore-errors` returns `nil`. The `while` evaluates its body as long as the test (the `ignore-errors`) returns non-`nil`. So it stops when `down-list` raises an error. > 1 votes --- Tags: list, motion, parentheses ---
thread-55410
https://emacs.stackexchange.com/questions/55410
Error when loading new version of org mode
2020-02-10T17:48:08.887
# Question Title: Error when loading new version of org mode I upgraded Org-mode to the latest version on the master branch (according to How to install latest version of org mode?) and now I get this error every few seconds: ``` Error running timer β€˜org-indent-initialize-agent’: (void-function org-time- add) [8 times] ``` When I run `org-version`, I get `9.1.9`, instead of the `9.3.3` from the master branch; yet I don't have this problem with just my local version. What is the problem, and how can I fix it? # Answer > 2 votes I found the culprit in opening org files before loading the new version: ``` (add-to-list 'load-path "~/code/org-mode/lisp") (require 'org-loaddefs) ``` In a comment in that thread, I mentioned that the above loading commands failed to load `9.3.3` if I ran `(org-version)` first, so I suspect that running any org command fixes the Org version to the built-in version of org mode and that loading a more recent version introduces compatibility issues. When I run the code to load the new Org version before any other Org command, org mode runs fine. See this answer for details on the mixed installation of built-in and latest versions: > The main idea is that you need to make sure that Org mode is set up, using the new bits that you downloaded only. Emacs comes with a version of Org mode bundled up with it, but that is inevitably older than what is available from the Org mode git repo. It is important to avoid loading any piece from the bundled up version or else you might end up with a "mixed" installation (there are many hits for that on the Org mode mailing list). > > As I mention in a comment, and @Tobias has verified in another comment, you do not need to byte-compile the new version - you only need to make autoloads. That creates an org-loaddefs.el file, so that all the common entry points into org will, when first invoked, load the appropriate file first. It is important ... to set the load-path before loading the org-loaddefs.el file: otherwise, you may end up with the dreaded "mixed" install I mentioned above. --- Tags: org-mode, git, version-compatibilty ---
thread-55324
https://emacs.stackexchange.com/questions/55324
How to install latest version of org mode?
2020-02-05T18:17:46.390
# Question Title: How to install latest version of org mode? I want to update to the latest version of Org-mode to test a bug fix. I followed the instructions: ``` cd ~/src/ git clone https://code.orgmode.org/bzg/org-mode.git cd org-mode/ make autoloads ``` Then I launch emacs without initialization: ``` emacs -nw -q ``` and evaluate: ``` (add-to-list 'load-path "~/src/org-mode/lisp") ;; result: ("~/src/org-mode/lisp" ...) (org-version) ;; result: "9.1.9" ``` which shows that it is using the built-in version, not the one from git (the compiled file `org-version.el` shows `"9.3.3"`). I was able to install the latest version when I filed the bug report. Then `package-list-packages` would show the built-in `org` package as masked by another; I can't remember how I did it and now the built-in package is not masked. I am on `macOS 10.14.6` and `GNU Emacs 26.3 (build 1, x86_64-apple-darwin18.2.0, NS appkit-1671.20 Version 10.14.3 (Build 18D109)) of 2019-09-02`. I have tried How to update Org to latest version using package repo's / git clone in Ubuntu without success. This thread is for Ubuntu. What is preventing my machine from using the latest version of org-mode? # Answer > 8 votes \[As requested, expanding the comment into an answer\] The main idea is that you need to make sure that Org mode is set up, using the new bits that you downloaded *only*. Emacs comes with a version of Org mode bundled up with it, but that is inevitably older than what is available from the Org mode git repo. It is important to avoid loading *any* piece from the bundled up version or else you might end up with a "mixed" installation (there are many hits for that on the Org mode mailing list). As I mention in a comment, and @Tobias has verified in another comment, you do not need to byte-compile the new version - you only need to `make autoloads`. That creates an `org-loaddefs.el` file, so that all the common entry points into org will, when first invoked, load the appropriate file first. It is important (and contrary to what the OP states in his (now deleted) comment) to set the `load-path` *before* loading the `org-loaddefs.el` file: otherwise, you may end up with the dreaded "mixed" install I mentioned above. So after cloning or updating the git repo into, say, `~/src/org-mode`, you can do `make autoloads` (or just `make` if you want to byte-compile the `.el` files). Then invoke emacs with an init file like this: ``` (add-to-list 'load-path "~/src/org-mode/lisp") (require 'org-loaddefs) ... ``` and make sure that those two lines are *before* anything else in the init file, just to make sure that *nobody* loads any old pieces of org-mode that may be lying around. Setting the load-path to begin with will shadow the old pieces and will prevent them from being loaded later. The Org mode manual has a section on installing (including a subsection on installing from the git repo). --- Tags: org-mode, git ---
thread-55418
https://emacs.stackexchange.com/questions/55418
Insert inactive date with elisp function including date arithmetic
2020-02-10T21:32:44.767
# Question Title: Insert inactive date with elisp function including date arithmetic For a capture template I want to insert inactive dates for the upcoming week (without a prompt). In this format (no time component): `[2020-02-10 Mo]` I've figured out that I could do something like this `[%(org-read-date nil nil "Tue")]` which yields `[2020-02-11]`. So it misses the weekday. I also know about this method `(org-insert-time-stamp (org-read-date nil t "+1d"))` but that timestamp is not inactive. # Answer > 2 votes I was close with my last try. Reading the documentation does help :) `%(org-insert-time-stamp (org-read-date nil t "+1d") nil t)` does the trick. And you can do any date arithmetic in the string part that you would do at the interactive prompt. --- Tags: org-mode, time-date ---
thread-55287
https://emacs.stackexchange.com/questions/55287
How to use helm to find files that match regex in subdirectory?
2020-02-03T23:57:34.373
# Question Title: How to use helm to find files that match regex in subdirectory? I had this functionality working until I recently revamped my init files. Now, I can't figure out how to get it back. I use helm-find-file (mapped to C-x C-f) for finding and opening files. I used to be able to execute the following keystrokes to find the location of a file in a sea of subdirectories. The following shows a sample project: ``` ~/src/Bar/Bar.cpp ~/src/Foo/Foo.cpp ~/src/FooBar/FooBar.cpp ``` If I executed the following, the file ~/src/Foo/Foo.cpp would open. ``` C-x C-f ~/src/*/Foo.cpp <return> ``` If I executed the following from my home directory, helm would let me select which file to open, either ~/src/Foo/Foo.cpp or ~/src/FooBar/FooBar.cpp ``` C-x C-f ~/src/*/Foo* ``` Since I revamped my init files, I can't figure out what setting I nixed. Can anyone point me in the right direction of how to acheive this functionality again? # Answer I apologize. My memory failed me. Helm, as far as I am aware, does not support this functionality. The configuration I was using was ido. I use these two packages simultaneously for different purposes, and thought it was Helm that allowed me to find files inside a subdirectory. > 0 votes --- Tags: helm, find-file, helm-for-files ---
thread-54183
https://emacs.stackexchange.com/questions/54183
Can redo be made to stop once the most recent state has been reached?
2019-12-05T14:33:12.180
# Question Title: Can redo be made to stop once the most recent state has been reached? Using emacs vanilla undo, I'd like to undo a series of operations, then hold a key to redo only the operations I just undid, and only those operations. --- This use case for example: * Hold undo key, copy some part of the old buffer. * Hold redo key until all operations have been redone. Then paste in the clipboard. While this is possible with emacs undo, it's made inconvenient because (as far as I know) there is no way to make redo stop at the point after undo began. It reaches the recent state, then begins undoing, it's easy to mess, then it's tricky to get the exact latest point because the redoing is now added to the history. Is there a way to detect this situation and prevent it from redoing non-undo operations? This should be possible since `Redo` / `Undo` is displayed in the message buffer. # Answer Emacs 28 adds a redo command (called `undo-redo`). If you want to have more typical undo/redo, the following commands can be used. ``` (global-set-key (kbd "C-z") 'undo-only) (global-set-key (kbd "C-S-z") 'undo-redo) ``` --- You can also check the package undo-fu which has this functionality, allowing to access the full non-linear undo history as well. There is also undo-tree although I wouldn't recommend it because of known undo corruption problems. > 3 votes --- Tags: undo ---
thread-55428
https://emacs.stackexchange.com/questions/55428
Add a number to every item in list
2020-02-11T06:39:26.400
# Question Title: Add a number to every item in list How do I add a number, say 2, to every item in a list? ``` (setq x '(1 2)) (+ 2 x) (mapcar '2+ x) (loop for i in x do (+ 2 i)) (dolist (i x) (+ 2 i)) ``` None of the above work. # Answer > 4 votes Possible solutions: ``` (mapcar (lambda (entry) (+ entry 2)) x) ``` ``` (mapcar (apply-partially #'+ 2) x) ``` And if you need to update `x`, then `setq` it to the result of one of the above forms, e.g.: ``` (setq x (mapcar (apply-partially #'+ 2) x)) ``` # Answer > 0 votes That's not very elegant (there's probably a much simpler answer) but this should work: ``` (setq x '(1 2 3 4)) (defun add-one (x) "Add 1 to each element of list X" (setq counter 0) (setq res x) (while (< counter (length x)) (setcar (nthcdr counter res) (1+ (car (nthcdr counter x)))) (setq counter (1+ counter))) res) (add-one x) ``` --- Tags: functions, list ---
thread-55423
https://emacs.stackexchange.com/questions/55423
How to access a value in a plist, given its key
2020-02-11T04:16:39.160
# Question Title: How to access a value in a plist, given its key I have a list of key-value pairs that is assigned to a variable. ``` (setq m-point '(:beg 2811 :end 3018 :op "(" :cl ")" :prefix "" :suffix "")) ``` How do I access the values of `:beg` and `:end` within it? --- # Context I wrote a function that makes use of `sp-forward-sexp` and `sp-backward-sexp` of `smartparens-mode` to get the positions of a pair of custom parenthesis. ``` (defun paren-position () "Returns a list of positions where parenthesis has been sitting." (interactive) (let ((m-point ;; find point with matching parenthesis with `(scan-sexps)`. (list (ignore-errors (sp-backward-sexp) (ignore-errors (sp-forward-sexp)))))) (flatten (remove nil m-point)))) ``` `(:beg 2811 :end 3018 :op "(" :cl ")" :prefix "" :suffix ""))` is the value returned when the function is called. This is the first time I am working with such a list with only key-value pairs (somewhat like a Python dictionary), and I don't quite know how to go about it. # Answer > I have a list of key-value pairs that is assigned to a variable. > > ``` > (setq m-point '(:beg 2811 :end 3018 :op "(" :cl ")" :prefix "" :suffix "")) > > ``` This is known as a *property list* or *plist*. > How do I access the values of `:beg` and `:end` within it? ``` (plist-get m-point :beg) => 2811 ``` See `C-h``i``g` `(elisp)Property Lists` for more information. > 8 votes # Answer Besides using the built-in `plist-get` function, you can also do this Common Lisp style using the `getf` function from the built-in `cl` package. ``` (require 'cl) (getf '(:a 1 :b 2) :a) ;; => 1 ``` One benefit is that you can then change the value associated with a key using `setf`: ``` (defvar l (list :a 1)) (setf (getf l :a) 2) l ;; => (:a 2) ``` Something similar can be achieved in vanilla Elisp using `plist-put`: ``` (setq l (plist-put l :a 3)) l ;; => (:a 3) ``` > 2 votes --- Tags: plists ---
thread-55430
https://emacs.stackexchange.com/questions/55430
How to use a macro append macro argument to a list?
2020-02-11T07:47:00.707
# Question Title: How to use a macro append macro argument to a list? I want use a macro to generate a package list. ``` (defvar xx-packages '()) (genpack evil) (genpack all-the-icons-ivy-rich :recipe (:host github :repo "seagle0128/all-the-icons-ivy-rich")) ``` this macro `genpack` will append argument to `xx-packages`,then `xx-packages` value is ``` xx-packages '((evil) (all-the-icons-ivy-rich :recipe (:host github :repo "seagle0128/all-the-icons-ivy-rich")) ``` How can i write this macro `genpack`, thanks # Answer > 1 votes Like this? ``` (defmacro genpack (&rest args) "Append ARGS to `xx-packages'." `(setq xx-packages (nconc xx-packages '(,args)))) ``` --- Tags: elisp-macros ---
thread-55443
https://emacs.stackexchange.com/questions/55443
Function within a function produces side-effect but failes to deliver logic test
2020-02-11T13:18:04.820
# Question Title: Function within a function produces side-effect but failes to deliver logic test This is a simple logic test that makes use of `down-list` and asks if another nested pair of parenthesis exits or not. ``` (not (eql (point) (progn (ignore-errors (down-list)) (point)))) ``` A weird thing occurred when this is re-written as a function that accepts another function as argument. ``` (defun next-pair-exists-in (func) "Check if inner or outer pair exists. Function employs `(up-list)` or `(down-list)` as argument to work." (not (eql (point) (progn (ignore-errors (func)) (point))))) ``` While the `eql` point test code returns `t` for positions to the left of 1, 2 and 3, the function, while moving the cursor inwards as expected, returns `nil` for all positions. > (1(2(3)4)5) How do we get the function to work? # Answer Each symbol has a **value** cell which you can address with `symbol-value` and a **function** cell which you can address with `symbol-function`. The `func` in the `defun` for `next-pair-exists-in` is the name of the local variable whose **value** is bound to the first argument in a function call of `next-pair-exists-in`. The variable `func` does not have any binding for its function cell. In `(ignore-errors (func))` you try to use the function binding of `func` which is undefined. The `ignore-errors` catches the error thrown because of the unbound function definition of `fun`. You can evaluate the function stored in the **value cell** of `func` by `(funcall func)`. Your code should look like: ``` (defun next-pair-exists-in (func) "Check if inner or outer pair exists. Function employs `#'up-list` or `#'down-list` as argument to work." (not (eql (point) (progn (ignore-errors (funcall func)) (point))))) ``` Two examples for calling `next-pair-exists-in` are `(next-pair-exists-in #'down-list)` and `(next-pair-exists-in #'up-list)`. > 3 votes # Answer Further to my comment on your OP, see here:- ``` (defun temp() (message "temp called") "done") (defun ese-55443-2 (func) "Check if inner or outer pair exists. Function employs `(up-list)` or `(down-list)` as argument to work." (not (eql (point) (progn (ignore-errors (funcall func)) (point))))) (ese-55443-2 'up-list) ;;(funcall 'temp) ;;(ese-55443-2 'temp) ``` Notice the use of funcall. The (f) syntax is when f is actually a lambda (I think thats the terminology). When it's a symbol you need to specifically use (funcall f). > 0 votes --- Tags: funcall ---
thread-55441
https://emacs.stackexchange.com/questions/55441
Is it possible to do word completion on `isearch` shell?
2020-02-11T12:55:20.083
# Question Title: Is it possible to do word completion on `isearch` shell? I want to apply word completion on `isearch` shell. When I press tab `^I` shows up on the shell instead of completing the word and show up a window for suggestions. =\> Is it possible to complete a word on `isearch` shell? # Answer > 1 votes The question seems unclear. What is "isearch shell"? You seem to be using `TAB` during Isearch and expecting completion against previous search strings (?). If so, the key you want is `C-M-TAB` (not `TAB`), which is bound to `isearch-complete` in `isearch-mode-map`. But you say "complete a word", not complete against a previous search pattern, so the question seems quite unclear. If you are just looking for full-word searching, that's on `M-s w` while isearching. --- Tags: completion, isearch ---
thread-55437
https://emacs.stackexchange.com/questions/55437
How to make Emacs edit JSON data in `json-mode`?
2020-02-11T12:23:37.740
# Question Title: How to make Emacs edit JSON data in `json-mode`? I am working with `GNU Emacs 23.1.1`. When working with a .json file it is treated in the Fundamental mode: How can I have the json file treated in the json mode? I note that `GNU Emacs 24.3.1` opens json files as Javascript which already allows formatting. # Answer Install json-mode might be the simplest. In my set up (I use straight.el) simply ``` (use-package json-mode) ``` > 2 votes --- Tags: json, auto-mode-alist ---
thread-55453
https://emacs.stackexchange.com/questions/55453
emacs' internal documentation missing info?
2020-02-11T18:08:16.163
# Question Title: emacs' internal documentation missing info? Emacs 26.1 on Debian 10 stable --- I have previously used the Windows version of Emacs and now I'm back in Linux (thanks to it). When pressing `C-h i d` there seemed to be a lot of more information in the Windows version. Now I can only see Org-mode, and Emacs FAQ among other things I don't really need right now. The Window Version had the (full) Emacs documentation, Lisp documentation and a lot more. Am I missing something? Or Looking in the wrong place? # Answer > 3 votes You need to consult your Linux distribution packages. eg in Debian many of the docs are bundled separately because of FSF policies. See here for more details. --- Tags: documentation ---
thread-55440
https://emacs.stackexchange.com/questions/55440
How to subtract 1 from the nth element of a list of numbers?
2020-02-11T12:44:57.773
# Question Title: How to subtract 1 from the nth element of a list of numbers? How do I subtract 1 from the second element of the list `(3 6)`? ``` (setq x '(3 6)) (- (nth 1 x) 1) ``` The above quote does the math but does not return a modified list. # Answer > 7 votes Using the built-in `cl-lib` package, you can write the following: ``` (eval-when-compile (require 'cl-lib)) (cl-decf (nth 1 x)) ``` Alternatively, in vanilla Elisp: ``` (setf (nth 1 x) (1- (nth 1 x))) ``` Be careful, though, to avoid modifying quoted constant lists such as `'(3 6)` in-place, as doing so modifies the constant globally and may cause the code to behave differently in separate runs. Instead, make sure to operate on a new list each time, e.g. via: ``` (setq x (list 3 6)) ``` # Answer > 1 votes Just tinkering, you can use `car` and `cdr` too. I'm sure someone will comment on whether this is good or bad. ``` (let ((v 99) (p 3) (l (list 1 2 3 4))) (setcar (nthcdr p l) (+ (car (nthcdr p l)) v)) l) ;; => (1 2 3 103) ``` --- Tags: list, numbers ---
thread-55451
https://emacs.stackexchange.com/questions/55451
Why does `narrow-to-region` complain that its args are not `integer-or-marker-p`?
2020-02-11T17:07:59.603
# Question Title: Why does `narrow-to-region` complain that its args are not `integer-or-marker-p`? I have some functions that depend on `smart-parens` code. ``` (defun outer-paren () "Move point to the outermost parenthesis." (interactive) (ignore-errors (while t (up-list))) (sp-backward-sexp)) (defun func () (let ((start (outer-paren)) (end (sp-forward-sexp))) (narrow-to-region start end))) ``` The above `func` code returns a plist set by `let`: ``` (:beg 145 :end 163 :op "γ€Œ" :cl "」" :prefix "" :suffix "") (:beg 145 :end 163 :op "γ€Œ" :cl "」" :prefix "" :suffix "") ``` This causes an error from `narrow-to-region()` when `func` is called. > (wrong-type-argument integer-or-marker-p (:beg 145 :end 163 :op "γ€Œ" :cl "」" :prefix "" :suffix "")) How do I access `start` and `end` as variables within `func`? # Answer You are trying to use the values returned by functions `outer-paren` and `sp-forward-sexp`, instead of the positions they move to. The error message tells you that `narrow-to-region` expects buffer positions - numbers or markers. So clearly your values of `start` and `end` aren't such. They aren't numbers or markers because functions `outer-paren` and `sp-forward-sexp` return something other than the position they move to. Don't confuse the side effect of a Lisp function with its return value. ``` (defun func () (let ((start (progn (outer-paren) (point))) (end (progn (sp-forward-sexp) (point)))) (narrow-to-region start end))) ``` > 2 votes # Answer I think you need to access the property values that narrow to region needs. ``` (use-package smartparens) (defun outer-paren () "Move point to the outermost parenthesis." (interactive) (ignore-errors (while t (up-list))) (sp-backward-sexp)) (defun func () (let ((start (outer-paren)) (end (sp-forward-sexp))) (narrow-to-region (plist-get start :beg ) (plist-get start :end )))) (func) (setq pl '(:beg 121 :end 141)) (plist-get pl :beg) ``` > 2 votes --- Tags: debugging, functions ---
thread-55449
https://emacs.stackexchange.com/questions/55449
How to replace first 100 digits with letters?
2020-02-11T16:50:25.507
# Question Title: How to replace first 100 digits with letters? I want to replace the first 104 digits as it follows: ``` 1 --> a ... 26 --> z 27 --> aa ... 52 --> az 53 --> ba ... 104 --> bz ``` I have tried as it follows: ``` (defun digits-to-letters () (interactive) (goto-char (point-min)) (save-excursion (save-restriction (narrow-to-region (search-forward "\\title" nil t) (search-forward "\\abstract" nil t)) (goto-char (point-min)) (while (search-forward-regexp "\\([0-9]+\\)" nil t) (setq digit (match-string 0)) ;; 1-26 to a-z (if (< digit 27) (perform-replace digit `((lambda (data count) (string (+ (1- ?a) digit)))) t t nil 1 nil (point-min) (point-max)) ;; 27-52 to aa-az (if (and (> digit 26) (< digit 53)) (perform-replace digit `((lambda (data count) (string (+ (1- ?a) (concat "a" digit))))) t t nil 1 nil (point-min) (point-max)) ;; 53-104 to ba-bz (if (and (> digit 52) (< digit 105)) (perform-replace "\\([0-9]+\\)" `((lambda (data count) (string (+ (1- ?a) (concat "b" digit))))) t t nil 1 nil (point-min) (point-max)) ))) )))) ``` It gives me the following error: ``` Debugger entered--Lisp error: (wrong-type-argument number-or-marker-p #("1" 0 1 (fontified t))) ``` P.S. I have just asked something like this, but for the first 26 digits: How to replace a digit by a letter?. **Updates** There is a mistake in the correspodence between digits and letters: ``` 53 --> ba ... 78 --> bz 79 --> ca ... 104 --> cz ``` I have corrected my code as it follows: ``` (defun digits-to-letters () (interactive) (goto-char (point-min)) (save-excursion (save-restriction (narrow-to-region (search-forward "\\title" nil t) (search-forward "\\abstract" nil t)) (goto-char (point-min)) (while (search-forward-regexp "\\([0-9]+\\)" nil t) (setq digit (string-to-number (match-string 0))) (setq sdigit (match-string 0)) ;; 1-26 to a-z (if (< digit 27) (replace-match (string (+ (1- ?a) digit))) ;; 27-52 to aa-az (if (and (> digit 26) (< digit 53)) (replace-match (concat "a" (string (+ (1- ?a) (- digit 26))))) ;; 53-78 to ba-bz (if (and (> digit 52) (< digit 79)) (replace-match (concat "b" (string (+ (1- ?a) (- digit 52))))) ;; 79-104 to ba-bz (if (and (> digit 78) (< digit 105)) (replace-match (concat "c" (string (+ (1- ?a) (- digit 78))))) )))) )))) ``` Now it works. # Answer > 2 votes 104 would be cz I think. Using org mode eval setup:-- I suspect there are better choices fr functions but I'm an elisp learner. These conversions might be more appropriates in your code in that there's less if/thens based on ranges. ``` #+begin_src emacs-lisp (setq c 104) (setq lsc (char-to-string (+ (% (- c 1) 26) (string-to-char "a")))) (setq msc (char-to-string (- (+ (/ (- c 1) 26) (string-to-char "a")) 1))) (concat msc lsc) #+end_src #+RESULTS: : cz ``` Tidy to your desires. I didnt check for \<27 so single digit but your framework does. # Answer > 2 votes You can use `org-number-to-letter` from `org-table.el` (requires at least Emacs 26.1 or Org 9.1.9?) ``` (require 'org-table) (org-number-to-letters 26) ;; => "Z" (org-number-to-letters 52) ;; => "AZ" ``` And type `C-M-%` (`query-replace-regexp`) with ``` [0-9]+ β†’ \,(org-number-to-letters \#&) ``` If you need to do the search-and-replace from Lisp, use `re-search-forward` and `replace-match` instead, don't use `perform-replace`: ``` (while (re-search-forward "[0-9]+" nil t) (replace-match (org-number-to-letters (string-to-number (match-string 0))))) ``` or `replace-regexp-in-string`: ``` (replace-regexp-in-string (rx (1+ num)) (lambda (s) (org-number-to-letters (string-to-number s))) "Hello, 731!") ;; => "Hello, ABC!" ``` --- Tags: replace, string, characters, numbers ---
thread-55439
https://emacs.stackexchange.com/questions/55439
auctex pdf-tools split buffers in separate frames
2020-02-11T12:43:30.617
# Question Title: auctex pdf-tools split buffers in separate frames This is an extension of my previous question auctex and pdf-tools in 2 separate frames which was nicely answered by Tobias. I use auctex in one frame and pdftools in another frame. Forward and inverse search work perfectly between the two frames. The question I have is this: how to make forward and inverse search work when I split each frame into 2 buffers? That is, I have the latex source of a file in one frame split into 2 buffers (with C-x 2); lets call these buffers latex1 and latex2. Similarly I have the corresponding pdf frame split into two buffers - lets call them pdf1 and pdf2. **My questions is: how to setup forward and inverse search between latex1 and pdf1, and also between latex2 and pdf2?** This helps working on two parts of a large latex document.I need the above setup of two separate frames, one frame for latex (with 2 buffers) and one frame for pdf (with 2 buffers), due to eyesight problems. # Answer The following code generalizes the answer to your other question about showing the pdf in another frame. It requires a bit more interaction from your side. I propose you set up your frame and window layout beforehand - two frames with two windows each. The windows do not need to show the right buffers yet. You certainly need the two windows with the LaTeX buffer since you need some starting point. Select one of the LaTeX windows and call `TeX-View`, e.g., via `C-c C-a`. The first time you are prompted with `Associate window.` Click in the pdf-window which you want to associate with the LaTeX window. Do the same for the other TeX window. Afterwards forwards and inverse search should just work as you want it. ``` (defun framesMenus-read-window (&optional prompt) "Prompt with PROMPT and read a window." (save-selected-window (let ((frame (selected-frame)) window ev) (while (progn (setq ev (read-event prompt)) (eq (event-basic-type ev) 'switch-frame)) (setq frame (cadr ev))) (with-selected-frame frame (and (window-live-p (setq window (posn-window (event-start ev)))) window ))))) (defvar-local framesMenus-associated-other-window nil "Alist of other windows associated with selected windows for a buffer.") (defun framesMenus-associated-other-window (&optional prompt force mutual) "Return the other window associated with the current buffer. PROMPT is forwarded to `framesMenus-read-window' when called. When FORCE is non-nil always prompt for the associated window. If MUTUAL is non-nil also associate other window with this one." (let* ((this-window (selected-window)) (assoc-window (assoc this-window framesMenus-associated-other-window)) (other-window (cdr assoc-window))) (unless (and (null force) (window-live-p other-window) other-window) (cl-pushnew (cons (selected-window) (setq other-window (framesMenus-read-window prompt))) framesMenus-associated-other-window :key #'car )) (when mutual (with-selected-window other-window (cl-pushnew (cons other-window this-window) framesMenus-associated-other-window :key #'car))) other-window)) (defun framesMenus-display-in-associated-window (buffer _action-list) "Display BUFFER in associated window." (let ((window (framesMenus-associated-other-window "Associate window." nil t))) (with-selected-window window (switch-to-buffer buffer)) window)) (defun framesMenus-display-buffer-use-associated-window (fun &rest args) "Use `display-buffer-use-some-frame' as `display-buffer-overriding-action'. Then run FUN with ARGS." (let ((display-buffer-overriding-action '(framesMenus-display-in-associated-window))) (apply fun args))) (advice-add 'TeX-pdf-tools-sync-view :around #'framesMenus-display-buffer-use-associated-window) (advice-add 'pdf-sync-backward-search-mouse :around #'framesMenus-display-buffer-use-associated-window) ``` > 1 votes --- Tags: auctex, pdf-tools ---
thread-55465
https://emacs.stackexchange.com/questions/55465
How do I get flyspell to ignore pandoc citations in markdown
2020-02-12T03:01:24.823
# Question Title: How do I get flyspell to ignore pandoc citations in markdown `Flyspell` regularly shows `pandoc` citations as a spelling error in `markdown` documents. For example `@chu2017` will come up as a spelling error for 'chu'. How can I get `Flyspell` ignore the citations and only check other words in the document? # Answer > 1 votes Try adding the following to your `init.el`: ``` (add-hook 'markdown-mode-hook '(lambda () (setq flyspell-generic-check-word-predicate 'my-pandoc-flyspell-verify))) (defun my-pandoc-flyspell-verify () (save-excursion (forward-word -1) (not (looking-back "@")))) ``` Essentially, it is telling `flyspell` not to check words that start with "@". --- Tags: flyspell, markdown, markdown-mode, pandoc ---
thread-55461
https://emacs.stackexchange.com/questions/55461
How to deal with unwanted cursor movement during logic test
2020-02-12T01:17:51.380
# Question Title: How to deal with unwanted cursor movement during logic test I have a function that tests if another nested pair of parenthesis exits or not. ``` (defun next-pair-exists-in (func) "Check if inner or outer pair exists. Function employs `up-list` or `down-list` as argument to work." (progn (forward-char) (let ((rslt (not (eql (point) (progn (ignore-errors (funcall func)) (point)))))) (backward-char) rslt))) ``` I use it to implement parenthesis integrity in Chinese texts, where double quotes must be nested within single quotes and vice versa `γ€Œγ€Žγ€Œγ€γ€γ€`. ``` (defun paren-integrity () "Double quote must follow single quote." (interactive) (outer-paren) ;; bring cursor to outermost parenthesis ;; check that two levels exist for the test. (if (and (next-pair-exists-in #'down-list) (next-pair-exists-in #'down-list)) (progn (single-quote-test) ;; make sure single quote is at point and move inwards. (double-quote-test)) (single-quote-test))) ``` `single-quote-test` and `double-quote-test` just makes sure the character at point is a single or double quote and move to the next nested pair of quotes, if they exist. One problem I encounter is that running `(and (next-pair-exists-in #'down-list)(next-pair-exists-in #'down-list))` itself brings the cursor inwards by 2 levels. > |γ€Œ1γ€Œ2γ€Œ3γ€Œ4γ€Œ5」」」」」--\> γ€Œ1γ€Œ|2γ€Œ3γ€Œ4γ€Œ5」」」」」 So when the actual code starts to run, it runs on 3 and 4 instead of the intended 1 and 2 the logic test is meant for: > γ€Œ1γ€Œ2γ€Œ3γ€Ž4γ€Œ5」4』3」2」1」 How do I get `(next-pair-exists-in #'down-list)` to return a `t`/`nil` value without moving the cursor? --- # Desired Outcome: > γ€Œ1γ€Ž2γ€Œ3γ€Ž4γ€Œ5」4』3」2』1」 --- # The Whole Codebase as it sits at present for testing purposes ``` ;;;; Nested Parentheses γ€Œγ€Žγ€γ€ (use-package smartparens) (defun outer-paren () "Move point to the outermost parenthesis." (interactive) (ignore-errors (while t (up-list))) (sp-backward-sexp)) (defun next-pair-exists-in (func) "Check if inner or outer pair exists. Function employs `up-list` or `down-list` as argument to work." (progn (forward-char) (let ((rslt (not (eql (point) (progn (ignore-errors (funcall func)) (point)))))) (backward-char) rslt))) (defun is-single-quote () "Check if symbol at point is γ€Œ." (eq ?γ€Œ (char-after))) (defun is-double-quote () "Check if symbol at point is γ€Ž." (eq ?γ€Ž (char-after))) (defun is-open-quote () "Check if symbol at point is γ€Œ." (or (eq ?γ€Œ (char-after)) (eq ?γ€Ž (char-after)))) ;;;;; Logic Functions (defun single-quote-test () "Test to see if current pair is γ€Œγ€. Replaceγ€Žγ€ with γ€Œγ€ if necessary. Move cursor to inner quote if it exists. " (interactive) ;; First condition: if it is γ€Žγ€, change to γ€Œγ€. (cond ((is-double-quote) (let ((current-paren (remove-paren))) ;; `remove-paren` would execute the removal. ;; subtract 1 from close-position (ie. second element of `current-paren`) (setf (nth 1 current-paren) (1- (nth 1 current-paren))) ;; subtract 2 to every point in `current-paren` to derive insertion position. ; (setq current-paren (mapcar (apply-partially #'- 2) current-paren)) ;; insert relevant symbol to positions by pair. (insert-single-quote current-paren) (sp-backward-sexp) (if (next-pair-exists-in #'down-list) (progn (down-list) (backward-char))))) ;; Second condition: if it is a γ€Œγ€, move to next nested if it exists. ((and (is-single-quote) (next-pair-exists-in #'down-list)) (down-list) (backward-char)) ;; `down-list` needs to be called twice because it brings point to content within the quote rather than on the quote itself. (t nil))) (defun double-quote-test () "Test to see if current pair is γ€Œγ€. Replaceγ€Žγ€ with γ€Œγ€ if necessary. Move cursor to inner quote if it exists. " (interactive) ;; First condition: if it is γ€Žγ€, change to γ€Œγ€. (cond ((is-single-quote) (let ((current-paren (remove-paren))) ;; `remove-paren` would execute the removal. ;; subtract 1 from close-position (ie. second element of `current-paren`) (setf (nth 1 current-paren) (1- (nth 1 current-paren))) ;; subtract 2 to every point in `current-paren` to derive insertion position. ; (setq current-paren (mapcar (apply-partially #'- 2) current-paren)) ;; insert relevant symbol to positions by pair. (insert-double-quote current-paren) (sp-backward-sexp) (if (next-pair-exists-in #'down-list) (progn (down-list) (backward-char))))) ;; Second condition: if it is a γ€Œγ€, move to next nested if it exists. ((and (is-double-quote) (next-pair-exists-in #'down-list)) (down-list) (backward-char)) ;; `down-list` needs to be called twice because it brings point to content within the quote rather than on the quote itself. (t nil))) ;;;;; Functions that handle γ€Œγ€γ€Žγ€ in pairs (defun paren-position () "Returns a list of positions where parenthesis has been sitting." (interactive) (if (is-open-quote) (setq paren-pos (list (point) (progn (sp-forward-sexp) (point)))) (setq paren-pos (list (progn (sp-backward-sexp) (point)) (progn (sp-forward-sexp) (point)))))) (defun remove-paren () "Delete pair of parenthesis at point. Return the position of point and its counterpart." (interactive) (let ((current-paren (paren-position))) (if (is-open-quote) (forward-char) (backward-char)) (sp-unwrap-sexp) current-paren)) (defun insert-single-quote (current-paren) (progn (goto-char (nth 0 current-paren)) (insert "γ€Œ") (goto-char (nth 1 current-paren)) (insert "」"))) (defun insert-double-quote (current-paren) (progn (goto-char (nth 0 current-paren)) (insert "γ€Ž") (goto-char (nth 1 current-paren)) (insert "』"))) ;; Set the rule (defun paren-integrity () "Double quote must follow single quote." (interactive) (save-excursion (outer-paren) (while (next-pair-exists-in #'down-list) (backward-up-list) (if (and (next-pair-exists-in #'down-list) (next-pair-exists-in #'down-list)) (progn (backward-up-list 2) (single-quote-test) (double-quote-test)) (if (next-pair-exists-in #'down-list) (single-quote-test)))))) ``` # Answer > 1 votes further to my comment on your own answer something like this makes more sense to me as the check doesnt alter anything. ``` (defun next-pair-exists-in (func) "Check if inner or outer pair exists. Function employs `up-list` or `down-list` as argument to work." (setq-local reslt nil) (save-excursion (forward-char) (setq rslt (not (eql (point) (progn (ignore-errors (funcall func)) (point)))))) rslt) ``` Obviously you would need to undo your "undo" code in the calling function and also specifically advance in your calling code. # Answer > 0 votes Here is my solution to the problem. I use `backward-up-list` to undo the cursor movement during the conditional before running the actual code. ``` (defun paren-integrity () "Double quote must follow single quote." (interactive) (save-excursion (outer-paren) (while (next-pair-exists-in #'down-list) (backward-up-list) (if (and (next-pair-exists-in #'down-list) (next-pair-exists-in #'down-list)) (progn (backward-up-list 2) (single-quote-test) (double-quote-test)) (if (next-pair-exists-in #'down-list) (single-quote-test)))))) ``` Please let me know if there is a better way to do this. --- Tags: save-excursion ---
thread-55467
https://emacs.stackexchange.com/questions/55467
How to add a suffix to the end of a string in a line?
2020-02-12T04:51:08.137
# Question Title: How to add a suffix to the end of a string in a line? Here's an example of content in a file ``` This_is_line_1 : 1 This_is_another_line :2 This_is_3rd_line :3 Here_is_line_4 :4 ``` So, how can using emacs to add char `@` immediately to the end 1 string on each line, i.e. ``` This_is_line_1@ : 1 This_is_another_line@ :2 This_is_3rd_line@ :3 Here_is_line_4@ :4 ``` # Answer Go to the beginning of the buffer an call `query-replace-regexp`. You can call `query-replace-regexp` by the menu item "Edit β†’ Replace β†’ Replace Regexp". Alternatively you can use the key-sequence `M-C-%` that is shown beside the menu item. Use `^[^[:space:]]+` as regular expression (regexp) and `\&@` as replacement string. Notes: 1. The first caret in the regexp matches the empty string at the beginnig of the line. It anchors the match at the beginning of the line. 2. The outer braces `[...]` describe a character set. Each of the contained characters match. 3. The caret in the character set negates the set. I.e., all characters not in the set do match. 4. The `[:space:]` is the character class of characters with space syntax. 5. The `+` matches one or more instances of the previous expression, i.e., of the character set. 6. The regexp is greedy by default. That means as many as possible chars are matched. 7. The `\&` in the replacement string references the full match. > 2 votes --- Tags: replace ---
thread-55463
https://emacs.stackexchange.com/questions/55463
Getting a dialogue box of custom scripts
2020-02-12T02:11:22.410
# Question Title: Getting a dialogue box of custom scripts I have a bunch of scripts for managing files/directories that I use on a regular basis. Would it be possible to assign a key binding such that whenever I hit this key binding I get a dialogue box that lists my scripts within emacs and I can choose one to execute on the fly? This may be fairly obvious but I couldn't find anything about this online possibly because I do not know what the term to search for is. # Answer > 1 votes You can use `easy-menu-define` for defining a popup menu and a menu in the menu bar. If you need to extend the menu later on you can use `easy-menu-add-item`. Example: ``` (defun foo () "Just an example script." (interactive) (message "*foo*")) (defun bar () "Just another example script." (interactive) (message "*bar*")) (easy-menu-define my-script-menu global-map "My Scripts" '("Scripts" ["Call foo" foo t])) ;; List of all menu items which you know when you create the menu. (easy-menu-add-item ;; For adding menu items later on. global-map '(menu-bar Scripts) ["Call bar" bar :keys ""]) (defun my-open-script-menu () "Open a popup menu at mouse location with my scripts." (interactive) (let* ((key-list (x-popup-menu t my-script-menu)) ;; x-popup-menu returns a list of events. (key-sequence (vconcat key-list)) ;; ... but key sequences are vectors (command (lookup-key my-script-menu key-sequence))) ;; now looking up the key sequence in the keymap (when (commandp command) ;; when successful call the command (call-interactively command)))) (global-set-key (kbd "C-c c") #'my-open-script-menu) ``` --- Tags: key-bindings, menus ---
thread-55462
https://emacs.stackexchange.com/questions/55462
org-capture scheduled for next Tuesday (or Friday)
2020-02-12T02:08:20.070
# Question Title: org-capture scheduled for next Tuesday (or Friday) I'd like to create a capture template that automatically schedules the date for the upcoming Friday (if today is a Tuesday, Wednesday, Thursday) or for the upcoming Tuesday (if today is a Friday, Saturday, Sunday, or Monday). Any ideas are much appreciated. # Answer > 2 votes Another way to do this is to determine the closest day of the week after today and send it to the `org-read-date` function. ``` (defun schedule-next-tuesday-or-friday () (let* ((dow (format-time-string "%a" (current-time))) (future-dow (pcase dow ((or "Sat" "Sun" "Mon") "Tue") (_ "Fri")))) (format-time-string (car org-time-stamp-formats) (org-read-date nil t future-dow)))) ``` In the template add: ``` \nSCHEDULED: %(schedule-next-tuesday-or-friday) ``` The `%(sexp)` is evaluated and replaced with the result. See `org-capture-templates` for more information. # Answer > 1 votes Here's an interesting solution to the "next Tuesday" issue. Note that it uses gnu date function. your next schedule date-time: ``` (defun schedule-next-friday-or-tuesday(&optional ti) (setq dowt (string-to-number (format-time-string "%w" (if ti ti (current-time))))) ;;(setq dowt 2) (setq human-time (if(and (>= dowt 2) (<= dowt 4)) "next Friday" "next Tuesday")) (parse-time-string (with-temp-buffer (call-process "env" nil t nil "LC_ALL=C" "LANGUAGE=" "date" "-d" human-time) (or (bobp) (delete-backward-char 1)) (buffer-string)))) (schedule-next-friday-or-tuesday) ``` --- Tags: org-capture, time-date ---
thread-55475
https://emacs.stackexchange.com/questions/55475
What's really behind an assignment in Emacs lisp?
2020-02-12T10:10:50.707
# Question Title: What's really behind an assignment in Emacs lisp? \[Warning : these are noob questions.\] I'm a beginner in Emacs Lisp and I would like to be sure that I understand well what I'm really doing when I set a value to a variable with `setq` or `let`. Here is a piece of code: ``` (setq x '(1 2 3 4)) ; define x (setq y x) ; define y (setcar y 9) ; modify CAR of y y ; -> (9 2 3 4): y has changed (ok) x ; -> (9 2 3 4): but x has changed too! ``` 1. It seems that when you define a symbol and give it the value of *another symbol*, this basically means that the two symbols become the same object? ``` (eq x y) ; -> t ``` (I expected that the instruction `(setq y x)` would make an "independant copy" of `x`, as it would be the case if you do `y <- x` in R language for example. Or, more formally, I thought this instruction would only fill the "value cell" of `y` by evaluating `(symbol-value 'x)`, but without "binding" those two objects together.) 2. This is really a matter of pointers, if I understand well. `(setq y x)`creates a new symbol which is basically bound to the same address as `x`? (I.e., `y` points towards `x` which points towards a given value, and so if you modify `y`, you will also modify `x` because both of them point towards the same address "by transitivity"?) 3. Robert Chassell's book says that "*when a Lisp variable is set to a value, it is provided with the address of the list to which the variable refers*", but I cannot figure out what this means formally (where is this address stored?). A Lisp symbol is made of 4 components (name, value, function, properties). So, when I do `(setq y x)`, the "value cell" of `y` is really an *address* / a pointer towards `x`? # Answer > 5 votes `setq` is doing like expected, the thing here is, that `(1 2 3 4)` is not a value, so it is not what you think it is. * a Place is a location in memory. * `x` and `y` are Symbols. * a Symbol merely points to a place. So `x` points to (the first `cons` of) your list. * `(1 2 3 4)` is a List of `cons`es (aka a "chain" of `cons`es). * `(1 2 3 4)` is not a value, but multiple chained values. * a list is constructed like this `(cons 1 (cons 2 (cons 3 nil)))`. * a cons consists of two pointers (car . cdr) to the places where the values are stored. * a cons by itself is stored at a place. (*I'm not perfectly sure with that one*) What did you do?: * your new `y` points, after `setq` to the same place like `x`, because you said: point to the list referenced by symbol `x`. * You changed the content of your list, which exists only once in memory. I hope I got that right. :) Good question, btw. --- Tags: elisp, variables, let-binding, setq ---
thread-55477
https://emacs.stackexchange.com/questions/55477
auctex and pdf-tools reverse search change keybinding
2020-02-12T11:01:22.823
# Question Title: auctex and pdf-tools reverse search change keybinding Inverse search from pdf-tools to auctex uses Ctrl-click on the pdf file to go to the corresponding part of latex file. Is it possible to also assign Alt-click to do inverse search? I am using ubuntu 18.04 (in case the OS is relevant). # Answer To do this, you need to know the keymap used by `pdf-sync-minor-mode`. Normally this will be something like `pdf-sync-minor-mode-map`. You can find out by calling `C-h v`, then using tab completion to get the full name. In this case, it is indeed `pdf-sync-minor-mode-map`. Now you can use the function `define-key` to bind your new key to the map. This function takes three arguments: the keymap, the key, and the function. The syntax for binding a mouse click is `[mouse-1]`, or `[M-mouse-1]` for clicking with the Alt key pressed. So: ``` (eval-after-load 'pdf-sync '(define-key pdf-sync-minor-mode-map [M-mouse-1] 'pdf-sync-backward-search-mouse)) ``` I used `eval-after-load` to make sure the code isn't run until *after* `pdf-sync` is loaded. > 1 votes --- Tags: key-bindings, auctex, pdf-tools ---
thread-55486
https://emacs.stackexchange.com/questions/55486
How do I change the default shell for `sh-mode`?
2020-02-12T16:57:33.170
# Question Title: How do I change the default shell for `sh-mode`? `sh-mode` usually does a great job of auto-magically detecting which shell a file is intended to be run by. It looks at the shebang, for instance. However, I have a bunch of files that are intended to be sourced, not run as executables, and thus I don't have a shebang. I have my `$SHELL` environment variable set to `bash`, but when I open the file, `sh-mode` still defaults to `sh`. How do I get it to default to `bash`? I've tried running `(getenv "SHELL")` in both `*scratch*` and with `eval-expression` in the shell file's buffer, and they both report `"usr/loca/bin/bash"`. Why doesn't `sh-mode` respect this? I've been digging through the source code and it really seems like this should be working. # Answer > 1 votes As @RichieHH mentioned you can set `sh-shell-file` via the custom facility or directly for a global default. Alternatively, and my preferred method, is to set the shell via file-local variables. For example, the first line of your file could look like: ``` ## -*- mode: shell-script; sh-shell: zsh; sh-basic-offset: 3; sh-indentation: 3; coding: utf-8 -*- ``` This sets the local file to `shell-script` mode, using the `zsh` shell, and indentation to 3. (The variable `sh-shell` is what is set when you call `M-x sh-set-shell`.) `shell-script-mode` will then figure out `sh-shell-file` on its own (presumably based on your path.) Obviously, you could do something similar with directory local variables. # Answer > 0 votes Did you look at `sh-shell-file`? It picks up the shell from that I think reading the docstring. --- Tags: sh-mode ---
thread-55409
https://emacs.stackexchange.com/questions/55409
Get value of a variable from another session in org-mode
2020-02-10T17:04:07.277
# Question Title: Get value of a variable from another session in org-mode How to share variables' values in org-mode between different sessions? Simple example: in session *one* I create `_gpg_tmpdir` ``` #+name: make_temporary_directories #+begin_src bash :session *one* _gpg_tmpdir="$( mktemp -d )" #+end_src ``` and need to clean up it in session *two*: ``` #+name: clean_temporary_directories #+begin_src bash :session *two* rm -rf $_gpg_tmpdir #+end_src ``` The example is for the demonstration purpose only. The question is what is the less painfull way to share variables between different code sessions (perhaps with different code languages) in org-mode. # Answer > 4 votes You can use `RESULTS` for the first session to write out the results, and `:var` in the second session to import results. ``` #+name: make_temporary_directories #+begin_src bash :session *one* :results output _gpg_tmpdir="$( mktemp -d )" echo $_gpg_tmpdir #+end_src ``` ``` #+RESULTS: make_temporary_directories : /tmp/tmp.iAE5oSlwcC ``` ``` #+name: clean_temporary_directories #+begin_src bash :session *two* :var gpg_tmpdir=make_temporary_directories :results output echo $gpg_tmpdir #+end_src ``` --- Tags: org-mode, org-babel, variables ---
thread-55497
https://emacs.stackexchange.com/questions/55497
Is there a command for opening emacs in shell mode?
2020-02-13T10:28:50.177
# Question Title: Is there a command for opening emacs in shell mode? Suppose I want to open emacs with a file and shell mode together. If there were two files I would do `emacs file1 file2` and emacs opens them both. Is there a command to do this with `emacs file [shell]`? # Answer > 3 votes The following works with emacs26 on Ubuntu: ``` emacs file --eval "(add-hook 'emacs-startup-hook #'shell)" ``` Adding the function `#'shell` to `emacs-startup-hook` (instead of calling it with `-f shell`) defers the call to `shell` until the initialization of Emacs is complete. That way the `*shell*`-buffer will be displayed in the window that is used for the `*scratch*` buffer when there is no other configuration in the init file of Emacs. Eventual, only the two buffers you are interested in, `file` and `*shell*`, will be displayed at startup. See the doc of the startup sequence of Emacs. # Answer > 2 votes Pass the command line option `-f` to run a function with no arguments, or `--eval` to run an arbitrary Lisp expression. To run a shell (whichever comes last is the one that's displayed in the Emacs window): ``` emacs filename.txt -f shell emacs -f shell filename.txt ``` Here are examples to split the window or open two frames. ``` emacs -f shell -f split-window-vertically filename.txt emacs -f shell -f split-window-vertically filename.txt -f other-window emacs -f shell -f make-frame filename.txt ``` --- Tags: shell, start-up ---
thread-22739
https://emacs.stackexchange.com/questions/22739
tags-add-tables / list of tag tables
2016-06-03T20:25:04.933
# Question Title: tags-add-tables / list of tag tables I can't find a concise answer to this question, only big manuals for which I'm not sure reading them will give me the answer... Spacemacs & haskell-mode are now giving me tag navigation by default (appeared with a MELPA upgrade, it's a feature I didn't have before). I'm using it now, however each time I change folder with tag navigation, emacs is asking: > Keep current list of tags tables also? (y or n) I've seen that other question and so I see that the `tags-add-tables` setting is the way to go, however I honestly have no idea whether I want to answer yes or no... Is there a builtin emacs manual I can look at with brief information on the topic of tag tables, that would explain which is the compromise here? Honestly I would expect `spacemacs`, or maybe `haskell-mode` to make that decision for me :-( # Answer > 2 votes From emacs describe-variable (SPC h d v): ``` tags-add-tables is a variable defined in β€˜etags.el’. Its value is nil Original value was ask-user Documentation: Control whether to add a new tags table to the current list. t means do; nil means don’t (always start a new list). Any other value means ask the user whether to add a new tags table to the current list (as opposed to starting a new list). You can customize this variable. ``` So whether you want to answer yes or no depends on if you want to keep the previous directory's symbols in your symbol table or not. --- Tags: spacemacs, ctags ---
thread-55489
https://emacs.stackexchange.com/questions/55489
'pdflatex' is not recognized as an internal or external command, operable program or batch file
2020-02-12T19:02:39.200
# Question Title: 'pdflatex' is not recognized as an internal or external command, operable program or batch file came across on windows 10 the following error message ``` Running `LaTeX' on `test_latex' with ``pdflatex -file-line-error -interaction=nonstopmode "test_latex.tex"'' **'pdflatex' is not recognized as an internal or external command, operable program or batch file.** ``` however, i do add the executable to the exec-path in init.el , as below: ``` (when (system-is-windows) (setq exec-path '( "C:/Users/user/AppData/Local/Programs/MiKTeX 2.9/miktex/bin/x64") ) ) ``` and the path `"C:/Users/user/AppData/Local/Programs/MiKTeX 2.9/miktex/bin/x64"` is also added to environment PATH variable. Any help/hint is much appreciated! # Answer > 1 votes I figured it out - it turned out that there is `(setenv "PATH" "C:/Users/user/")` at the beginning of the .init file. commented out this line and works fine now. It basically overwrote the windows environment PATH variable. (It also broke my Spyder launch). I forgot why I added that line in the first place. but adding the path `"C:/Users/user/AppData/Local/Programs/MiKTeX 2.9/miktex/bin/x64"` to the windows environment PATH variable is one way to let Emacs know where to find tex related .exe --- Tags: auctex ---
thread-55509
https://emacs.stackexchange.com/questions/55509
Symbol's value as variable is void
2020-02-13T16:55:18.940
# Question Title: Symbol's value as variable is void first, defined this interactive function: ``` (defun system-is-windows () (interactive) (string-equal system-type "windows-nt")) ``` then call this function in one setting.el file ``` ; don't show the scroll bar (if system-is-windows (scroll-bar-mode 0)) ``` and it throws back the following error: ``` Debugger entered--Lisp error: (void-variable system-is-windows) (if system-is-windows (scroll-bar-mode 0)) eval-buffer(#<buffer *load*-51294> nil "c:/Users/user/.emacs.d/settings/general-settings.el" nil t) ; Reading at buffer position 1439 load-with-code-conversion("c:/Users/user/.emacs.d/settings/general-settings.el" "c:/Users/user/.emacs.d/settings/general-settings.el" nil t) require(general-settings) eval-buffer(#<buffer *load*> nil "c:/Users/user/.emacs.d/init.el" nil t) ; Reading at buffer position 849 load-with-code-conversion("c:/Users/user/.emacs.d/init.el" "c:/Users/user/.emacs.d/init.el" t t) load("c:/Users/user/.emacs.d/init" t t) #f(compiled-function () #<bytecode 0x1000be22d>)() command-line() normal-top-level() ``` # Answer The following code: ``` (if system-is-windows (scroll-bar-mode 0)) ``` Does not evaluate `system-is-windows` as a function, but tries to evaluate it as a variable. That's why you're getting the `(void-variable system-is-windows)` error message. Instead, you need to write: ``` (if (system-is-windows) (scroll-bar-mode 0)) ``` The parentheses tell Emacs that you are evaluating it as a function. > 2 votes --- Tags: defun ---