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-58222
https://emacs.stackexchange.com/questions/58222
find-file using ido as case sensitive
2020-05-02T01:44:04.797
# Question Title: find-file using ido as case sensitive I was using regular `find-file`, where when I type `D` and press tab it will consider case sensitive file names, such as `Driver.py` and ignore others such as `driver`. I have enabled: `(ido-mode 1)`. I realize when I type `D` and press tab it also suggests `driver` and opens a complete suggestion window. =\> Is there any way to have ido to have same configuration as `find-file`, where case-sensitive is considered? # Answer Set `ido-case-fold` to `nil` ``` -- User Option: ido-case-fold If the value of this user option is non-‘nil’, searching of buffer and file names should ignore case. ``` --- # update Take care of: * do not mistake the behavior of several options and how they affect the matching results, like case-fold, prefix matching and flexible matching. * There can be a difference in how you set a variable which was defined using `defcustom` and `defvar`, sometimes it doesn't matter, but you can't assume that `setq` in a config file always will do the right thing. * There is section in the manual which explains how the results are sorted. It might be opinionated, but it is documented and you can manipulate it. > 2 votes --- Tags: ido ---
thread-58224
https://emacs.stackexchange.com/questions/58224
How to set the mark using keybindings when C-SPC is unavailable to emacs
2020-05-02T02:59:32.170
# Question Title: How to set the mark using keybindings when C-SPC is unavailable to emacs Suppose I have the following code block in an org file. ``` #+begin_src sql SELECT id FROM product WHERE name = 'Apple' #+end_src ``` I want to select this part: ``` SELECT id FROM product WHERE name = 'Apple' ``` I was taught to use `C-SPC`, but `C-SPC` was already used by my OS, is there any way to do this? For example, bind this function to another shortcut? By the way, I'm using spacemacs. # Answer > 1 votes You can rebind `set-mark-command` to anything (`C`-`.` in the example) ``` (global-set-key (kbd "C-.") 'set-mark-command) ``` or ``` (define-key 'global-map (kbd "C-.") 'set-mark-command) ``` Alernatively, without having to rebind anything: * it's also bound to `C`-`@`. * You can exchange point and mark `C`-`x``C`-`x` -- *if you're not using the current mark already it'll be the same*. * You can mark the paragrah, or org-element with `M`-`h`, move the point to first line you want, then reduce region exchanging point and mark first, and moving the point again to the desired end. Sounds far more complicated than it is, but sometimes it's faster than any other method. Sure there are more ways, but I do use those. --- Straight to the example, to select directly only the src block contents you can use `org-babel-mark-block` which is bound to `C`-`c` `C`-`v` `C`-`M`-`h`. Sure not really the most friendly shortcut for the memory muscle. Thanks to bertfred for pointing it in this answer --- Tags: spacemacs ---
thread-58229
https://emacs.stackexchange.com/questions/58229
How to delete backward word in find-file using ido?
2020-05-02T11:27:29.310
# Question Title: How to delete backward word in find-file using ido? I was using regular `find-file`, and have a current setup to delete a word, which was working inside `find-file`. ``` (defun backward-delete-word (arg) "Delete characters backward until encountering the beginning of a word. With argument ARG, do this that many times." (interactive "p") (delete-region (point) (progn (backward-word arg) (point)))) (global-set-key "\C-o" 'backward-delete-word) ``` --- When I switch to `ido` via `(ido-mode 1)` word deletion does not work in ido-find-file minibuffer. **\[Q\]** Is there any way to do backward word deletion in `ido-find-file`? # Answer > 2 votes It was conflicting with `ido`'s keybinding so I disabled it. ``` (defun bind-ido-keys () "Keybindings for ido mode." (define-key ido-completion-map (kbd "\C-o") 'nil)) (add-hook 'ido-setup-hook #'bind-ido-keys) ``` --- Tags: find-file, ido ---
thread-58178
https://emacs.stackexchange.com/questions/58178
configuring spacemacs for python development
2020-04-30T07:11:27.840
# Question Title: configuring spacemacs for python development It's been really frustrating trying to get spacemacs to work so far. I've grown to really love it - coming from vim - for its capabilities in manipulating and navigating text, but it's just been so hard to get it do behave like an IDE for python that I'm actually about to give up. (caveat - I'm working on a windows machine.) I have a couple of questions that I would love some help with. I've tried both the official python layer, and using elpy directly through use-package and I couldn't get completions with either. I've now moved to installing Emacs on the linux subsystem for windows (an Ubuntu), and I now get completions with the python layer but only through "Helm completion at point" which opens in a new window - and not through a popup with company-complete. `M-x: company-diag` gives: ``` Emacs 28.0.50 (x86_64-pc-linux-gnu) of 2020-04-28 on lgw01-amd64-049 Company 0.9.12 company-backends: (company-anaconda (company-semantic company-dabbrev-code company-gtags company-etags company-keywords) company-files company-dabbrev) Used backend: company-anaconda Major mode: python-mode Prefix: ("a." . t) Completions: none ``` I'd really appreciate any help you could give - thanks! # Answer I am not sure how spacemacs does their settings, but here is my elpy setup for Python 3. See if this helps? ``` ;; elpy (use-package elpy :ensure t :init (elpy-enable) (setq python-shell-interpreter "python3" elpy-rpc-python-command "python3" python-shell-completion-native-enable nil python-remove-cwd-from-path nil ;; don't prompt before running compile compilation-read-command nil) ;; to keep the unhelpful warning from *Flymake log* buffer (remove-hook 'flymake-diagnostic-functions 'flymake-proc-legacy-flymake) :hook (elpy-mode . (lambda () (highlight-indentation-mode -1))) :bind (:map elpy-mode-map ("C-q" . elpy-goto-definition) ("C-e" . elpy-format-code) ("C-w" . elpy-pdb-debug-buffer) ("M-w" . elpy-pdb-toggle-breakpoint-at-point) ("C-l C-p" . elpy-pdb-break-at-point) ("C-h f" . python-eldoc-at-point) ("M-<backspace>" . (lambda () (interactive) (with-current-buffer (process-buffer (elpy-shell-get-or-create-process)) (comint-clear-buffer)))))) ``` I am not an expert by any means so this may have redundancies and there maybe better ways to do what I am doing. But, this for the most part works for me. > 0 votes --- Tags: spacemacs, python, ide ---
thread-35137
https://emacs.stackexchange.com/questions/35137
orgmode agenda view doesn´t display any results
2017-08-26T19:48:35.470
# Question Title: orgmode agenda view doesn´t display any results I´m new to emacs and especially org-mode, and I am testing it´s different possibilies. When trying the schedule-function with `TODO`, I don´t get any results displayed in the weekly or daily list. ``` * TODO Get schwifty SCHEDULED: <2017-09-03 So> ``` I then set the global-keys as it is recommended in the manual with C-c a to reach the weekly schedule, but I only get a blank list of weekdates with no content. What´s wrong? # Answer > 31 votes In order for org-mode to show events scheduled or with a deadline in the agenda-view, the org-file containing these events must be listed in the variable `org-agenda-files`. While one can customize this variable, the more practical way is to invoke the function `org-agenda-file-to-front`, which is commonly bound to `C-c [`. For further details see the org-mode manual: Agenda files # Answer > 5 votes Perhaps this answer will help future Doom Emacs users who run into this problem. I think it had to do with the order in which multiple configuration files are loaded. My solution was to put the following in `config.el`: ``` (after! org (setq org-agenda-files '("~/org/inbox.org" "~/org/gtd.org" "~/org/tickler.org"))) ``` The `after! org ...)` is the important bit. It will set the property *after* going into org mode, whereas, I believe, Doom is setting its own default location on startup. # Answer > 1 votes Try adding a ':' in front of SCHEDULE. So it would become :SCHEDULED: \<2017-09-03 So\> I had a similar problem and this solved it. However if there are any side effect, I am not aware. Someone may like to comment on this. --- Tags: org-mode, org-agenda ---
thread-30420
https://emacs.stackexchange.com/questions/30420
resize Emacs (GUI) window to exactly half the screen?
2017-02-03T14:55:29.580
# Question Title: resize Emacs (GUI) window to exactly half the screen? When I maximize the Emacs frame, it uses the full width of the screen, no background showing. But if I e.g. snap-to-edge (in XFCE), it shows a little "margin" of background outside the frame. And if I drag to resize, it always over- or undershoots the edge – it looks like it wants to always resize by whole lines/characters. Is there a way to have a 50% size Emacs frame that aligns with the edge of the screen? (I'm using 20170203:93058-ce88155-emacs-25.1~ubuntu16.04.1) Mousepad can take exactly 50% width and 100%height, with height from the top of the screen down to the panel: Emacs seems to overshoot/undershoot: When I "snap" Emacs to the edges with XFCE, it fits the width on my laptop, but not on my external monitor. It never matches the full height. # Answer Reading `C-h f set-frame-width` as mentioned by user @lawlist, I saw a mention of `frame-resize-pixelwise`. Putting this in .emacs.d/init.el ``` (setq frame-resize-pixelwise t) ``` makes the window "snap" to the right height in XFCE (haven't tried on my external monitor yet, so don't know if it gets the exact right width too); it also snaps to the right height when I set the height with my wmctrl scripts. > 6 votes # Answer Here is an example using some of the functions mentioned in the comment and link underneath the original question hereinabove: ``` (let ((frame (selected-frame)) (one-half-display-pixel-width (/ (display-pixel-width) 2))) (set-frame-width frame one-half-display-pixel-width nil 'pixelwise) (set-frame-position frame 0 0)) ``` --- **FYI**: Feature request #21415 was incorporated into Emacs 25 -- frame creation may now include a pixel specification -- this includes items such as the `initial-frame-alist`, `default-frame-alist`, and the `make-frame` function. Example of usage for the `width` parameter: `'(width . (text-pixels . 1900))` Example of usage for the `height` parameter: `'(height . (text-pixels . 1054))` > 2 votes # Answer Functions `moom-fill-left` and `moom-fill-right` in `moom` package resizes the frame to exactly half of the screen: https://github.com/takaxp/moom > 1 votes --- Tags: frames, gui ---
thread-24964
https://emacs.stackexchange.com/questions/24964
Resize/move frame/window
2016-07-31T07:12:29.970
# Question Title: Resize/move frame/window Are there emacs commands which will let me resize/move the frames/windows? By frame/window I mean the GUI object that X/Windows/whateverAppleCallsIt to contain the interface to emacs. Sorry, emacs language conflicts with OS-GUI language. # Answer > 6 votes There are the built in functions `set-frame-size`, `set-frame-height`, `set-frame-width` and `set-frame-position` which let's you programmatically set the frame size and position. For example `(set-frame-size (selected-frame) 300 300 t)` would set the currently selected frame size to 300x300 pixels. If you want to set the size interactively there is the frame-cmds package available on melpa that you can install via `M-x package-install RET frame-cmds RET` if you have melpa in you package-archives list or download from it from the emacs wiki. # Answer > 2 votes * In addition to `frame-cmds.el`, which is mentioned by @Tephra, you have library **`frame-fns.el`**, on which it depends, and which provides some general frame-manipulation utility functions. * Libraries **`fit-frame.el`** and **`autofit-frame.el`**, which shrink-wrap a frame to fit the text that is in its selected window (used typically in a one-window frame). See Shrink-Wrapping Frames. * Library **`zoom-frm.el`** lets you easily zoom the text in a frame (or a buffer) in and out. It extends and is more flexible than the standard Emacs text "scaling" provided by vanilla Emacs. * Library **`doremi-frm.el`** provides another way to incrementally resize frames. # Answer > 1 votes Yes, one can find the official detailed list here: Those could be combined to do all sort of things, like for example: ``` (defun my/frame-move-resize (position) "Resize selected frame to cover exactly 1/3 of screen area, and move frame to given third of current screen. Symbol POSITION can be either left, center, right." (pcase position ('left (setf x 0)) ('center (setf x 1)) ('right (setf x 2))) (let* ((HEIGHT (display-pixel-height)) (WIDTH (display-pixel-width))) (set-frame-size (selected-frame) (/ WIDTH 3) HEIGHT t) (set-frame-position (selected-frame) (* x (/ WIDTH 3)) 0))) ;; Example: (my/frame-move-resize 'center) ``` # Answer > -1 votes `moom-move-frame` and other related functions in `moom` package move/resize Emacs frame (not window) https://github.com/takaxp/moom --- Tags: frames ---
thread-57558
https://emacs.stackexchange.com/questions/57558
helm-bibtex and Zotero with better-bibtex -- Cannot find PDF
2020-04-03T10:25:27.340
# Question Title: helm-bibtex and Zotero with better-bibtex -- Cannot find PDF Using `org-ref` and `helm-bibtex` I can insert a reference into my org file that will be displayed as a link in the shape of `cite:kaufmann_eigensolver_2007`. I can hit `RET` and get a menu from `helm-bibtex` with common actions on that citation. ### The goal What I'd like is to be able to directly open the PDF given in the `file` field of the bibtex entry (supplied by Zotero). ### The problem When picking "Open PDF" in the `helm-bibtex` menu I get the message "`no pdf found for <key>`" ### My configuration I have set up `better-bibtex` to export by Zotero library to a `bib` file. The entries look like this: ``` @incollection{kaufmann_eigensolver_2007, title = {Eigensolver {{Methods}} for {{Progressive Multidimensional Scaling}} of {{Large Data}}}, ..., file = {C\:\\Users\\Ben\\Zotero\\storage\\Q2YBABVH\\Brandes and Pich - 2007 - Eigensolver Methods for Progressive Multidimension.pdf}, ... } ``` My config looks like this ``` ;; configure bibtex layer (setq org-ref-default-bibliography '("/Users/Ben/Dropbox/Library.bib") org-ref-bibliography-notes "/Users/Ben/Dropbox/org/org-ref-notes.org") (setq bibtex-completion-bibliograph "/Users/Ben/Dropbox/Library.bib") (setq bibtex-completion-pdf-field "file") (setq bibtex-completion-pdf-open-function (lambda (fpath) (debug) (start-process "open" "*open*" "open" fpath))) ``` ### What I've tried * Changing the PDF file name to accomodate the bibtex key (`kaufmann_eigensolver_2007.pdf`) * Manually editing the `file` field and try different variations of double/single/forward/backward slashes * Some basic debugging but I have to say im pretty lust on how to use `debug` in emacs. * Looking at the source code of the relevant function of helm-bibtex but I cant really make sense of it. # Answer I had the same problem. In my case, it was fixed by setting `org-ref-get-filename-function`: ``` (setq org-ref-get-pdf-filename-function (lambda (key) (car (bibtex-completion-find-pdf key)))) ``` > 2 votes # Answer You seem to be on a MAC, but the PDF key in the bibtex contains a Windows path. Maybe Zotero should export differently? Not sure if this helps but I setup the variable ``` (setq bibtex-completion-library-path "~/cloud/Papers/") ``` to the path which contains all my papers. And then the bibtex entries only have the name of the file (with no path) in them. Given your setup you could debug by calling both ``` (bibtex-completion-pdf-open-function <fullpath>) (bibtex-completion-pdf-open-function (concat <dirpath> <pdfname>)) ``` trying to substitute in the appropriate values. BTW I don't think you need to change the PDF open function unless you have specific reasons to do so. > 1 votes --- Tags: org-mode, org-ref, helm-bibtex ---
thread-58249
https://emacs.stackexchange.com/questions/58249
Save attachments
2020-05-03T11:55:31.943
# Question Title: Save attachments I'm trying to simply save attachments in Gnus. I've read this: https://www.gnu.org/software/emacs/manual///html\_node/mh-e/Viewing-Attachments.html and, I don't have `mm-decode` installed. For some reason Gnus is trying to use Emacs to open PDF files when I press `RET` on them. I've searched the help buffer for anything related to attachments / article parts / w/e other names I can imagine Gnus may give to attachments, but no luck. # Answer Ok, nevermind, it's `o`. Or `gnus-mime-save-part` > 3 votes --- Tags: gnus, attachment ---
thread-57861
https://emacs.stackexchange.com/questions/57861
show-paren-mode or similar to highlight multi-character parentheses
2020-04-17T13:53:02.457
# Question Title: show-paren-mode or similar to highlight multi-character parentheses In latex, "parentheses" such as `\(\)`, `$$` and `\[\]` are constantly used. Is there a way to customize `show-paren-mode` or is there some other mode to highlight these multi-character parentheses in `latex-mode` as well as the traditional ones, `()[]{}`? Taking this to the next level, is there a way to highlight beginning and end of latex environments? As in the example below (`item` is just an example) ``` \begin{item} % <- should be hightlighted together when point is inside OTHER TEXT \end{item} % <- should be hightlighted together ``` # Answer > 0 votes I just found about the Simple Minded Indentation Engine in Emacs which uses show-paren to highlight multi-character parenthesis like `\(` `\)` (See `smie-closer-alist`). --- Tags: latex, syntax-highlighting, parentheses ---
thread-58239
https://emacs.stackexchange.com/questions/58239
ein org mode results raw drawer
2020-05-02T20:58:57.270
# Question Title: ein org mode results raw drawer I am trying to use `ein` with `org-mode` in emacs but I am having problems with exporting the results. Here is a very simple example: ``` #+BEGIN_SRC ein-python :session localhost :results raw drawer :exports both import pandas as pd x = pd.DataFrame({'Num': a, 'Text': ['a', 'b', 'c', 'd']}) x #+END_SRC :results: Num Text 0 1 a 1 3 b 2 5 c 3 12 d :end: ``` So, using `:results raw drawer` writes the results inside `:results:` block, and are not shown when I export to html. If instead I use `:results output` or `:results value` it simply prints `[...]` (no data). And `:results raw` prints the following ``` #+RESULTS: b2757239-e41b-4626-9aef-d2abf968c1ee Num Text 0 1 a 1 3 b 2 5 c 3 12 d Num Text 0 1 a 1 3 b 2 5 c 3 12 d [....] [....] ``` Which of course does not look good in the html file. The question, what is the best way to print results to export in html? # Answer Probably the simplest way to get reasonable looking results when exporting is to wrap the results in an example block, which will export it as pre-formatted text: ``` #+BEGIN_SRC python :session localhost :results value :wrap example :exports results import pandas as pd x = pd.DataFrame({'Num': 3, 'Text': ['a', 'b', 'c', 'd']}) x #+END_SRC #+RESULTS: #+begin_example Num Text 0 3 a 1 3 b 2 3 c 3 3 d #+end_example ``` (BTW, I had to change the value of the `'Num'` entry in the dataframe to avoid a traceback). Another possibility is to have the python code produce an HTML table which you then export verbatim. You can have Pandas produce the HTML table for the dataframe by using `x.to_html()` instead of `x` in the source block. Then, the trick is to wrap the results appropriately so that the export does not muck around with the HTML that is produced. That is accomplished by wrapping the results in a `#+BEGIN_EXPORT html ... #+END_EXPORT` block - see the Quoting HTML tags section of the manual. The `:wrap` header can be used for that as well: ``` #+BEGIN_SRC python :session localhost :results value :wrap export html :exports both import pandas as pd x = pd.DataFrame({'Num': 3, 'Text': ['a', 'b', 'c', 'd']}) x.to_html() #+END_SRC #+RESULTS: #+begin_export html <table border="1" class="dataframe"> <thead> <tr style="text-align: right;"> <th></th> <th>Num</th> <th>Text</th> </tr> </thead> <tbody> <tr> <th>0</th> <td>3</td> <td>a</td> </tr> <tr> <th>1</th> <td>3</td> <td>b</td> </tr> <tr> <th>2</th> <td>3</td> <td>c</td> </tr> <tr> <th>3</th> <td>3</td> <td>d</td> </tr> </tbody> </table> #+end_export ``` Exporting this to HTML produces a "real" HTML table. I would recommend that you avoid `raw` if possible (and in this case you can): `raw` does not let Org mode know where the results begin and end, so evaluating the block repeatedly adds more and more crud that you have to clean up manually. > 1 votes --- Tags: org-mode, org-export, org-babel, ein ---
thread-58253
https://emacs.stackexchange.com/questions/58253
How to redefine key binding for "C-m" without clobbering <return>?
2020-05-03T13:44:34.970
# Question Title: How to redefine key binding for "C-m" without clobbering <return>? I am trying to remap "C-m" but it seems to prevent from working. It actually seems to make the same as "C-m". I have no idea why. I have tried this, which causes the problem: (bind-keys :map global-map ("C-m" . jump-char-backward) ("C-," . jump-char-forward)) And I tried this to fix it, which causes the problem that everywhere (for example on helm completion) now causes a new line: ``` (bind-keys :map global-map ("C-m" . jump-char-backward) ("C-," . jump-char-forward) ("<return>" . newline)) ``` How can I fix this? And what mistakes have I made understanding how remapping keys work?! # Answer > 0 votes As kindly pointed out, this question explains it: C-m and are equivalent in ASCII so we need to first amend how emacs interprets the key sequence C-m. So this should work: ``` (define-key input-decode-map [?\C-m] [C-m]) (global-set-key (kbd "<C-m>") 'jump-char-backward) ``` --- Tags: key-bindings, bind-key.el ---
thread-58264
https://emacs.stackexchange.com/questions/58264
error Key sequence starts with non-prefix key
2020-04-29T13:15:01.150
# Question Title: error Key sequence starts with non-prefix key After trying to define a custom binding: ``` (global-set-key (kbd "g l") 'evil-end-of-line) ``` I get: `(error Key sequence g h starts with non-prefix key g)` because `g` is the start of navigation for many commands in evil. How can I make it use my binding (which isn't bound to any other command: `g l`) whilst keeping evil's prefix binding? Since `g` is the prefix for other evil commands, I'm unable to use it with another combo. I still want to keep other `g <key>` commands like `g g` # Answer You're manipulating the wrong map: ``` (with-eval-after-load 'evil (define-key evil-motion-state-map (kbd "g l") 'evil-end-of-line)) ``` > 5 votes --- Tags: key-bindings ---
thread-56128
https://emacs.stackexchange.com/questions/56128
How can I use Emacs and iTerm for the same key binding?
2020-03-13T13:50:17.213
# Question Title: How can I use Emacs and iTerm for the same key binding? In my `.emacs` file I have also set `ctrl-o` to delete a word: ``` (defun backward-delete-word (arg) "Delete characters backward until encountering the beginning of a word. With argument ARG, do this that many times." (interactive "p") (delete-region (point) (progn (backward-word arg) (point)))) (global-set-key "\C-o" 'backward-delete-word) ``` Please note that this works. I want to have same setup on my Terminal shell. By default `\C-w` does it (link). --- So I created following key binding (`\C-o`) in `iTerm2` in order to delete a word by following this solution, which works on Terminal shell. > Delete a word - Send escape sequence - `0x1b 0x08 or 0x17` But when I enable it, my key binding for `C-o` in Emacs starts to not work. iTerm's keybinding suppresses Emacs's, even though they do the same job. **\[Q\]** How can I use link Emacs and iTerm for the same key binding? I think I have to do a `incode-decode-map` (https://stackoverflow.com/q/36613839/2402577) but I wasn't able to do it. # Answer > 1 votes # tl;dr @drew is right, you have a conflict. Use `C-backspace` in Emacs to delete the word to the left of the point. At your shell command like use `C-w` to do the same. # Long answer @Drew is correct, you have a conflict between iTerm and Emacs. Unfortunately there's not much you can do about that, so let's focus on what you want to do, "delete word". As you've discovered, Emacs has a "delete word" function, `backward-kill-word`. This will delete the word<sup>1</sup> to the left of the point. By default `backward-kill-word` is bound to `C-backspace`. Now, when you have iTerm open in front of you, and you're at your shell command line, you can also "delete word". By default this is bound to `C-w`, in both `bash` and `zsh`.<sup>2</sup> Generally both `bash` and `zsh` have "emacs keybindngs" by default, so general movement and editing use the same keys. "Delete word" is one place where they differ. Like in Emacs, you can rebind keys in your shell, but unifying your keybindings so you have a common "delete word" key in your shell and in Emacs isn't that simple. In Emacs, rebinding `backward-kill-word` to `C-w` will step on the default binding of `kill-region`, which I don't recommend. Binding `C-backspace` in your shell isn't that simple, or simple of a conflict. Generally, in your shell, when you press the backspace key, the shell does not receive a "backspace event" like Emacs does. The shell receives `C-?`<sup>3</sup> and this is bound to `backward-delete-character`. This is also something you don't want to overwrite for obvious reasons. ## Recommendations While you could bind "delete word" to a single unused key in Emacs and your shell, say `C-o`<sup>4</sup>, I strongly recommend you don't. The same goes for any of the basic movement and editing keys. (up, down, left, right, forward-word, backward-word, kill-word, kill-backward-word, end-of-line, beginning-of-line, etc.) You'll always be able to sit at a "unix" computer and get things done. There's nothing like sitting at a customer's system, and they're quite literally breathing down your neck to fix something "now!", and you choke because your "weird" keybindings and aliases are missing. (Pro tip.) Obviously if you have a real need to rebind keys, do it. But learn the defaults too. -- \[1\]: The Emacs definition of a "word" depends on the syntax table active in the buffer you're visiting. For the sake of discussion we'll just assume a "word" is a group of letters and numbers by characters that are not letters or numbers. \[2\]: In `bash` `C-w` is actually bound to `unix-word-rubout` and can be described as "delete the previous group of letters and numbers bounded by whitespace" and is closer to `zsh`'s `backward-kill-word`. `bash`'s `backward-kill-word` and can be described as "delete the previous group of letters and numbers bounded by charactars that are not letters or numbers" and is bound to `Escape-Control-Backspace`. \[3\]: Your shell *could* receive `C-h` which is also bound to `backward-kill-character`. It's something you might see on other older "unix" systems. In our case, macOS + iTerm + bash/zsh, it's going to be `C-?`. \[4\]: `C-o` is actually bound in `bash` and `zsh`, but you could get away with overwriting it. # Answer > 1 votes I'm not familiar with iTerm. But it sounds like it is capturing the keys you specified, which you want, in general. You just don't want it to do that when Emacs has the input focus. You'll probably need to check the iTerm doc to see if there is some way to exclude certain applications (e.g. Emacs) from iTerm's key capturing. # Answer > 0 votes The actual solution was pretty simple; I added following lines into `.zshrc` or `.bashrc`. ``` bindkey -r "^O" bindkey "^O" backward-kill-word ``` Link: https://unix.stackexchange.com/questions/285208/how-to-remove-a-zsh-keybinding-if-i-dont-know-what-it-does/285210#285210 --- Tags: key-bindings, term ---
thread-58267
https://emacs.stackexchange.com/questions/58267
What function will return the total EFFORT of the subtree at point?
2020-05-04T14:13:47.127
# Question Title: What function will return the total EFFORT of the subtree at point? I am looking for an elisp function that will return the total EFFORT of the subtree at point. By "total EFFORT" I mean the "Sum times" value that would be produced by giving the subtree a :COLUMNS: property of %EFFORT{:}, and then switching the subtree to column view, and looking at the column value. So in the example below, if point is on headline 'test' and I call hypothetical function get-subtree-effort, the function would return "0:14". ``` * test :PROPERTIES: :COLUMNS: %EFFORT{:} :END: ** e1 :PROPERTIES: :Effort: 0:07 :END: ** e2 :PROPERTIES: :Effort: 0:07 :END: ``` # Answer > 1 votes Here's one way: ``` (defun to-integer-mins (s) "Convert a string in HH:MM format to integer minutes." (if s (seq-reduce (lambda (x y) (+ y (* x 60))) (mapcar #'string-to-number (split-string s ":")) 0) 0)) (defun int-to-hh-mm (n) "Convert an integer to an HH:MM format string." (let* ((h (/ n 60)) (m (- n (* h 60)))) (format "%02d:%02d" h m))) (defun get-effort() (org-entry-get (point) "Effort")) (defun get-total-effort() (int-to-hh-mm (seq-reduce #'+ (mapcar #'to-integer-mins (org-map-entries #'get-effort t 'tree)) 0))) ``` If you do `ESC ESC : (get-total-effort) RET` with point at the "test" headline, you will get `00:14`. The main point here is the call to `org-map-entries`: ``` (org-map-entries #'get-effort t 'tree) ``` which will traverse the subtree, apply the `get-effort` function on each headline and accumulate the results in a list. The `get-effort` function checks for an `Effort` property and returns it if found (if not, it returns nil). If you run the above call to `org-map-entries` at the top-level headline with `ESC ESC : (org-map-entries #'get-effort t 'tree) RET` you will get: ``` (nil "0:07" "0:07") ``` the sequence of Effort values at each headline of the tree. All you have to do now is add them all together, but that is a bit messier than it sounds: you have to convert the strings to numbers (the number of minutes for each one), add them together to get the total number of minutes and then convert the numeric result to a string in `HH:MM` format. There are many ways to do that, but they have nothing to do with Org mode: they are generic data manipulations using standard emacs-lisp functions. I chose to implement them in functional style using `mapcar` and `seq-reduce` but they can be implemented using a more imperative style using loops instead. --- Tags: org-mode ---
thread-58274
https://emacs.stackexchange.com/questions/58274
Enforce order of ERT tests?
2020-05-04T20:54:06.273
# Question Title: Enforce order of ERT tests? When running `ert` tests, the seem to be run by default in `string<` order. For instance running tests ``` (require 'ert) (ert-deftest t1111 () (print 'AAAA)) (ert-deftest t3333 () (print 'BBBB)) (ert-deftest t2222 () (print 'CCCC)) (ert-run-tests-batch :new) ``` will print ``` ;; Actual output ;; Wanted output AAAA AAAA passed 1/3 t1111 passed 1/3 t1111 CCCC BBBB passed 2/3 t2222 passed 2/3 t3333 BBBB CCCC passed 3/3 t3333 passed 3/3 t2222 ``` For interpretation it would be helpful to guarantee the order of the tests. How can this be achieved? # Answer > 1 votes As far as I could tell, it is not possible to cause the selectors `t` (universe) or `:new` to run tests in the order of definition. The `(member TEST1 TEST2 ...)` selector however executes tests in the order specified. For my tests I am therefore using one of two workarounds (both written ad-hoc and not tested for balanced parentheses): ## 1. Wrapper, that records the tests in a list. ``` (defconst NAMESPACE-test-list nil) (defmacro NAMESPACE-deftest (name &rest args) `(progn (ert-deftest ,name ,@args) (setq NAMESPACE-test-list (nconc NAMESPACE-test-list (list ',name))))) ;; TEST DEFINITIONS (ert `(member ,@NAMESPACE-test-list)) ``` ## 2. Scan file for ert-deftest with regular expression search. ``` ;; TEST DEFINITIONS (ert (cons 'member (with-temp-buffer (insert-file load-file-name) (cl-loop while (search-forward-regexp (rx bol "(ert-deftest" (+ blank) (group-n 1 symbol-start (*? nonl) symbol-end))) nil t) collect (intern (match-string 1)))))) ``` ## 3. Numbered test names Alternatively, the alphabetic order of the tests can be (ab?)used, e.g. ``` (ert-deftest NAMESPACE-001:some-function () ...) (ert-deftest NAMESPACE-002:other-function () ...) ... (ert :new) ``` or ``` (defvar NAMESPACE-test-counter 0) (defmacro NAMESPACE-deftest (name &rest args) `(ert-deftest ,(intern (format "NAMESPACE-%03d:%s" (cl-incf NAMESPACE-test-counter) name)) ,@args)) (NAMESPACE-deftest some-function () ...) (NAMESPACE-deftest other-function () ...) ``` Both variants have serious downsides however: * The first variant causes maintenance issues. Want to reorder the test definitions? Now we also need to renumber all tests, which in turn confuses the version history. * The second variant breaks interactive lookup of the test definition from the `M-x ert` buffer. --- If I have just missed a setting, that enables "execute in definition order", I'll be happy to hear of it however. --- Tags: testing, ert ---
thread-58243
https://emacs.stackexchange.com/questions/58243
emacs-nox framebuffer access
2020-05-03T00:14:26.467
# Question Title: emacs-nox framebuffer access First of all, I am not familiar with how `emacs-nox` is implemented internally. Suppose we can access framebuffer directly (`/dev/fb...`) Is it possible to access the framebuffer directly using emacs? For example, I want to view pictures or pdfs using `emacs-nox`. I believe this is totally feasible since I can see pictures and videos on tty using `fbi` or `mplayer`. # Answer No, emacs has no capability for using the framebuffer. You're right that it wouldn't be impossible to add it, but apparently it's never been done. > 0 votes --- Tags: terminal-emacs, emacs-nox ---
thread-58290
https://emacs.stackexchange.com/questions/58290
Why is the order of : and - important in a regexp character class
2020-05-05T11:49:47.867
# Question Title: Why is the order of : and - important in a regexp character class Defining the following function ``` (defun windows-path-backwards () (interactive) (skip-chars-backward "a-zA-Z0-9\\\\_-:")) ``` and running it while standing at | in the below text ``` C:\this\path| ``` moves it to ``` C:|\this\path ``` Redefining the function as ``` (defun windows-path-backwards () (interactive) (skip-chars-backward "a-zA-Z0-9\\\\_:-")) ``` and repeating the same procedure moves the pointer from ``` C:\this\path| ``` to ``` |C:\this\path ``` Why is there difference between these two functions when the only change is the order of the `:` and `-` characters in the character class `skip-chars-backward` takes as an argument. # Answer > 3 votes It is because `-` is used to denote ranges of characters. One will have to escape `-` for it to not have that meaning when placed between two other characters. See the function definition below: ``` (defun windows-path-backwards () (interactive) (skip-chars-backward "a-zA-Z0-9\\\\_\\-:")) ``` In other words, `:` is not important in itself, it just happened to be one of two characters surrounding a `-` in the nonfunctioning example given in the question. --- Tags: regular-expressions ---
thread-58287
https://emacs.stackexchange.com/questions/58287
Interactive function to convert Windows path to POSIX path
2020-05-05T09:54:10.267
# Question Title: Interactive function to convert Windows path to POSIX path Here at 'dayjob I'm often sent paths from developers using Windows in Windows format: ``` D:\Some\Path ``` These paths can uniformly be converted to paths valid on at least some Linux machines at 'dayjob like: ``` /mnt/remote-d/Some/Path ``` I would like to write an interactive function to automate this conversion, so that I may simply tap something along the lines of `C-t C-p` to perform this conversion. The string transformation part of the function will probably be something along the lines of ``` (replace-regexp-in-string "\\\\" "/" str) ``` But then we also have to capture the string from the buffer. For that purpose `thing-at-point` looks promising, but I've thus far been unable to tame it. I have also found the following function which I think captures what I'm after with some modification: https://github.com/akicho8/string-inflection/blob/master/string-inflection.el#L184 # Answer I was able to construct a function based on the code in string-inflection. ``` (defconst path-characters "a-zA-Z0-9:\\\\_-") (defun win-to-posix-posix-path () "Rewrites a Windows formatted path to be of POSIX style." (interactive) (let* ((start (if mark-active (region-end) (progn (skip-chars-forward path-characters) (point)))) (end (if mark-active (region-beginning) (progn (skip-chars-backward path-characters) (point)))) (str (buffer-substring start end)) (slash-fix (replace-regexp-in-string "\\\\" "/" str)) (m-fix (replace-regexp-in-string "[Mm]:" "/mnt/m" slash-fix t)) (v-fix (replace-regexp-in-string "[Vv]:" "/mnt/v" mls-fix t))) (delete-region start end) (insert v-fix))) ``` > 1 votes # Answer To get the file path you can try: ``` (let ((thing-at-point-file-name-chars (concat thing-at-point-file-name-chars "\\"))) (thing-at-point 'filename)) ``` > 0 votes --- Tags: buffers, commands ---
thread-58288
https://emacs.stackexchange.com/questions/58288
List of hooks inhibited by inhibit-modification-hooks
2020-05-05T11:14:35.600
# Question Title: List of hooks inhibited by inhibit-modification-hooks The documentation of `inhibit-modification-hooks` states ``` Non-nil means don't run any of the hooks that respond to buffer changes. This affects before-change-functions and after-change-functions, as well as hooks attached to text properties and overlays. Setting this variable non-nil also inhibits file locks and checks whether files are locked by another Emacs session, as well as handling of the active region per select-active-regions. ``` Besides `before-change-functions` and `after-change-functions`, how can I get a list of all "hooks attached to text properties and overlays"? Are these the only hooks that `inhibit-modification-hooks` inhibits or are there others? For example, wouldn't `first-change-hook` be inhibited as well? # Answer An overlay can have property `modification-hooks`, which specifies particular hooks. Buffer text or a string can have text property `modification-hooks`, which is similar but slightly different. See the Elisp manual: There you'll see how `inhibit-modification-hooks` relates to these properties. > 1 votes --- Tags: buffers, hooks, text-properties, documentation, overlays ---
thread-3753
https://emacs.stackexchange.com/questions/3753
prettify-symbols-mode character replacement regex
2014-11-20T16:27:32.953
# Question Title: prettify-symbols-mode character replacement regex I'm using the new emacs 24.4 `prettify-symbols-mode`, but it isn't behaving consistently. I turn it on with: ``` (prettify-symbols-mode t) (global-prettify-symbols-mode t) ``` And I'm trying to change the way python source code looks with the follownig setup: ``` (add-hook 'python-mode-hook (lambda () (push '("**2" . ?²) prettify-symbols-alist) (push '("_x" . ?ᵪ) prettify-symbols-alist) (push '("sum" . ?∑) prettify-symbols-alist))) ``` This works, but not consistently. For example, `x**2 x_x and sum(x)` all look good. The inconsistent part is that x\**23 maintains the superscript 2, but the 3 is regular. But if I say `x**2+2`, or `x**2,` then the `**2` is not pretty (and it should be). I'd like the 2 to only be superscript when it is followed by certain characters (space, plus, comma, etc.). Alternatively, not superscript if followed by \[0-9\]. Meanwhile, sum behaves correctly. `sum(`, `sum**2`, `sum+`, and others are pretty (as they should be) and `summer` is not (correctly). # Answer According to the documentation for `prettify-symbols-alist`, you cannot use regular expressions here: > Each element looks like (SYMBOL . CHARACTER), where the symbol matching SYMBOL **(a string, not a regexp)** will be shown as CHARACTER instead. `pretty-symbols-mode` uses `regexp-opt` internally, which creates a big regular expression from all the strings in the car position of each of the alist pairs. If you really want regular expressions, you are probably better off defining font-lock keywords yourself, outside of the confines of `prettify-symbols-mode`. > 4 votes # Answer The closest I have gotten to replicating this is to customize the way emacs sets the font for characters for each mode I want to change ``` (add-to-list 'font-lock-extra-managed-props 'display) (font-lock-add-keywords 'latex-mode ;; you can change the mode here '(("\\(wordone\\).*?wordtwo" 1 '(face nil display "∑")))) ``` This will replace `wordone` with as long as it is on the same line as `wordtwo` when font-lock-mode is enabled in latex-mode The 1 refers to regexp group one in the string denoted by `\\( \\)` > 5 votes # Answer @rekado is right. > Each element looks like (SYMBOL . CHARACTER), where the symbol matching SYMBOL (a string, not a regexp) will be shown as CHARACTER instead. but there is more > CHARACTER can be a character, or it can be a list or vector, in which case it will be used to compose the new symbol as per the third argument of ‘compose-region’. So it can let you do some cool stuffs like y superscript star index i ``` (setq prettify-symbols-alist '(("yy" . (?y (tr . Bc) 1645 (br . cr) ?i)))) ``` see the `C-h compose-region`. I'm not going to lie it took me a long time to figure out how to do it and I still have many questions but my understanding of the doc says that the N, are the characters. 0, 2, 4, and the N+1 are the composition rules. But these composition rules seems to be reversed. For example 'Bc' is for 'y' and 'tr' is for '1645'. > 0 votes --- Tags: python, prettify-symbols-mode ---
thread-54394
https://emacs.stackexchange.com/questions/54394
Sum org-mode table column based on other column
2019-12-16T03:19:44.703
# Question Title: Sum org-mode table column based on other column I have this org-mode table: ``` | Category | Category Budget | Needs Transfer | |------------------+-----------------+----------------| | Rent | 3000 | t | | Internet | 125 | t | | Food | 1000 | | | Coffee | 500 | | | Cellphone | 120 | t | | Cigarettes | 100 | | | Total | 9945 | | ``` I want the "Total" row, in the "Needs Transfer" column, to show the sum of all of the budgets that have "t" in their "Needs Transfer" column. I already tried this solution to no avail: ``` @>$3 = '(apply '+ '(org-lookup-all "t" '(@2$3..@-1$3) '(@2$2..@-1$2) 'string=));E ``` # Answer You almost have it: you have quoted the `org-lookup-call` which prevents its evaluation; and you need to convert the strings in the second list to numbers in order to add them together. This works for me: ``` #+TBLFM: @>$3 = '(apply '+ (org-lookup-all "t" '(@2$3..@-1$3) (mapcar #'string-to-number '(@2$2..@-1$2)) 'string=));E ``` > 2 votes # Answer You may use the `orgtbl-aggregate` package available on http://melpa.org Give a name to your table, for instance ``` #+name: mytable ``` Then create an aggregation block with `C-c C-x i` ``` #+BEGIN: aggregate :table "mytable" :cols "'Needs Transfer' vsum('Category Budget')" | 'Needs Transfer' | vsum('Category Budget') | |------------------+-------------------------| | t | 3245 | | | 11545 | #+END: ``` You get the sum for rows with `t`, and as a bonus the sum of rows without `t`. > 2 votes --- Tags: org-mode, spacemacs ---
thread-28559
https://emacs.stackexchange.com/questions/28559
How to have the sum of a column (with computed data) in the first row?
2016-11-09T15:32:51.737
# Question Title: How to have the sum of a column (with computed data) in the first row? In org-mode is it possible to generate a table, where there is a column which contains a value computed from values in the other columns and which contains the sum of these values? More specifically, at the moment I have a table with seven columns, where the last two columns contain values computed from values in the other columns using the following formula: ``` #+TBLFM: $6=$4-$3;t::$7=$4-$3-$2;t ``` I would like to include the sum of the last column. Is this possible? If yes, how can this be achieved? When I tried to do this I always got zero. Ideally I would like to have the sum somewhere outside of the table or in the last row (even if I add new rows). # Answer > 8 votes You should use cell formulas (prefixed by `:=` instead of `=`) for your results. The example below gives the sum of the last column both at the first and the last rows. ``` | | | 8 | | Col1 | Col2 | Sum | |------+------+-----| | 1 | 3 | 4 | | 2 | 8 | 10 | | 3 | -9 | -6 | |------+------+-----| | | | 8 | #+TBLFM: $3=$1+$2::@1$3=vsum(@I..@II)::@6$3=vsum(@I..@II) ``` `vsum` sums a vector of numbers; `@I` and `@II` refer to the first and second hlines. # Answer > 3 votes You may use the `orgtbl-aggregate` package available on http://melpa.org The sum of `Col1` and `Col2` is given in the aggregated table below. ``` #+name: cc | Col1 | Col2 | Sum8 | |------+------+------| | 1 | 3 | 4 | | 2 | 8 | 10 | | 3 | -9 | -6 | #+TBLFM: $3=$1+$2 #+BEGIN: aggregate :table "cc" :cols "vsum(Col1+Col2)" | vsum(Col1+Col2) | |-----------------| | 8 | #+END: ``` Documentation here: https://github.com/tbanel/orgaggregate --- Tags: org-mode, org-table ---
thread-45791
https://emacs.stackexchange.com/questions/45791
Separately sum positive/negative numbers?
2018-11-06T14:49:43.480
# Question Title: Separately sum positive/negative numbers? By example: ``` | | Amount | |---+--------| | | 3.50 | | | 1.00 | | | -6.00 | | | 5.00 | | | -2.50 | |---+--------| | | 9.50 | | ^ | wins | |---+--------| | | 8.50 | | ^ | losses | ``` *What is the value of `TBLFM` to calculate wins and losses as above?* # Answer > 2 votes If you want to use Calc instead of Emacs Lisp: ``` #+TBLFM: $wins=vsum(map(max,@I..II,0));%.2f::$losses=-vsum(map(min,@I..II,0));%.2f ``` # Answer > 2 votes These seem to work: ``` #+TBLFM: $wins='(format "%0.2f" (apply '+ (seq-filter (lambda (x) (> x 0)) (list @2..@-1))));L::$losses='(format "%0.2f" (- (apply '+ (seq-filter (lambda (x) (< x 0)) (list @2..@-2)))));L ``` You might need to `(require 'seq)` to use `seq-filter`. I am not sure how you would do this in calc. If it can do elementwise multiplication and logical comparisons, you might be able to multiply the numbers by L \< 0, and then sum the result to get the negative sum, and by L \> 0 for the positive sum. # Answer > 1 votes You may want to take a look at the `orgtbl-aggregate` package available on http://melpa.org Documentation here: https://github.com/tbanel/orgaggregate First you create a column which tells it is a `win` or a `lose`. ``` #+name: winlose | Amount | Win? | |--------+------| | 3.50 | win | | 1.00 | win | | -6.00 | lose | | 5.00 | win | | -2.50 | lose | #+TBLFM: $2='(if (>= (string-to-number $1) 0) "win" "lose") ``` Then you aggregate the `Amount` column grouped by `Win?` tags. ``` #+BEGIN: aggregate :table "winlose" :cols "'Win?' vsum(Amount)" | 'Win?' | vsum(Amount) | |--------+--------------| | win | 9.5 | | lose | -8.5 | #+END: ``` --- Tags: org-mode, org-table ---
thread-56316
https://emacs.stackexchange.com/questions/56316
Cumulative Column in Org Table
2020-03-24T02:51:51.380
# Question Title: Cumulative Column in Org Table I would like to create a table with Coronavirus case counts for the state of Utah in the United States. I have a table with two columns: a date column and a column of total new cases for that day in my state. I would like Org to generate a third column that is a cumulative sum of all the previous case counts. The output should look like this: ``` |------------------+----+-----| | <2020-02-27 Thu> | 0 | 0 | | <2020-02-28 Fri> | 1 | 1 | | <2020-02-29 Sat> | 0 | 1 | | <2020-03-01 Sun> | 0 | 1 | | <2020-03-02 Mon> | 0 | 1 | | <2020-03-03 Tue> | 0 | 1 | | <2020-03-04 Wed> | 1 | 2 | | <2020-03-05 Thu> | 1 | 3 | | <2020-03-06 Fri> | 2 | 5 | | <2020-03-07 Sat> | 2 | 7 | | <2020-03-08 Sun> | 1 | 8 | | <2020-03-09 Mon> | 0 | 8 | | <2020-03-10 Tue> | 1 | 9 | | <2020-03-11 Wed> | 3 | 12 | | <2020-03-12 Thu> | 5 | 17 | | <2020-03-13 Fri> | 6 | 23 | | <2020-03-14 Sat> | 13 | 36 | | <2020-03-15 Sun> | 11 | 47 | | <2020-03-16 Mon> | 8 | 55 | | <2020-03-17 Tue> | 22 | 77 | | <2020-03-18 Wed> | 13 | 90 | | <2020-03-19 Thu> | 31 | 121 | | <2020-03-20 Fri> | 27 | 148 | | <2020-03-21 Sat> | 33 | 181 | | <2020-03-22 Sun> | 69 | 250 | | | | | |------------------+----+-----| #+TBLFM: $3=$2+@-1$3 ``` But when I run `C-u C-c *` to recompute the entire table line by line, that generates the error: > row descriptor -1 leads outside table Also, I would appreciate if anyone knows how to plot this data using gnuplot or perhaps just an ascii plot. # Answer > 4 votes You can use `vsum` for the cumulative sum as shown in the following Org code. There are two options for plotting the data with `gnuplot`. You can either use a meta comment line `#+PLOT:` or a `gnuplot` source block. Both cases are shown in the following example. You have to type `[[file:coronaMeta.png]]` yourself in the case of the meta line. The source block adds itself a `#+RESULTS:` and a line with the file link. ``` #+NAME: corona #+PLOT: file:"coronaMeta.png" title:"Corona Cases" ind:1 deps:(3) | Date | Cases | Cumulative | |------------------+-------+-------------| | <2020-02-27 Thu> | 0 | 0 | | <2020-02-28 Fri> | 1 | 1 | | <2020-02-29 Sat> | 0 | 1 | | <2020-03-01 Sun> | 0 | 1 | | <2020-03-02 Mon> | 0 | 1 | | <2020-03-03 Tue> | 0 | 1 | | <2020-03-04 Wed> | 1 | 2 | | <2020-03-05 Thu> | 1 | 3 | | <2020-03-06 Fri> | 2 | 5 | | <2020-03-07 Sat> | 2 | 7 | | <2020-03-08 Sun> | 1 | 8 | | <2020-03-09 Mon> | 0 | 8 | | <2020-03-10 Tue> | 1 | 9 | | <2020-03-11 Wed> | 3 | 12 | | <2020-03-12 Thu> | 5 | 17 | | <2020-03-13 Fri> | 6 | 23 | | <2020-03-14 Sat> | 13 | 36 | | <2020-03-15 Sun> | 11 | 47 | | <2020-03-16 Mon> | 8 | 55 | | <2020-03-17 Tue> | 22 | 77 | | <2020-03-18 Wed> | 13 | 90 | | <2020-03-19 Thu> | 31 | 121 | | <2020-03-20 Fri> | 27 | 148 | | <2020-03-21 Sat> | 33 | 181 | | <2020-03-22 Sun> | 69 | 250 | |------------------+-------+-------------| #+TBLFM: $3=vsum(@I$2..@+0$2) [[file:coronaMeta.png]] #+BEGIN_SRC gnuplot :var data=corona :file coronaSrcBlock.png :results graphics set style data linespoints set title "Corona Cases" plot data using 1:3 #+END_SRC ``` # Answer > 0 votes * Initialize the first cell with `@1$3=$2`. This override the column formula which is correct. * use `orgtbl-ascii-draw` for an ascii plot ``` |------------------+----+-----+--------------| | <2020-02-27 Thu> | 0 | 0 | | | <2020-02-28 Fri> | 1 | 1 | | | <2020-02-29 Sat> | 0 | 1 | | | <2020-03-01 Sun> | 0 | 1 | | | <2020-03-02 Mon> | 0 | 1 | | | <2020-03-03 Tue> | 0 | 1 | | | <2020-03-04 Wed> | 1 | 2 | . | | <2020-03-05 Thu> | 1 | 3 | . | | <2020-03-06 Fri> | 2 | 5 | : | | <2020-03-07 Sat> | 2 | 7 | ; | | <2020-03-08 Sun> | 1 | 8 | c | | <2020-03-09 Mon> | 0 | 8 | c | | <2020-03-10 Tue> | 1 | 9 | c | | <2020-03-11 Wed> | 3 | 12 | l | | <2020-03-12 Thu> | 5 | 17 | V | | <2020-03-13 Fri> | 6 | 23 | W. | | <2020-03-14 Sat> | 13 | 36 | Wh | | <2020-03-15 Sun> | 11 | 47 | WW; | | <2020-03-16 Mon> | 8 | 55 | WWl | | <2020-03-17 Tue> | 22 | 77 | WWWh | | <2020-03-18 Wed> | 13 | 90 | WWWW; | | <2020-03-19 Thu> | 31 | 121 | WWWWWV | | <2020-03-20 Fri> | 27 | 148 | WWWWWWW. | | <2020-03-21 Sat> | 33 | 181 | WWWWWWWWh | | <2020-03-22 Sun> | 69 | 250 | WWWWWWWWWWWW | |------------------+----+-----+--------------| #+TBLFM: $3=$2+@-1$3::@1$3=$2::$4='(orgtbl-ascii-draw $3 0 250 12) ``` --- Tags: org-mode, org-table ---
thread-58289
https://emacs.stackexchange.com/questions/58289
How to type a backslash in emacs "\"
2020-05-05T11:19:40.973
# Question Title: How to type a backslash in emacs "\" I'm on Prelude, and there is no way I can type a `\`. I was thinking maybe I should create a keybinding but I don't know how to create it to output a character such as `\`. Any help welcome! Thank you! # Answer Emacs by default doesn't associate `\` with any command… You should be able to directly type it without any trouble. If you cannot, then you should have a module enabled, which takes it. If you need further help, please answer the following questions: * are you using emacs in terminal (in a TTY?) or in graphical mode? * where do you want to type a backslash? In a document body, in the minibuffer, elsewhere? * as @phils asks, what does `C-h k \` give you? * what is your keyboard layout? > 1 votes # Answer As a work-around you can try `C-q \`. Try Étienne Deparis answer for a permanent resolution. > 0 votes --- Tags: key-bindings, backslash ---
thread-58305
https://emacs.stackexchange.com/questions/58305
Asterisks render as question marks in org mode
2020-05-05T22:26:42.337
# Question Title: Asterisks render as question marks in org mode I am trying to join the Church of Emacs and I installed it because I wanted to use the org-mode. I am using the Doom Emacs distribution. The problem I am facing is that when I put `*` and press space I see a `?` rather than a nice bullet. (See the image). What is wrong? EDIT: Cross posted here at github. # Answer > 2 votes My wild guess would be that the customization that Doom does replaces the `*` with some fancy symbol, but that the font you are using is unable to display that symbol. You could try switching the font or trying to find out which font Doom expects. --- Tags: org-mode ---
thread-58257
https://emacs.stackexchange.com/questions/58257
Synonyms search for Spanish
2020-05-03T18:57:17.927
# Question Title: Synonyms search for Spanish I write from time to time: tales, short novels, etc. Everything in Spanish (I'm not very fluent in English). And I use Emacs since long time ago for everything I write (not only Literature related texts, but for programming, task management, etc.). I would like to set up a synonyms service to be used from inside Emacs. And I needed for Spanish. I know there are some very good ones for English, but I couldn't find anything for Spanish. Is there anyone that knows one of this services, and how to set them up with one of the already known Emacs packages? An alternative would be to try to find such a service with a REST API, and try to set up some functions to request synonyms for the word at point to this service using the REST interface. I'm an experienced programmer, but not with Emacs Lisp, and I don't know if this is two much for me. Any hints on libraries of ways to do this, if an already existing solution is not available? # Answer Following the suggestion of Muihlinn I used www-synonyms.el, and it works quite well. You have to log onto altervista to get the `key` that you have to include in your set up (you can do it with a Google account). Then, I put in my init.el (or .emacs): ``` ;;;---{{{ Sinonimos }}}------------------------- (require 'www-synonyms) ;; Get key here: http://thesaurus.altervista.org/mykey (setq www-synonyms-key "<my-key>") ;; any of: it, fr, de, en, el, es, no, pt, ro, ru, sk (setq www-synonyms-lang "es_ES") ;; Set C-x w as key binding to insert a synonym of the word at place (global-set-key (kbd "\C-x w") 'www-synonyms-insert-synonym) ``` Some remarks: I put `es_ES`, instead of `es`, since this is the key of the mapping in the code. In addition, I have set Control-x w as the keybinding to call the function to show the possible synonyms of a given word. Also, with my Emacs version and setup, and my OS, I had to add the following at the beginning of the `www-synonyms.el` code file (and re-byte-compile the file): ``` (require 'cl-extra) ``` and change a call to `mapcan` to `cl-mapcan`; otherwise I get an error on `mapcan`. It works like a charm! > 1 votes # Answer You can use www-synonyms.el which is available from melpa. It takes altervista as source. Although it's functional and supports spanish, as well as a couple of other languages other than english, UI can use some help. Personally, I miss something able to work locally as spell checkers do. > 2 votes --- Tags: restclient, synonyms ---
thread-58312
https://emacs.stackexchange.com/questions/58312
Org mode not working as expected
2020-05-06T08:48:14.783
# Question Title: Org mode not working as expected Running Doom Emacs 2.0.9 on Emacs 26.3. I have a `test.org` as follows: ``` * h1 :tag1:tag2: * h2 :tag2: ** h21 ** h22 * h3 :tag1: ** h31 ** h32 ``` `init.el` does not carry any customization for any org variable. When I run `org-agenda m` it provides tag1 and tag2 to choose from. But when selected it does not produce any results. Can this be achieved without a predetermined list of agenda files? When I do `org-sparse-tree m` for tag1, it continues to show the file as it is. I thought it would only show tag1 items. What is wrong? How do I set things right? # Answer > 1 votes If the value of `org-agenda-files` is a directory, by default all files with the extension `.org` will be considered for the agenda. See `C-h v org-agenda-files` for more information. --- Tags: org-mode, org-agenda ---
thread-58319
https://emacs.stackexchange.com/questions/58319
How to rebind "special meaning" of C-u to a different key?
2020-05-06T13:14:21.393
# Question Title: How to rebind "special meaning" of C-u to a different key? Excerpt from GNU Emacs manual: ``` C-u alone has the special meaning of “four times”: it multiplies the argument for the next command by four. C-u C-u multiplies it by sixteen. Thus, C-u C-u C-f moves forward sixteen characters. ``` Is there a way to get this multiplication by sixteen when rebinding `universal-argument` to a different key? I did the following: ``` (global-set-key (kbd "C-i") 'universal-argument) ``` But when I press `C-i C-i a` only 4 copies of `a` are inserted, not 16 (if I rebind `universal-argument` back to `C-u` then I get 16 copies as advertised in the manual). # Answer > 6 votes Add *at least* one additional definition: ``` (global-set-key (kbd "C-i") 'universal-argument) (define-key universal-argument-map (kbd "C-i") 'universal-argument-more) ``` See additional `universal-...` definitions in *both* `bindings.el` and `simple.el` that may be rebound if so desired. --- Tags: key-bindings, prefix-argument ---
thread-58318
https://emacs.stackexchange.com/questions/58318
How could I assign key binding for `C-=`
2020-05-06T12:57:45.190
# Question Title: How could I assign key binding for `C-=` In general I have key bindings as follows: `(define-key isearch-mode-map (kbd "C-h") 'isearch-del-char)` Now I want to define a key binding for `C-=` (Control plus equal sign, which is next to Backspace on my keyboard); where it does not work. Is it possible to do it? # Answer Without more context, the direct answer to "is it possible to generate a keybinding for `C-=`" is "Yes". For example, ``` (global-set-key (kbd "C-=") (lambda () (interactive) (message "Hello world!"))) ``` There are many other ways. For instance, my init contains the following `use-package` definition: ``` (use-package expand-region :ensure t :bind (("C-=" . er/expand-region) ("C-+" . er/contract-region))) ``` Both of these define global keybindings. Key map specific bindings can be defined like you state in the question. An example of this, again taken from my init, defines the `<insert>` key to insert an Org structure template only for buffers with Org mode enabled: ``` (define-key org-mode-map (kbd "<insert>") 'org-insert-structure-template) ``` > 1 votes --- Tags: key-bindings ---
thread-48414
https://emacs.stackexchange.com/questions/48414
Monthly date tree
2019-03-17T23:31:41.410
# Question Title: Monthly date tree I'd like to use datetree with month (alternatively week) granularity. Currently the datetree looks like that: ``` * 2019 ** 2019-03 March *** 2019-03-17 Sunday **** TODO Weekly review ``` I'd like to drop the level 3 -- day, and how something like that: ``` * 2019 ** 2019-03 March *** TODO Weekly review ``` I've looked at https://orgmode.org/manual/Template-elements.html and it doesn't seem this is a build-in feature. Can you suggest any workaround how to achieve such a simplified datetree? There is a similar question on the orgmode mailing list http://lists.gnu.org/archive/html/emacs-orgmode/2018-02/msg00092.html but without any answer. # Answer > 3 votes Defining the following function should help: ``` (defun org-find-month-in-datetree() (org-datetree-find-date-create (calendar-current-date)) (kill-line)) ``` Then use an org-capture template like this: ``` '(org-capture-templates (quote ("w" "Weekly review" plain (file+function "~/org/test.org" org-find-month-in-datetree) "*** TODO Weekly review\n%?" ;;\n for newline )))) ``` To get the same for a weekly date-tree change the function to ``` (defun org-find-week-in-datetree() (org-datetree-find-iso-week-create (calendar-current-date)) (kill-line)) ``` --- Tags: org-capture ---
thread-58325
https://emacs.stackexchange.com/questions/58325
How to find usages of a variable/function etc in Python?
2020-05-06T20:24:06.370
# Question Title: How to find usages of a variable/function etc in Python? So going to the declaration is great. However I want frequently to go the other way. There used to be a way to do this with one of the older ada-modes, but I've not seen anything in the python support that does this. Is this possible in emacs and if so is there a package for it? # Answer > 2 votes This is in the `elpy` package built in and amazing. elpy docs are brilliant. As an aside, it binds to `M-?` --- Tags: python ---
thread-58317
https://emacs.stackexchange.com/questions/58317
How to change keybinding for all similar functions across all modes?
2020-05-06T12:11:05.350
# Question Title: How to change keybinding for all similar functions across all modes? Suppose I rebind `C-e` (`move-end-of-line`) to `C-o` in the global-map. How can I make `C-o` the *corresponding* function in all modes (if it exists). So, for example, in org-mode `C-o` should be `org-end-of-line`, not `move-end-of-line`. NB: I do not simply want, in this example, `C-o` to be `move-end-of-line` everywhere. Rather I want it to be the corresponding command for that mode, which in this case is `org-end-of-line`. # Answer Not sure I understand your question. Are you asking how, in each major mode, to bind to `C-o` whatever that mode normally binds to `C-e`? If so, then in `after-change-major-mode-hook` add a function such as this: ``` (defun my-remap-C-e-to-C-o () "Remap whatever command is locally bound to `C-e` to `C-o`." (let* ((map (current-local-map)) (C-e-bind (lookup-key map (kbd "C-e") t))) (define-key map (kbd "C-o") (or C-e-bind 'move-end-of-line)))) (add-hook 'after-change-major-mode-hook #'my-remap-C-e-to-C-o) ``` If the local mode does not, itself, bind `C-e` then the `C-o` gets bound, in that mode, to `move-end-of-line`. This code does not remove the global binding of `C-e`. If you also want to do that then: ``` (global-unset-key (kbd "C-e")) ``` > 2 votes --- Tags: key-bindings ---
thread-54375
https://emacs.stackexchange.com/questions/54375
Changing the width of the columns of the bookmarks display?
2019-12-14T17:23:32.853
# Question Title: Changing the width of the columns of the bookmarks display? I love the bookmarks features of Emacs. I have managed my bookmarks kind of hierarchic. But that leads to longer bookmarks, which now don't fit into the column any more. Is there a way, to enlarge the first column of the bookmark display buffer? # Answer > 2 votes As explained in the comments on the question, you can change the width of the bookmark name column by adding this line to your `init.el`: ``` (setq bookmark-bmenu-file-column 50) ``` Or you can use Customize: 1. Type `M-x cu-var RET bo-b-f-c RET` 2. Edit the **Bookmark Bmenu File Column** field. 3. Click **Apply And Save.** Note you have to kill and relaunch the Bookmark List buffer before you can see your changes. --- Tags: bookmarks ---
thread-58328
https://emacs.stackexchange.com/questions/58328
How to open the agenda overview when open an orgmode file automatically?
2020-05-06T21:58:11.347
# Question Title: How to open the agenda overview when open an orgmode file automatically? I have a personal orgmode file where I organize my life. Always when I open it I have to press: ``` C-c a a ``` That opens my agenda and shows to me my habits, the scheduled and deadline tasks. But it's annoying to remember it and make manually. I'd like to open my orgmode file and automatically opens my agenda overview. # Answer You can use file variables (or in this case, a pseudo-variable) to do something when you open a particular file. Add something like this at the bottom of the file: ``` # Local Variables: # eval: (progn (org-agenda-list) (split-window-below)) # End: ``` In order to avoid confirmation questions, you'll also have to set a couple of variables in your init file: ``` (setq enable-local-eval t) (setq safe-local-eval-forms '((progn (org-agenda-list) (split-window-below)))) ``` I still find this annoying because the agenda splits the window and so I end up with two small windows: one for the file and one for the agenda (in addition to the window that I started with). But if I don't split the window, then the file gets opened in the agenda window and hides it. Despite that, I hope this helps. # Update: A better alternative Here's a slightly different method, using `other-window` to switch windows between opening the agenda and opening the file. The variable settings are like this: ``` (setq enable-local-eval t) (setq safe-local-eval-forms '((progn (org-agenda-list) (other-window 1)))) ``` and the file-locals section in the file itself becomes: ``` # Local Variables: # eval: (progn (org-agenda-list) (other-window 1)) # End: ``` I think this behaves better and in the few tests I did (with just a couple of windows), it seemed robust. I'm not sure whether I would like it if I had a lot of windows open however. > 3 votes --- Tags: org-mode, org-agenda ---
thread-41402
https://emacs.stackexchange.com/questions/41402
Any advice? - Struggling with text reuse in emacs buffer
2018-05-09T07:27:36.783
# Question Title: Any advice? - Struggling with text reuse in emacs buffer I'm basically a level 0 emacs/orgmode user, trying to get the hang of Emacs/Orgmode. Doing this like for the 5th time already, as most Emacs beginners obviously. I have this feeling I'll like and be happy with the Emacs world, but oh well it takes a lot of patience. So I'm trying to do things little by little. So I'm trying to do something that seemingly should be quite doable but can't understand how to make it work. The idea is to reuse predefined text within a buffer. I think that what I want is to define kind of "text variables" or "snippets" and reuse that in my text later on. Let's say I'm writing some specification for my laptop. I'd like to something like define a term in buffer (don't pay attention to syntax, it's just my interpretation), let's say "Thinkpad T470p, black, with dedicated graphics card, XYZ". So I'd define this term at the beginning of my buffer. The term, presumably, would have a label/name (not sure if this is the correct term) and some value. Let's say, the value is as above and label is "MyThinkPad". Then when writing text, I'd like to start writing "MyThinkPad" and that would auto-insert the previously predefined text "Thinkpad T470p, black, with dedicated graphics card, XYZ" at the cursor position. AND what is most important - if I change value of this "variable" in the buffer , that should auto-update throughout the buffer. I'm not sure what is the right direction to look. I have a feeling this has to do with some of these "#+NAME" or "#+LABEL", or citations, or local variables, or something of that sort. After reading online resources and trying out various ideas, I'm stuck and turning to community help. Really looking forward to your suggestions. Thanks in advance! # Answer **Tl;dr** Use Yasnippet Hi, from the use case you describe, Yasnippet could provide a solution for you. On the EmacsWiki page for this project it is explained that: > \[Yasnippet\] allows you to type an abbreviation and automatically expand it into function templates. In your case, the function template would just be a constant string. --- **Detailed Example** I could not find a simple example on how to make yasnippet work on my machine so I decided to add a little bit more detail to this answer myself. 1. I downloaded the yasnippet package to `~/.emacs.d/lisp/yasnippet` and put the following lines in my `~/.emacs.d/init.el`: ``` (require 'yasnippet) (setq yas-snippet-dirs '( "~/.emacs.d/snippets" )) (yas-global-mode 1) ``` This tells yasnippet to look in the folder `~/.emacs.d/snippets` for your personal snippets. 2. Inside the `~/.emacs.d/snippets` directory, I have created another directory called `org-mode`. The important point to notice is that yasnippet apparently expects the name of the folder to be equal to the name of the (minor-) mode you wish to use later. 3. In the `~/.emacs.d/snippets/org-mode` directory create a file `test` with the following content: ``` # name: thinkpad # key: thinkpad # -- "Thinkpad T470p, black, with dedicated graphics card, XYZ" ``` Now, whenever you are editing a file with orgmode, just type `thinkpad`+`<TAB>` and it will automatically expand the string `thinkpad` to `"Thinkpad T470p, black, with dedicated graphics card, XYZ"` as desired. Obviously you can later change the string to something else if you like. > 1 votes --- Tags: org-mode ---
thread-58339
https://emacs.stackexchange.com/questions/58339
async-shell-command: run COMMAND without displaying the output
2020-05-07T14:26:12.223
# Question Title: async-shell-command: run COMMAND without displaying the output I want to use `async-shell-command` to run a `.bat` file on Windows. Reading the function documentation it says: ``` (defun async-shell-command (command &optional output-buffer error-buffer) "Execute string COMMAND asynchronously in background. ... To run COMMAND without displaying the output in a window you can configure `display-buffer-alist' to use the action `display-buffer-no-window' for the buffer `*Async Shell Command*'. ``` Where I mark in bold what I want to achieve: **run COMMAND without displaying the output.** So, I guess I need to configure `display-buffer-alist` variable to use `display-buffer-no-window` action for `*Async Shell Command*` buffer. It seems simple... Checking the `display-buffer-alist` documentation: ``` (defcustom display-buffer-alist nil "Alist of conditional actions for `display-buffer'. This is a list of elements (CONDITION . ACTION), where: CONDITION is either a regexp matching buffer names, or a function that takes two arguments - a buffer name and the ACTION argument of `display-buffer' - and returns a boolean. ACTION is a cons cell (FUNCTION . ALIST), where FUNCTION is a function or a list of functions. Each such function should accept two arguments: a buffer to display and an alist of the same form as ALIST. See `display-buffer' for details. ``` Well... this is where my head starts to get lost on Emacs/Elisp ecosystem. Should I do something like this (where I do not know what to put on ???): ``` (add-to-list 'display-buffer-alist '("*Async Shell Command*" . (display-buffer-no-window . ???)) ) ``` Any help/hints will be appreciated. # Answer Try this: ``` (add-to-list 'display-buffer-alist '("*Async Shell Command*" display-buffer-no-window (nil))) ``` The buffer is still created and it still gets the output of the command (or the error output): it is just not displayed automatically, but you can still get to it to look at what happened with the usual buffer selection mechanisms (`C-x b` etc). > 6 votes # Answer Basically I added a nil, instead ??? to my question, and it is working: ``` (add-to-list 'display-buffer-alist '("*Async Shell Command*" . (display-buffer-no-window . nil)) ) ``` > 0 votes --- Tags: microsoft-windows, shell-command, async, display-buffer-alist ---
thread-25044
https://emacs.stackexchange.com/questions/25044
How do I set up indentation to 2 spaces in web-mode
2016-08-03T11:47:15.570
# Question Title: How do I set up indentation to 2 spaces in web-mode I just installed web-mode. It works, but the indentation seems to be set to 4 spaces by default. How does one properly set it to 2 spaces? # Answer According to the web-mode documentation, you can do that with the following: ``` (defun my-web-mode-hook () "Hooks for Web mode." (setq web-mode-markup-indent-offset 2) ) (add-hook 'web-mode-hook 'my-web-mode-hook) ``` You can also set values for `web-mode-css-indent-offset` for CSS, and `web-mode-code-indent-offset` Javascript, Java, PHP, etc. > 34 votes # Answer With `use-package`: ``` (use-package web-mode :custom (web-mode-markup-indent-offset 2) (web-mode-css-indent-offset 2) (web-mode-code-indent-offset 2)) ``` > 14 votes --- Tags: web-mode ---
thread-55635
https://emacs.stackexchange.com/questions/55635
How can I set up clang-format in emacs?
2020-02-19T16:22:23.540
# Question Title: How can I set up clang-format in emacs? When running `clang-format-buffer` or `clang-format-region` when a region has been been selected, no change is made to the formatting. However, in `*Messages*`, I see `(clang-format: success)`. Using `clang-format` in the terminal works fine, and the emacs package `clang-format` is configured to point towards the correct location where `clang-format` is installed. These are the only lines I have in my init.el related to `clang-format` (I've also tried all variations of setting / not setting `clang-format-style` and `clang-format-style-option`): ``` ;; Clang stuff (require 'clang-format) (setq clang-format-style "file") ``` Is there something I'm missing? # Answer > 8 votes You need to generate a `.clang-format` file in your project's root, with the command `clang-format -style=llvm -dump-config > .clang-format`. More info on this page. # Answer > 3 votes You set `clang-format-style` to `"file"`. In that case, `clang-format.el` will first look for a `.clang-format` file. It it finds one, it will use it. Otherwise, it will check the `clang-format-fallback-style`. If that is set to `"none"`, no changes will be made. If that is not want you want, you have two options: * Provide a `.clang-format` file (\*) * Change the `clang-format-fallback-style` to `"llvm"` (\*) To generate a `.clang-format` file, you can use: ``` clang-format -style=llvm -dump-config > .clang-format ``` --- Tags: init-file, clang ---
thread-58345
https://emacs.stackexchange.com/questions/58345
How to refile to the top of another heading?
2020-05-07T17:13:19.233
# Question Title: How to refile to the top of another heading? When refile a heading in org mode, I would like to refile it to the top of the target heading so that the new subheading is the first entry. For my use case, I use `org-capture` for meeting notes, and when I'm done, I will file the meeting notes to my `* MEETINGS` heading. I order all the meeting notes in reverse order under `* MEETINGS`, and I'd like to refile the new meeting notes to the top. # Answer Found the answer on Reddit: https://www.reddit.com/r/emacs/comments/7kt7nh/is\_it\_possible\_to\_refile\_an\_orgmode\_header\_in/ To recap, use `(setq org-reverse-note-order t)` to revert the new notes order when refiling. Documentation for `org-rev-note-order`: ``` Non-nil means store new notes at the beginning of a file or entry. When nil, new notes will be filed to the end of a file or entry. This can also be a list with cons cells of regular expressions that are matched against file names, and values. ``` > 2 votes --- Tags: org-mode, org-refile ---
thread-26454
https://emacs.stackexchange.com/questions/26454
Manage freedesktop trashcan with dired mode
2016-08-22T07:02:40.417
# Question Title: Manage freedesktop trashcan with dired mode Trashed files are stored in the FreeDesktop standard location: ~/.local/share/Trash/files. How do I restore or permanently delete files in that folder using dired? # Answer > 0 votes You can use Trashed in MELPA. This package provides you a simple but convenient user interface to manage trashed files. It supports both MS Windows Recycle Bin and freedesktop.org Trash Can. See https://github.com/shingo256/trashed --- Tags: dired, files ---
thread-58350
https://emacs.stackexchange.com/questions/58350
How to schedule todo in org for every even day, and similar for every odd day?
2020-05-07T21:41:02.683
# Question Title: How to schedule todo in org for every even day, and similar for every odd day? I would like to schedule a todo item every Monday, Wednesday, Friday. I followed this one: Org-mode schedule 1 event for multiple days? and get something like this: ``` * stuff to do SCHEDULED: <Monday 4/5/2020 +1w><Wed 6/5/2020 +1w><Fri 8/5/2020 +1w> ``` This doesnt show up on my agenda. So I think the way I write it down is wrong. Could anyone give some pointers? # Answer > 1 votes One idea would be to create a custom function that tests for specified days of the week. The following example is hard-coded to return `t` for Monday (i.e., `1`), Wednesday (i.e., `3`) and Friday (i.e., `5`). This can be used in an `org-mode` file such as: ``` * My Task SCHEDULED: <%%(diary-monday-wednesday-friday date)> ``` Or, it can be used in a `diary` file and seen in the agenda view with `(setq org-agenda-include-diary t)` using a diary entry such as: ``` %%(diary-monday-wednesday-friday date) Monday or Wednesday or Friday ``` **CODE**: ``` (require 'calendar) ;;; ORG-MODE: * My Task ;;; SCHEDULED: <%%(diary-monday-wednesday-friday date)> ;;; ;;; DIARY: %%(diary-monday-wednesday-friday date) Monday or Wednesday or Friday ;;; ;;; See also: (setq org-agenda-include-diary t) ;;; ;;; (diary-monday-wednesday-friday '(5 7 2020)) => nil ;;; ;;; (diary-monday-wednesday-friday '(5 8 2020)) => t ;;; ;;; 0 => Sunday ;;; 1 => Monday ;;; 2 => Tuesday ;;; 3 => Wednesday ;;; 4 => Thursday ;;; 5 => Friday ;;; 6 => Saturday ;;; (defun diary-monday-wednesday-friday (date) "Return `t` if DATE is a Monday, Wednesday or Friday." (let ((day-of-week (calendar-day-of-week date))) (member day-of-week '(1 3 5)))) ``` # Answer > 1 votes If this is really an appointment reminder, rather than a scheduled task, then the easiest thing to do is to forego the `SCHEDULED:` marker and just have the three timestamps listed (I like putting the timestamps on different lines, but you can put them on a single line if you want): ``` * stuff to do <Monday 4/5/2020 +1w> <Wed 6/5/2020 +1w> <Fri 8/5/2020 +1w> ``` Assuming that the file is indeed an agenda file, `stuff to do` will appear in the agenda every Monday, Wednesday and Friday. --- Tags: org-mode, org-agenda ---
thread-58356
https://emacs.stackexchange.com/questions/58356
Symbol's value as variable is void: command
2020-05-08T06:07:43.240
# Question Title: Symbol's value as variable is void: command I wonder why this keybind start not working, it used to work but not today. ``` ;; defun my-exwm-launch (defun my-new-exwm-launch (command) (lambda () (interactive) (start-process-shell-command command nil command))) (exwm-input-set-key (kbd "s-g") (my-new-exwm-launch "gkamus")) ``` I think I have this problem in the past too and I solved it by giving it lambda but that solution not work anymore Update If I move the function and function to set keybind in elisp or .el file, it work but If I use .org as dotfiles it not working I use this to load org file as dotfiles ``` (require 'org) (org-babel-load-file (expand-file-name "~/.doom.d/personal/cheats_conf.org" user-emacs-directory)) ``` # Answer > 1 votes Try this instead: ``` (defun my-new-exwm-launch (command) "Doc-string." (start-process-shell-command command nil command)) (exwm-input-set-key (kbd "s-g") (lambda () (interactive) (my-new-exwm-launch "gkamus"))) ``` --- Based upon a comment from the O.P., here is a different example using a previous answer written by @sds at https://emacs.stackexchange.com/a/17421/2287 -- this example contains a general call to `ls` and passes the ARG of `-la`: ``` (defmacro defkey-arg (map key func &rest args) `(define-key ,map ,key (lambda () (interactive) (,func ,@args)))) (defun test-fn (arg) "Doc-string" (display-buffer (process-buffer (start-process "ls-process" "*OUTPUT-BUF*" "ls" arg)) t)) (defkey-arg global-map [f5] test-fn "-la") ``` --- Tags: exwm ---
thread-58355
https://emacs.stackexchange.com/questions/58355
Unusual Emacs Error scss-mode runs into 'duplicate source' error when compiling scss file
2020-05-08T02:54:10.010
# Question Title: Unusual Emacs Error scss-mode runs into 'duplicate source' error when compiling scss file Usually with Emacs errors are syntax related. This one seems anyway a bit obscure. On windows 10 installed sass-dart with chocolaty. ``` choco install sass ``` Note: at much earlier time installed sass-node globally, and then at the same much earlier time installed sass-node into directory with `npm install sass-node -D`, then removed the sass-node global installation. At time of error, there's no sass on windows path variable. This should be irrelevant. Added scss-mode from melpa and configure as such: ``` (use-package scss-mode :commands (scss-mode scss-compile) :mode ("\\.scss" . scss-mode) :config (require 'scss-mode) ;;(setq scss-sass-command "C:/ProgramData/chocolatey/lib/sass/tools/sass.bat") ;;(setq exec-path (cons (expand-file-name "C:/ProgramData/chocolatey/bin/sass.exe") exec-path)) (setq scss-compile-at-save 'nil) ;;(autoload 'scss-mode "scss-mode") );end scss-mode ``` I get the same error using the `setq scss-sass-command`, the `setq exec-path`, switching the program paths in the same two lines (`sass.bat` and `sass.exe`), using both of them or neither of them. ``` "sass 'c:/Users/Username/Desktop/wd/sass-test.scss' 'c:/Users/Username/Desktop/wd/sass-test.css' Duplicate source "'c"." ``` Duplicate source error. What is this error? What is the `c` in it? How to fix it? I suspect Emacs runs somewhere into the option of using one or another sass executable, though I shouldn't know where it's getting the second one (the one not specified in the init file). Is it somehow accessing node-sass from a local npm package directory? That seems unlikely. In any case, when I run sass directly from the command line, or from an Emacs wrapper on the command line, it works no problem. It just won't compile from scss-mode. Also, and possibly relevant? Chocolatey won't upgrade dart-sass. It gives this error: ``` " - dart-sdk (exited 1) - dart-sdk not upgraded. An error occurred during installation: Updating 'dart-sdk 2.7.0' to 'dart-sdk 2.8.1' failed. Unable to find a version of 'sass' that is compatible with 'dart-sdk 2.8.1'." ``` Should I dump dart-sass like yesterday's news and go back to libSass via node? # Answer I've never used `sass-dart`, but this looks like an error having to do with filenames and paths on Windows. You're configuring it to run a command that looks file `sass file1.scss file2.scss`, but with full path names. However, those path names are not using the normal Windows syntax, which looks like `C:\foo\bar\file1.scss`; instead you're giving it `c:/foo/bar/file1.scss`. I suspect that this is confusing the scss program, it the error message that it spits out is simply not very helpful. Combined with the misparsing of the filenames, it becomes downright gnomic; it thinks both files are just named "c". It may be that this package simply doesn't work on Windows (yet), or it may be that by setting `scss-sass-command` you've overridden the part of the code that handles the paths correctly. Also, `exec-path` should have the path containing the binary in it, not the full name of the binary itself. You've got that commented out, probably because it didn't work as written. Thirdly, you don't need to use `(require 'foo)` when you want to set variables that are defined in a package; Emacs can handle that gracefully without loading the full package first (this won't cause it to fail, it's just marginally slower than it could be). I suspect that if you remove your setting for `scss-sass-command` and fix the one that sets `exec-path`, it may just start working. But you might need to talk to whoever wrote the package and see if they've tested it on Windows. > 1 votes --- Tags: load-path ---
thread-58298
https://emacs.stackexchange.com/questions/58298
Default shell path with Tramp from MacOS to Linux
2020-05-05T19:43:14.080
# Question Title: Default shell path with Tramp from MacOS to Linux I have a local environment which is MacOS Catalina and a remote environment which is standard Linux. I use tramp to connect to the remote linux machine to work on it. Unfortunately, Catalina now defaults to zshell (`/bin/zsh`) and the linux is standard bash (`/bin/bash`) Depending on how I configure my `.emacs` file, when I invoke `M-x shell`, it either will default to bash or zshell regardless of the environment. I've tried multiple fixes so that emacs defaults to bash on linux and zshell on macos. The current `.emacs` I have so far, based on the tramp manual, looks like this: ``` (defun connect-my-linux-host () (interactive) (dired "/scp:myname@my-linux-host-url:~")) (add-to-list 'tramp-connection-properties (list (regexp-quote "/scp:myname@my-linux-host-url:") "remote-shell" "/bin/bash")) (connection-local-set-profile-variables 'remote-bash '((explicit-shell-file-name . "/bin/bash"))) (connection-local-set-profiles '(:application tramp :protocol "scp" :machine "myname@my-linux-host") 'remote-bash) ``` The above configuration defaults to zshell in every environment. What am I doing wrong? # Answer > 1 votes Emacs 26.3 knows connection-local variables. Your approach is OK. However, you must set the `:user` property explicitly, like ``` (connection-local-set-profiles '(:application tramp :protocol "scp" :user "myname" :machine "my-linux-host") 'remote-bash) ``` --- Tags: osx, tramp ---
thread-58361
https://emacs.stackexchange.com/questions/58361
Is it possible to have different color in between a specific patterns?
2020-05-08T10:34:08.223
# Question Title: Is it possible to have different color in between a specific patterns? I am using `\begin{comment} hello world \end{comment}` in order to comment out text in AucTex mode. In general I am using different color for comments but when I use `\begin{comment}` \[text\] `\end{comment}`, the text in between them shows up as white (normal text color). I want it to be seen as in original comment color. ``` (setq LaTeX-item-indent 0) (add-hook 'LaTeX-mode-hook 'turn-on-auto-fill) (require 'tex) (add-hook 'LaTeX-mode-hook (lambda () (TeX-global-PDF-mode t) )) ``` General question: Is it possible to have different color in between a specific pattern? Narrowed question: How can I have different color in auxtex for text for all kind of comments such as in between `\begin{comment}` and `\end{comment}` # Answer > 2 votes This should be automatic if you have `\usepackage{comment}` or `\usepackage{verbatim}` in your preamble. At the time the question was asked, it was actually automatic only with `\usepackage{comment}`, but AUCTeX 12.3 onwards will do it for `\usepackage{verbatim}` as well. If you've just added the `\usepackage` command, run `TeX-normal-mode` (`C-c C-n`) to tell AUCTeX to parse the preamble again. More generally, if you define your own environments using a LaTeX package that AUCTeX doesn't know about, you can ask AUCTeX to parse the `.sty` file. See automatic customization. As a last resort, if your LaTeX code is too complex for AUCTeX to parse, write your own style support. You can look at `style/comment.el` in the AUCTeX distribution to see how the `{comment}` environment from the `comment.sty` package is declared: it adds an entries to `font-latex-syntactic-keywords-extra`, which is used to override syntax information to declare `\begin{comment}` as having comment-start syntax and `\end{comment}` as having comment-end syntax. --- Tags: auctex, faces ---
thread-58365
https://emacs.stackexchange.com/questions/58365
How to prompt user for tags and use the result in a org-ql-search function?
2020-05-08T15:01:04.260
# Question Title: How to prompt user for tags and use the result in a org-ql-search function? Is there a way to read tags *with completion* from the user in the same way `read-number` or `read-string` allows? I would like to have a custom function defined where I ask the user for a tag (or list of tags) and use that in a `org-ql-search` query. # Answer > 3 votes You can get all the buffer tags by calling `org-get-buffer-tags`. You can then combine that with `completing-read` whose doc string reads as follows: > completing-read is a built-in function in ‘C source code’. > > (completing-read PROMPT COLLECTION &optional PREDICATE REQUIRE-MATCH INITIAL-INPUT HIST DEF INHERIT-INPUT-METHOD) > > ... > > Read a string in the minibuffer, with completion. PROMPT is a string to prompt with; normally it ends in a colon and a space. COLLECTION can be a list of strings, an alist, an obarray or a hash table. COLLECTION can also be a function to do the completion itself... So here's a function to do what you want: ``` (defun my-read-tag-with-completion () (interactive) (completing-read "Enter a tag: " (org-get-buffer-tags))) ``` --- Tags: org-mode, completing-read, org-ql ---
thread-58369
https://emacs.stackexchange.com/questions/58369
How to activate Coq for Org source blocks?
2020-05-08T16:42:02.917
# Question Title: How to activate Coq for Org source blocks? I have been writing some Coq code in Org, but when I try to run a source block, I get the following message: ``` No org-babel-execute function for coq! ``` I have tried to initialize the coq language in the org-babel-load-languages variable, but coq isn't an option on the list. Is there anyway of running coq src blocks outside of the temporary buffer? My overall goal is to be able to define terms in one block and reference them in another, which activating the language should hopefully let me do (I think). # Answer > 2 votes It's looking for a function called `org-babel-execute:coq` and not finding one. Your idea to modify `org-babel-load-languages` is the right one, since it doesn't load any of these functions by default; you must specifically request that they be loaded. I've double checked, and my emacs does come with a file called `ob-coq.el` which looks like it has everything needed for this to work, but Coq is still not one of the choices available when customizing `org-babel-load-languages`. Apparently it's just not been added to the possible choices for the variable, which is defined in org.el. Maybe they forgot? Or maybe it's experimental still? At any rate, you can still set the value of the variable directly. You can either add something like this to your init file: ``` (org-babel-do-load-languages 'org-babel-load-languages '((coq . t) …)) ``` Or you can choose "Show Saved Lisp Expression" in the menu you get by clicking the State button, then edit it to add coq to the list. --- Tags: org-mode, org-babel, proof-general ---
thread-58364
https://emacs.stackexchange.com/questions/58364
Issue building Emacs's docs with texi2dvi - '-recorder' and '\openout' not supported
2020-05-08T12:44:43.060
# Question Title: Issue building Emacs's docs with texi2dvi - '-recorder' and '\openout' not supported I'm trying to build the latest version of Emacs from source, but I seem to be running into an issue. The binary itself works fine, but when it comes to building the docs, the `make` process runs into this issue: ``` make -C doc/lispref pdf make[1]: Entering directory '/home/drbluefall/.cache/pikaur/build/emacs-lucid-git/src/emacs/doc/lispref' GEN elisp.pdf /usr/bin/texi2dvi: TeX neither supports -recorder nor outputs \openout lines in its log file make[1]: *** [Makefile:161: elisp.pdf] Error 1 make[1]: Leaving directory '/home/drbluefall/.cache/pikaur/build/emacs-lucid-git/src/emacs/doc/lispref' make: *** [Makefile:976: lispref-pdf] Error 2 ``` I'm not entirely sure what's up here, since I have the needed dependencies, according to Emacs's `PKGBUILD`. # Answer A web search suggests your TeX installation may be incomplete. Eg https://lists.gnu.org/r/bug-texinfo/2016-10/msg00031.html > 0 votes # Answer I just tested it with sources emacs-28.0.50 with some minor TeX warnings like underfull \hbox. The result: Output written on elisp.pdf (1332 pages, 4682046 bytes). Transcript written on elisp.log. Your Makefile seem to refer to texi2dvi, but texi2pf would be required. which texi2pdf /usr/bin/texi2pdf Could you please provide the Makefile in doc/lispref -Dieter > 0 votes --- Tags: info, build, texinfo ---
thread-21488
https://emacs.stackexchange.com/questions/21488
Highlighting upcoming dates in org mode agenda
2016-04-07T10:18:58.680
# Question Title: Highlighting upcoming dates in org mode agenda I have entries in my org file similar to: ``` * Birthdays :PROPERTIES: :CATEGORY: birthday :END: %%(org-anniversary 1981 1 2) Harry (%d) ``` What I would like is for these to appear in the agenda (say) 2 weeks before they're due, similar to how a deadline works. Is that possible? # Answer > 1 votes You can do something similar to how deadline works with the diary-remind function: ``` %%(diary-remind '(org-anniversary 1981 1 2) -14) Harry is %d ``` which shows up in the agenda as: ``` Reminder: Only N days until Harry is 38 ``` # Answer > 0 votes Why not set the variable `org-scheduled-delay-days`? # Answer > 0 votes Related but not a direct answer to your question (unless you decide to switch :-) ): I use BBDB for anniversaries and then have this in one of my agenda files: ``` * Anniversaries %%(org-bbdb-anniversaries-future) ``` By default it adds warnings to the agenda starting seven days in advance. You can change that by calling the function with an argument: `(org-bbdb-anniversaries-future 4)`. --- Tags: org-mode, syntax-highlighting ---
thread-58227
https://emacs.stackexchange.com/questions/58227
Multiuser wiki that I can edit/archive in Emacs Org-mode
2020-05-02T09:46:08.087
# Question Title: Multiuser wiki that I can edit/archive in Emacs Org-mode If I could live entirely in Emacs, I would. But... I now have to collaborate with others on a shared wiki and my team requires a web interface to edit pages. So I need to select a wiki engine. Ideally, while my team can update pages though the web, I would be able to do the same, entirely from within Emacs. The features I am looking for broadly include: 1. Open source and self-hosted 2. Git based wiki that I can checkout and archive locally, pulling changes and pushing updates as I go. Bonus points if it works with `Magit` 3. Access and edit via Emacs org-mode. If the entire wiki could live on my computer as a single `org-mode` document, that would be fantastic! 4. Easily install the wiki engine locally on my mac for config/testing and then easily porting this to the production server for deployment 5. Bootstrap themes available 6. Supported with a healthy developer community 7. Flat file architecture. I don't want to mess with databases Any ideas? # Answer Maybe you can use dokuwiki, there is an interesting mode to publish content with it, and you can always use xwidget browser or eww if you need to use the interface, oxk.el is a great package for exporting org mode to wiki format. If you still need more functionality, you can always use the dokuwiki api and create an Emacs package. > 1 votes --- Tags: org-mode, emacs-wiki ---
thread-58373
https://emacs.stackexchange.com/questions/58373
Version control: registered or unregistered?
2020-05-08T18:14:54.243
# Question Title: Version control: registered or unregistered? I'm a bit confused when writing code using the VC interface. After executing the following commands in the shell (committing a dummy file `~/test/file` in a fresh git repo `~/test`): ``` cd mkdir test cd test git init touch file git add file git commit -am "test" ``` I end up in a situation in which Emacs `(vc-state "~/test/file")` evaluate to `unregistered` but `(vc-registered "~/test/file")` reports the converse as it evaluates to `t`. What's wrong? # Answer Apparently, I'm supposed to be on the buffer. Hence, the following snippet ``` (with-current-buffer (find-file-noselect "~/test/file") (vc-state "~/test/file")) ``` is evaluated to `up-to-date`. > 0 votes --- Tags: vc ---
thread-37492
https://emacs.stackexchange.com/questions/37492
How restore file from trash?
2017-12-14T08:28:45.093
# Question Title: How restore file from trash? Windows 10, Emacs 25.1 In my `init.el` I set: ``` delete-by-moving-to-trash t ``` So as result when I delete file it move to trash. Nice. But how I restore delete file from trash by Emacs? # Answer I don't use trash, so this is a bit of a guess. And I don't find anything about restoring trashed files in the Emacs or Elisp manuals. You might want to just check your system docs for info about restoring from your system trash can. Anyway... --- First, customize option `trash-directory`, if you have not already. Thereafter, trashed files will be put in that directory. To restore a file that has been trashed there, use `C-x d` to open Dired on that directory, then use `R` to move one or more trashed files to another directory. `R` moves all marked files (or just the file of the current line, if none are marked). At the prompt, type the name of the target directory. --- If you have *not* set option `trash-directory` then files get trashed to your system recycle bin (trash can), provided function `system-move-file-to-trash` is defined. In that case, use `C-x d` to open your system trash folder (it may be `$trash/files`). However, See https://specifications.freedesktop.org/trash-spec/trashspec-latest.html for information about the kind of trash can that is used by default, and how to obtain the original file name of a trashed file. > 2 votes # Answer You can use Trashed in MELPA. This package provides you a simple but convenient user interface to manage trashed files. It supports both MS Windows Recycle Bin and freedesktop.org Trash Can. See https://github.com/shingo256/trashed > 0 votes --- Tags: files ---
thread-58384
https://emacs.stackexchange.com/questions/58384
showing lunar and solar ephemerides in Emacs agenda
2020-05-09T06:14:35.557
# Question Title: showing lunar and solar ephemerides in Emacs agenda Is there a way to show the calendar functions for phases of the moon? I know it's an inbuilt function of Emacs, but I have never seen it pop up in my agenda. Thank you, EG # Answer > 1 votes It depends on what you're expecting out of it. On a given date agenda, pressing `M` will show you all the relevant info about moon ephemerides. If you want it inside your, say, daily agenda you'll have to add them as sexps in any of your agenda files. Note that there shouldn't be any subtree indentation before `%%` ``` * Moon phases %%(my-moon-phases-function) ``` Where `my-moon-phases-function` returns a string with the phase for a given day getting the info from `lunar.el` There is a detailed howto in the org hacks page, here. A sunrise/sunset snippet is also shown in that page. It doesn't tell how to show eclipses, but if you know how to find such info, it'll be easily adaptable using these clues as well. --- Tags: init-file, org-agenda, calendar ---
thread-58388
https://emacs.stackexchange.com/questions/58388
Use tramp to play remote videos on the local
2020-05-09T08:04:46.920
# Question Title: Use tramp to play remote videos on the local I use tramp to access my phone through termux and locates the Movies directory ``` /ssh:termux:/storage/emulated/0/Movies: total 162M Superbook - In The Beginning - Season 1 Episode 1 - Full Episode (Official HD Version).mp4 Superbook - In The Beginning - Season 1 Episode 1 - Full Episode (Official HD Version).srt ``` Upon placing cursor on the video file `Superbook*.mp4` and invoke asynchronous execute & vlc with intention to play it. but get the error report as ``` /bin/sh: 2: vlc: Permission denied ``` then try `sudo` but get the same error report. ``` /bin/sh: 2: sudo: Permission denied ``` In fact, `Permission denied` might be a wrong report, since I have the full privilege to edit or rm the video file. What's the problem? Is it an alternative to play remote videos from the dired of emacs? If the videos are local, they play smoothly after strike `& vlc`. # Answer > 1 votes When you try to invoke a shell command whilst visiting a remote buffer (a directory in your case), tramp will try to run it on the remote machine. In this case it tries to ssh to your phone and run VLC but this doesn’t work. You’ll need some other way to get the file into your local filesystem so that vlc may access it. You could just copy it but maybe you could mount it or use some fuse thing. Tramp is not magic, it just tells emacs how to read and write remote files or directories or how to run commands remotely. That plumbing does not help programs like VLC which are not emacs. --- Tags: tramp, remote ---
thread-18173
https://emacs.stackexchange.com/questions/18173
How to jump from "Emacs Command History" to "Emacs Commands" in helm
2015-11-17T19:37:38.470
# Question Title: How to jump from "Emacs Command History" to "Emacs Commands" in helm I'm using Prelude. When I press `M-x`, I get `helm-M-x`. Recently I've used `query-replace-regexp`. Now when I type "replace-regexp", it automatically reaches for element in my history. There is separate section for commands below, where my beloved `replace-regexp` is, but I don't know how to reach it. How can I get in there and use the command I want to? # Answer > 7 votes You can use `C-n` (`helm-next-line`) to move line-wise or `C-o`/`<right>` (`helm-next-source`) to move source-wise. See the Basic Usage section of the Helm guide for more info: > Once you are in the helm session (of `helm-M-x` or any one else) you can hit either `C-h m` or `C-c ?`, the former is will popup a general info buffer about helm while the second will popup a specialized info of the current source you are into. `C-h m` will give you a nice basic hotkey table and plenty of more info. # Answer > 0 votes I had this problem until I noticed that I had `helm-move-to-line-cycle-in-source` set to `t`. I set it to `nil` and this problem vanished. --- Tags: helm ---
thread-58316
https://emacs.stackexchange.com/questions/58316
Toggling minor modes based on other minor modes
2020-05-06T11:37:02.557
# Question Title: Toggling minor modes based on other minor modes I wrote a function to enable some minor modes when another minor mode is enabled: ``` (defun prose-mode() (display-line-numbers-mode) (variable-pitch-mode)) ``` I added `prose-mode` as a hook for `olivetti-mode`: ``` (add-hook 'olivetti-mode-hook 'prose-mode) ``` The hook is working fine and `prose-mode` gets ivoked on `M-x olivetti-mode`. However, when I do that again to disable the mode, the line numbers don't reappear. `variable-pitch-mode` is toggling and I get my monospaced font back. In general, is this the right way to do what I'm trying to do? Inside `prose-mode`, should I check for the current minor mode using a conditional statement to enable/disable the other modes? # Answer As xuchunyang noted in comments, your shouldn't use `prose-mode` to name a function that doesn't define a mode, so you could define your function like this: ``` (defun sixter-olivetti-mode-setup() "Load additional stuff with olivetti-mode." (display-line-numbers-mode 'toggle) (variable-pitch-mode) ) ``` Note that `display-line-numbers-mode`, accepts an optional argument to specify what you want to do. `toggle` is what your need in your case. You can ask for its documentation typing `C`-`h` `f` `display-line-numbers-mode`. Then add it to the hook as you already did: ``` (add-hook 'olivetti-mode-hook 'sixter-olivetti-mode-setup) ``` > 2 votes --- Tags: init-file, hooks, minor-mode ---
thread-20123
https://emacs.stackexchange.com/questions/20123
How to not show habits in global todo list in org-mode?
2016-02-06T19:16:38.133
# Question Title: How to not show habits in global todo list in org-mode? The agenda view helpfully only shows habits for the current day, but habits that should not yet be done still show up in the global todo list. How can I prevent this from happening? # Answer The global todo list is *global*, meaning that it lists *all* matching entries. Unfortunately, habit entries require `TODO` to be present in its headings, thus they will show up in the global todo list by default. You can filter the global list by `tags`, `categories`, `efforts`, or `regexp` but these will not work with habits, because a habit entry is just an ordinary entry with a property `STYLE` set to `habit`. You can, however, a) tag all your habit entry, say, `:habit:` or b) use `#+CATEGORY: habit` to filter out. See "10.4.4 Filtering/limiting agenda items" for more information. > 2 votes # Answer Since habits are scheduled, you can just do this: `(setq org-agenda-todo-ignore-scheduled 'all)` and now they should be hidden. There are also a few other options like this to filter for different things: ``` org-agenda-todo-ignore-deadlines org-agenda-todo-ignore-timestamp org-agenda-todo-ignore-with-date org-agenda-tags-todo-honor-ignore-options ``` > 0 votes --- Tags: org-mode, org-agenda, org-habit ---
thread-58394
https://emacs.stackexchange.com/questions/58394
Magit configuration file location on Mac
2020-05-09T18:31:20.623
# Question Title: Magit configuration file location on Mac I want to reset Magit defults for particular pop up that was previously saved using `magit-popup-save-default-arguments` (https://magit.vc/manual/magit-popup.html). Where is the file created by `magit-popup-save-default-arguments` command located on Mac? Thanks, # Answer > 1 votes Found it: - looks like this config is saved by `transient` package and file with values could be found at `~/.emacs.d/transient/values.el` --- Tags: magit ---
thread-37634
https://emacs.stackexchange.com/questions/37634
How to replace matching parentheses?
2017-12-20T08:51:36.040
# Question Title: How to replace matching parentheses? I write (and rewrite) a lot of mathematical formulas in LaTeX with Emacs. I frequently run into situations where I want to change a pair of matching parentheses, to improve readability. My Emacs is kind enough to show me the matching delimiter, but how do I change it programmatically? For example, change the outer delimiters in one go: ``` ( (\sqrt{a} + b)^{-1} + c^{-1} ) ``` to ``` [ (\sqrt{a} + b)^{-1} + c^{-1} ] ``` # Answer Use `smartparens` package. It includes a function called `sp-rewrap-sexp`, which is exactly what you need. The project homepage (https://github.com/Fuco1/smartparens) has some gifs clearly showing the functionality. > 3 votes # Answer For those using evil you can use evil-surround which gives you the `c s` motion (change, surround). For your example then just do `c s ( [` (motion, from type of paren, to type of paren) > 11 votes # Answer I use the code below and bind `yf/replace-or-delete-pair` to `M-D`. Example usage : with point on `(`, I hit `M-D [` and the `()` pair becomes a `[]` pair. If you hit `M-D RET` instead, the pair will be removed. This code uses the syntax table, which means that for some pairs you'll have to specify the closing paren yourself. e.g. in html-mode, `()` can be replaced by `<>` by hitting `M-D <`. However, in many modes `<>` isn't a recognized pair, and `M-D <` will say "Don't know how to close \<". You can then you just type `>`. ``` (defun yf/replace-or-delete-pair (open) "Replace pair at point by OPEN and its corresponding closing character. The closing character is lookup in the syntax table or asked to the user if not found." (interactive (list (read-char (format "Replacing pair %c%c by (or hit RET to delete pair):" (char-after) (save-excursion (forward-sexp 1) (char-before)))))) (if (memq open '(?\n ?\r)) (delete-pair) (let ((close (cdr (aref (syntax-table) open)))) (when (not close) (setq close (read-char (format "Don't know how to close character %s (#%d) ; please provide a closing character: " (single-key-description open 'no-angles) open)))) (yf/replace-pair open close)))) (defun yf/replace-pair (open close) "Replace pair at point by respective chars OPEN and CLOSE. If CLOSE is nil, lookup the syntax table. If that fails, signal an error." (let ((close (or close (cdr-safe (aref (syntax-table) open)) (error "No matching closing char for character %s (#%d)" (single-key-description open t) open))) (parens-require-spaces)) (insert-pair 1 open close)) (delete-pair) (backward-char 1)) ``` > 6 votes # Answer `ar-parentized2bracketed-atpt` would do the task. It comes along with `ar-braced2parentized-atpt` and basically all respective combinations. Get it from thingatpt-transform-delimited.el of URL: https://github.com/andreas-roehler/thing-at-point-utils An abstracted class of commands transforms all delimited forms, for example: ``` ar-delimited2bracketed-atpt ``` These commandes are delivered in same repo by thingatpt-transform-generic-delimited.el > 2 votes # Answer Matching parentheses are visualised with `show-paren-mode`. The logical approach is to base the function to change parens to the same underlying logic and function. When matching parens are highlighted, you can call the function `toggle-parens` defined below: ``` (defun toggle-parens () "Toggle parens () <> [] at cursor. Turn on `show-paren-mode' to see matching pairs of parentheses and other characters in buffers. This function then uses the same function `show-paren-data-function' to find and replace them with the other pair of brackets. This function can be easily modified and expanded to replace other brackets. Currently, mismatch information is ignored and mismatched parens are changed based on the left one." (interactive) (let* ((parens (funcall show-paren-data-function)) (start (if (< (nth 0 parens) (nth 2 parens)) (nth 0 parens) (nth 2 parens))) (end (if (< (nth 0 parens) (nth 2 parens)) (nth 2 parens) (nth 0 parens))) (startchar (buffer-substring-no-properties start (1+ start))) (mismatch (nth 4 parens))) (when parens (pcase startchar ("(" (toggle-parens--replace "[]" start end)) ("[" (toggle-parens--replace "()" start end)))))) (defun toggle-parens--replace (pair start end) "Replace parens with a new PAIR at START and END in current buffer. A helper function for `toggle-parens'." (goto-char start) (delete-char 1) (insert (substring pair 0 1)) (goto-char end) (delete-char 1) (insert (substring pair 1 2))) ``` > 0 votes --- Tags: latex, replace, balanced-parentheses ---
thread-58366
https://emacs.stackexchange.com/questions/58366
Font-lock Yasnippet template from within Org-Babel block
2020-05-08T15:04:02.380
# Question Title: Font-lock Yasnippet template from within Org-Babel block I want to manage my library of snippets from a single `org-mode` document and tangle these to their respective snippet files, as needed. Now functionally, this works out-of-the box, with the one exception: `org-babel` does not know how to font-lock a snippet and I cannot find an `ob-snippet.el` file anywhere on the web. Now Yasnippet does has a `snippet` major mode that it uses to font-locks snippets, when viewed from their own buffer. How can I get `org-babel` to use this to fontify snippets from within a babel code block? To better illustrate, here is a screenshot of my `article` snippet from within `org-mode` and here it is, nice and fontified under the `snippet` major mode: Any ideas? # Answer Your source code block has `text` set as the mode. Try changing that to read `#+BEGIN_SRC snippet :tangle ~/org/snippets/bibtex-mode/article` > 3 votes --- Tags: org-mode, org-babel, font-lock, yasnippet ---
thread-58393
https://emacs.stackexchange.com/questions/58393
Unable to install emacs-26.3 after removing emacs-28 (stuck without an editor!)
2020-05-09T15:35:31.763
# Question Title: Unable to install emacs-26.3 after removing emacs-28 (stuck without an editor!) I've installed emacs28 from snapshot (emacs-snapshot-common) without realizing it's the latest bleeding edge and not the latests stable version. I tried installing 26.3 from Kevin Kelly's repo, as described here, but got an error: > Unpacking emacs26-common (26.3~1.git96dd019-kk1+18.04) ... > > dpkg: error processing archive /var/cache/apt/archives/emacs26-common\_26.3~1.git96dd019-kk1+18.04\_all.deb (--unpack): > > trying to overwrite '/usr/include/emacs-module.h', which is also in package emacs-snapshot-common 20200427:100116-e49d3a4~ubuntu18.04.1 I then tried to uninstall both of them but I get: > ``` > jonathan@DESKTOP-2VSOFC3:~$ sudo apt-get remove emacs-snapshot-common > > Reading package lists... Done > > Building dependency tree > > Reading state information... Done > > You might want to run 'apt --fix-broken install' to correct these. > > The following packages have unmet dependencies: > > emacs-snapshot : Depends: emacs-snapshot-common (= 20200427:100116-e49d3a4~ubuntu18.04.1) but it is not going to be > > ``` > > installed > > ``` > emacs26 : Depends: emacs26-common but it is not going to be installed > > E: Unmet dependencies. Try 'apt --fix-broken install' with no packages (or specify a solution). > > ``` I also tried: > sudo dpkg-divert --package emacs26 --divert /usr/include//emacs-module.h.moved --rename /usr/include/emacs-module.h but that didn't help either... Eventually, somehow, running remove again for both versions worked, but I still get the same error trying to install emacs-26... > jonathan@DESKTOP-2VSOFC3:~$ sudo apt install emacs26 > > Reading package lists... Done > > Building dependency tree > > Reading state information... Done > > The following packages were automatically installed and are no longer required: > > emacs-snapshot-common libjansson4 liblockfile-bin liblockfile1 > > Use 'sudo apt autoremove' to remove them. > > The following additional packages will be installed: > > emacs26-common > > The following NEW packages will be installed: > > emacs26 emacs26-common > > 0 upgraded, 2 newly installed, 0 to remove and 18 not upgraded. > > Need to get 0 B/21.8 MB of archives. > > After this operation, 117 MB of additional disk space will be used. > > Do you want to continue? \[Y/n\] y > > (Reading database ... 57830 files and directories currently installed.) > > Preparing to unpack .../emacs26-common\_26.3~1.git96dd019-kk1+18.04\_all.deb ... > > Unpacking emacs26-common (26.3~1.git96dd019-kk1+18.04) ... > > dpkg: error processing archive /var/cache/apt/archives/emacs26-common\_26.3~1.git96dd019-kk1+18.04\_all.deb (--unpack): > > trying to overwrite '/usr/include/emacs-module.h', which is also in package emacs-snapshot-common 20200427:100116-e49d3a4~ubuntu18.04.1 > > dpkg-deb: error: paste subprocess was killed by signal (Broken pipe) > > Selecting previously unselected package emacs26. > > Preparing to unpack .../emacs26\_26.3~1.git96dd019-kk1+18.04\_amd64.deb ... > > Unpacking emacs26 (26.3~1.git96dd019-kk1+18.04) ... > > Errors were encountered while processing: > > /var/cache/apt/archives/emacs26-common\_26.3~1.git96dd019-kk1+18.04\_all.deb > > E: Sub-process /usr/bin/dpkg returned an error code (1) > > while running "emacs&" returns: > > emacs-28.0.50: command not found and running the suggested --fix-broken install returns the familiar: > jonathan@DESKTOP-2VSOFC3:~$ sudo apt --fix-broken install > > Reading package lists... Done > > Building dependency tree > > Reading state information... Done > > Correcting dependencies... Done > > The following packages were automatically installed and are no longer required: > > emacs-snapshot-common libjansson4 liblockfile-bin liblockfile1 > > Use 'sudo apt autoremove' to remove them. > > The following additional packages will be installed: > > emacs26-common > > The following NEW packages will be installed: > > emacs26-common > > 0 upgraded, 1 newly installed, 0 to remove and 18 not upgraded. > > 1 not fully installed or removed. > > Need to get 0 B/17.9 MB of archives. > > After this operation, 72.0 MB of additional disk space will be used. > > Do you want to continue? \[Y/n\] y > > (Reading database ... 58480 files and directories currently installed.) > > Preparing to unpack .../emacs26-common\_26.3~1.git96dd019-kk1+18.04\_all.deb ... > > Unpacking emacs26-common (26.3~1.git96dd019-kk1+18.04) ... > > dpkg: error processing archive /var/cache/apt/archives/emacs26-common\_26.3~1.git96dd019-kk1+18.04\_all.deb (--unpack): > > trying to overwrite '/usr/include/emacs-module.h', which is also in package emacs-snapshot-common 20200427:100116-e49d3a4~ubuntu18.04.1 > > dpkg-deb: error: paste subprocess was killed by signal (Broken pipe) > > Errors were encountered while processing: > > /var/cache/apt/archives/emacs26-common\_26.3~1.git96dd019-kk1+18.04\_all.deb > > E: Sub-process /usr/bin/dpkg returned an error code (1) So now I'm completely without a working version of emacs :'( I'd really appreciate any help you could give, Thanks! # Answer > 1 votes This problem is rare when using the standard supported repositories, but all too common when using 3rd party PPAs. You want to assure that you get rid of the configuration and intermediate files that a package installation creates, not only the binaries. So you should use `apt purge` on everything installed by that `emacs28` package. Something like the following should clear things up: `sudo apt purge `dpkg --get-selections | grep emacs | cut -f1`` Carefully review what will be removed - it will probably be a combination of `emacs26` and `emacs28` packages. Once you have purged all those, once more run ``` sudo apt -f install sudo apt autoremove ``` To be extra cautious, I would also make sure to remove the path that your previous steps complained about `sudo rm -iv /usr/include/emacs-module.h` --- Tags: emacs26, emacs-snapshot ---
thread-58407
https://emacs.stackexchange.com/questions/58407
Can behavior of `W` be changed by modifying syntax entries?
2020-05-10T06:46:19.207
# Question Title: Can behavior of `W` be changed by modifying syntax entries? I want `dW` and `dB` to not delete brackets in racket (all 3 kinds `[`, `(`, `{`). I'm looking at changing `W` and not `w` because `w` is still useful for changing parts of an identifier, e.g. I can easily change `any-of-these-dash-separated-parts` individually. There is no explicit entry for `W` in documentation https://www.emacswiki.org/emacs/EmacsSyntaxTable So I'm left wondering how I might modify it. # Answer Short answer: No. Long answer: `evil-maps.el` defines inner and outer text objects, `dW` and `dB` corresponding to the following outer ones: ``` (define-key evil-outer-text-objects-map "W" 'evil-a-WORD) (define-key evil-outer-text-objects-map "B" 'evil-a-curly) ``` Their definition in `evil-commands.el`: ``` (evil-define-text-object evil-a-WORD (count &optional beg end type) "Select a WORD." (evil-select-an-object 'evil-WORD beg end type count)) (evil-define-text-object evil-a-curly (count &optional beg end type) "Select a curly bracket (\"brace\")." :extend-selection nil (evil-select-paren ?{ ?} beg end type count t)) ``` You'll have to define your own text objects instead. The API for that is that a text object is expected to be a range of start and end position. `evil-select-an-object` is the most generic way of doing this, it repurposes the `thingatpt.el` API for which defines objects in terms of forward (and optionally backward) movement. This means that all that's necessary to use `evil-WORD` as argument, is to define `forward-evil-WORD`. Look at its definition to get an idea how simple it is to define a custom version of that: ``` (defun forward-evil-WORD (&optional count) "[...]" (evil-forward-nearest count #'(lambda (&optional cnt) (evil-forward-chars "^\n\r\t\f " cnt)) #'forward-evil-empty-line)) ``` Chances are you only need to adjust the charset passed to `evil-forward-chars`. For the other text object, tricky, you'd most certainly be better off defining text objects for symbols and s-expressions. This has been done before: https://github.com/luxbock/evil-cleverparens > 0 votes --- Tags: evil ---
thread-58380
https://emacs.stackexchange.com/questions/58380
Error running timer ‘lsp--on-idle’: (error "The connected server(s) does not support method textDocument/documentLink
2020-05-08T23:12:42.360
# Question Title: Error running timer ‘lsp--on-idle’: (error "The connected server(s) does not support method textDocument/documentLink I'm trying to setup C++ IDE on spacemacs. Below are the layers configured . ``` dotspacemacs-configuration-layers '( helm (auto-completion :variables auto-completion-return-key-behavior 'complete auto-completion-tab-key-behavior 'cycle auto-completion-complete-with-key-sequence nil auto-completion-complete-with-key-sequence-delay 0.1 auto-completion-private-snippets-directory nil auto-completion-enable-snippets-in-popup nil ) (lsp :variables lsp-ui-doc-enable t lsp-ui-sideline-enable nil) emacs-lisp c-c++ (cmake :variables cmake-enable-cmake-ide-support nil) go java treemacs syntax-checking ) ``` Below are the additional packages - ``` dotspacemacs-additional-packages '(bazel-mode lsp-haskell ccls lsp-ui company-lsp dap-mode) ``` My c++ configuration layer settings are - ``` (setq-default dotspacemacs-configuration-layers '((c-c++ :variables c-c++-backend 'lsp-ccls c-c++-adopt-subprojects t c-c++-lsp-enable-semantic-highlight 'rainbow c-c++-default-mode-for-headers 'c++-mode c++-enable-organize-includes-on-save t c-c++-lsp-cache-dir ".cache" c-c++-lsp-extra-init-params '(:completion (:detailedLabel t) :index (:comments 2)) c-c++-lsp-sem-highlight-method 'font-lock c-c++-lsp-sem-highlight-rainbow nil ))) (setq ccls-executable "/usr/bin/ccls") (add-hook 'prog-mode-hook #'lsp) ``` After adding the below settings I'm getting below error - **Settings** ``` (setq ccls-executable "/usr/bin/ccls") (add-hook 'prog-mode-hook #'lsp) ``` Error - > Error running timer ‘lsp--on-idle’: (error "The connected server(s) does not support method textDocument/documentLink To find out what capabilities support your server use ‘M-x lsp-describe-session’ and expand the capabilities section.") I don't get this error for other programming languages like go, java etc I only get this for C++. What is wrong with my configuration? How can I fix this error? Note: My OS details - ``` raj@localhost:~> lsb_release -a LSB Version: core-2.0-noarch:core-3.2-noarch:core-4.0-noarch:core-2.0-x86_64:core-3.2-x86_64:core-4.0-x86_64:desktop-4.0-amd64:desktop-4.0-noarch:graphics-2.0-amd64:graphics-2.0-noarch:graphics-3.2-amd64:graphics-3.2-noarch:graphics-4.0-amd64:graphics-4.0-noarch Distributor ID: openSUSE Description: openSUSE Leap 15.1 Release: 15.1 Codename: n/a ``` # Answer > 3 votes I got the solution from gitter.im. Setting the below in .spacemacs file worked ``` (setq lsp-enable-links nil) ``` --- Tags: spacemacs, c++ ---
thread-58410
https://emacs.stackexchange.com/questions/58410
Display latex output natively in emacs in a vertically split window
2020-05-10T10:39:33.387
# Question Title: Display latex output natively in emacs in a vertically split window Running Doom Emacs 2.0.9 on Emacs 26.3. Currenly, when I do `TeX-command-run-all` on a tex file, it opens the output in `okular` pdf viewer in a separate KDE window. I was wondering if it is possible to have the output displayed natively in emacs in a vertically split window next to the tex file window. # Answer > 1 votes You'll first need something that renders pdf files in Emacs and plays well with Latex such as pdf-tools. Then you'll need to setup AucTex. Here are my configurations for both of these. Note that there maybe other possible configurations that achieve the same end result but since I have gotten this to work for me, I am sharing this, ``` ;; pdf-tools (use-package pdf-tools :ensure t :init (pdf-tools-install)) ;; auctex (use-package auctex :ensure t :after latex :init (setq tab-width 2 LaTeX-item-indent 0 latex "latex" pdf-latex-command "xelatex" TeX-view-program-selection '((output-pdf "PDF Tools")) TeX-view-program-list '(("PDF Tools" TeX-pdf-tools-sync-view))) (setq-default TeX-engine 'xetex) (add-hook 'TeX-after-compilation-finished-functions #'TeX-revert-document-buffer) :hook ;; (TeX-after-compilation-finished-functions ;; . TeX-revert-document-buffer) (LaTeX-mode . (lambda() (add-to-list 'TeX-command-list '("XeLaTeX" "%`xelatex --synctex=1%(mode)%' %t" TeX-run-TeX nil t)) (setq TeX-command-default "XeLaTeX" TeX-source-correlate-mode t))) :bind (:map LaTeX-mode-map ("C-c C-c" . (lambda (ARG) (interactive "P") (save-buffer) (TeX-command-run-all ARG))) ("C-l <backspace>" . (lambda () (interactive) (TeX-clean) (message "Cleaned!"))))) ``` You may want to adjust these as per your need and then try `C-c C-c`. --- Tags: latex, pdf ---
thread-50631
https://emacs.stackexchange.com/questions/50631
Removing the last element of a list
2019-05-21T14:14:37.060
# Question Title: Removing the last element of a list Is there a simpler way to remove the last element of a list than this? ``` (setq list (reverse (cdr (reverse list)))) ``` # Answer > 17 votes Yes there is: `(setq list (butlast list))` That is a function from `subr.el`. (Loaded by default. No need to load anything.) You can also cut a tail with `N` elements by `(setq list (butlast list N))` --- A word about phils' comment: > If it's safe to modify the original list structure, then `nbutlast` will be slightly more efficient (n.b. you still need to assign the result back to the variable). The comment is right and useful but it has to be considered very cautious. For an exmple the application of `nbutlast` is safe if the following three conditions are fulfilled: * if you are in a pure function (you have **local** non-leaking **bindings**) * you generate the list **from its elements** within the function * you want to split off the last element **at the end** of the function (i.e. in the last evaluated form before exiting the function) Be aware that `nbutlast` modifies the argument `list` in the calls of the following functions! ``` (defun queue (el list) "Prepend el and remove last element." (nbutlast (cons el list))) (defun foo (head list) "Prepend head and remove last element." (nbutlast (append head list))) (setq list (list 2 3 4)) (queue 1 list) list ;; -> (2 3) (foo '(1) list) list ;; -> (2) ``` # Answer > 1 votes Another solution would be to use `dash.el`'s slicing: `(setq list (-slice 0 -1 list))` I don't know if this is too much 'soy' for those hardcore lispers, but `-slice` really takes the hassle out of lists for me. ;) # Answer > 0 votes The sequences library bundled with Emacs makes this easily generalized. Here I demonstrate a possible implementation in an IELM buffer. ``` ELISP> (defun seq-butlast-elt (seq) "Return a copy of SEQ without its final element." (seq-take seq (1- (seq-length seq)))) seq-butlast-elt ELISP> (seq-butlast-elt '(1 2 3)) (1 2) ELISP> (seq-butlast-elt '(1)) nil ELISP> (seq-butlast-elt '()) nil ELISP> (seq-butlast-elt ["oak" "cherry" "apple"]) ["oak" "cherry"] ELISP> (seq-butlast-elt ["apple"]) [] ELISP> (seq-butlast-elt []) [] ELISP> (seq-butlast-elt "dogs") "dog" ELISP> (seq-butlast-elt "d") "" ELISP> (seq-butlast-elt "") "" ``` https://www.gnu.org/software/emacs/manual/html\_node/elisp/Sequence-Functions.html This might not be the fastest possible implementation. --- Tags: list, deletion ---
thread-57649
https://emacs.stackexchange.com/questions/57649
Org babel: Use variable to set a figure caption
2020-04-07T08:51:50.793
# Question Title: Org babel: Use variable to set a figure caption This is what I want to do: In `some-file.org`: ``` * Table 1 #+NAME: table-1-title Characteristcs of Data #+BEGIN_SRC R :file table-1.svg :results output graphics file ( ggplot(mtcars, aes(mpg, cyl)) + geom_point() ) #+END_SRC #+caption: > HERE I WANT TO USE THE table-1-title VAR DEFINED ABOVE < #+attr_latex: :width 375px :placement [H] #+RESULTS: ``` I want to use the `table-1-title` variable to set the caption. Any ideas? # Answer You can use src babel blocks for org like the following: ``` * Table 1 #+NAME: table-1-title Characteristcs of Data #+BEGIN_SRC R :file table-1.svg :results output graphics file ( ggplot(mtcars, aes(mpg, cyl)) + geom_point() ) #+END_SRC #+name: result-file #+RESULTS: table-1.svg #+begin_src org :results replace :var title=table-1-title file=result-file #+caption: $title #+attr_latex: :width 375px :placement [H] $file #+end_src #+RESULTS: #+caption: Characteristcs of Data #+attr_latex: :width 375px :placement [H] table-1.svg ``` > 2 votes --- Tags: org-mode, org-babel ---
thread-58416
https://emacs.stackexchange.com/questions/58416
Why does printf not work in Emacs octave-mode?
2020-05-10T15:20:02.170
# Question Title: Why does printf not work in Emacs octave-mode? I've recently started using Emacs **octave-mode** and discovered that when using `printf` Emacs seems to block and I have to kill the execution of an Octave script with `C-g`. I can reproduce that problem by having a file `testprintf.m` with just that single following line: > printf("Test"); or, alternatively, more authentical: > printf("Test: %d", 10); Then, I execute this file with `C-c C-i a` (or, if you like, just that line with `C-c C-i l`) and I am seeing the mouse pointer turning into the waiting symbol signalling me that this Emacs command seems to hang. `C-g` terminates the command and allows further editing of the buffer. The Inferior Octave buffer does not show any output during and after this action. Converting `printf` into a `disp` statement works but I'd like to make use of the convenient C-style formatting, Octave offers. Also, the same `printf` command **works when directly copied into the Inferior Octave buffer** with the expected out. I am using *GNU Emacs 26.3 (build 2, x86\_64-pc-linux-gnu, GTK+ Version 3.24.11)* and *Octave 4.4.1*. I have also tried it without my `~/.emacs` with the same result, the mouse pointer turning into the waiting symbol. # Answer I can reproduce this, but I think it's a buffering issue: try ``` printf("Test\n"); ``` instead. Without the newline, `accept-process-output` seems to wait indefinitely. Re: the comment from the OP - it should be fine to have multiple printf's without newlines, as long as there is a printf *with* a newline that is at the end of the code and is evaluated as part of that code - you just won't be able to evaluate things line by line. \[LATER CORRECTION\] But now that I have tried it, I see that it does not work: *every* printf has to have a newline, else `accept-process-output` waits indefinitely. > 2 votes --- Tags: octave ---
thread-31115
https://emacs.stackexchange.com/questions/31115
Arrow keys on helm mini buffer
2017-02-28T06:26:54.027
# Question Title: Arrow keys on helm mini buffer I am a beginner of helm-mode. Why remapping of arrow keys (`(kbd "<left>")`, `(kbd "right")`, ...) on `helm-map` doesn't work while others work fine? Here are the entire settings: ``` (require 'helm-config) (helm-mode 1) (define-key global-map (kbd "C-;") 'helm-mini) (define-key global-map (kbd "M-y") 'helm-show-kill-ring) (define-key global-map (kbd "C-x C-r") 'helm-recentf) (define-key global-map [remap find-file] 'helm-find-files) ; (define-key global-map [remap execute-extended-command] 'helm-M-x) (define-key helm-map (kbd "C-h") 'delete-backward-char) (define-key helm-find-files-map (kbd "<left>") 'backward-char) (define-key helm-find-files-map (kbd "<right>") 'forward-char) ;; no effects and default key bind works for following two lines (define-key helm-map (kbd "<left>") 'backward-char) (define-key helm-map (kbd "<right>") 'forward-char) ``` Thank you. # Answer I searched in GitHub repository by "left", then the problem solved by inserting `(setq helm-ff-lynx-style-map nil)` before `(helm-mode 1)`. https://github.com/emacs-helm/helm/blob/91ced00ad8bac63ca1311a39b0045677f9b2caae/helm-files.el#L409 Hence my complete settings will be following: ``` (require 'helm-config) (setq helm-ff-lynx-style-map nil) (helm-mode 1) (define-key global-map (kbd "C-;") 'helm-mini) (define-key global-map (kbd "M-y") 'helm-show-kill-ring) (define-key global-map (kbd "C-x C-r") 'helm-recentf) (define-key global-map [remap find-file] 'helm-find-files) ; (define-key global-map [remap execute-extended-command] 'helm-M-x) (define-key helm-map (kbd "C-h") 'delete-backward-char) (define-key helm-map (kbd "<left>") 'backward-char) (define-key helm-map (kbd "<right>") 'forward-char) ``` > 4 votes # Answer To provide a more 'up-to-date' answer (for anyone new reading this): Looking at the helm source documentation it seems that we should use customize, and it clearly states that declaring `helm-ff-lynx-style-map` manually with `setq` will not work... I disagree, and this was found to be working fine: ``` (require 'helm) (require 'helm-config) ;; to enable fuzzy matching with helm-mini, add the following settings: (setq helm-buffers-fuzzy-matching t helm-recentf-fuzzy-match t) ;; helm-find-files - file navigation on steroids! ;; if the point is located on a folder path, C-x C-f will ;; start in that folder. (Use C-l C-r to navigate directories) (global-set-key (kbd "C-x C-f") 'helm-find-files) ;; move to end or beginning of source when reaching top or bottom (setq helm-move-to-line-cycle-in-source t) ;; use arrow keys to navigate helm-find-files menu (setq helm-ff-lynx-style-map t) (helm-mode 1) ``` > 0 votes --- Tags: key-bindings, helm ---
thread-58419
https://emacs.stackexchange.com/questions/58419
swap files created when I open a new frame
2020-05-11T02:28:03.923
# Question Title: swap files created when I open a new frame When I use `C-x 5 2`, it opens a new frame showing the same file that I'm already editing. So, every time I open a new frame, I get an unwanted need to "swap" to another file. Is there a way to get around this? Thanks. # Answer > 1 votes Found it! `find-file-other-frame` (`C-x 5 f`) works nicely. --- Tags: frames ---
thread-58421
https://emacs.stackexchange.com/questions/58421
How can I lint a C file?
2020-05-11T04:42:39.153
# Question Title: How can I lint a C file? I have the following: ``` int main() { int a = 1; int b = 2; return 0; }; ``` I am expecting some lint to align the indentation. My file is open with `(C/*l AC Abbrev)`. I try `C-c .` which asks me: > Which C/\*l indentation style? I select `k&r` and hit enter. Then nothing happens. I try the others, `awk`, or `python`, and same thing, no linting occurs to tab the `int b` back over. When I try again with `C-c .` it asks again but never lints my code. What should I do to get formatting in C in emacs? # Answer `C-c .` just sets the formatting style to use when indenting the code, it doesn't actually change the indentation of anything the buffer. You can change the indentation of a region with the `indent-region` command, bound by default to `C-M-\`. `c-mode` also has the `c-indent-exp` command that indents an expression; this is handy for multi-line expressions near the cursor. `TAB` is bound to `c-indent-line-or-region`, which will reindent the current line should it be out of place. It also reindents regions like `C-M-\`, which is a little unusual. Most modes leave them separate. > 1 votes --- Tags: formatting, c ---
thread-58337
https://emacs.stackexchange.com/questions/58337
How remove active date from a dynamic block using columnview
2020-05-07T12:59:18.227
# Question Title: How remove active date from a dynamic block using columnview This post explains how you can setup dynamic blocks to create tables based on meeting minutes. In short, you can extract the TODOs of the minutes and put them in a table of actions like so: ``` * Actions #+BEGIN: columnview :id global :match "/TODO|DONE" :format "%ITEM(What) %TAGS(Who) %DEADLINE(When) %TODO(State)" | What | Who | When | State | |--------------------------+--------------+-----------------+-------| | Inventory of equipment | :@Fred: | | TODO | | Definition of main goals | :@Sara: | | TODO | | Talk to companies | :@Lucy:@Ted: | <2020-03-01 So> | DONE | #+END: ``` This uses the `columnview` dynamic block to automatically generate and keep the table up-to-date. It works well except for the date. It extracts the active date in the `<2020-03-01 So>` format. This causes the insertion of an empty duplicated entry in my agenda view for this date. Is there a way to convert the date to inactive, so it is displayed as `[2020-03-01 So]` in the table? # Answer Thank you, @NickD for the tip. I posted to the mailing list and got a solution from Kyle Meyer. They are keeping the behaviour above, that is, keeping the active dates to prevent breaking other parts of the code and third-party libraries. And they are updating the docs instead. Then, in my case, to remove the angle brackets, the solution is to add the following to my init.el file: ``` (defun my/org-columns-remove-brackets (_title value) (and (string-match org-ts-regexp value) (match-string 1 value))) (setq org-columns-modify-value-for-display-function #'my/org-columns-remove-brackets) ``` > 0 votes --- Tags: org-mode, org-table, time-date ---
thread-58426
https://emacs.stackexchange.com/questions/58426
Why doesn't autocomplete work on MS Windows?
2020-05-11T08:10:33.947
# Question Title: Why doesn't autocomplete work on MS Windows? my init.el file content: ``` (require 'package) ;; You might already have this line (add-to-list 'package-archives '("melpa" . "https://melpa.org/packages/")) (when (< emacs-major-version 24) ;; For important compatibility libraries like cl-lib (add-to-list 'package-archives '("gnu" . "http://elpa.gnu.org/packages/"))) (package-initialize) ;; You might already have this line ;;disable splash screen and startup message (setq inhibit-startup-message t) (setq initial-scratch-message nil) ``` # Answer All your init file does is setting up Emacs so it's aware of an additional package repository. Merely installing a package is not sufficient for enabling it, you need to follow its documentation and add the corresponding code to your init file. In this case, the README suggests to add the following (after the `package-initialize` line): ``` (ac-config-default) ``` > 1 votes --- Tags: init-file, auto-complete-mode ---
thread-58431
https://emacs.stackexchange.com/questions/58431
Disabling Magit's untracked files status
2020-05-11T08:48:03.587
# Question Title: Disabling Magit's untracked files status I'm trying out Magit for a monstrously large monorepo at work (think millions of lines of code) and there are many untracked build artifacts. From my shell I always use `git status -uno` to avoid having git try to unenumerate all of the artifacts that should be ignored but aren't. I wish I could just add things to the `.gitignore` files, but sadly this is just not feasible (layer 8 problem in the networking stack...). *Can I configure magit to not interact with untracked files at all when refreshing?* I found this question, but I don't want to just hide the untracked section, but avoid the mega latency from git attempting to enumerate the thousands of untracked files (that I don't care about). # Answer If telling git to ignore those untracked files to `.gitignore` would solve your problem, then do that. You can't modify the `.gitignore` files, ok, so use another method: * `.git/info/exclude` (same effect as `.gitignore` at the root, except that it only applies in this working tree). * `~/.config/git/ignore` (same effect as `.gitignore` at the root, except that it applies to all your working trees). > 3 votes --- Tags: magit ---
thread-58430
https://emacs.stackexchange.com/questions/58430
How to pass the result of yank to find-file?
2020-05-11T08:39:28.960
# Question Title: How to pass the result of yank to find-file? So I wanted to basically copy the current selection, then yanking it into `find-file`, as when using: * `C-SPC`: `set-mark-command` * `M-w`: `kill-ring-save` * `C-x C-f`: `find-file` * `C-y`: `yank` While that works great, I wanted to make it into a command if possible, so I tried and came up with this so far: ``` (define-advice kill-ring-save (:around (old-fun &rest args) highlight) "Save the text selection and keep the selection highlight." (let (deactivate-mark) (apply old-fun args))) (defun find-file-region () (interactive) (execute-extended-command nil "kill-ring-save" nil) (call-interactively 'find-file) (yank nil)) ``` Now, I'm using this particular `kill-ring-save` function, mostly because I found it work better than the default one, but that's just what I noticed in my workflow. *And also because i didn't know how to use the default one in this particular endeavor* So this doesn't obviously work, my guess being is that it doesn't run `yank` after running `(call-interactively 'find-file)` I've tried: * using default `find-file` but since it require a filename and doesn't just "open with current directory of the buffer/file" like it usually do if used in the keybinding, that didn't work either. * was replacing `(call-interactively 'find-file)` with `(execute-extended-command nil "find-file" nil)` but it did the same thing as far as I'm aware (that is, it didn't work either). ## Question How could I pass the current selection/region (from `C-SPC`) to `find-file` and open the file whether it exists or not? (since usually, I recall `find-file` creates the file if it doesn't exist, which is what I want too). Don't really care if it's done interactively or in the background, as I just did that to tinker around and see if it'll work. # Answer > 1 votes The main problem lies in yanking nowhere useful because it'll yank after `call-interactively` returns, not *inside* its execution. Basically you don't need anything else than calling this if you already have done `M`-`w` on region, as it actually adds it to kill-ring. ``` (defun find-file-region() (interactive) (find-file (substring-no-properties (car kill-ring)))) ``` The idea is passing the equivalent of `pop`'ing the `kill-ring` without discarding it. Or you can skip the kill-ring steps using region's content making use of a similar approach. ``` (defun find-file-region() (interactive) (if (region-active-p) (let ((str (buffer-substring (region-beginning) (region-end)))) (find-file str)) (message "No region active"))) ``` --- Tags: find-file, kill-ring ---
thread-58424
https://emacs.stackexchange.com/questions/58424
Is ELPA broken?
2020-05-11T07:16:03.943
# Question Title: Is ELPA broken? Emacs 26.1 as packaged in Debian buster. After doing `M-x package-list-packages` I can select any package from the MELPA repo https://melpa.org/packages/ and then install it. But when I try to get any package from the GNU ELPA repo https://elpa.gnu.org/packages/ I get an error: ``` Contacting host: elpa.gnu.org:443 package-install-from-archive: https://elpa.gnu.org/packages/ack-1.8.tar: Bad Request ``` And of course I get the same error if I try to install it directly, outside the package menu with `M-x package-install <RET> ack`. When I browse `elpa.gnu.org` with Firefox I can download the file just fine, and I can also download it directly from the command line with ``` curl -L -O https://elpa.gnu.org/packages/ack-1.8.tar ``` What gives? Update: I found https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=942413 . But I checked and I already have the latest signing key in `~/.emacs.d/elpa/gnupg` , namely `066DAFCB81E42C40`. So my problem must be different. # Answer > 7 votes It might be this bug: https://debbugs.gnu.org/34341. It's fixed in Emacs 26.3+ and the workaround is: `(setq gnutls-algorithm-priority "NORMAL:-VERS-TLS1.3")` Source --- Tags: package-repositories, http ---
thread-58436
https://emacs.stackexchange.com/questions/58436
How to use unicode character for truncation and wrap slots in the standard display table
2020-05-11T13:22:53.770
# Question Title: How to use unicode character for truncation and wrap slots in the standard display table I'm trying to set unicode characters for the truncation and wrap slots in the standard display table (see code below) that are used in terminal mode or GUI when there is no fringe. It is working for truncated lines, but not for wrapped lines: the `↩︎` is not displayed and is replaced by an hollow box. I suspect I may have to use `make-glyph-code` but I'm not sure of the syntax. ``` (set-display-table-slot standard-display-table 'truncation ?…) (set-display-table-slot standard-display-table 'wrap ?↩︎) ``` **Solution**: The problem was the "↩︎" glyph being substituted by the glyph from a fallback font (Fira Code in my case). I'm not sure this is a bug but here is the solution: ``` (defface fallback '((t :family "Fira Code")) "Display") (set-display-table-slot standard-display-table 'wrap (make-glyph-code ?↩ 'fallback)) ``` # Answer > 1 votes `(set-display-table-slot·buffer-display-table 'wrap ?↩)` works for me, with one caveat. In a terminal the arrow shows up correctly, but in the gui (with fringe-mode turned off), the glyph is drawn with a replacement character; apparently it couldn't find a glyph for the arrow in the chosen font. It does render correctly in the scratch buffer, but it's using a slightly different font in the fringe. Note that in the code you put in your question, you have a second character after the `?`, which makes it invalid syntax. I assume the error you're getting is `(invalid-read-syntax "?")`, since you didn't say. --- Tags: unicode, buffer-display-table ---
thread-32781
https://emacs.stackexchange.com/questions/32781
support for regex look behind and ahead?
2017-05-14T07:09:38.277
# Question Title: support for regex look behind and ahead? I need to perform regex query replace, such that `foo` in `foo bar` is matched, but `foo` in `foo baz` is not. Normally I would use regex look ahead, e.g. `foo(?=bar)`. However, it seems like Emacs cannot do this? Vim seems capable, but evil mode in spacemacs cannot. # Answer > 19 votes No, Emacs regular expressions do not support arbitrary zero-width look-ahead/behind assertions. n.b. Evil and Spacemacs (like all elisp libraries) are irrelevant when it comes to questions about the Emacs Lisp language implementation. # Answer > 6 votes https://github.com/benma/visual-regexp-steroids.el/ Visual regexp steroids allows you to replace, search, etc. using python regex. Python regex has support for look ahead and look behind. It even highlights the regexp expressions for you. --- Tags: regular-expressions ---
thread-19440
https://emacs.stackexchange.com/questions/19440
Magit extremely slow in Windows. How do I optimize?
2016-01-11T16:28:46.760
# Question Title: Magit extremely slow in Windows. How do I optimize? I am forced to use Windows 10 for a project. Yes, I would rather use GNU/Linux. To keep my sanity, I've tried to regard Windows as a bootloader for Emacs :) Unfortunately, Magit (one of my favorite parts of Emacs, which also makes up for the lack of a good command line on Windows) is unbearably slow. I have an SSD, 16 GB of RAM and a quad-core i7 but it takes **eight seconds** to execute `magit-status` on a small repository. Then, when I want to stage another change, it takes about 5 seconds *per file*. Here's what I've tried: * `$ git config --global core.preloadindex true` * `$ git config --global core.fscache true` * `$ git config --global gc.auto 256` * Adding the entire project to the Windows Defender (my only AV) exclusion list * Setting the `magit-git-executable` to the regular msysgit one I downloaded (https://git-for-windows.github.io/). I checked and `git status` here takes \< 1 second. I know that `magit-status` does way more, but this is too much. Can anyone suggest ways to make this faster? I can't imagine anyone using Magit on Windows like this. It was suggested that this question is a duplicate, but they asked: > I'm struggling to understand why Emacs have noticeably shorter startup time on Ubuntu than Windows. Anyone knows the answer? I know at least some reasons why Emacs, Git, and Magit are slower on Windows. I am asking *how do I optimize Magit* to do fewer things, or cache results, or something, even if it's at the expense of functionality. # Answer I have actually done rather a lot of research on this and fundamentally the problem is that git for windows **sucks** This is the upstream bug: https://github.com/git-for-windows/git/issues/596 and it requires somebody to rewrite shell scripts in C so that there is no more command forking. For me, its the interactive rebase that is the real killer (I can kick off an interactive rebase, go make tea, come back, read some news, drink the tea, and then **maybe** it's finished. It's much worse than a lot of people think it is), but general status-like calls are also enough to interrupt the work stride. An alternative might be to update jGit to support the commands that magit uses, and then run it in nailgun to reduce the JVM startup time, I started a thread to discuss this: http://dev.eclipse.org/mhonarc/lists/jgit-dev/msg03064.html You might want to read https://stackoverflow.com/questions/4485059 for some potential speedups, but honestly you'll barely notice them. Something you can do in magit is to follow the author's advice in setting up a minimal `magit-status` just for staging ``` ;; WORKAROUND https://github.com/magit/magit/issues/2395 (define-derived-mode magit-staging-mode magit-status-mode "Magit staging" "Mode for showing staged and unstaged changes." :group 'magit-status) (defun magit-staging-refresh-buffer () (magit-insert-section (status) (magit-insert-untracked-files) (magit-insert-unstaged-changes) (magit-insert-staged-changes))) (defun magit-staging () (interactive) (magit-mode-setup #'magit-staging-mode)) ``` so, do you know any experienced C or Java developers who'd be able to help with either of the solutions to fix git or jGit? > 13 votes # Answer Having recently looked at the a list of `call-process` calls from `magit-status` for another reason, it occured to me that some of them can be cached. With the following advice `magit-status` on Magit's repo goes from 1.9 to 1.3 seconds (my previous measurement of 0.8s mentioned in the comments was for a different (faster) computer). If you are already using `magit-staging` from the other answer it's probably not going to help much: I saw a reduction from 0.16 to 0.12 seconds (but that's barely larger than measurement noise). ## WARNING: This doesn't take care of updating the cache, so things may go wrong (especially if you are fiddling with your git configuration). ``` (defvar-local magit-git--git-dir-cache nil) (defvar-local magit-git--toplevel-cache nil) (defvar-local magit-git--cdup-cache nil) (defun memoize-rev-parse (fun &rest args) (pcase (car args) ("--git-dir" (unless magit-git--git-dir-cache (setq magit-git--git-dir-cache (apply fun args))) magit-git--git-dir-cache) ("--show-toplevel" (unless magit-git--toplevel-cache (setq magit-git--toplevel-cache (apply fun args))) magit-git--toplevel-cache) ("--show-cdup" (let ((cdup (assoc default-directory magit-git--cdup-cache))) (unless cdup (setq cdup (cons default-directory (apply fun args))) (push cdup magit-git--cdup-cache)) (cdr cdup))) (_ (apply fun args)))) (advice-add 'magit-rev-parse-safe :around #'memoize-rev-parse) (defvar-local magit-git--config-cache (make-hash-table :test 'equal)) (defun memoize-git-config (fun &rest keys) (let ((val (gethash keys magit-git--config-cache :nil))) (when (eq val :nil) (setq val (puthash keys (apply fun keys) magit-git--config-cache))) val)) (advice-add 'magit-get :around #'memoize-git-config) (advice-add 'magit-get-boolean :around #'memoize-git-config) ``` > 2 votes # Answer Use Emacs on WSL. I did an extensive use of magit when I worked on a Linux box. But was kind of forced to use Windows 10. I tried to use Magit though I couldn't stand how slow it was. So I just switched to SublimeMerge for git use. After one year using it, I haven't looked back. But since I have tried native Emacs on Windows and Emacs on WSL... Just made a test to check `magit-status` on same repo. I manually started a stopwatch with a hotkey in Windows. So there is a bit of time gap between when `magit-status` ends and when the watch stops. In my case *Emacs-on-WSL* beats *Emacs-on-Windows* by ~2 secs vs ~6 secs. Both tests made starting emacs with `emacs -Q`. > 2 votes --- Tags: magit, microsoft-windows, git, performance ---
thread-58446
https://emacs.stackexchange.com/questions/58446
Wrong number of arguments: (0 . 0), 1 error on suspend-emacs and run command in shell
2020-05-11T20:35:33.640
# Question Title: Wrong number of arguments: (0 . 0), 1 error on suspend-emacs and run command in shell I am trying to `suspend-frame` and run command: `clear` in the shell in order to hide warning message: `[3] + 31360 suspended (signal) TERM=xterm-256color emacsclient -t -q ~/.emacs` I have add this script from this answer (https://emacs.stackexchange.com/a/33449/18414): ``` (defun suspend-and-clear () (interactive) (suspend-frame "clear")) (global-set-key "\C-]" 'suspend-and-clear); ``` This gives me following error: `Wrong number of arguments: (0 . 0), 1`. How can I fix this error? # Answer AFAIK in a terminal you genuinely are *suspending the process*. So Emacs can't *do* anything after that -- it was a foreground process, and it has been stopped. However, it's `suspend-tty` which is ultimately called (see which), and that runs an abnormal hook `suspend-tty-functions`. The functions are run with one argument, the terminal object to be suspended. So if you can establish a way to clear the terminal based on that value, you might be able to achieve what you want. Note that the message you are wanting to hide is a job control message; and while I can't remember if it's the shell or the tty/OS which generates it, either way it won't be generated until *after* Emacs has been stopped, which means whatever you were going to do via that hook (i.e. while Emacs is running) would need to take delayed effect. > 1 votes # Answer `suspend-frame` doesn't take any arguments, which is why you're getting that error message. Call `suspend-emacs` instead. > 1 votes --- Tags: terminal-emacs, suspend ---
thread-24127
https://emacs.stackexchange.com/questions/24127
No "full service" Haskell org mode?
2016-06-22T18:06:03.770
# Question Title: No "full service" Haskell org mode? I'm guessing that since Haskell's ghci is not a full-fledged REPL, you can't really use it for defining functions in orgmode source blocks, i.e., ``` #+begin_src haskell doubleMe x = x + x #+end_src ``` isn't allowed in the ghci. But then ``` #+begin_src haskell let doubleMe x = x + x #+end_src ``` works, but ``` #+begin_src haskell let doubleSmallNumber4 x = if x > 0 then x else x*2 #+end_src ``` complains about parsing the `else`. I'm assuming Haskell and orgmode simply don't play well together -- at least when it comes to using orgmode source blocks . . . or am I missing something? # Answer You need to enable multi-line commands support in GHCi. Put `:set +m` to GHCi config file or execute it directly in org-babel session as shown in the following code: ``` #+begin_src haskell :set +m let doubleSmallNumber4 x = if x > 0 then x else x*2 doubleSmallNumber4 42 #+end_src #+RESULTS: : 42 ``` > 10 votes # Answer Another option for Haskell source blocks in org-mode is to use emacs-jupyter with the IHaskell kernel. Multi-line code blocks work as expected, e.g. ``` #+begin_src jupyter-haskell let doubleSmallNumber4 x = if x > 0 then x else x*2 doubleSmallNumber4 2 #+end_src #+RESULTS: : 2 ``` > 1 votes --- Tags: org-mode, org-babel, haskell-mode ---
thread-58453
https://emacs.stackexchange.com/questions/58453
SMIE precedence conflict
2020-05-12T01:55:02.273
# Question Title: SMIE precedence conflict ``` (defvar foo-smie-grammar (smie-prec2->grammar (smie-bnf->prec2 '((exp (exp "+" exp) (exp "*" exp) ("let" let-decls "in" exp)) (let-decls (let-decls ";" let-decls) (exp))) '((assoc ";") (assoc "+") (assoc "*"))))) ``` The above gives warnings: ``` Warning (smie): Conflict: in >/< * Warning (smie): Conflict: in >/< + Warning (smie): Total: 2 warnings ``` Without the `let-decls` non-terminal, all is fine. How do I fix this? The grammar isn't obviously problematic to me. # Answer > 1 votes I need to add an associativity level for `in`, making it weaker/looser than the other binary operators. E.g., changing the last line to ``` '((assoc "in") (assoc ";") (assoc "+") (assoc "*"))))) ``` This is because the parser needs to be able to see that ``` let e1 in e2 + e3 ``` should be parsed as ``` let e1 in (e2 + e3) ``` rather than ``` (let e1 in e2) + e3 ``` --- Tags: indentation, smie ---
thread-58456
https://emacs.stackexchange.com/questions/58456
Split Emacs Screen Three Ways
2020-05-12T04:53:23.447
# Question Title: Split Emacs Screen Three Ways In my .emacs file I have `(split-window-right)`. This has been working fine so far, but now I'm finding it would be easier if my workspace looked like: where each box is a separate window. So really I just need to split the right window in half after the initial split on startup. How can I do this? # Answer > 9 votes you can: * add this to your `.emacs` file ``` (split-window-right) (other-window 1) (split-window-below) (other-window -1) ``` * set it up manually any time: `C-x 3` `C-x o` `C-x 2` `C-- C-x o` * consider using one of those window manager extensions, like edwina, if your requeriments become more complex. Any option you choose taking a look to `C-h i m emacs [RET] m windows` will be useful. --- Tags: window-splitting ---
thread-58425
https://emacs.stackexchange.com/questions/58425
How to access Query-replace history in replace format (for eg: "ABC → XYZ")
2020-05-11T07:57:13.693
# Question Title: How to access Query-replace history in replace format (for eg: "ABC → XYZ") I have enabled query replace save history as below. When I am in query-replace mode, I see previous search-replace patterns of the current session in the form "ABC -\> XYZ". But the search-replace patterns from previous emacs sessions dont show up as "LMN -\> PQR" instead they show up as LMN for search pattern and then I need to again search for PQR as replace pattern. Is there a way to improve this? ``` ;;Save Search history (setq savehist-additional-variables '(search-ring regexp-search-ring compile-history) savehist-file "~/.emacs.d/savehist") (savehist-mode t) ``` # Answer > 2 votes The history of query-replace replacement pairs can be saved by adding `query-replace-defaults` (and also optionally `query-replace-history`) to `savehist-additional-variables`. --- Tags: search, query-replace ---
thread-10884
https://emacs.stackexchange.com/questions/10884
mu4e - multiple accounts
2015-04-23T08:38:06.373
# Question Title: mu4e - multiple accounts I am using `mu4e` for email in Emacs, and it is currently only configured for one mail account, and I set key to view different inbox. I wonder how to use mu4e for managing multiple email accounts? # Answer I'm using mu4e with two accounts. Each account has its own maildir: ``` ~/Mail | +---- work | `---- private ``` The manual comes with an example function to choose an account: ``` (defun my-mu4e-set-account () "Set the account for composing a message." (let* ((account (if mu4e-compose-parent-message (let ((maildir (mu4e-message-field mu4e-compose-parent-message :maildir))) (string-match "/\\(.*?\\)/" maildir) (match-string 1 maildir)) (completing-read (format "Compose with account: (%s) " (mapconcat #'(lambda (var) (car var)) my-mu4e-account-alist "/")) (mapcar #'(lambda (var) (car var)) my-mu4e-account-alist) nil t nil nil (caar my-mu4e-account-alist)))) (account-vars (cdr (assoc account my-mu4e-account-alist)))) (if account-vars (mapc #'(lambda (var) (set (car var) (cadr var))) account-vars) (error "No email account found")))) ;; ask for account when composing mail (add-hook 'mu4e-compose-pre-hook 'my-mu4e-set-account) ``` For that to work you will also need the `my-mu4e-account-alist`: ``` (defvar my-mu4e-account-alist '(("private" (user-mail-address "private@domain.net") (user-full-name "My Name") (mu4e-sent-folder "/private/Sent Items") (mu4e-drafts-folder "/private/Drafts") (mu4e-trash-folder "/private/Deleted Items") (mu4e-refile-folder "/private/Archive")) ("work" (user-mail-address "work@domain.net") (mu4e-sent-folder "/work/Sent Items") (mu4e-drafts-folder "/work/Drafts") (mu4e-trash-folder "/work/Deleted Items") (mu4e-refile-folder "/work/Archives")))) (setq mu4e-user-mail-address-list (mapcar (lambda (account) (cadr (assq 'user-mail-address account))) my-mu4e-account-alist)) ``` You can simply switch between mail folders with `j`, as long as all of your maildirs are subdirectories of `mu4e-maildir`. I'm actually using a more elaborate function for `mu4e-trash-folder` and `mu4e-refile-folder` to avoid moving emails from one maildir over to another, but the information above should be sufficient to use multiple accounts. > 17 votes # Answer I'm using two different accounts that I want to mix as little as possible. *offlineimap* is configured with two accounts, one delivering mail into `~/.maildir-work` the other one into `~/.maildir-home`. My configuration for *mu4e* uses the new context mechanism: ``` (setq mu4e-contexts `( ,(make-mu4e-context :name "home" :match-func (lambda (_) (string-equal "home" (mu4e-context-name mu4e~context-current))) :enter-func '() :leave-func (lambda () (mu4e-clear-caches)) :vars '((mu4e-maildir . "~/.maildir-home") (mu4e-mu-home . "~/.mu-home") (mu4e-get-mail-command . "offlineimap -a Home") ...)) ,(make-mu4e-context :name "work" :match-func (lambda (_) (string-equal "work" (mu4e-context-name mu4e~context-current))) :enter-func '() :leave-func (lambda () (mu4e-clear-caches)) :vars '((mu4e-maildir . "~/.maildir-work") (mu4e-mu-home . "~/.mu-work") (mu4e-get-mail-command . "offlineimap -a Work") ...)))) ``` > 10 votes # Answer I'm using a setup very similar to Magnus', and just wanted to add that `(mu4e-quit)` exists, and it works fine for cleaning up accounts without restarting. Actual mechanism: ``` (defun mail-gmail () (interactive) (setenv "MAILDIR" "/Users/foo/Maildir/gmail") (setenv "MU_HOME" "/Users/foo/.mu/gmail") (setq mu4e-maildir "/Users/foo/Maildir/gmail") (setq user-mail-address "...") (mu4e-quit)) ``` > 5 votes # Answer After reading all previous answers in this thread and tweaking around, I came up with the following solution, that assumes separate contexts have been defined, which include a redefinition of `mu4e-maildir` and `mu4e-mu-home`. As stated in comments to older answers, it is necessary to quit and restart `mu4e` when these two variables are redefined. The trick is to replace the default behaviour of `;` in order to accomplish this automatically when changing context (it will still ask for confirmation for the "quit" step): ``` (defun dak-switch-mail-account () "quit and reload mu4e to properly change context, i.e. account" (interactive) (mu4e-context-switch) ; will ask for new context (mu4e-quit) ; necessary for new context to change maildir and mu-home (sit-for .5) ; mu4e-quit needs a bit of time before mu4e can be properly restarted (mu4e) ) ;; rebinding of context switch key: (define-key mu4e-main-mode-map (kbd ";") 'dak-switch-mail-account) (define-key mu4e-headers-mode-map (kbd ";") 'dak-switch-mail-account) ;; and possibly on other mu4e modes as well ``` > 3 votes --- Tags: mu4e ---
thread-58285
https://emacs.stackexchange.com/questions/58285
orgmode latex export: How to create repeatable labels?
2020-05-05T08:43:41.507
# Question Title: orgmode latex export: How to create repeatable labels? Every time I export org-mode document to LaTeX, most sections get new and unique labels, e.g., ``` \section{Introduction} \label{sec:orge0665da} ``` The next time I export the document, the label will change, e.g., ``` \section{Introduction} \label{sec:orgcd0c5bf} ``` If I want to do a `diff` of the LaTeX documents to a previous version, I get a ton of changed labels that hide the changes I have made to the text. Sometimes this confuses `latexdiff` as well. Is there a way to ensure that the exported labels are the same between exports? At least for as long as the number of (sub)sections does not change? Set a seed to a random number generator? Write a hook function that returns a label given a section? I am aware of Is there a way to suggest label names in org-mode latex export?, that solves the problem for a specific label, but not the (in org-mode) un-labelled sections. # Answer > 2 votes I think you hit on the solution yourself: > Set a seed to a random number generator? That seems to work just fine in my limited testing. The function `org-export-new-reference` in `ox.el` does indeed call `random` to generate the reference label. To seed the random number generator, call `random` with some *string* (it seeds the generator with some value computed from the string). If you want the generator seeded before every single export use the `org-export-before-processing-hook`: ``` (defun seed-random-generator (_) (random "a fixed and unchanging string")) (add-hook 'org-export-before-processing-hook #'seed-random-generator) ``` (To be honest, I don't really understand why you'd want to diff the generated LaTeX files instead of diffing the original org files. At least you're not diffing PDFs. :P) --- Tags: org-mode, org-export, latex ---
thread-58450
https://emacs.stackexchange.com/questions/58450
How to add a specific extension on filename for new files?
2020-05-11T22:04:48.333
# Question Title: How to add a specific extension on filename for new files? Say i create a new file using `find-file` (by typing a non-existing filename, since it create a newfile with said filename) How could i add the .org extensions at the end automatically? I heard of hooks on emacs but i wasn't sure if this was the solution, so here i am. To Clarify: I don't mind if every new files created have a .org extensions, as i center my workflow around `org-mode` like a lots of others do. Here `find-file` is just to be specific, but in general, i wouldn't mind if it happen even outside of using `find-file`. # Answer I'd do it this way: ``` (defun add-default-extension (retval) (let ((filename (car retval))) ; retval is (filename t) (if (or (file-exists-p filename) (file-name-extension filename)) retval (message "Adding default .org extension") (list (concat filename ".org") t)))) (advice-add 'find-file-read-args :filter-return #'add-default-extension) ``` (Well, it would be more accurate to say "I wouldn't do it, but if I had to, I'd do it this way:" :P) --- **EDIT**: The above answer only add `.org` to file names typed interactively at the `find-file` prompt, but I read in the comments to the question that you are actually not using `find-file` but this function instead: ``` (defun find-file-region() (interactive) (if (region-active-p) (let ((str (buffer-substring (region-beginning) (region-end)))) (find-file str)) (message "No region active"))) ``` In that case, just add the extension there: ``` (defun find-file-region () (interactive) (if (region-active-p) (let ((str (buffer-substring (region-beginning) (region-end)))) (find-file (if (or (file-exists-p str) (file-name-extension str)) str (concat str ".org")))) (message "No region active"))) ``` > 1 votes --- Tags: find-file ---
thread-58462
https://emacs.stackexchange.com/questions/58462
emacs deamon how to keep mode-line-frame-identification at 1
2020-05-12T13:07:08.230
# Question Title: emacs deamon how to keep mode-line-frame-identification at 1 Each time when I open a new file using `emacsclient -t -q file.txt`, `mode-line-frame-identification` number keep increases. What is the reason for it, and can I reaccess to previously numbered frames? ``` -UU-:---F1 -UU-:---F2 -UU-:---F3 ... -UU-:---F50 ``` Is it possible to keep it at `1`, or when `emacsclient` starts connect to `F1` instead of incrementing its value? # Answer > 1 votes Every time you connect to emacs with `emacsclient -t`, it creates a new frame, hence the number keeps increasing. Those frames are destroyed when you disconnect with `C-x #`, so there's no way to get back to them. If you want to change what's displayed in the mode-line, you can change `mode-line-format` to remove or replace `mode-line-frame-identification`. --- Tags: menu-bar ---
thread-58441
https://emacs.stackexchange.com/questions/58441
How to replace the highlighted word in yasnippet?
2020-05-11T16:04:04.853
# Question Title: How to replace the highlighted word in yasnippet? After the snippet gets expanded the cursor is put to the first section (long\_name). What key do I need to press in order to **replace long\_name**? Evil operations like e.g. `cw` or `ce` change *long* or to the line end, while I only want to replace **long\_name** # Answer I think what you're looking for is to treat the underscore as part of the word, as Vim does. The best answer is probably this one \- look at the solution adding advice around `evil-inner-word` > 1 votes --- Tags: spacemacs, yasnippet ---
thread-58471
https://emacs.stackexchange.com/questions/58471
Why isn't Melpa showing some packages?
2020-05-12T17:58:34.070
# Question Title: Why isn't Melpa showing some packages? I want to install the following package in spacemacs: https://github.com/clojure-emacs/clj-refactor.el, but when I do this: M-x package-install clj-refactor, I don't see a clj-refactor option in Melpa suggestions. Instead I see a discover-clj-refactor package. Why isn't Melpa showing the cli-refactor package? Do I have to update Melpa or something? # Answer `clj-refactor` is included with Spacemacs. `package-install` only lists packages that aren't already installed. Try `package-list-packages` to see all packages, installed and uninstalled. > 1 votes --- Tags: package-repositories ---
thread-58476
https://emacs.stackexchange.com/questions/58476
Any example of using SVG bultin library?
2020-05-13T03:49:19.890
# Question Title: Any example of using SVG bultin library? I heard that you could draw SVG in emacs using the `svg.el` library, but while i managed to get the right dependencies (I'm on ubuntu 19.10) and while compiling the latest version from the savannah.gnu repo work great, i couldn't see anything related to svg (`svg.el`) being used.(that is, i couldn't find it using `M-x`) Though, from what i seen, it does work as i managed to install `svg-clock` but, nothing else show up in the `M-x` prompt about svg... And yes, i also added `imagemagick` support to emacs, but no dice. Additional details: I'm also using `lucid` instead of the gtk gui. Here the full configure flags i used `./configure --with-x-toolkit=lucid --with-xml2 --with-xft --with-libotf --with-imagemagick --with-rsvg` Basically i want either examples of how to use the `svg.el` (mostly so i can check if it's actually being used, or to check if it wasn't meant to be launched using `M-x`) Lastly, i did used `(image-type-available-p 'svg)` to check whether it was available or not, and it was indeed...it just didn't appear in the prompt of `M-x`. # Answer > 3 votes The SVG library is a library for programmatic generation of SVG images. Check out the source code of svg-clock.el for an example of how to use it: http://git.savannah.gnu.org/cgit/emacs/elpa.git/tree/packages/svg-clock/svg-clock.el Here's a simplified example you can evaluate in the scratch buffer: ``` (require 'svg) (let ((buffer "*svg-test*") (width 200) (height 100)) (with-current-buffer (get-buffer-create buffer) (let (buffer-read-only) (erase-buffer) (let ((svg (svg-create width height))) (svg-gradient svg "bg" 'linear '((0 . "#000") (100 . "#fff"))) (svg-rectangle svg 0 0 width height :gradient "bg") (svg-insert-image svg)) (special-mode))) (display-buffer buffer)) ``` --- Tags: graphics ---
thread-58477
https://emacs.stackexchange.com/questions/58477
Any ways to Draw SVG?
2020-05-13T04:40:59.110
# Question Title: Any ways to Draw SVG? I'm used to the `artist-mode` and though it work decently, i was wondering if it was already possible (with builtin or external library) to draw SVG, either with the mouse, or any other method beside using elisp code to construct it. I'm aware of a couple project that generate SVG on github, but most if not all construct it with elisp, which isn't really what i want.(while i want to draw it in emacs using either the mouse or keyboard like `artist-mode` does). # Answer > 3 votes There is an interactive SVG generation demo on GitHub: https://github.com/sabof/svg-thing Honestly though, I recommend you to use a dedicated vector graphics program for the task. Inkscape hit version 1.0 recently. --- Tags: graphics ---
thread-58487
https://emacs.stackexchange.com/questions/58487
How can I fix if: Invalid search bound (wrong side of point) in mu4e?
2020-05-13T12:59:36.873
# Question Title: How can I fix if: Invalid search bound (wrong side of point) in mu4e? mu4e works quite well here, but I have one big problem: When I try to reply to an email, I get this error: ``` re-search-forward("^#![ ]?\\([a-zA-Z_./]+\\)" 50 t) (if (re-search-forward "^#![ ]?\\([a-zA-Z_./]+\\)" 50 t) (let ((interpreter (buffer-substring (match-beginning 1) (match-end 1)))) (if (or (not (= (string-match "/" interpreter) 0)) (not (and (file-exists-p interpreter) (file-executable-p interpreter)))) (message "%sWarning: `%s' is not a valid interpreter.")))) (save-excursion (goto-char 1) (if (re-search-forward "^#![ ]?\\([a-zA-Z_./]+\\)" 50 t) (let ((interpreter (buffer-substring (match-beginning 1) (match-end 1)))) (if (or (not (= (string-match "/" interpreter) 0)) (not (and (file-exists-p interpreter) (file-executable-p interpreter)))) (message "%sWarning: `%s' is not a valid interpreter."))))) shebang-check-interpreter() run-hooks(after-save-hook) basic-save-buffer(nil) save-buffer() (closure (mu4e-compose-mode-abbrev-table mu4e-compose-mode-syntax-table t) nil (if (eq mu4e-compose-type 'reply) (progn (mu4e~remove-refs-maybe))) (if use-hard-newlines (progn (mu4e-send-harden-newlines))) (set-buffer-modified-p t) (save-buffer) (mu4e~compose-setup-fcc-maybe) (widen))() run-hooks(message-send-hook) message-send(nil) message-send-and-exit(nil) funcall-interactively(message-send-and-exit nil) call-interactively(message-send-and-exit nil nil) command-execute(message-send-and-exit) ``` The normal mail headers, when replying, look like this: ``` From: Markus Grunwald <markus@the-grue.de> To: Markus Grunwald <markus@the-grue.de> Subject: Re: Attachment Signatur? Date: Wed, 13 May 2020 14:52:15 +0200 In-reply-to: <87d078qazs.fsf@bob.galaxy.home> --text follows this line-- ``` When I delete the `In-reply-to:` header, the mail is sent... # Answer > 1 votes I installed shebang.el from emacswiki: https://www.emacswiki.org/emacs/MakingScriptsExecutableOnSave Removing it solved the issue. --- Tags: mu4e ---
thread-58489
https://emacs.stackexchange.com/questions/58489
How do I debug `Package cl is deprecated`?
2020-05-13T14:17:20.647
# Question Title: How do I debug `Package cl is deprecated`? While compiling an Elisp package from github, I get the > Warning: Package cl is deprecated **How do I find out what triggers it?** The specific file that triggers this is tiny and has no CL code. I think there should be a way to turn the warning into an error and get the stack trace. Has anyone done this before? # Answer Try the following in an Emacs session with the code in question loaded up: ``` (require 'loadhist) (file-dependents (feature-file 'cl)) ``` > 26 votes --- Tags: debugging, warning, cl ---
thread-58478
https://emacs.stackexchange.com/questions/58478
How to send a string to the SQLi (sql-mode/sql-interactive-mode) buffer after processing?
2020-05-13T05:11:50.153
# Question Title: How to send a string to the SQLi (sql-mode/sql-interactive-mode) buffer after processing? How can I send a selected region in the sql-mode buffer to an external shell command and let the result be displayed in the sql-interactive-mode buffer (REPL)? For example, normally, if I select a region in the sql-mode buffer (e.g. `my_table`) and hit `C-c C-r`, the text in the region is sent to the sql-interactive-mode buffer (REPL area) and evaluated as a SQL statement (which will generate an error since `my_table` isn't a valid statement). Can I alter this behavior so that, the text is first sent to a unix shell command as input, and then the output of shell command is collected and displayed in the interactive-mode buffer? The shell command I have in mind is this: ``` { read message; psql -c "\\d+ $message"; } ``` The closest thing I can find is this emacs.SE example, ``` (defun wc-region (beg end) "Count words in the active region." (interactive "*r") (if (region-active-p) (shell-command-on-region beg end "wc -w") (message "No active region"))) ``` which sends the select text to the Unix shell that does something (a word count) on it, and shows the result in a buffer called "Shell Command Output". But I'd like to have it work in a sql-mode buffer, and have the processed result displayed in the sql-interactive-mode buffer (REPL area) instead of a new buffer. Just as if I had sent a SQL statement to the REPL. I adapted the example above to: ``` (defun wc-region (beg end) "Count words in the active region." (interactive "*r") (if (region-active-p) (shell-command-on-region beg end " { read message; psql -c \"\\d+ $message\"; } ") (message "No active region"))) ``` which almost works except it's not sending output of the unix command to sql-interactive-mode buffer. Instead, it creates a new buffer for output. Ultimately, I want to select a table name in SQL-mode, and display its definition in the sql-interactive-mode buffer by hitting a shortcut key. But I don't know elisp well enough. -- Update -- @phils Thanks a lot for your answer. I have two more very basic questions: 1. can the shell `command` be fixed so that it doesn't have to be keyed in? The following command seems to work (with the second version): ``` { read s; echo "\\d+ $s"; } ``` Is there a way to fix `command` to the above string in a wrapper function or using `setq` somehow? 2. After executing the command, the focus is in the sql-mode, how can I automatically switch the focus to the sql-interactive-mode buffer after the command is issued? # Answer > 2 votes If you look at any of the definitions of the `sql-send-*` commands, you'll see they all hand off to `sql-send-string`. E.g.: ``` (defun sql-send-region (start end) "Send a region to the SQL process." (interactive "r") (sql-send-string (buffer-substring-no-properties start end))) ``` `shell-command-on-region` is a good place to look for how to obtain a string to pass to `sql-send-string`. That uses `call-process-region` behind the scenes, so a simple (will not handle errors) combination of the two could look like this: ``` (defun my-sql-send-region-via-shell-command (command start end) "Send a region to the SQL process via shell COMMAND." (interactive (list (read-shell-command "Shell command on region: ") (region-beginning) (region-end))) (let* ((buf (current-buffer)) (sql (with-temp-buffer (let ((tmpbuf (current-buffer))) (with-current-buffer buf (call-process-region start end shell-file-name nil tmpbuf nil shell-command-switch command)) (buffer-string))))) (sql-send-string sql))) ``` or perhaps this: ``` (defun my-sql-send-region-via-shell-command (command start end) "Send a region to the SQL process via shell COMMAND." (interactive (list (read-shell-command "Shell command on region: ") (region-beginning) (region-end))) (let ((temp-buffer-show-function (lambda (buf) (sql-send-string (with-current-buffer buf (buffer-string))) (kill-buffer buf)))) (with-output-to-temp-buffer (generate-new-buffer "sql") (call-process-region start end shell-file-name nil standard-output nil shell-command-switch command)))) ``` Entering `cat` as the shell command ought to give the same outcome as `sql-send-region`. --- > Is there a way to fix `command` in a wrapper function? Sure, you just need to read the `start` and `end` and then pass them along with a hard-coded `command`. ``` (defun my-sql-send-region-via-FOO (start end) "Send a region to the SQL process via shell command FOO." (interactive "r") (my-sql-send-region-via-shell-command "FOO" start end)) ``` You could also make `start` and `end` optional, and have the main function figure them out when they're not passed. I'll leave that as an exercise for the reader... > how can I automatically switch the focus to the `sql-interactive-mode` buffer after the command is issued? It looks like `sql-send-string` supports that directly; try adding `(sql-pop-to-buffer-after-send-region t)` to the outermost `let` bindings. --- Tags: sql-mode, sql-interactive-mode ---
thread-58486
https://emacs.stackexchange.com/questions/58486
Trying to use `pdfgrep` program from within my command
2020-05-13T12:45:03.407
# Question Title: Trying to use `pdfgrep` program from within my command I want to be asked what string `%s` I want \[0\] pdfgrep to search for? While `M-x pdfgrep mysearchString` works, I'm somehow missing something on wrapping it up as sole function? ``` (require 'pdfgrep) (pdfgrep-mode) (defun myPdfSearch () (interactive) (pdfgrep -H -n -i -r %s /home/pdf/)) Symbol’s value as variable is void: -H [0] https://github.com/jeremy-compostella/pdfgrep ``` # Answer > 2 votes The `pdfgrep` *function* that you call from lisp is not the `pdfgrep` *program* that you invoke from the command line, so you have to format the arguments as the function expects. Try: ``` (defun myPdfSearch (s) (interactive "sSearch string: ") (pdfgrep (format "pdfgrep -H -n -i -r -e \"%s\" /home/pdf/*.pdf" s))) ) ``` This is the equivalent of the command line invocation ``` pdfgrep -H -n -i -r -e "<string>" /home/pdf/*.pdf ``` It's a good idea to use `-e` to signal that the next argument is the expression to search for and to quote that expression to protect spaces and metacharacters from tripping up the shell invocation. AFAICT, `pdfgrep` requires *files* as arguments, not directories, so you have to use the glob pattern to pick up all the PDF files in the specified directory. I also had to load the `pdfgrep` library and evaluate `(pdfgrep-mode)` before I could use the above. --- Tags: interactive ---
thread-58483
https://emacs.stackexchange.com/questions/58483
Syntax coloring: Unable to color special syntax
2020-05-13T07:09:01.970
# Question Title: Syntax coloring: Unable to color special syntax I am writing a mode to color a few common syntax in a symbolic language called FORM. I am a new user of emacs and I took the help of this website to write down the following code. I modified the original code changing the syntax that I want to be colored. But keywords that have special characters (hash # / dot . /underscore _ ), such as "#define", "...", "(dot)sort", "(dot)end", "d\_" etc, **do not show color**. ``` (setq form-font-lock-keywords (let* ( ;; define several category of keywords (x-keywords '("S" "s" "V" "v" "I" "i" "F" "f" "CF" "cf")) (x-types '("#define" "...")) (x-constants '(".sort" ".end" ".store" ".global" ".clear" )) (x-events '("break" "bracket" )) (x-functions '("d_" "g_" "g5_" "g6_" "g7_" "gi_")) ;; generate regex string for each category of keywords (x-keywords-regexp (regexp-opt x-keywords 'words)) (x-types-regexp (regexp-opt x-types 'words)) (x-constants-regexp (regexp-opt x-constants 'words)) (x-events-regexp (regexp-opt x-events 'words)) (x-functions-regexp (regexp-opt x-functions 'words))) `( (,x-types-regexp . font-lock-type-face) (,x-constants-regexp . font-lock-constant-face) (,x-events-regexp . font-lock-builtin-face) (,x-functions-regexp . font-lock-function-name-face) (,x-keywords-regexp . font-lock-keyword-face) ;; note: order above matters, because once colored, that part won't change. ;; in general, put longer words first ))) (define-generic-mode form-mode nil "form mode" "Major mode for editing FORM symbolic tool." ;; code for syntax highlighting (setq font-lock-defaults '((form-font-lock-keywords)))) (provide 'form-mode) ``` To my understanding, what I did was: 1. I have defined categories of the keywords --\> x-*name of the category* 2. Generated regular expression - regex (I am not sure of its function in this context) for each category 3. assigned regex to a font that has unique color 4. set nil as parent mode At first I thought that my parent mode was not accurate to show color for #/./\_ symbols, but now I think that's not the main issue. I think the problem comes from 1-3 options. Please provide your valuable suggestion on this problem. Many thanks! # Answer > 1 votes I think that is because `(regexp-opt foo 'words)` assumes that your keywords are, well, words. Try to rewrite those expressions (and *only* those, leave the alphabetic ones alone) like this: ``` (defun gmunu--concat-regexp (stuff) (if (null stuff) "" (let ((result (regexp-quote (car stuff))) (remaining (cdr stuff))) (while remaining (setq result (concat result "\\|" (regexp-quote (car remaining)))) (setq remaining (cdr remaining))) result))) ``` and then change `(regexp-opt foo 'words)` to `(gmunu--concat-regexp foo)` Untested, but I'm confident this is the gist of the problem. --- Tags: fonts, font-lock, syntax-highlighting, colors, syntax ---
thread-54499
https://emacs.stackexchange.com/questions/54499
org cycle visibility of drawers
2019-12-22T22:33:45.493
# Question Title: org cycle visibility of drawers I use drawers extensively. As a result, They tend to get long.I would like a mechanism to fold them like headlines. I found `outline-show-all` command which makes drawers visible. I would like a global, headline specific and headline recursive mechanisms for toggling the visibility of drawers. # Answer For now I figured out that running `org-mode` on file automatically folds everything including drawers. Doesn't have the granularity that I am looking for but a great counter part for `outline-show-all`. > 1 votes --- Tags: org-mode ---
thread-58283
https://emacs.stackexchange.com/questions/58283
How do I modify magits behavior to use the date that I finalize the commit and not the date that I start the commit
2020-05-05T05:59:34.043
# Question Title: How do I modify magits behavior to use the date that I finalize the commit and not the date that I start the commit Desired Solution: I want magit to make a commit with a datetime set to the time that I "create" the commit, not the time that I start the commit "creation" flow. **Background:** So committing in magit in general follows these steps: 1. `S` Stages all files. 2. `c c` Initiates a commit, then write the message in the "commit buffer". 3. `C-c C-c` to actually create the commit. The thing that surprises me is that the datetime of the created commit is actually the datetime that I pressed `c c`, NOT the time that I pressed `C-c C-c`. I find this very annoying as I am trying to be better about writing more detailed commits (often spending a few minutes on them). The date of the commit does not reflect when I actually *created* the commit, it instead reflects when I *started* the commit. **Details**: Why do I care about being off by a few minutes? Because I am recording videos as I work and would like to slice them at the commit points. However, the commit points are all a few minutes before the actual commit was made in the video. This is kind of annoying. # Answer > 3 votes `magit-commit-reshelve` on `c n` is intended for that use-case. \[Well not your very specific use-case in particular, more the general idea.\] It is disabled by default; see Enabling and Disabling Suffixes. A multi-commit variant exists as well; `magit-reshelve-since` on `r t`. # Answer > 1 votes My solution to the problem was to register a post-commit hook that "nudged" the commit & author date. It has the possibility of running endlessly, but on my machine it only runs once or twice. Anyway, it does set the commit time to be immediately after I submit my commit message. ``` #!/bin/sh STR1=$(git log -1 --format=%cd --date=iso | sed 's/[^0-9]*//g') STR2=$(date --iso-8601=seconds | sed 's/[^0-9]*//g') if [ "$STR1" != "$STR2" ]; then sleep 0.1s git commit --amend --no-edit --date=now fi ``` Source Code Here --- Tags: magit, git ---