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-59635
https://emacs.stackexchange.com/questions/59635
Wrong type argument: undo-tree, [cl-struct-undo-tree [nil ([nil ([nil nil ]]]
2020-07-14T23:03:42.960
# Question Title: Wrong type argument: undo-tree, [cl-struct-undo-tree [nil ([nil ([nil nil ]]] The way I installed `undo-tree`: * M-x `package-install` `undo-tree` My setup: * GNU Emacs 26.3 * undo-tree 0.7.4 installed Treat undo history as a tree ``` (global-undo-tree-mode 1) (setq undo-tree-auto-save-history t) (setq undo-tree-history-directory-alist '(("." . "~/.emacs.d/undo"))) ``` --- Error I am getting: ``` Warning (initialization): An error occurred while loading ‘/home/netlab/.emacs’: Wrong type argument: undo-tree, [cl-struct-undo-tree [nil ([nil ([nil nil ((q . -1) (undo-tree-id0 . -1) 2) nil (24247 15636 187465 670000) 0 nil]) ((1 . 2) (t 24232 5976 416148 754000)) nil (24247 15636 187476 578000) 0 nil]) nil nil (24247 15636 187481 124000) 0 nil] [nil nil ((q . -1) (undo-tree-id0 . -1) 2) nil (24247 15636 187465 670000) 0 nil] 41 2 nil] To ensure normal operation, you should investigate and remove the cause of the error in your initialization file. Start Emacs with the ‘--debug-init’ option to view a complete error backtrace. ``` I am not sure how can I fix this error or what causing it. --- ### Update: Output of the debug output: ``` Debugger entered--Lisp error: (wrong-type-argument undo-tree [cl-struct-undo-tree [nil ([nil ([nil nil (... ... 2) nil (24247 15636 187465 670000) 0 nil]) ((1 . 2) (t 24232 5976 416148 754000)) nil (24247 15636 187476 578000) 0 nil]) nil nil (24247 15636 187481 124000) 0 nil] [nil nil ((#("q" 0 1 (fontified t)) . -1) (undo-tree-id0 . -1) 2) nil (24247 15636 187465 670000) 0 nil] 41 2 nil]) signal(wrong-type-argument (undo-tree [cl-struct-undo-tree [nil ([nil ([nil nil ... nil ... 0 nil]) ((1 . 2) (t 24232 5976 416148 754000)) nil (24247 15636 187476 578000) 0 nil]) nil nil (24247 15636 187481 124000) 0 nil] [nil nil ((#("q" 0 1 (fontified t)) . -1) (undo-tree-id0 . -1) 2) nil (24247 15636 187465 670000) 0 nil] 41 2 nil])) undo-tree-load-history(nil noerror) undo-tree-load-history-from-hook() run-hooks(find-file-hook) after-find-file(nil t) find-file-noselect-1(#<buffer __init__.py> "~/folder/__init__.py" nil nil "~/folder/__init__.py" (29887794 2050)) find-file-noselect("/home/alper/folder/__init__.py") mapcar(find-file-noselect ("/home/alper/folder/Driver.py" "/home/alper/folder/__init__.py" "/home/alper/folder/config.py" "/home/alper/folder/end_code.py" "/home/alper/folder/garbageCollector.py" "/home/alper/folder/imports.py" "/home/alper/folder/ipfs_daemon.py" "/home/alper/folder/lib.py" "/home/alper/folder/link.py" "/home/alper/folder/setup.py" "/home/alper/folder/start_code.py" "/home/alper/folder/thread_log.py" "/home/alper/folder/utils.py" "/home/alper/folder/whisper_state_receiver.py")) find-file-noselect("*.py" nil nil t) find-file("*.py" t) eval-buffer(#<buffer *load*> nil "/home/alper/.emacs" nil t) ; Reading at buffer position 25178 load-with-code-conversion("/home/alper/.emacs" "/home/alper/.emacs" t t) load("~/.emacs" t t) #f(compiled-function () #<bytecode 0x2967a1>)() command-line() normal-top-level() ``` --- ### desktop output: # Answer > 3 votes A few years ago, I created a fork of `undo-tree` that was compatible with Emacs 25 (but not later/newer versions of Emacs) and I spent a considerable amount of time debugging in relation thereto. As part of that work, I inspected and debugged countless `undo-tree` saved history files -- that prior work helped me to identify the initial cursory debugging message and *guess*-timate the problem. Initial attempts at troubleshooting the problem in the comments underneath the question above were complicated because the O.P. had suppressed visibility of hidden files in the `undo-tree` saved history file directory, and the O.P. was under the initial misimpression that the directory was empty. It turned out that the saved `undo-tree` history file was indeed where it was supposed to be, just hidden from view. Deleting that file resolved the issue. It is possible to spend additional time trying to ascertain why the `undo-tree` saved history file became problematic, but we will leave that issue for another question at some point in the future (should the need arise). @NickD requested a lengthier backtrace as suggested by the initial cursory debugging message; i.e., "*Start Emacs with the `--debug-init` option to view a complete error backtrace.*" And once the O.P. provided that detailed backtrace, it became crystal clear where the problem was as mentioned hereinabove. --- Tags: undo-tree-mode ---
thread-59649
https://emacs.stackexchange.com/questions/59649
The global value of a variable I set with setq in my config differs from the local value. How can I get my value to be what I want in every buffer?
2020-07-15T17:33:29.393
# Question Title: The global value of a variable I set with setq in my config differs from the local value. How can I get my value to be what I want in every buffer? I want `web-mode-script-padding` to be set to 0 at all times. In my config, I have tried both > ``` > (with-eval-after-load 'web-mode > (setq web-mode-script-padding 0) > ) > > ``` As well as simply, > ``` > (setq web-mode-script-padding 0) > > ``` If I open a new window, and then a webmode file, the behavior of pressing TAB and other things indicates that the value is not set how I want it to be (this after reset so my new config is reloaded). So, I do `M-x describe-variable web-mode-script-padding`. I see: ``` web-mode-script-padding is a variable defined in ‘web-mode.el’. Its value is 2 Original value was 1 Local in buffer Navbar.vue; global value is 0 ``` This is not what I want. I want the value to be 0. So I do `M-x set-variable web-mode-script-padding 0` in that buffer. Now, `describe-variable` shows ``` web-mode-script-padding is a variable defined in ‘web-mode.el’. Its value is 0 Original value was 1 Local in buffer CardList.vue; global value is the same. ``` Furthermore, in this buffer, the script-padding behaves as I want. However, opening a new buffer means I have to manually `set-variable` again to maintain this behavior. **How can I either `set-variable` so it applies to the entire frame, or get my `setq` in my config to "stick?"** Edit: In case this was a buffer-local variable, I tried setq-default, still not getting the desired behavior though. # Answer > 0 votes The description of the variable (`C-h``v`) also mentions: > You can customize this variable. Click on "customize", fill in the value and click "Apply and Save". This will add the line ``` '(web-mode-script-padding 0) ``` into the ``` (custom-set-variables ``` list, or create it, if it didn't exist. # Answer > 0 votes As @choroba has pointed out, this is apparently a user option (aka a customize variable). As a general rule, do *not* use `setq` or `setq-default` to set the value of a user option. This answer explains why. (I'm guessing this question seems to be about this problem, so I'm voting to close it as essentially a duplicate of that other question. If I'm mistaken, then this answer might help.) # Answer > 0 votes In file `.editorconfig`, someone had put this: ``` indent_size = 2 ``` For some reason, this overwrote the `web-mode-script-padding` value locally to this project. I removed that line, and it worked as expected. --- Tags: spacemacs, variables, web-mode, setq ---
thread-59662
https://emacs.stackexchange.com/questions/59662
How to pass an optional agrument to kill-emacs?
2020-07-16T11:05:10.340
# Question Title: How to pass an optional agrument to kill-emacs? I would like a way to make emacs to return a non-zero exit code when exiting. This page https://www.gnu.org/software/emacs/manual/html\_node/elisp/Killing-Emacs.html lists the command **kill-emacs** *&optional exit-data* as a mechanism for making emacs return with non-zero return code, stating *"If exit-data is an integer, that is used as the exit status of the Emacs process"*. How do I add this optional exit-data? I have tried: * Interactively using *`M-x` kill-emacs* but cannot type a space after that. * Setting up a binding in my *init.el* using `(global-set-key (kbd "C-x C-M-c") 'kill-emacs)`, but do not know the syntax well enough to pass an argument. I see this is related to How to set the exit status for emacsclient and How to make emacs or emacsclient exit with nonzero return code? , but I cannot get the answer I want from those questions/answers. Please can someone explain how to quit emacs with a non-zero return code and/or provide the syntax to setup a keyboard binding. # Answer Interactively, you can use a prefix argument. E.g.: * $ `emacs -Q` * `M-7` `M-x` `kill-emacs` `RET` * $ `echo $?` =\> `7` A command to do this, which you could bind to a key sequence, would be: ``` (defun my-kill-emacs () (interactive) "Exit emacs with status 7." (kill-emacs 7)) ``` > 2 votes --- Tags: exit ---
thread-59652
https://emacs.stackexchange.com/questions/59652
Is there a way to spread a list like in Typescript or Golang?
2020-07-15T18:35:34.943
# Question Title: Is there a way to spread a list like in Typescript or Golang? I have a variable with some common values between `dap-mode` debug templates and I want to use that variable along with other cons elements for `:environment-variable` in languages like Golang or Typescript you would do something like this: ``` variable = [1, 2, 3] another_variable = [...variable, 4, 5, 6] ``` then `another_variable` will carry the value of `[1, 2, 3, 4, 5, 6]` How can I do this in Emacs Lisp? **EDIT:** I know how you can evaluate something inside a list, this is using the backquote, my problem was that I didn't know how Elisp processes lists in a fashion that keep the result plain because, for instance in Python, you can end with something like `[1, [2, 3, 4]]` if `x` is `[1]` and you do `x.append([2, 3, 4])`; I didn't know that `,@` was a thing and that neither `append` keeps a plain list. # Answer You can use the backquote mechanism in combination with `,@` to splice the value of a variable into a list; or equivalently, use `append`: ``` (setq variable '(1 2 3)) (1 2 3) (setq another-variable `(-2 -1 0 ,@variable 4 5 6)) (-2 -1 0 1 2 3 4 5 6) ;; or... (setq another-variable (append '(-2 -1 0) variable '(4 5 6))) (-2 -1 0 1 2 3 4 5 6) ``` > 6 votes # Answer **Note:** A Lisp program should not try to modify self-evaluating forms or constant lists (bug#40671). These are internal data structures \[Message 42\]. Be aware that the final argument for `append` is not copied. ``` ELISP> (setq var1 (vector 'a 'b)) ELISP> (symbol-value 'var1) [a b] ELISP> (setq lst (append var1 (list 1))) ELISP> (symbol-value 'lst) (a b 1) ``` > 1 votes --- Tags: variables, list ---
thread-59659
https://emacs.stackexchange.com/questions/59659
encrypted password file with emacs & gpg
2020-07-16T01:40:45.007
# Question Title: encrypted password file with emacs & gpg I want to keep all my passwords and logins in a gpg-encrypted file, that I want to access using emacs in the terminal on ubuntu. I want to be prompted for the 'master' password when opening the file, but not when saving it. I don't want to use anything like a 'keyring'. I managed to almost achieve my desired setup by following the instructions here, the only problem being that I have to enter the password twice when saving the file. The problem is that I fear that when accidentally entering the password incorrectly twice, I could lock myself out of my password file forever. Is there a way not to be prompted for the password when saving, or alternatively for the save-password to be rejected when its hash doesn't match the password that I opened the file with? # Answer > 1 votes I remember struggling with this for quite some time. Like you, I'm using public/private key with a pass phrase, **not** symmetric encryption. What works is the following: ``` ;; let's get encryption established (require 'epa-file) (epa-file-enable) (setq epg-pinentry-mode 'loopback) (require 'org-crypt) (org-crypt-use-before-save-magic) ``` I do **not** unset `GPG_AGENT_INFO`. You should set `epg-gpg-program` if `gpg` is not in your `$PATH` by default. Setting `epg-pinentry-mode` to `loopback` is especially valuable to allow Emacs to query passphrase rather than external programs which might block the window or not work properly in containers and so forth. --- Tags: gpg ---
thread-59669
https://emacs.stackexchange.com/questions/59669
How emacsclient automatically startup with the most recent file?
2020-07-16T15:07:07.143
# Question Title: How emacsclient automatically startup with the most recent file? With the help of `recentf` I am able to open recently open files from its `buffer list`. As an example when I execute `icicle-buffer`, I can see the *buffer list*. I was wondering can I do this operation automatically where the most recent file (buffer) will be open with the help of a function instead of manually selecting. *Basically my main goal is:* when I open `emacsclient` I want to start it with the most recently file, which is I belive the first index file on the *buffer list*. # Answer > -1 votes In your .emacs file add the following (desktop-save-mode 1) Emacs will open back up exactly like it was sans any buffers not tied to files --- Tags: emacsclient, recentf ---
thread-59634
https://emacs.stackexchange.com/questions/59634
How to display agenda start day / end day in the header-line?
2020-07-14T20:42:56.090
# Question Title: How to display agenda start day / end day in the header-line? I'm trying to display the `org-starting-day` in the header line using the code below. It's working when I first display the agenda but it is not updated when I navigate forward / backward in the agenda. I guess I need some eval but I'm not sure how to do it. ``` (add-hook 'org-agenda-mode-hook #'(lambda () (setq header-line-format (format-time-string "%e %B %Y" org-starting-day)))) ``` Here is the result with a slightly modified code: # Answer > 0 votes I ended up with a slightly more complex code: ``` (defun iso-time (sd) (pcase-let ((`(,m ,d ,y) (calendar-gregorian-from-absolute sd))) (encode-time 0 0 0 d m y))) (add-hook 'org-agenda-mode-hook #'(lambda () (if org-agenda-overriding-arguments (setq agenda-start (iso-time (nth 1 org-agenda-overriding-arguments)) agenda-span (nth 2 org-agenda-overriding-arguments)) (setq agenda-start org-starting-day agenda-span org-agenda-span)) (cond ((and (numberp agenda-span) (> agenda-span 1)) (setq agenda-end (time-add agenda-start (* agenda-span 24 3600))) (setq agenda-range (concat (format-time-string "%e %B %Y" agenda-start) " - " (format-time-string "%e %B %Y" agenda-end)))) ;; Weekly view ((eq agenda-span 'week) (setq agenda-end (time-add agenda-start (* 7 24 3600))) (setq agenda-range (concat (format-time-string "%e %B %Y" agenda-start) " - " (format-time-string "%e %B %Y" agenda-end)))) ;; Two weeks view ((eq agenda-span 'fortnight) (setq agenda-end (time-add agenda-start (* 14 24 3600))) (setq agenda-range (concat (format-time-string "%e %B %Y" agenda-start) " - " (format-time-string "%e %B %Y" agenda-end)))) ;; Month view ((eq agenda-span 'month) (setq agenda-range (concat (format-time-string "%B %Y " agenda-start)))) ;; Default (t (setq agenda-range (concat (format-time-string "%e %B %Y " agenda-start))))) (setq header-line-format agenda-range))) ``` # Answer > 0 votes Here's an implementation that uses `org-agenda-finalize-hook`. The hook is run when the agenda is first run and also when the agenda is changed and `org-agenda-redo` is called, e.g. when you change the view from, say, a weekly agenda to a monthly agenda: the starting and ending dates are recalculated and redisplayed. The implementation depends on the following details: when the agenda is displayed, text properties are added to every line. You can check those properties with `C-u C-x =` with the cursor at the beginning of each line. The lines that contain the dates are distinguished by having the `org-date-line` property set to `t`. In addition, the date lines have a `day` property whose value is the absolute (i.e. Julian calendar) day number of that date, e.g. for today (2020-07-16) the value of the `day` property is 737622. You can turn an absolute day number into a calendar-like `(month day year)` date, using the following function: ``` #+begin_src emacs-lisp :results drawer (calendar-gregorian-from-absolute 737622) #+end_src #+RESULTS: :results: (7 16 2020) :end: ``` The function `ndk/org-agenda-first-last-day` below calculates the first day of the displayed agenda by going to the beginning of the agenda buffer and moving forward until it finds the first line with the `org-date-line` property, and then gets the value of the `day` property: that's the first day of the agenda. Similarly, it calculates the last day by going to the end of the buffer and moving backwards until it finds a date line: that's the last day of the agenda. It then returns a list of the two days: ``` (defun ndk/org-agenda-first-last-day () "Assumption: we are in the agenda buffer. Returns the first and last day of the current agenda as integers (Julian dates)." (let (first last) (save-excursion ;; find the first date line (goto-char (point-min)) (setq first (catch 'first (while (equal (forward-line) 0) (when (get-text-property (point) 'org-date-line) (throw 'first (get-text-property (point-at-bol) 'day)))))) ;; find the last date line (goto-char (point-max)) (setq last (catch 'last (while (equal (forward-line -1) 0) (when (get-text-property (point) 'org-date-line) (throw 'last (get-text-property (point-at-bol) 'day))))))) (list (or first (org-today)) (or last (org-today))))) ``` Note that there is no checking that we are in the agenda buffer, but since this will be called from the `org-agenda-finalize-hook`, there is not much danger: but even if you go calling it in an arbitrary buffer, it will return two "today"s, although it might take a long time to do so... The same thing happens in other agenda views (e.g. the global TODO list) where no such text properties are found. Since this function will still be called in such cases, we need to make sure that whatever it returns does not raise errors: today's absolute day will satisfy the calendar call below and seems like a reasonable default. The next function calls `ndk/org-agenda-first-last-day` above, converts the absolute day numbers to gregorian `(month day year)` lists, using the calendar function `calendar-gregorian-from-absolute`, and then formats a string with the two dates and sets the header line: ``` (defun ndk/org-agenda-first-last-day-head () (let ((dates (mapcar #'calendar-gregorian-from-absolute (org-agenda-first-last-day)))) (setq header-line-format (format "%s TO %s" (format-time-string (org-agenda-format-date-aligned (nth 0 dates))) (format-time-string (org-agenda-format-date-aligned (nth 1 dates))))))) ``` The formatting leaves a lot to be desired, but that should be easy to adjust to taste. Finally, we add this last function to `org-agenda-finalize-hook`, so that it gets called at `org-agenda-finalize` time. As noted above, this happens both when the agenda is created to begin with and after every reformatting that calls `org-agenda-redo`: ``` (eval-after-load 'org-agenda '(add-hook 'org-agenda-finalize-hook #'ndk/org-agenda-first-last-day-head)) ``` And that's all: all the code needs to be added to the init file: the `add-hook` has to be done after `org-agenda` is loaded to make sure that `org-agenda-finalize-hook` is defined, hence the `eval-after-load`. Since the agenda uses `calendar`, when the agenda is loaded, `calendar` will be loaded as well. --- Tags: org-agenda, header-line ---
thread-59682
https://emacs.stackexchange.com/questions/59682
Get keyboard macro mapping
2020-07-17T12:19:08.683
# Question Title: Get keyboard macro mapping What functionality is available in emacs to get information about a keyboard macro? Even something as simple as printing out what the macro evaluates. # Answer > 1 votes In *general* terms you can't really say what a keyboard macro does without executing it, because it's all contextual. What does `C-c C-c` do? It depends. What does `C-x o C-c C-c` do? That depends on even more things (like the window configuration you happen to have at the time). However... if you invoke the keyboard macro editor, it'll do the best it can to show you which commands the keys are going to call. It might be wrong about them, because the context available in the editor may not be the context in which you use the macro; but if your macro is pretty generic, you'll at least have a good idea. Use `C-x``C-k``e` to edit a keyboard macro. --- Tags: keyboard-macros ---
thread-59593
https://emacs.stackexchange.com/questions/59593
Exclude some headings from numbering
2020-07-12T13:35:35.773
# Question Title: Exclude some headings from numbering I would like to exclude some headings from numbering in `org-num-mode`. Is there a way to achieve this? # Answer You should read the commentary in the file: "You can select what is numbered according to level, tags, `COMMENT` keyword, or `UNNUMBERED` property. You can also skip footnotes sections. See `org-num-max-level`, `org-num-skip-tags`, `org-num-skip-commented`, `org-num-skip-unnumbered`, and `org-num-skip-footnotes` for details." For setting `org-num-skip-tags` (or most other variables) per file, one can always use file local variables. For example: ``` * foo foo * bar :unnumbered: bar * baz baz * Local variables :unnumbered: # Local Variables: # org-num-skip-tags: ("unnumbered") # End: ``` It's a very general customization mechanism. > 2 votes --- Tags: org-mode ---
thread-52198
https://emacs.stackexchange.com/questions/52198
Control depth level of table of contents with org-mode and beamer
2019-08-18T01:07:14.407
# Question Title: Control depth level of table of contents with org-mode and beamer I have the following in my org-mode file that I am exporting to beamer on the basis of this simple template: ``` * Introduction * More ** etc * Still more ** Some a ** Some b ** Some c ``` However, my TOC only renders: ``` More Still more ``` It neither renders the \** levels, nor the introduction, oddly. I'm sure this setting exists, but I don't understand how to ask the TOC to render all \** levels. What setting is controlling the level of TOC depth? # Answer > 1 votes This seems to be a Beamer-level issue, suggesting an Org Mode solution like so: ``` #+OPTIONS: H:1 num:t toc:nil \n:nil @:t ::t |:t ^:t -:t f:t *:t <:t #+BEAMER_FRAME_TITLE: 1 #+BEAMER_FRAME_LEVEL: 1 #+PROPERTY: header-args :exports both #+OPTIONS: H:1 #+LaTeX_HEADER: \input{list-of-frames.tex} * Outline :PROPERTIES: :BEAMER_env: ignoreheading :END: \addtocounter{framenumber}{-1} \begin{minipage}[c][\textheight][c]{\linewidth} \listofframes \end{minipage} * Main content Hello Beamer! ``` where the input file has these contents: ``` \makeatletter \newcommand\listofframes{\@starttoc{lbf}} \makeatother \addtobeamertemplate{frametitle}{}{% \addcontentsline{lbf}{section}{\protect\makebox[2em][l]{% \protect\usebeamercolor[fg]{structure}\insertframenumber\hfill}% \insertframetitle\par}% } ``` # Answer > 0 votes This is related to the number of levels exported as headlines, which is controlled by `org-export-headline-levels`. Which value does this variable have? The template you pointed to includes `#+OPTIONS: H:3`, are you sure you didn't alter that value? --- Tags: org-mode, beamer ---
thread-59351
https://emacs.stackexchange.com/questions/59351
Centering within comment blocks or ASCII art
2020-06-30T12:04:48.717
# Question Title: Centering within comment blocks or ASCII art I have C comments like this: ``` /****************************************************************************** * Includes * ******************************************************************************/ ``` I want to be able to center within the `*`'s like this: ``` /****************************************************************************** * Includes * ******************************************************************************/ ``` I've been unable to do this. If I try `M-x narrow-to-region` and use `M-x center-line`, it deletes all the spaces on the right hand side instead of preserving them. Using `M-x picture-mode` does not improve matters. I tried moving to the fill column using `M-x move-to-column` hoping it would fill in the spaces, but it stops at the current length in both picture and non-picture mode. # Answer > 0 votes I never found what I was looking for, so I ended up hacking the `center-line` elisp code like so: ``` (defun c-center-comment (&optional nlines) "Center the boxed comment point is on, within the width specified by `fill-column'. This means adjusting the space around the comment enclosed by asterisks (*) so that it equals the distance between the end of the text and `fill-column'. The argument NLINES says how many lines to center." (interactive "P") (if nlines (setq nlines (prefix-numeric-value nlines))) (while (not (eq nlines 0)) (save-excursion (let ((lm (current-left-margin)) line-length) (beginning-of-line) (delete-char 1) (delete-horizontal-space) (end-of-line) (forward-char -1) (delete-char 1) (delete-horizontal-space) (setq line-length (current-column)) (if (> (- fill-column lm line-length) 0) (progn (indent-line-to (+ lm (/ (- (- fill-column 1) lm line-length) 2))) (beginning-of-line) (if (< (% (- (- fill-column 1) lm line-length) 2) 1) (delete-char 1)) (insert-char ?\*) (end-of-line) (insert-char ?\ (+ lm (/ (- (- fill-column 1) lm line-length) 2))) (insert-char ?\*))))) (cond ((null nlines) (setq nlines 0)) ((> nlines 0) (setq nlines (1- nlines)) (forward-line 1)) ((< nlines 0) (setq nlines (1+ nlines)) (forward-line -1))))) ``` Note that this is very primitive. It assumes the line already starts and ends with an asterisk (change the `insert-char` commands to modify the character). If you want to center a new line, surround it with any sacrificial character, but I only wrote this for fixing existing comments, not for composing new ones. --- Tags: text-editing, c, narrowing, picture-mode ---
thread-59689
https://emacs.stackexchange.com/questions/59689
How to call `org-sparse-tree` from Lisp?
2020-07-17T15:13:13.917
# Question Title: How to call `org-sparse-tree` from Lisp? While viewing `org-mode` files I am used to typing `, - / t` to produce a sparse tree of todo items. I am trying, unsuccessfully, to write some Lisp to achieve the same thing. Here's the sort of thing I'm playing with, added to my init file: ``` (defun my-sparse-todo () (interactive) (org-sparse-tree nil "t")) (define-key evil-normal-state-map [f10] 'my-sparse-todo) ``` If I run this by hitting `f10`, I am prompted to enter the sparse tree type character. What am I doing wrong please? # Answer Try ``` (defun my-sparse-todo () (interactive) (call-interactively 'org-show-todo-tree)) ``` This is what `org-sparse-tree` does *after* you have selected `t` from the menu. > 1 votes --- Tags: org-mode ---
thread-59693
https://emacs.stackexchange.com/questions/59693
No php highlighting in .blade.php using web-mode
2020-07-17T19:01:27.473
# Question Title: No php highlighting in .blade.php using web-mode there's no highlighting php into a `.blade.php` file using `web-mode`. I just installed from MELPA and added this to my `.emacs` file: ``` (require 'web-mode) (add-to-list 'auto-mode-alist '("\\.html?\\'" . web-mode)) (add-to-list 'auto-mode-alist '("\\.php\\'" . web-mode)) (setq web-mode-engines-alist '(("php" . "\\.phtml\\'") ("blade" . "\\.blade\\.php\\.")) ``` # Answer > 0 votes You've told it this: ``` '(("php" . "\\.phtml\\'") ("blade" . "\\.blade\\.php\\.")) ``` One of those things is not like the other. Try opening a filename containing `.blade.php.` anywhere. --- Tags: web-mode ---
thread-19808
https://emacs.stackexchange.com/questions/19808
Align columns in Org mode table with Japanese fonts
2016-01-24T22:59:50.730
# Question Title: Align columns in Org mode table with Japanese fonts How can I mix Japanese and English in the same org-mode table (that uses fixed-width fonts)? Something like: ``` | m m m m m m | | | はどう デシウ | | | ハーフ | ハーフ | ``` won't align. Emacs simply counts the Japanese characters as one, when indeed they are more like 10% bigger. Could the width of a column be set in pixels? I know that \<10\> would set the width, but that does not help, since it counts in terms of fixed-width letters. The problem is basically how emacs aligns columns (using the font width). # Answer > 5 votes This depends on the fonts you are using. And I don't think Elisp has pixel level alignment capability. Org calculate width of string with `string-width` instead of `length`. `string-width` returns 1 for ASCII and Half width CJK chars or 2 for Full width chars. Evaluate the following code will show you that: ``` (string-width "m") 1 (string-width "ハ") 1 (string-width "は") 2 ``` Now, even though Org mode got the right answer from the sting property, and added pads around strings, it is the Emacs display engine's job to place where those bits go on the screen. Emacs display engine gets font information from the underlying OS. To make the complex problem simple, let's say that, with your configuration, `m`'s width is 5 pixels and "は" is 10. In this case they will be perfectly aligned because Org mode's assumption ("は" takes twice the width of "m") matches with the actual pixels on your screen. Instead, if your fonts configuration has 7 pixel for "m" and 10 pixel for "は", the things won't match up. And there is nothing Org mode nor the Display engine can do. They did what they told, by your configuration, to do. # Answer > 1 votes You need to prepare the monospace font with 1:2 height-width aspect ratio, so called "narrow" font, such as Inconsolata. Most programmer's fonts have the aspect ratio of 3:5, or so called "wide" font, that can not be fit with Japanese font when used with org-mode tables. Also, you must set your font height to be an even number. Otherwise, its width (half of height) wouldn't be an integer and would also cause problem on org-mode table alignment. --- Tags: fonts, org-table, display, align ---
thread-59601
https://emacs.stackexchange.com/questions/59601
Emacs org export shell script from txt file
2020-07-13T09:24:37.437
# Question Title: Emacs org export shell script from txt file I have a `.txt` file which is an org file but not with the `.org` file extension. I want to export the file to html on the command line, but it does not work if the file extension is `.txt`, only if the file extension is `.org`. ``` $ emacs alspac_data_guide.txt --batch -f org-html-export-to-html --kill Symbol’s function definition is void: org-html-export-to-html ``` I think this might be because it is not loading in org-mode? How do I modify the shell command to work correctly? # Answer > 0 votes Type `-*- mode:org -*-` at the top of file --- Tags: org-mode, org-export, batch-mode ---
thread-59661
https://emacs.stackexchange.com/questions/59661
Keybindings with Shift key does not work when CAPS is on
2020-07-16T04:17:26.177
# Question Title: Keybindings with Shift key does not work when CAPS is on I have this mnemonic keybinding which I placed in my config ``` ;; Switching window backwards (global-set-key (kbd "C-x O") (lambda () (interactive) (other-window -1))) ``` Which works fine, but works in the opposite direction when my CAPS are on. I have tried ``` ;; Switching window backwards (global-set-key (kbd "C-x S-o") (lambda () (interactive) (other-window -1))) ``` but this does not work at all, it just gives me the regular forward buffer # Answer > 1 votes The comments clarified that the question was about the behaviour of holding down the `Shift` modifier key *while* `Caps Lock` was on. It's common for the shift key to *invert* the state of caps lock, rather than to unconditionally enable caps. Hence: 1. `t` =\> `t` 2. SHIFT + `t` =\> `T` 3. CAPS + `t` =\> `T` 4. CAPS + SHIFT + `t` =\> `t` In that latter case, Emacs sees only a lower-case `t`. It is not aware that the shift key and the caps lock key were both involved in producing it, so you cannot make case (4) behave differently to case (1). To prevent this, I think you'll need to look for some kind of "do not allow shift to invert an active caps lock" option in your OS or window manager. --- Tags: key-bindings ---
thread-35698
https://emacs.stackexchange.com/questions/35698
Helm: helm-find-files: how find files recursive?
2017-09-23T10:14:44.650
# Question Title: Helm: helm-find-files: how find files recursive? Windows 10, Emacs 25.1 If I want to find file in Helm I use command `helm-find-files`. Suppose I want to find in current folder all files with extenstion **\*.gradle**. Here result: OK. It's work. But now I want to find all files with extension **\*.gradle** not only in current folder, but also in all subfolders (recursive). How I can do this by command `helm-find-files`? # Answer > 7 votes Just type `TAB`, input `shell` and `RET` use `Find shell command` to find files with filename recursively. Or simply `C-c /` # Answer > 4 votes Instead of doing this with `helm-find-files`, you could do it with `helm-find`. `helm-find` has the same fuzzy match but searches the directories recursively. It is smart in avoiding some not useful files / directories (like `.git/` etc). Just make sure you have find program installed on your machine. It comes by default on Unix based machines. On Windows, have git bash installed. Set Git bash to your default shell and then set the complete path of find to `find-program` variable in your `.emacs` file. If you want to search from your `default-directory`. The standard shortcut is: `C-x c /`. If you want to parameterize it with a different directory: `C-u C-x c /` `<The directory to start search from> <RET>` `<Your search string>` # Answer > 2 votes This will do what you want: ``` (defun my/helm-find-file-recursively () (interactive) "Recursively find files in glob manner, in the specified directory." (helm-find 'ask-for-dir)) (global-set-key (kbd "C-c o f") 'my/helm-find-file-recursively) ``` --- Tags: helm, microsoft-windows ---
thread-59683
https://emacs.stackexchange.com/questions/59683
How to find a file recursively on Microsoft Windows with findutils (gnu find) installed?
2020-07-17T12:20:21.383
# Question Title: How to find a file recursively on Microsoft Windows with findutils (gnu find) installed? I'm trying to find file recursively from `default-directory` with `helm-find` (`C-x c /`). It works out of box in linux. I tried setting `find-program` like (I have git bash installed) ``` (setq find-program "c:/Program\ Files/Git/usr/bin/find.exe") ``` It didn't work. Then I tried installing findutils (gnu find) from chocolatey and then tried. ``` (setq find-program "C:/ProgramData/chocolatey/bin/find.exe") ``` This did not work either. What am I doing wrong? # Answer > 0 votes The problem is that `helm-find` uses `find-cmd.el`. This `find-cmd` function generates a GNU find style command that runs without issues on bash, but fails to run on powershell. The default shell in Emacs is PowerShell. If you set your default shell to Git bash (You can follow the steps in this answer to do that.), then it works. Some Elisp script to do that: ``` (prefer-coding-system 'utf-8-unix) (setq shell-file-name "C:\\Program Files\\Git\\usr\\bin\\bash.exe") (setq explicit-bash.exe-args '("--login" "-i")) (setq find-program "C:/ProgramData/chocolatey/bin/find.exe") ``` --- Tags: helm, microsoft-windows, find ---
thread-59557
https://emacs.stackexchange.com/questions/59557
Org agenda should show all todos of the current week (not separated by days)
2020-07-09T20:36:30.967
# Question Title: Org agenda should show all todos of the current week (not separated by days) # Problem The default `agenda-list-view` separates the todo items of the current week by days and sort them by time within each day if there are timestamps. Instead, I want to combine all the todo items without any timestamps. # Motivation The power of weekly plan is well known. The default agenda view `agenda-list-view` however does not allow one to easily see what has been achieved and what has to be done in the current week, as what a Kanban board would be able to do. There is `org-kanban`, but it is not as powerful as what `org-agenda` can offer and cannot pick items from the current week. # Example Given the following Org file stored as `file_name.org` ``` * TODO No Timestamp * TODO Deadline last Sunday SCHEDULED: <2020-07-04 Sat> DEADLINE: <2020-07-05 Sun> * NEXT Scheduled for last Sunday SCHEDULED: <2020-07-05 Sun> * DONE Scheduled for this Monday SCHEDULED: <2020-07-06 Mon> * TODO Scheduled for this Tuesday SCHEDULED: <2020-07-07 Tue> * TODO Scheduled for next Monday SCHEDULED: <2020-07-13 Mon> ``` Assuming today is \<2020-07-08 Wed\> I'd like to have an agenda view that only shows the DONE/NEXT/TODO items from the current week, sorted by todo state: ``` file_name: DONE Scheduled for this Monday file_name: NEXT Scheduled for last Sunday file_name: TODO Scheduled for this Tuesday ``` # Details Note that only items satisfying one of the two conditions are included in the desired agenda view: * TODO items that are scheduled for previous weeks or for the current week. * DONE items scheduled for current week. This implies the following items are excluded: * DONE items scheduled for a day before the current week. * Items whose deadlines are before the current week. * Items scheduled for a day after the current week. What would be the best way to achieve this? I played around with the custom agenda view using `tags-todo`, but couldn't find a way to pick only the todo items from the current week. The closest command I can find for picking the todo items from the current week is something like `tags-todo "SCHEDULED>=\"<-7d>\"SCHEDULED<=\"<+7d>\""` but this is not exactly what I want. # Answer As Toon Claes suggested I checked out `org-super-agenda` and came up with the following solution. Hope this could be useful for some people. ``` (defun start-and-end-date-of-the-week (date) (-let* (((month day year) date) (org-today (format "%d-%02d-%02d" year month day)) (today-absolute (org-time-string-to-absolute org-today)) (remaining-days-of-the-week (mod (- (calendar-week-end-day) (calendar-day-of-week date)) 7)) (first-day-of-the-week-absolute (1+ (- today-absolute (calendar-day-of-week date)))) (last-day-of-the-week-absolute (+ today-absolute remaining-days-of-the-week)) (first-day-of-the-week (calendar-gregorian-from-absolute first-day-of-the-week-absolute)) (last-day-of-the-week (calendar-gregorian-from-absolute last-day-of-the-week-absolute)) ((month1 day1 year1) first-day-of-the-week) ((month2 day2 year2) last-day-of-the-week) (start-date (format "%d-%02d-%02d" year1 month1 day1)) (end-date (format "%d-%02d-%02d" year2 month2 day2))) (list start-date end-date))) (setq org-agenda-custom-commands '(("k" "Kanban View" ((todo "DONE" ((org-agenda-sorting-strategy '(priority-down)))) (todo "NEXT" ((org-agenda-sorting-strategy '(priority-down)))) (todo "TODO" ((org-agenda-sorting-strategy '(priority-down))))) ((org-super-agenda-groups (-let* (((start-date end-date) (start-and-end-date-of-the-week (calendar-current-date)))) `((:name none :not (:and (:not (:and (:tag "work" :todo "DONE" :scheduled (after ,start-date) :not (:deadline (before ,start-date)) :not (:tag "drill"))) :not (:and (:tag "work" :todo "NEXT" :scheduled (before ,end-date) :not (:deadline (before ,start-date)))) :not (:and (:tag "work" :todo "TODO" :scheduled (before ,end-date) :not (:deadline (before ,start-date)) :not (:regexp "+[12][dw]")))))) (:discard (:anything t))))))))) ``` N.B. The implementation requires the `dash` package. > 4 votes --- Tags: org-agenda, org-super-agenda ---
thread-32585
https://emacs.stackexchange.com/questions/32585
Set web-mode engine per directory
2017-05-04T21:15:24.707
# Question Title: Set web-mode engine per directory I'm hoping this is possible. I work in a variety of environments and languages. Right now it's mostly django and Node.js, but there have been others. What I would like to do is set the `web-mode` engine based on the project I am currently working on, and not the file extension. I know I could use `.djhtml` as the file extension, but that messes things up for others who aren't using Emacs because, for example, Pycharm doesn't know what to do with a `.djhtml` file. I would prefer to keep my `.html` if at all possible. I am wondering if there is any way to set the `web-mode` engine based on the project I'm working in. I'd rather not have to put `-*- engine: django -*-` into each of my files either, if I can avoid it. **UPDATE**: I've tried adding the following to a `.dir-locals.el` file, but it doesn't seem to make a difference. I get prompted to allow the variable change, and the value of the variable `web-mode-engines-alist` has changed to `(("django" . "\\.html\\'"))`, but `django` is not set as the template engine when I open a `.html` file. ``` ((web-mode . ((web-mode-engines-alist . (("django" . "\\.html\\'")))))) ``` **UPDATE 2** To clarify, I can set all `.html` files to open with the django engine by putting the following in my `.spacemacs` file: ``` (setq web-mode-engines-alist '(("django" . "\\.html\\'"))) ``` That works just fine, but sets it globally, meaning I'll get the django engine in any `.html` file, regardless if it's a django project or another language. **SYSTEM INFORMATION** * Emacs: 25.2.1 * OS: Windows 10 I found this bug reported in `web-mode` (https://github.com/fxbois/web-mode/issues/799), but it's just referred to be asked as a question here. # Answer Have you tried adding a web-mode-hook to check if you are in a projectile project? You would also have to check if the projectile project is a django one, but I am not that familiar with django. ``` (defun cesco/django () (if (projectile-project-p) (if (file-exists-p (concat (projectile-project-root) "manage.py")) (web-mode-set-engine "django") (message "do not exists") ;; You can safely delet this line ) ) ) (add-hook 'web-mode-hook 'cesco/django) ``` > 3 votes # Answer I have found a solution thanks to this recipe: https://www.emacswiki.org/emacs/LocalVariables . I set a custom variable in `.dir-locals`: ``` ((nil . ((mik-web-mode-engine . "django"))) (python-mode (pyvenv-activate . "../pyenv/api_bo")) (mhtml-mode . ((mik-web-mode-engine . "django") (mode . web)))) ``` Then I read it from a hook defined in my init file: ``` ;; web-mode (defun my-web-mode-hook () "Hooks for Web mode. Add a local hook which set the engine to the one specified by `mik-web-mode-engine` local variable." (add-hook 'hack-local-variables-hook (lambda () (if (boundp 'mik-web-mode-engine) (progn (message "web-mode-engine is %s" mik-web-mode-engine) (web-mode-set-engine mik-web-mode-engine)) (progn (message "no web-mode-engine settled") (web-mode-set-engine "none")))))) (add-hook 'web-mode-hook 'my-web-mode-hook nil nil) ``` Note that I switch from `mhtml-mode` (the default on my setup) to `web-mode`. If you have defined `web-mode` as the default for HTML you don't need that. > 0 votes --- Tags: syntax-highlighting, web-mode ---
thread-59712
https://emacs.stackexchange.com/questions/59712
What ASCII character is C-q C-E?
2020-07-18T22:53:00.583
# Question Title: What ASCII character is C-q C-E? I did a spurious replacement across many files that shows in Emacs as '^E', equivalently the result of C-q C-E. What ASCII character does that correspond to, so I can undo the replacement? # Answer Control characters `^A` to `^Z` are ASCII 1 to 26; therefore `^E` is ASCII 5. You could also ask Emacs: Type `C-x``=` with point at one of those characters, and it would tell you `Char: C-e (5, #o5, #x5)` Note that `C-q` calls `quoted-insert` which inserts the next character you type, and the next thing you typed was `C-e`. > 1 votes --- Tags: ascii, control-characters ---
thread-59714
https://emacs.stackexchange.com/questions/59714
Emacs fails to open gnuplot files with extension .gp
2020-07-19T01:30:12.827
# Question Title: Emacs fails to open gnuplot files with extension .gp May I get some help understanding what it is that Emacs does not like about the extension `.gp` * Using emacs 24.5.2 on Mac OS X 10.13.6 * I get the following error message when I try to open a file with extension .gp. ``` Debugger entered--Lisp error: (file-error "Cannot open load file" "no such file or directory" "gnuplot") gnuplot-mode() set-auto-mode-0(gnuplot-mode nil) set-auto-mode() normal-mode(t) after-find-file(nil t) find-file-noselect-1(#<buffer gpiofl.gp> "~/gpiofl.gp" nil nil "~/gpiofl.gp" (8739733818 16777220)) find-file-noselect("/Users/cizmas/gpiofl.gp" nil nil nil) find-file("/Users/cizmas/gpiofl.gp") command-line-1(("gpiofl.gp")) command-line() ``` * In this case, the file name is `gpiofl.gp`. If I change the extension to `.gnuplot`, all is fine. # Answer `(file-error "Cannot open load file" "no such file or directory" "gnuplot")` means that it was looking for `gnuplot.el` or `gnuplot.elc`, but couldn't find it. It was doing this because it was trying to call the function `gnuplot-mode` in order to activate Gnuplot mode. Are you sure that Gnuplot mode is actually installed? It sounds like you have associated it with files named `*.gp` in your init file, but have not actually installed the Gnuplot mode's code correctly. To check whether the `gnuplot-mode` library is installed, you can say `M-x locate-library RET gnuplot-mode RET`. See the github page for installation instructions. > 1 votes --- Tags: osx ---
thread-10336
https://emacs.stackexchange.com/questions/10336
read e-books in Emacs
2015-03-27T08:31:31.227
# Question Title: read e-books in Emacs I use eww to read online articles in Emacs instead of in a browser because it is less distracting and I can take notes in an org-mode quickly without switching applications. I wonder how feasible it is to read an e-books in epub, or pdf format in Emacs? I found the epubmode.el on emacswiki.org but it is broken and haven't been updated since 2011. # Answer Try nov (installable via melpa). It is a reasonable start for reading ePUBs in Emacs. > 10 votes # Answer `.epub` are in fact `.zip` file with `.xhtml` file inside. You can just open them, find the .xhtml file that has the content (often content.html), and open it. Then you can call `shr-render-buffer` to display the html. This do not solve several problem: * finding automatically the correct .xhtml * use the table of content, * bigger epub have several .xhtml (say, one by chapter), one need a way to go from one to the next. > 4 votes # Answer I recommend emacs-ereader. My experience is that it errs out less often while parsing an epub than nov and it too is installable as a package. Further, it supports annotations, integrates decent with Org, in a slightly more primitive way than the awesome pdf-tools does for PDFs. > 2 votes # Answer EDIT Actually this answer seems more useful than presumed initially. I only tried this method on one book, and that book's conversion looked bad. I have tried multiple other books now, and most look reasonably well after conversion. Still, it might be possible to make the conversion look even better using mutool its epub/css config options. END EDIT Although maybe not a very useful answer here, I still like to inform about the following possibility. Emacs comes with doc-view-mode already. If you have the `mutool` command available on your system then Emacs doc-view-mode will use it to convert pdf's to png. Now mutool is also able to convert epub to png. So by making doc-view to recognize an epub as a pdf, i.e. add `("epub" pdf)` to the pdf options in the `doc-view-set-doc-type` function, you can read an epub by opening your epub file and then switch to doc-view-mode. The conversion takes some time, and it takes a while (~30sec) before the png image will appear. Now I tried this succesfully myself, but the converted document did not look great. However, the `mutool draw` command offers some configuration options for epub conversion. Unfortunately I do not understand these options well yet, as mutool tells me the following when using a very simple css stylesheet. ``` error: css syntax error: expected keyword in property (content/stylesheet.css:3) ``` Maybe someone who understands mupdf or css or epub could comment on this answer for how to get a nice epub conversion with mutool. Then doc-view-mode might be another nice option for reading epubs (and a feature request could be opened for official epub support in doc-view-mode). > 2 votes --- Tags: pdf, docview ---
thread-59719
https://emacs.stackexchange.com/questions/59719
Spacemacs kept repositioning the cursor when there's unmatched parenthesis
2020-07-19T09:02:01.913
# Question Title: Spacemacs kept repositioning the cursor when there's unmatched parenthesis I'm new to Emacs, and there's one thing I don't understand. Suppose there's a file called `test.el`, which have the following contents: ``` (setq ``` Yes, the parenthesis is not closed, because I haven't finished this file. But when I positioned my cursor just after `setq` and typed a `SPC` to continue to write the code, the cursor moved back to the beginning of the line. Why? How can I prevent it from repositioning the cursor, it's annoying. This problem only occurs with Spacemacs and lisp code, I didn't found the problem with the vanilla Emacs. # Answer > 0 votes After lots of checking and searching, I find the following auto save command to be the culprit. ``` (run-with-timer 3 3 (lambda () (save-some-buffers t))) ``` It saves the current buffer every 3 seconds, and it seems that Emacs repositions the current elisp file after saving. Removing this line works. --- Tags: spacemacs, motion ---
thread-59711
https://emacs.stackexchange.com/questions/59711
Displaying some characters with all-icon instead of my current font
2020-07-18T17:37:40.507
# Question Title: Displaying some characters with all-icon instead of my current font Usually people want to print some characters and end up having strange squares clearly telling them this character is unknown by their default font and they have no fallback font for it. My problem is quite the opposite, my current font (Fira Code) actually knows all the characters and seems to not agree with all-icons on some of them. In my custom.el file I have a function to display some bullets as special characters and I explicitly wrote: I put screenshots because it looks like StackExchange can't handle these unicode characters: ``` '(? ? ? ?) ``` When I put my cursor on one of these characters and `M`-`x` `describe-char` I get the following answer: Note that the code for this character is #xe3d0 (and the other three are `#xe3d(1/2/4)`" so I could write my list like this: ``` '(#xe3d0 #xe3d1 #xe3d2 #xe3d4) ``` Anyway, when I restart my emacs to have my prettified bullets: And even better, if I go back to my customisation file (at least it's coherent): I tried adding: ``` (set-fontset-font "fontset-default" '(#xe3d0 . #xe3d4) (font-spec :name "FontAwesome")) ``` But it didn't change anything. --- \[EDIT\] If I write this list (according to https://en.wikipedia.org/wiki/Enclosed\_Alphanumerics): ``` '(#x2460 #x2461 #x2462 #x2463) ``` I have the wanted result: # Answer > 0 votes Looks like the font I need to use is not "FontAwesome" but "Material Icons" : ``` (set-fontset-font t '(#xe3d0 . #xe3d4) "Material Icons") ``` And it works :-) --- Tags: fonts ---
thread-59726
https://emacs.stackexchange.com/questions/59726
Can the ring data structure really be rotated?
2020-07-19T18:42:51.477
# Question Title: Can the ring data structure really be rotated? According to the doc page describing Emacs Lisp's ring data structure, rings "support \[...\] rotation". However, the word "rotate" appears nowhere else on the page, and none of the documented interface functions appear to perform it. When I visit `ring.el` I find this in the header comments: `You can insert to, remove from, and rotate a ring.` But again, the word "rotate" appears nowhere else in the file, and none of the functions defined there (some of which are not mentioned on the web page above) do rotation, as far as I can tell. Am I missing something, or is the documentation wrong? Obviously a one-place rotation in one particular direction is possible by doing `(ring-insert ring (ring-remove ring))`, and probably quite efficiently at that, but it seems like a far cry from "supporting" rotation. # Answer > 2 votes Yes. Functions `ring-next` and `ring-previous` do what you're asking, forward and backward, respectively. It may not be obvious, but invoking `ring-next` on the last ring element cycles/rotates to the first element: wrap-around. Similarly, for `ring-previous` on the first element: it rotates to the last element. I've filed Emacs bug #42430, to ask that the Elisp manual mention these functions. Thx. --- To respond to your comment: > simple indexed access modulo the length of the structure isn't what I'd call "rotation." To me, "you can rotate a ring" sounds like a mutating action that takes a distance N and has the effect that every element previously at index I is now at index I - N (modulo the length of the ring, of course). For example, given a ring with elements (1 2 3 4 5), I'd expect to have a function like (ring-rotate my-ring 2) and have the ring now contain (3 4 5 1 2). No, that functionality is not offered as such, nor is it really needed, in general. It's not what was meant by "rotating" a ring. Perhaps that word isn't the best one for what is meant. A ring in Elisp is not a list whose order matters. It's an instance of an abstract data type, if you like. This is true of `kill-ring`, `search-ring`, etc. You have access to the ring elements by ring position, not implementation-list position, and you can change the position of a given element if you need to (as you suggested, with insertion and deletion). But the more typical operations are insertion at the head, deletion of a given element, accessing an element by its position/index, and accessing the next/previous ring element. Something like this seems to be what you're looking for: ``` (defun ring-rotate (ring &optional n) "Rotate RING N places. N defaults to 1. Moves ring element 2 to position 1, 3 to 2, 4 to 3, etc. Moves element 1 to the end of the ring." (setq n (or n 1)) (let ((rng ring)) (dotimes (ii n rng) (ring-insert rng (ring-remove rng))))) ``` --- **Update:** FYI, Emacs bug #42430 was closed by the Emacs maintainer, with this comment: > The manual says: > > > For yanking, one entry in the kill ring is designated the front of the ring. Some yank commands rotate the ring by designating a different element as the front. But this virtual rotation doesn’t change the list itself—the most recent entry always comes first in the list. > That's all. I don't see any reason to expand this description of a "virtual rotation", since that would require bringing many internal details into the ELisp manual, with no apparent gain. --- Tags: rings ---
thread-59680
https://emacs.stackexchange.com/questions/59680
how to set ranger to be default mode in dired in Doom emacs?
2020-07-17T09:12:21.523
# Question Title: how to set ranger to be default mode in dired in Doom emacs? I'm new to doom emacs and I like it but I'm still new, so I saw this package called ranger that is a minor mode inside emacs and I want to make it run by default whenever I open dired. The documentation says set this variable `ranger-override-dired-mode t`, but I don't know where to start. I tried to add this in `~/.doom.d/config.el` but it crashes when launch emacs can you please guide me !! # Answer > 5 votes Doom's `:emacs dired` module has a `+ranger` flag. Enable it and run `doom sync` on the command line. i.e. uncomment `:emacs (dired +ranger)` in `~/.doom.d/init.el`. Then ranger will be the default UI for dired. --- See this entry in the manual for details on what Doom modules (and flags) are. --- Tags: doom, ranger ---
thread-5451
https://emacs.stackexchange.com/questions/5451
How do I force kill Emacs?
2014-12-16T20:34:22.080
# Question Title: How do I force kill Emacs? I often find myself with an incomplete or invalid emacs config, which breaks the normal behavior of `kill-emacs` such that it stops at an error. In this case, I would like to forcefully kill emacs, without resorting to hunting down the PID and issuing a `kill` from the shell. Can I do this in pure Emacs Lisp? # Answer You can try setting `kill-emacs-hook` to `nil` before calling `kill-emacs`: ``` (defun really-kill-emacs () "Like `kill-emacs', but ignores `kill-emacs-hook'." (interactive) (let (kill-emacs-hook) (kill-emacs))) ``` Alternatively, you can get Emacs's PID using `emacs-pid` and make it commit suicide by calling `call-process` with "`kill -9`": ``` (defun brutally-kill-emacs () "Use `call-process' to send ourselves a KILL signal." (interactive) (call-process "kill" nil nil nil "-9" (number-to-string (emacs-pid)))) ``` > 15 votes # Answer Sometimes, I end up with several unreachable emacs processes laying around. My emacsclient normally automatically starts an emacs and calls `server-start`--I guess there is some bug in my configuration somewhere which results in this happening more than once. I kill the extra emacsen with `killall emacs` in a shell. So far, `-9` hasn't been needed. (It works when there's only one emacs running, too, and I don't have to hunt down a pid!) > 1 votes # Answer This will force kill emacs daemon from `bash`. If there is no emacs running and when we run `emacsclient -e "(kill-emacs)"`, which starts emacs and kills it again. I just added simple if/else to prevent that. * Instead of `kill-emacs` you can use `brutally-kill-emacs ()` that is defined in @Constantine's answer. ``` #!/bin/bash num=$(ps aux | grep -E "[e]macs --daemon" | wc -l) if [ $num -ge 1 ]; then emacsclient -e "(brutally-kill-emacs)" > /dev/null 2>&1 # following commands guarantees kill -9 $(ps aux | grep -E "emacs" | awk '{print $2}') (killall emacs) > /dev/null 2>&1 (killall emacsclient) > /dev/null 2>&1 kill -9 $(ps aux | grep -E "[e]macs" | awk '{print $2}') > /dev/null 2>&1 else echo "emacs is already killed." fi ---- If you are a m Sometimes following zombie process remain opened and consumes all the memory so `kill -9 $(ps aux | grep -E "emacs" | awk '{print $2}')` will be your friend. ``` alper 4785 100.0 0.0 4461068 7860 ?? R 1:27AM 41:42.43 /usr/local/Cellar/emacs-head@26/26.3\_1/Emacs.app/Contents/MacOS/Emacs -Q -l /Users/alper/.emacs.d/elpa/async-20200809.501/async.elc -batch -f async-batch-invoke > 0 votes --- Tags: emacs-internals ---
thread-59733
https://emacs.stackexchange.com/questions/59733
How can I more easily see interactively whether `overwrite-mode` is enabled?
2020-07-19T22:57:53.663
# Question Title: How can I more easily see interactively whether `overwrite-mode` is enabled? I am sick of pressing `Insert` instead of `Backspace` and running into problems in certain modes. How can I fix it? One option is to have some visual indication that overwrite mode has been activated, so I can press `Insert again` and correct my mistake. # Answer > 1 votes If it is the position of the key that is the problem, then you can unbind the key so that it does not enable `overwrite-mode` any longer: ``` (global-set-key (kbd "<insert>") nil) ``` If you still want to be able to enable the mode with a key, you can bind some other key to it, perhaps a function key: ``` (global-set-key (kbd "<f8>") #'overwrite-mode) ``` although you will have to figure out what would work for you. # Answer > 0 votes In the end, I used https://www.emacswiki.org/emacs/AlarmBell and added some code to overwrite-mode-hook. So now I get a visible alarm, which may be better than completely disabling the key. Time will tell if this is better than the other answer. ``` (defun double-flash-mode-line () (let ((flash-sec (/ 1.0 20))) (invert-face 'mode-line) (run-with-timer flash-sec nil #'invert-face 'mode-line) (run-with-timer (* 2 flash-sec) nil #'invert-face 'mode-line) (run-with-timer (* 3 flash-sec) nil #'invert-face 'mode-line))) (add-hook 'overwrite-mode-hook #'(lambda () (double-flash-mode-line))) ``` --- Tags: read-only-mode, overwrite ---
thread-39158
https://emacs.stackexchange.com/questions/39158
How to execute sudo command in org-babel in relative path under current working directory
2018-03-01T07:39:21.277
# Question Title: How to execute sudo command in org-babel in relative path under current working directory I want to execute sudo command in org-babel like this: ``` #+begin_src shell :dir "/sudo::" :cache no make sudo make install #+end_src ``` It works fine. It use TRAMP /sudo: method. But I need to execute sudo command relative under current working directory. As following block shows: ``` #+begin_src shell :dir "/sudo::data/code/quirc" :cache no make sudo make install #+end_src ``` But it does not work. It is under `/root` instead of current working directory. So how can I execute sudo command under a specific directory as in org-babel like upper? EDIT: Might add an advice to change TRAMP sudo method default directory to babel src block's directory? Don't know how to change this in TRAMP code. Have not found any `tramp-default-directory` related variables. # Answer > 6 votes I suddenly come up with string concat idea. Here is the very simple solution. ``` #+begin_src sh :dir (concat "/sudo::" (expand-file-name "data/code")) pwd #+end_src #+RESULTS[(2020-07-20 10:34:50) b20fc4ca99ae523b3497adaa26b8945c57b06254]: : /home/stardiviner/Org/Wiki/Computer Technology/Programming/Emacs/Data/Emacs Packages/Org Mode/data/code ``` # Answer > 8 votes You must use an absolute local directory path. Like this: ``` #+begin_src shell :dir "/sudo::/data/code/quirc" :cache no make sudo make install #+end_src ``` See the leading slash in `/data/code/quirc`. Edit: You must recompute the directory for the root shell. Something like this: ``` #+begin_src shell :dir "/sudo::" :var dir=(expand-file-name "data/code/quirc") :cache no cd $dir make make install #+end_src ``` --- Tags: org-babel, tramp, sudo ---
thread-59742
https://emacs.stackexchange.com/questions/59742
Fixed length buffer for shell
2020-07-20T05:43:05.000
# Question Title: Fixed length buffer for shell I launch a shell in my session with `M-x shell` and then I launch a python script that produces a lot of output to stdout---so many lines of output that my emacs session beomes quite slow. Is there a command I can run to ask my buffer to be fixed length and automatically delete lines older than N? I have tried looking this up, but don't even know what terms to use in my query beyond "automatically delete," "circular buffer" and "fixed length" which were not helpful. # Answer ``` comint-buffer-maximum-size is a variable defined in ‘comint.el’. Its value is 1024 Documentation: The maximum size in lines for Comint buffers. Comint buffers are truncated from the top to be no greater than this number, if the function ‘comint-truncate-buffer’ is on ‘comint-output-filter-functions’. You can customize this variable. ``` ``` (defun my-shell-mode-hook () "Custom `shell-mode' behaviours." (add-hook 'comint-output-filter-functions 'comint-truncate-buffer nil :local)) (add-hook 'shell-mode-hook 'my-shell-mode-hook) ``` > 1 votes --- Tags: shell ---
thread-59745
https://emacs.stackexchange.com/questions/59745
How to overwrite by pasting a string without selecting a region?
2020-07-20T10:25:14.340
# Question Title: How to overwrite by pasting a string without selecting a region? I can't figure out how to paste a string, for example 145 characters long, into a text line in a way, that the next 145 characters after the string are overwritten by this string or simply erased. An example with a 34 character string would be `| |` which is supposed to become this by pasting in the 34 character string *"This is an example for the problem"* `| This is an example for the problem |` ## Why should one want to do that? While working with huge org mode tables any refreshing or re-aligning can become a pain in the ass, involving 20 minutes of frozen emacs session. So, avoiding the need for re-freshing or re-aligning becomes very interesting, by editing a table in a way that doesn't break aligning or trigger refresh in any way. ## What I've tried (and didn't work) * A manual way to do so is going into a field containing let's say 180 space characters between both vertical column separator lines `|`, place cursor behind the 1st space character, paste the 145 character string, delete the 145 space characters after the pasted string. Then everything is still aligned in relation to neighbor lines and how the edited line was before, and no re-fresh is triggered. But the problem with that approach is, that it can't be automated effectively by keyboard makros - that's my only tool so far, because I can't program: For that you need to be able to count how many characters the string is built of by `M-=` \- as a consequence the number of characters is explicitely mentioned in `*Messages*` buffer - then go to `*Messages*` buffer, navigate in a general way to that number, copy it, go back to your table at the spot right after the pasted string, and doing `C-d` with prefix argument of that copied number. But that doesn't work out: You can do all that, but at the very end it fails by not handling the pasted number from `*Messages*` buffer as numeric input for the prefix argument. So instead of doing `C-u 145 C-d`, pasting by `C-y` after having typed in `C-u` right before simply ends the `C-u C-d` operation and instead simply pastes that number `145` into the buffer right after the pasted 145 character string. The way all this came up is, that I've noticed that while filling the tables with huge amounts of data mistakes sneaked in for no reason. That made me start verifying every line filling to make sure that it's filled correctly. That procedure was always the same, so after a while I made it so often, that it was so clear for me how to do it and so dull as a task, that I've created a keyboard macro for it. Whenever verification failed, it was always the same way so far, and that happened so often, that now I want to create a keyboard marco also for the fixing of lines where verification failed. * That overwriting by pasting I've done so far was like a manual re-construction of writing in overwrite mode, so why not going into overwrite mode instead, doing the pasting, and then going out of it again within the keyboard macro? That 2nd possibility, though, doesn't work, either. It works just for typing in 1 character after another, not pasting a 145 character string. One could mark or select a region before and then paste the 145 character string, but that just leads you back to the core problem: You have the number of characters counted in the cache - this failed verification fix it's 145, but the next one maybe 89, or 458, it's always different from routine run to routine run - and you need to work with that number, apply it so that the selected region is just as long as 145 characters like the pasted string, and if you could do that, if you achieved this, then you could stick to the 1st possibility in the first place and wouldn't need to try the 2nd possibility, because the problem is already solved. I've tried a lot, checked the manual, but couldn't solve that by myself. There gotta has to be a straight way to do it. When using isearch pasting with `C-y` a number like 145 is taken just as if one typed 1-4-5 straight away into the mini-buffer. But prefix arguments are not really mini-buffer and don't work like that. So that way I've tried didn't work, so far. # Answer You can write ``` (defun overwriting-yank () "Like `yank` but overwrites the corresponding text." (interactive) (let ((txt (current-kill 0))) (insert-for-yank txt) (delete-char (length txt)))) ``` But this will misbehave in all kinds of circumstances (e.g. when yanking a multiline string, when yanking into a line shorter than the text you're yanking, ...). Also, IIUC you're interested in *columns* more than in number of chars, so the behavior won't be quite right if there are double-width chars or TAB chars involved. etc... Finally, your description makes it clear that the only reason you want such an operation is in order to work around bugs in Org. So please make sure you report those bugs and try to work with Org mode's maintainers to get rid of them. > 1 votes --- Tags: org-mode, copy-paste, keyboard-macros, overwrite ---
thread-59737
https://emacs.stackexchange.com/questions/59737
How to display list of previous copies/kills (`M-w` or `C-w`)?
2020-07-20T00:46:37.067
# Question Title: How to display list of previous copies/kills (`M-w` or `C-w`)? `C-n C-y` retrieves the n-last call to `C-w`, I think. Is there a way to show all that were saved? # Answer Check the value of the `kill-ring` variable e.g. with C-h v kill-ring RET, or perhaps better, evaluate it in the `*scratch*` buffer with `kill-ring C-j`. The doc string of the variable says: > List of killed text sequences. > > Since the kill ring is supposed to interact nicely with cut-and-paste facilities offered by window systems, use of this variable should interact nicely with `interprogram-cut-function` and `interprogram-paste-function`. The functions `kill-new`, `kill-append`, and `current-kill` are supposed to implement this interaction; you may want to use them instead of manipulating the kill ring directly. See also the kill ring section in the Emacs Lisp manual. > 0 votes # Answer The command `counsel-yank-pop` which is part of the swiper package, gives you an interactive way to browse and insert elements from you kill ring. > 1 votes # Answer I would say what you want is provided by one of theses packages : Spacemacs uses `consel-yank-pop` acessible with `SPC-r-y` (command already cited by @Heikki) provided by swipper. So you can also look at it. > 0 votes --- Tags: kill-ring ---
thread-28284
https://emacs.stackexchange.com/questions/28284
tramp and sudo: how to edit files under another account
2016-10-31T09:21:13.520
# Question Title: tramp and sudo: how to edit files under another account On local machine, I am using the account as test1, and I could use the same account to login remote server. After login as test1 on remote server, I could run `sudo su - oracle` to change as oracle user, and then I could all files under account of oracle. But I don't know the password of oracle, I could only change to oracle using `sudo su - oracle`. So how to use tramp to edit the file from oracle account on remote server? I read the tramp document, it said we have sudo and su option. I can't simple use su since I don't have the password of oracle. But if using sudo, looks like it doesn't work as the emacs hangs forever. # Answer > 11 votes To ssh in as you, and then run sudo su oracle, and then edit a file, do this: ``` /ssh:you@remotehost|sudo:oracle@remotehost:/path/to/file ``` # Answer > 2 votes This is probably a (cross-site) duplicate, as the question has a fairly comprehensive answer on Stack Overflow: Open file via SSH and Sudo with Emacs > But if using sudo, looks like it doesn't work as the emacs hangs forever. As you neither show what you've tried, nor provide any details on how far tramp gets (customize the `tramp-verbose` option), it's extremely difficult to tell whether there's still a problem, or what it might be. # Answer > 0 votes `sudo su - oracle` is not supported by Tramp out-of-the-box. You would need to define an own method in `tramp-methods` for this, kind of tricky. I fear it will be to detailed to fiddle it out here on stackexchange. You might rather ask on the `tramp-devel@gnu.org` mailing list. --- Tags: tramp ---
thread-59751
https://emacs.stackexchange.com/questions/59751
Easily accessing org files
2020-07-20T17:15:40.053
# Question Title: Easily accessing org files I've just started to use org-mode in emacs (spacemacs). One simple thing that is confusing me is how to quickly access my org files. What is a solid and simple strategy for quickly pulling up a list of org files? By way of example, let's say I have a directory where I store org files (though the solution I'm looking for would hopefully work for multiple directories). I want to be able to quickly access that directory, search for a specific file, and load it. How would I do that? The functionality I am thinking of here is similar to that the the `projectile` project provides for a coding project... # Answer > 1 votes Emacs provides a lot of different ways to quickly find files, and even more are available with add on packages. For your specific case, finding `org` files in a particular directory, you could use the built-in `ido-find-file-in-dir`: ``` (ido-find-file-in-dir "~/org/") ``` Running this command will open an interactive file selection dialogue in the "~/org/" directory. You'll see a list of all the files that are present, and you can progressively narrow that list by typing in part of the name you are looking for. If that's good enough, you'll need to create a keybinding: ``` (defun my-org-finder () (interactive) (ido-find-file-in-dir "~/org/")) (global-set-key (kbd "C-c f") 'my-org-finder) ``` The sky is the limit here. If you have a specific requirement, be explicit, and there will likely be something available for you. --- Tags: org-mode ---
thread-59759
https://emacs.stackexchange.com/questions/59759
Filter list by regexps
2020-07-21T03:04:59.147
# Question Title: Filter list by regexps How can I get all elements of a list which don't match multiple patterns? The patterns are given as a list. For instance, I want all files without `'("no" "nix")` in them. ``` (setq se-have '("~/site/src/good-org.org" "~/site/src/bad-no-org.org" "~/site/src/yes-to-org.org" "~/site/src/nix-this.org" "~/site/src/know-this-will-go.org" "~/site/src/is-always-next-to.org")) ``` ``` (setq se-want '("~/site/src/good-org.org" "~/site/src/yes-to-org.org" "~/site/src/is-always-next-to.org")) ``` I can do it for a single pattern: ``` (seq-filter (lambda (x) (not (string-match-p (regexp-quote "no") x))) se-have) ``` How could I do this for each pattern in a list? # Answer > 4 votes You're essentially saying you want to match *any* of a list of patterns. `regexp-opt` takes a list of strings and produces a single regexp which matches any of them. ``` (regexp-opt '("no" "nix")) => "\\(?:n\\(?:ix\\|o\\)\\)" ``` Note that the individual strings in the input list are not regexps -- the end result will be analogous to using `regexp-quote` for each string. The equivalent `rx` syntax is: ``` (rx (or "no" "nix")) ``` # Answer > 4 votes ``` (seq-filter (lambda (x) (and (not (string-match-p (regexp-quote "no") x)) (not (string-match-p (regexp-quote "nix") x)))) se-have) ``` Or use `cl-remove-if-not`. Or use `seq-filter` or `cl-remove-if-not` twice, instead of `and`. And so on. --- Tags: regular-expressions, list, filtering, sequences ---
thread-59761
https://emacs.stackexchange.com/questions/59761
Get a table of org-mode file from elisp to be passed to R
2020-07-21T05:43:50.793
# Question Title: Get a table of org-mode file from elisp to be passed to R I am bad at elisp. I am trying to return to follow the idea of just getting everything from the orgfile, then pass it to R code to do easier analysis for me. This works to generate only tags table ``` #+name: orgtable #+begin_src emacs-lisp (let (orgtable) (org-map-entries (lambda () (dolist (tag (org-get-tags)) (push (list tag) orgtable)))) orgtable) #+end_src #+begin_src R :var orgtable=orgtable table(orgtable) #+end_src ``` The above snippet works good. But I am trying to make a full table of the following columns ``` * TODO Task 1 :tag1: deadline:1-9-2021 * Waiting Task2 ** DONE subtask :tag2: ::LOGBOOK:: completed: 7-7-2020 clock: start time- endtime => 2hours #+begin_src ;;some script #+End_src #+ results todo:task name:tags: schedule:deadline: clock: completed: ----------------------------------------------------------------------- todo: task1 : tag1: :1-9-2021: : waiting: task2: : : : : done: subtask : tag2: : : 2hrs: 7-7-2020 ``` I just don't know how to nest all of that in elisp code something like: ``` #+begin_src emacs-lisp (let (orgtable) (org-map-entries (lambda () (dolist (tag '((org-get-tags) (org-get-todo-state) (org-get-property-block) )) (push (list tag) orgtable)))) orgtable) #+end_src ``` This just fails and not evaluated. Also it would be nice if I can extract every property on it's own column. # Answer Here's an example Org file (based on what you provided but fixed up for syntax etc). It does not contain everything you want, but it does most of it - if I find time, I might come back for the rest: ``` #+TODO: TODO WAITING | DONE #+STARTUP: logdrawer logdone * TODO Task 1 :tag1:tag2: DEADLINE: <2020-07-21 Tue> * WAITING Task2 SCHEDULED: <2020-07-21 Tue> ** DONE subtask :tag2:tag3: CLOSED: [2020-07-21 Tue 15:50] :LOGBOOK: CLOCK: [2020-07-21 Tue 15:47]--[2020-07-21 Tue 15:49] => 0:02 :END: * COMMENT Code #+name: tags #+begin_src emacs-lisp (defun entry-get (prop) (or (org-entry-get (point) prop) "")) (defun ndk/entries-table () (interactive) (let ((tbl '(hline ("Name" "TODO" "Tags" "Scheduled" "Deadline" "Clock" "Closed")))) (org-clock-sum) (org-map-entries (lambda () (push (list (entry-get "ITEM") (entry-get "TODO") (entry-get "TAGS") (entry-get "SCHEDULED") (entry-get "DEADLINE") (entry-get "CLOCKSUM") (entry-get "CLOSED")) tbl)) t 'file 'comment) (reverse tbl))) (ndk/entries-table) #+end_src #+RESULTS: tags | Name | TODO | Tags | Scheduled | Deadline | Clock | Closed | |---------+---------+-------------+------------------+------------------+-------+------------------------| | Task 1 | TODO | :tag1:tag2: | | <2020-07-21 Tue> | | | | Task2 | WAITING | | <2020-07-21 Tue> | | 0:02 | | | subtask | DONE | :tag2:tag3: | | | 0:02 | [2020-07-21 Tue 15:50] | ``` Some notes: * I've added a `#+TODO:` setting, defining the `TODO` states, to make the file self-contained. * I have not worried about the `LOGBOOK` stuff yet: that needs fixing up, both in the file and in the code. * I've marked the `Code` section as a `COMMENT` and I make sure in the code to skip `COMMENT`ed sections from processing. * The call to `org-map-entries` is limited to the current file and is instructed to skip `COMMENT` sections. * The table is initialized with the column labels and a separator (see next item for why they are in the "wrong" order). * We push new elements to the front of the table, so at the end we need to reverse it. * If something is missing, it is shown in the table as `nil` because that's what `org-entry-get` returns. We can replace those calls with `(or (org-entry-get (point) "....") "")` to make it return an empty string instead. * The special properties I use are documented here where you may find other interesting ones. EDIT: Added the following changes: * Added CLOCK and CLOSED entries in the file and the corresponding entries in the table. For the clock times to be shown correctly, you need to run the function `org-clock-sum` in the buffer before you try to retrieve the CLOCKSUM property, so I added a call to it. * Added a small wrapper around `org-entry-get` to deal with the "nil vs empty string" problem above. * Made the table production code into a function `ndk/entries-table` and added a call to it in the source block to produce the table. I believe this completes everything you asked for in the original question. For the question in your comment, there are a couple of ways of dealing with it: probably the easiest is to leave everything as is, but change the `ndk/entries-table function to take an argument, either a filename or a buffer. We then do everything in that buffer (but still produce the output in *this* buffer). Here's an implementation (for the whole file: you can't pick just a headline with this version, but I probably won't be able to do that any time soon - the implementation could be something like this though: make the headline a second optional argument, search in the chosen buffer for the desired headline, make sure you are in the right place, then call` org-map-enries`with a`tree`argument instead of a`file`argument`org-map-entries\` is nothing if not flexible ;-) ): ``` #+name: tags #+begin_src emacs-lisp (defun entry-get (prop) (or (org-entry-get (point) prop) "")) (defun ndk/entries-table (&optional file-or-buffer) (interactive) (cond ((null file-or-buffer) ;; just use the current buffer ) ((bufferp file-or-buffer) (set-buffer file-or-buffer)) (t (set-buffer (find-file-noselect file-or-buffer)))) (let ((tbl '(hline ("Name" "TODO" "Tags" "Scheduled" "Deadline" "Clock" "Closed")))) (org-clock-sum) (org-map-entries (lambda () (push (list (entry-get "ITEM") (entry-get "TODO") (entry-get "TAGS") (entry-get "SCHEDULED") (entry-get "DEADLINE") (entry-get "CLOCKSUM") (entry-get "CLOSED")) tbl)) t 'file 'comment) (reverse tbl))) (ndk/entries-table "./bar.org") #+end_src #+RESULTS: tags | Name | TODO | Tags | Scheduled | Deadline | Clock | Closed | |-------------------+------+-------------+------------------+------------------+-------+------------------------| | Task bar1 | TODO | :tag1:tag2: | | <2020-07-21 Tue> | | | | WAITING Task bar2 | | | <2020-07-21 Tue> | | 0:02 | | | subtask bar | DONE | :tag2:tag3: | | | 0:02 | [2020-07-21 Tue 15:50] | ``` BTW `bar.org` is more or less a copy of the original file with the titles changed, and no code included. > 2 votes --- Tags: org-mode ---
thread-59656
https://emacs.stackexchange.com/questions/59656
emacsclient unable to connect to daemon under snap installation of Emacs
2020-07-15T19:50:30.770
# Question Title: emacsclient unable to connect to daemon under snap installation of Emacs I am facing with a well know problem, when I try to start `emacs --daemon` on a remote machine, I am getting following error `emacsclient: connect: Connection refused`: ``` $ ps aux | grep -E "[e]macs" # returns empty $ emacsclient -t -q doo.py emacsclient: connect: Connection refused Warning: due to a long standing Gtk+ bug https://gitlab.gnome.org/GNOME/gtk/issues/221 Emacs might crash when run in daemon mode and the X11 connection is unexpectedly lost. Using an Emacs configured with --with-x-toolkit=lucid does not have this problem. ## ... Starting Emacs daemon. Unable to start the daemon. Another instance of Emacs is running the server, either as daemon or interactively. You can use emacsclient to connect to that Emacs process. Error: server did not start correctly Error: Could not start the Emacs daemon ``` --- The way I connect into the remote machine `ssh -Y4t user@IP zsh --login -i` I don't know what can I debug more to handle this or what is the issue. I also have same configuration on a different remote machine where it works without a problem. --- **Update** based on @phils guide(please see in comments) debug in depth. ``` $ kill -9 $(ps aux | grep -E "[e]macs" | awk '{print $2}') $ ps aux | grep -E "[e]macs" # returns empty $ emacsclient -t -q doo.py emacsclient: can't find socket; have you started the server? emacsclient: To start the server in Emacs, type "M-x server-start". Warning: due to a long standing Gtk+ bug https://gitlab.gnome.org/GNOME/gtk/issues/221 Emacs might crash when run in daemon mode and the X11 connection is unexpectedly lost. Using an Emacs configured with --with-x-toolkit=lucid does not have this problem. $ ps aux | grep -E "[e]macs" # returns empty netlab 9885 14.1 0.4 464628 67812 ? Ssl 01:40 0:04 /snap/emacs/296/usr/bin/emacs --daemon $ kill -9 $(ps aux | grep -E "[e]macs" | awk '{print $2}') $ ps aux | grep -E "[e]macs" # returns empty $ unset ALTERNATE_EDITOR $ echo $ALTERNATE_EDITOR $ ls -l /tmp/emacs1002/server srwx------ 1 netlab netlab 0 Jul 16 01:40 /tmp/emacs1002/server $ rm -rf /tmp/emacs1002/server $ ls -l /tmp/emacs1002/server ls: cannot access '/tmp/emacs1002/server': No such file or directory $ emacsclient -t emacsclient: can't find socket; have you started the server? emacsclient: To start the server in Emacs, type "M-x server-start". emacsclient: No socket or alternate editor. Please use: --socket-name --server-file (or environment variable EMACS_SERVER_FILE) --alternate-editor (or environment variable ALTERNATE_EDITOR) $ emacs -Q --daemon Warning: due to a long standing Gtk+ bug https://gitlab.gnome.org/GNOME/gtk/issues/221 Emacs might crash when run in daemon mode and the X11 connection is unexpectedly lost. Using an Emacs configured with --with-x-toolkit=lucid does not have this problem. Starting Emacs daemon. $ ls -l /tmp/emacs1002/server srwx------ 1 netlab netlab 0 Jul 16 01:42 /tmp/emacs1002/server $ emacsclient -t emacsclient: can't find socket; have you started the server? emacsclient: To start the server in Emacs, type "M-x server-start". emacsclient: No socket or alternate editor. Please use: --socket-name --server-file (or environment variable EMACS_SERVER_FILE) --alternate-editor (or environment variable ALTERNATE_EDITOR) ``` # Answer Thanks to hands up here (https://github.com/tealeg/emacs-snap/issues/1#issuecomment-660462402) and `@phils`'s help on comments > It seems the current snap is https://github.com/alexmurray/emacs-snap I made a clean installation using `Alex Murray`'s `snap` (*emacs 26.3 from Alex Murray*). I verify that `emacs --daemon` works perfectly fine. --- ### The mistake I made: When I was facing the error, I believe I I have used following ppa link :-( =\> `sudo add-apt-repository ppa:kelleyk/emacs` due to this documentation (https://linuxhint.com/ubuntu\_emacs\_installation/), which had the socket problem related to `emacs --daemon` issue I faced. --- > 0 votes --- Tags: emacsclient, daemon, snap ---
thread-59767
https://emacs.stackexchange.com/questions/59767
Force Emacs to start in text mode
2020-07-21T22:39:55.343
# Question Title: Force Emacs to start in text mode \[Have been using Emacs for at least 40 years, but still ...\] What to put in `.emacs` so that Emacs opens in text mode? I have tried: ``` (setq initial-major-mode #'text-mode) (setq default-major-mode #'text-mode) (setq-default major-mode #'text-mode) (setq major-mode #'text-mode) ``` I use: `GNU Emacs 22.2.1` `GNU Emacs 25.1.1` They open always with Lisp Interaction mode. No need to tell me that I can use: `M-x text-mode`. And opening a file with a `.txt` extension. So? # Answer Put this at the end of your configuration file: ``` (setq initial-major-mode 'text-mode) ``` I see that you have tried putting it in your `.emacs` but it could be the case that it is somewhat dependent on where you put it. I tried putting this at either end of my `.emacs` and both worked. The `*scratch*` buffer is in `text-mode`. If you continue to have problems, try using the customisation system to change the value of `initial-major-mode`. Easy way to get there is `C-h v initial-major-mode` then take the option to customise this variable. > 3 votes --- Tags: init-file ---
thread-48317
https://emacs.stackexchange.com/questions/48317
Display #+INCLUDE File Contents in Github README.org?
2019-03-13T19:13:52.103
# Question Title: Display #+INCLUDE File Contents in Github README.org? I learned from How to embed external file contents in org file? about including contents from another file into the org file. I tried that for my README.org. My code in org file looked like this: ``` #+INCLUDE: "~/.emacs.d/init.el" src emacs-lisp :lines "2-20" ``` This indeed worked when I export the org file into html, looked very neat and even have syntax highlighting. However, when I upload the README into Github and try to view it in my Github project homepage's README area, the entire section of code disappeared. I wish to be able to function like `BEGIN_SRC emacs-lisp`, so that I am able to view the chunk of code within README. How can I do this? # Answer I believe the best solution is to *export to Org* (export to MD can be faulty, or deficient). This can be done using the function `org-org-export-to-org`. You can then store your regular readme in, say, `doc/README.org`, and have it automagically export to `./README.org` upon changes. That's the approach I followed for this repo. > 2 votes # Answer Github and Gitlab both use `org-ruby` to convert org syntax to markdown. The `#+INCLUDE:` syntax is available in org-ruby but requires two environmental variables to be set at run time by the server administrators to to enable this functionality. See parser.rb#L102 ``` # # Include file feature disabled by default since # it would be dangerous in some environments # # http://orgmode.org/manual/Include-files.html # # It will be activated by one of the following: # # - setting an ORG_RUBY_ENABLE_INCLUDE_FILES env variable to 'true' # - setting an ORG_RUBY_INCLUDE_ROOT env variable with the root path # - explicitly enabling it by passing it as an option: # e.g. Orgmode::Parser.new(org_text, { :allow_include_files => true }) # # IMPORTANT: To avoid the feature altogether, it can be _explicitly disabled_ as follows: # e.g. Orgmode::Parser.new(org_text, { :allow_include_files => false }) # ``` As a workaround, I also recommend exporting your original org file as a separate org file just as Michaël recommended. I use org to org exports everyday. I use the first org file as template to manage my projects. As an added benefit this allows me fine grained control over multiple documents, source code files and other file types as needed. For some real life examples in order of increasing complexity, look at Literate DevOps common-project-files.org file, Literate Devops How to Migrate LaTeX Template into org-mode and the Atom editor org-mode package. Thanks for asking your question! Hope that helped! > 0 votes --- Tags: org-mode ---
thread-12148
https://emacs.stackexchange.com/questions/12148
How to pretty-format code (auto-insert newlines, indent, etc)?
2015-05-05T10:56:56.847
# Question Title: How to pretty-format code (auto-insert newlines, indent, etc)? I'm using `spacemacs` but presumably it's emacs knowledge that's required here. I have a JSON file with a single long line, let's say this JSON from json.org/example: ``` {"menu": {"id": "file", "value": "File", "popup": {"menuitem": [{"value": "New", "onclick": "CreateNewDoc()"}, {"value": "Open", "onclick": "OpenDoc()"}, {"value": "Close", "onclick": "CloseDoc()"}]}}} ``` I would like emacs to reindent this, which means to me not change the leftmost character of line to the proper indentation level, but break the line in several lines. If I use `spacemacs/indent-region-or-buffer` (`SPC j =`) then the text is not changed at all. How could I ask from emacs to actually break this long line and reindent to get something like this: ``` {"menu": { "id": "file", "value": "File", "popup": { "menuitem": [ {"value": "New", "onclick": "CreateNewDoc()"}, {"value": "Open", "onclick": "OpenDoc()"}, {"value": "Close", "onclick": "CloseDoc()"} ] } }} ``` I'm not interested in a JSON-specific answer, for instance I believe that intelliJ does that for any language it supports (java, json...). I would think it's achievable for any language emacs has a major mode for, or let's say the most popular ones. **EDIT** I discovered `M-x json-reformat-region` that `spacemacs` ships with and works, but yes, I would like that for any language and with always the same shortcut, based on the major mode... **EDIT2** Ok so my conclusion is that it's implemented for various languages, JSON & lisp at least, presumably others, and it would be easy for yet more (XML/XHTML, go which has go-fmt and also using clang). However there's no generic function name that would do it for all the languages. There is space here to implement it in `spacemacs` layers for the various languages... I didn't find a X/HTML implementation though, which surprises me a bit. # Answer It looks like you need the `fill-region` function more than the indentation. * Select that line and do `M-x fill-region`. * Select the same, now split across multiple lines, and do `M-x indent-region`. That will, though, not insert new lines at the exact points as shown in your example. It will simply make the line fit in the fill columns. > 16 votes # Answer `json.el` package provides `json-pretty-print-buffer`. This is what it produces for your example: ``` { "menu": { "popup": { "menuitem": [ { "onclick": "CreateNewDoc()", "value": "New" }, { "onclick": "OpenDoc()", "value": "Open" }, { "onclick": "CloseDoc()", "value": "Close" } ] }, "value": "File", "id": "file" } } ``` Seems pretty decent to me. > 36 votes # Answer According to the tip here, you can use external command to format a region in your Json file: ``` (defun json-format () (interactive) (save-excursion (shell-command-on-region (region-beginning) (region-end) "python -m json.tool" (buffer-name) t))) ``` You can easily extend it to format the whole buffer: ``` (defun json-format () (interactive) (save-excursion (shell-command-on-region (point-min) (point-max) "python -m json.tool" (buffer-name) t))) ``` Emacs does not have formatting tool for programming languages (except for Lisp), only indentation commands. > 7 votes # Answer For this specific scenario `M-x json-pretty-print` will prettify the highlighted lump of json. > 4 votes # Answer BTW, for major modes using SMIE as their indentation engine, there is some part of what you need for that in the form of an `auto-fill-mode` support. I think `fill-paragraph` or `fill-region` won't do a good job, but if you put your code onto a single line, then go to the end of that line and do `M-: (smie-auto-fill)` it should give sane results (probably not perfect by a long stretch, tho). > 2 votes # Answer With emacs 26.3 you can just use the stock `json-pretty-print` function. > json-pretty-print is an interactive and compiled function defined in json.el.gz. > > -- Emacs 26.3 documentation select the region and `M-x json-pretty-print`. I've just executed this procedure taking your example as input. Here is the result: ``` { "menu": { "id": "file", "value": "File", "popup": { "menuitem": [ { "value": "New", "onclick": "CreateNewDoc()" }, { "value": "Open", "onclick": "OpenDoc()" }, { "value": "Close", "onclick": "CloseDoc()" } ] } } } ``` > 1 votes # Answer I use `json-mode-beautify` GNU Emacs 24.3.1 ``` ;;; json-mode.el --- Major mode for editing JSON files. ;; Copyright (C) 2011-2014 Josh Johnston ;; Author: Josh Johnston ;; URL: https://github.com/joshwnj/json-mode ;; Version: 1.6.0 ``` > 1 votes --- Tags: indentation, spacemacs ---
thread-59118
https://emacs.stackexchange.com/questions/59118
flycheck cannot use gfortran, executable not found
2020-06-17T13:57:00.730
# Question Title: flycheck cannot use gfortran, executable not found Previously I had been able to use flycheck for fortran files, but something seems to have broken perhaps during an update. ``` Mac OSX catalina (latest) gfortran 9.3.0 from homebrew emacs 26.3 from homebrew ``` When I call `flycheck-select-checker` and then select `fortran-gfortran` I get the following error buffer: ``` Syntax checker in buffer test.f90 in f90-mode: fortran-gfortran (disabled) - major mode: `f90-mode' supported - may enable: Automatically disabled! - executable: Not found Flycheck cannot use this syntax checker for this buffer. Flycheck Mode is enabled. Use M-x universal-argument C-c ! x to enable disabled checkers. -------------------- Flycheck version: 32snapshot (package: 20191108.2129) Emacs version: 26.3 System: x86_64-apple-darwin18.2.0 Window system: ns ``` perhaps relevant is that it cannot find gfortran from within a shell inside emacs, but it is available from a regular mac osx terminal # Answer Make sure `fortran-gfortran` is in your `exec-path`. (You can check your `exec-path` with `C-h v exec-path`.) Or, explicitly set somewhere in your init `flycheck-fortran-gfortran-executable` to point to the executable. > 1 votes # Answer This method worked for me. I have Emacs on Windows and Flycheck could not find the executable for my c/c++-gcc checker. I have added: ``` (setq flycheck-c/c++-gcc-executable "D:\\StandaloneApps\\strawberry\\c\\bin\\gcc.exe") ``` in my `init.el` file, and now .. Flycheck works in C/C++ mode. ( now, you can guess that I point to the `gcc.exe` packaged with perl :) ;) ;D ) > 0 votes --- Tags: osx, flycheck, fortran ---
thread-3022
https://emacs.stackexchange.com/questions/3022
Reset custom variable to default value programmatically
2014-11-03T09:02:45.353
# Question Title: Reset custom variable to default value programmatically **Q:** Using Elisp, how can I reset a variable to its default value without knowing what that value is? I tried to figure out how to do this by bringing up the Customize interface for a variable I set to a non-default value in my init-file and pressing `C-h k` followed by a click on the "Revert..." button. That brought up the documentation for `widget-button-click`, which obviously didn't help much. (Similarly, `C-h k` `RET` with point on the button shows help for `Custom-newline`, which is also not what I am looking for.) # Answer > 28 votes `C-h``i``g` `(elisp) Variable Definitions` > Internally, `defcustom` uses the symbol property `standard-value` to record the expression for the standard value, `saved-value` to record the value saved by the user with the customization buffer, and `customized-value` to record the value set by the user with the customization buffer, but not saved. See Symbol Properties. These properties are lists, the `car` of which is an expression that evaluates to the value. Hence: ``` (setq foo (eval (car (get 'foo 'standard-value)))) ``` Note that this only applies to `defcustom` variables (i.e. "user options"). Emacs does not save the initial value of a `defvar` variable anywhere. # Answer > 17 votes Another, probably cleaner, way to reset the value of a variable: > `custom-reevaluate-setting` is a compiled Lisp function in `custom.el`. > > `(custom-reevaluate-setting SYMBOL)` > > Reset the value of `SYMBOL` by re-evaluating its saved or standard value. Use the `:set` function to do so. This is useful for customizable options that are defined before their standard value can really be computed. E.g. dumped variables whose default depends on run-time information. So for example: ``` (custom-reevaluate-setting 'emms-player-next-function) ``` will replace the previous value with that symbol's `standard-value`. **EDIT** Read @phils comment below for a very important detail regarding this function. # Answer > 2 votes Building up from the accepted answer I've made a function for it. ``` (defun custom/reset-var (symbl) "Reset SYMBL to its standard value." (set symbl (eval (car (get symbl 'standard-value))))) (custom/reset-var 'somevar) ``` --- Tags: elisp, variables, custom ---
thread-59773
https://emacs.stackexchange.com/questions/59773
Symbol’s function definition is void
2020-07-22T07:27:54.717
# Question Title: Symbol’s function definition is void I am trying to make an interactive toggle in `emacs 27.0.90` When I `eval-region` no warnings or errors are shown. However, when I do `(helm/toggle-frame)` in `ielm` it throws `Symbol’s function definition is void: helm-in-frame-p` Here is the code, ``` (let ((helm-in-frame-p t)) (defun helm/toggle-frame () "Toggle helm in frame or in buffer. Default is buffer because it is faster on Xforwarding." (interactive) (setq helm-in-frame-p (not helm-in-frame-p)) (if (helm-in-frame-p) (progn (global-set-key (kbd "M-x") 'helm-M-x-in-frame)) (progn (global-set-key (kbd "M-x") 'helm-M-x))) (message "Helm in frame is now %s" (if helm-in-frame-p "Enabled" "Disabled")))) ``` Here is the `ielm` output ``` ELISP> helm/toggle-frame *** Eval error *** Symbol’s value as variable is void: helm/toggle-frame ELISP> (helm/toggle-frame) *** Eval error *** Symbol’s function definition is void: helm-in-frame-p ``` # Answer You define a local *variable*, then later call a non-existent *function* with the same name in the `if`: ``` (if (helm-in-frame-p) ``` Drop the surrounding parentheses and it should work again. > 7 votes --- Tags: functions, variables ---
thread-59779
https://emacs.stackexchange.com/questions/59779
Emacs auto-indenting comments in an unhelpful manner
2020-07-22T17:56:57.133
# Question Title: Emacs auto-indenting comments in an unhelpful manner New Emacs user here. Hitting enter after a semicolon commented line in any file type (.el and .lisp at the very least) indents the comment in a very unhelpful way that I have to assume is not intended behavior. This problem does not occur if I move away from that comment line in any way besides hitting return (triggering auto-indent presumably). For example, If I type the following ``` ; this is a comment ``` Then hit return, I get the following (32 spaces indentation) ``` ; this is a comment ``` What is causing this behavior, and how can I prevent it? I am running Emacs 26.3.0.20191219 installed through Chocolatey on Windows 10 # Answer Unable to post this as a comment, but the indentation is likely part of one of the active modes (probably `lisp-mode` based on your description). You can do `M+x` `describe-modes` to see which modes are active. This answer provides some background on the history of the common lisp commenting style https://stackoverflow.com/a/6365579 This question and answers describe why the single `;` indents differently than multiple consecutive `;` characters: https://stackoverflow.com/questions/14190488/set-comments-at-the-same-indentation-level-as-all-forms, namely that `lisp-indent-line` hardcodes it with the following comment ``` ;; Single-semicolon comment lines should be indented ;; as comment lines, not as code. ``` > 6 votes --- Tags: indentation, comment ---
thread-55305
https://emacs.stackexchange.com/questions/55305
SVG image display blurry
2020-02-04T21:09:53.730
# Question Title: SVG image display blurry When I open SVG files in Emacs they appear blurry. The SVG files themselves are fine (when I open them in Firefox they scale perfectly). My Emacs is compiled with svg support (librsvg), so it should use that for rendering, right? ``` (init-image-library 'svg) ``` returns `t`. Additionally, I looked at the image overlay properties with `describe-char` and I'm seeing ``` (image :type svg :file "/home/matt/src/blog/org/img/test.svg" :scale 1.726482213438735) ``` which as far as I can tell looks right. I did notice that `display-mm-width` and height were way too big and I thought that might be giving librsvg a wrong DPI, so I changed them with ``` (setq display-mm-dimensions-alist '(t . (126 . 37))) ``` But that had no effect, even after clearing the image cache. I also thought maybe imagemagick was getting in the way, so I disabled imagemagick for svg with ``` (add-to-list 'imagemagick-types-inhibit 'SVG) (imagemagick-register-types) ``` but that also had no effect. How can I get SVGs to display properly? I'm using Emacs v28, although I had the same issue with 27 and if I remember correctly, 26 as well. In any event I don't think it's a version issue. --- Edit: I was able to get this to work by changing the dvisvgm command options I was using to generate the file. I still don't understand what the issue was because firefox was able to display the SVG fine in either case. --- Edit 2: Here's a MWE of the issue. Note the comment above is wrong, I'd simply changed the dvisvgm scale with the -c flag. This hides the issue, but doesn't seem to fix it and messes up image sizes. I start with a tex document input: ``` \documentclass{standalone} \usepackage{xcolor} \begin{document} $a=b+c$ \end{document} ``` then convert it to pdf with ``` pdflatex file.tex ``` and then use dvisvgm with ``` dvisvgm --pdf file.pdf -n -b min -c 1 -o file.svg ``` Here's how it appears in an emacs buffer after several `image-increase-size` commands: Here's the same file zoomed to 300% in my browser In reference to the first edit, here's what happens when I change the dvisvgm scale (`-c`) to 10 That looks nice now, but its much larger and when you zoom in you start to see the blurriness reappear # Answer This is a known issue with Emacs, documented as issue #1 in bug report 40845. I've copied that portion of the report here for convenience > Manually scaling an image, as is done for the second image, doesn't re-render the svg: is scales the bitmap-rendered version of it, causing blurriness. There's a patch in that chain, although it doesn't seem to have been thoroughly tested and has not yet been accepted. I'll update this answer when there's a fix in master. --- As of August 23, 2020 this is now fixed (see linked bug report for details). > 1 votes --- Tags: images ---
thread-59794
https://emacs.stackexchange.com/questions/59794
Colored string in mode line
2020-07-23T13:37:10.193
# Question Title: Colored string in mode line I have: ``` (setq mode-line-end-spaces "string") ``` That displays `string` in the mode-line. How can I get `string` in red there? # Answer > 3 votes You need to create a string with the appropriate face. You do that by attaching a `face` text property to the string, giving it value of some face (predefined or defined for the specific purpose - you can look at all the predefined faces with `M-x list-faces-display` and pick one from there, or you can define your own face). E.g. here's a snippet to use a predefined face: ``` (setq s (copy-sequence "sring")) (put-text-property 0 6 'face 'custom-invalid s) (setq mode-line-end-spaces s) ``` # Answer > 4 votes @NickD provided a good answer: use a face. OP's comment to Nick's answer says that he'll try to write a function that, given a string, returns a propertized string. Such functions already exist: `propertize` does that, and so does `add-face-text-property`. For example: ``` (setq ss (propertize "abcde" 'face '(:foreground "red"))) ``` or ``` (setq ss "abcde") (add-face-text-property 0 (length ss) '(:foreground "red") nil ss) ``` --- Tags: faces, mode-line, colors, string ---
thread-59792
https://emacs.stackexchange.com/questions/59792
fill-paragraph on multiple paragraphs at once
2020-07-23T12:14:08.447
# Question Title: fill-paragraph on multiple paragraphs at once I often cut and paste non "filled" text into text files (mostly in org-mode). I then have to go line by line and call `fill-paragraph` or `org-fill-paragraph` in org-mode to clean up the text. I was wondering if there's a way to apply this operation to multiple paragraphs at once maybe in a region. For example, if we have the following paragraphs in org-mode with fill-column set to 20: ``` - This is the first paragraph. - This is the second paragraph. ``` I'd like to mark both with a region, and then have them transform into: ``` - This is the first paragraph. - This is the second paragraph. ``` It seems that `fill-region` is suppose to do this. I've tried calling it with various parameter combinations but it just condenses that entire region as one paragraph: ``` - This is the first paragraph. - This is the second paragraph. ``` # Answer Dunno about Org mode, but in normal circumstances those two lines are not considered paragraphs, because they are separated only by a single newline character (`C-j`). However, if you separate them by a blank line (i.e., another newline char), then `M-x fill-region` does what you expect: ``` - This is the first paragraph. - This is the second paragraph. ``` becomes (assuming `fill-column` is 20): ``` - This is the first paragraph. - This is the second paragraph. ``` See the Emacs manual, node Paragaphs, and the Elisp manual, node Standard Regexps. See, in particular, option `paragraph-separate`. > 0 votes --- Tags: org-mode, fill-paragraph, paragraphs ---
thread-59622
https://emacs.stackexchange.com/questions/59622
Copy the extra information lines from *Org Agenda*
2020-07-14T05:25:33.797
# Question Title: Copy the extra information lines from *Org Agenda* It's somehow strange. In the `*Org Agenda*` you can get extra information with `v c` (time gaps) or `v E` (some entry text). What I want is just to copy the extra information (text lines) with the rest of the text, so just to copy all the text from the `*Org Agenda*` buffer -- nothing else. I have tried `org-copy-visible` or even `C-x C-w`; org ignores the extra information and doesn't copy them. `C-x h` also ignores the extra information lines. How can I copy the whole buffer text? # Answer > 2 votes Although it's an extra step, you might have a look at Overlays to text. In your example, using that function by typing `M-x overlays-to-text` successfully copies all visible text, including the extra lines from `v E` and the time gap information from `v c`. The function places all that text in a new buffer. You can select anything you want from the resulting buffer. --- Tags: org-mode, org-agenda ---
thread-59790
https://emacs.stackexchange.com/questions/59790
Using openwith (or alternative) on Mac
2020-07-23T10:35:22.087
# Question Title: Using openwith (or alternative) on Mac My `openwith-associations` includes: ``` ("\\.xlsx\\'" "Microsoft Excel" (file))) ``` But this doesn't work. How should this association be written? Is there a better way to open the file link at point than using `openwith`? # Answer The shell command is just `open`, which makes `openwith` very handy indeed. ``` ("\\.xlsx\\'" "open" (file))) ``` > 1 votes --- Tags: openwith ---
thread-59802
https://emacs.stackexchange.com/questions/59802
icicles search and replace; need help to do a successfull replace
2020-07-23T17:09:40.817
# Question Title: icicles search and replace; need help to do a successfull replace I try to use Icicles to search and replace. I understand to search with it (some details, that I need), but I'm unable to do a replace. The link below shows a recipe, that I try to follow, but it doesn't seem to work. Question on stackoverflow Here is a recipe to do a search and replace: > this is text1 this is text2 and this is text3 I want to search for the string `text` and replace it with `othertext`. Set option replacing whole search context to `nil` in my config. Here we go: 1. Initiate Icicles search: Menu: Edit-Search-Icicles-Search(regexp) or `M-s M-s M-s` 2. Type `text` 3. `S-TAB` and see the contexts 4. `C-down` to first candidate. I do not want to narrow further on. 5. Minibuffer shows choose an occurrence: `text`. Cursor in the minibuffer is at the end of `text` . 6. I press `S-RET`. Nothing happens... no prompt. Unfortunately that's it. What is wrong? # Answer The key to use is `C-S-RET`, not `S-RET`. That's `Control` with `Shift` and `Return`. And you *do* want to replace the whole context, if your context is `text`. So option `icicle-search-replace-whole-candidate-flag` should be non-`nil`. --- I think that answers your question, but here is some more info, in case it helps. There are of course other ways to perform the simple replacement described. Perhaps you narrowed down a more elaborate problem to this example, which gets to the heart of the problem you were having. But if not, let me point out two things: 1. Icicles search helps even in this simple case, if you just want to replace certain occurrences, on demand, rather than being queried for each occurrence. That's really the only advantage it offers for such a simple case. And even for that there are other ways -- for example, if you use library Isearch+ then you can replace specific matches, on demand, using `C-M-RET`. 2. Icicles search is especially for searching and replacing ***within** defined contexts*, not just replacing entire regexp matches. For example, you might want to search only for occurrences of `text` within matches for regexp `is \(text\)[^ ]+`. In that case you'd provide that regexp and the number `1`, to define the context as matches for the *first* subgroup, which is `\(text\)`. You'd then proceed the same way as for your example. That would exclude other occurrences of `text`. Even more generally, you might want to define the context that way, but then search for *some text within* matches for the context, e.g., search for `xt` within the matches for `text` within the matches for `is \(text\)[^ ]+`. In that case, you'd define the contexts the same way, but then use `xt` as your minibuffer input, to, first, filter to only contexts that contain `xt` (which doesn't do any filtering, in this case, since all matches for the context regexp contain `xt`), and second, replace particular such occurrences of `xt`. To replace only matches for your minibuffer input (e.g. only the `xt` in this case), you need to turn off option `icicle-search-replace-whole-candidate-flag`, because you don't want to replace the entire search context, but just the part that matches your input. You can toggle the option value anytime during search using `M-_`. --- See Icicles - Search And Replace for more info. > 1 votes --- Tags: search, replace, icicles ---
thread-59782
https://emacs.stackexchange.com/questions/59782
Autoloaded variable overrides the one from the init file
2020-07-23T00:37:45.317
# Question Title: Autoloaded variable overrides the one from the init file I added the following line to my init file to replace `ruby-mode` with `enh-ruby-mode`: ``` (setq auto-mode-alist (mapcar (lambda (x) (if (eq (cdr x) 'ruby-mode) (cons (car x) 'enh-ruby-mode) x)) auto-mode-alist)) ``` But it works only for the first file. The first `ruby` file I open is in `enh-ruby-mode`. But in the process the following command is executed: `/usr/share/emacs/26.3/lisp/progmodes/ruby-mode.el.gz`: ``` ;;;###autoload (add-to-list 'auto-mode-alist (cons (purecopy (concat "\\(?:\\.\\(?:" "rbw?\\|ru\\|rake\\|thor" "\\|jbuilder\\|rabl\\|gemspec\\|podspec" "\\)" "\\|/" "\\(?:Gem\\|Rake\\|Cap\\|Thor" "\\|Puppet\\|Berks" "\\|Vagrant\\|Guard\\|Pod\\)file" "\\)\\'")) 'ruby-mode)) ``` (The same line is in `/usr/share/emacs/26.3/lisp/loaddefs.el`.) Which means the second and the following files are opened in `ruby-mode`. I guess to remedy this I've got to not change the line in `auto-mode-alist`, but add one. Anyways, how does this autoload thing work? When does `loaddefs.el` get executed? Is there a way to keep the line out of the file? # Answer The thing can be reproduced with `expand-region` package installed. From what I can see, when `enh-ruby-mode` gets activated, `expand-region` loads `enh-ruby-mode-expansions.el`. But that in its turn loads `ruby-mode-expansions.el`, which requires `ruby-mode.el`. As a result, when you open a ruby file, `enh-ruby-mode` gets activated, but still `ruby-mode.el` is also loaded. So, if I change `auto-mode-alist` in my init file, then when I open a ruby file, `ruby-mode.el` gets executed, and adds the association with `ruby-mode` back. To avoid that one has to require `ruby-mode.el` in advance (before opening ruby files). > 0 votes --- Tags: autoload, ruby-mode, ruby, enh-ruby-mode ---
thread-59812
https://emacs.stackexchange.com/questions/59812
Find clocking errors in org-mode entries: list/edit all clock entries with duration until next day(s)
2020-07-24T10:47:46.213
# Question Title: Find clocking errors in org-mode entries: list/edit all clock entries with duration until next day(s) I discovered the excellent org-analyzer tool and used it to analyze my clock entries in `Emacs org-mode`. Unfortunately the results are not usable yet, because there are a lot (dozens) of faulty clock entries. Most of them are "over night", so I worked on something in the afternoon, forgot to clock out and then the clock-out was generated the next morning. My question: how can I get a list of all clock intervals with 2 different dates, e. g. CLOCK: \[2020-07-24 Fri 15:38\]--\[2020-07-25 Sat 08:38\] =\> 17:00 * How can I create a search agenda to list all of them, so that I can fix them manually? Criteria would be 2 different days like in the example above. (Or is there some other way in `Emacs` to search all .org files in a directory for such entries and easily edit the faulty lines?) * or is there already a tool for cleaning up such clock entries in `org-mode`? # Answer > 2 votes Use elgrep which is available on Melpa. After a successful install, call `M-x` `elgrep-menu` or you click on the menu entry `Tools``Elgrep`. There are two features that make `elgrep` especially suited for that task: 1. Specify whole lines that start with `CLOCK:` as search records. * You can do so by setting `Beginning of Record` to `Regexp` and typing `^ *CLOCK:` into the corresponding text field. * Also set `End of Record` to `Regexp` and set the text field to `$` to specify the end of line as record end. 2. Instead of a single regexp use a list of regexps with one positive regexp and one negative one. * You can leave the positive regexp empty. In that case also `CLOCK`-lines with missing time stamps or with only a single time stamp are detected. * An exclamation mark `!` at the beginning of the second regexp negates the regexp. That means that only such records are listed that match the first regexp but **not** the second one. Behind the `!` use a regexp that matches a time interval starting and ending on the same day, i.e., including the exclamation mark `!\[\([0-9]\{4\}-[0-9]\{2\}-[0-9]\{2\}\).*\]--\[\1.*\]`. You get all the above settings automatically if you paste the following line into the first `Form:` line of the Elgrep call list and click the `[SET]` button above the input field. ``` (elgrep/i "~/" "\\.org\\'" ("" "!\\[\\([0-9]\\{4\\}-[0-9]\\{2\\}-[0-9]\\{2\\}\\).*\\]--\\[\\1.*\\]") :r-beg "^ *CLOCK:" :r-end "$" :async t) ``` You just need to replace `~/` in the text field for `Directory` with the right path. Completion by `M-TAB` works in that text field. If you need that kind of search more often for a certain directory I suggest you run the search once and afterwards give the search a name in the Elgrep call list. Those named Elgrep calls are preserved in the call list and you can even directly run them with the `[RUN]` button. The search results are listed in the `*elgrep*` buffer. That buffer has an `Elgrep` menu where you can activate `Elgrep-edit` (bound to `C-c C-e`). Afterwards you can **edit** the clock lines to your liking and save the buffer with `C-x C-s`. This modifies and saves the matching lines of the original buffers. Background info: Named elgrep calls are automatically stored in the `elgrep-data-file` relative to the `user-emacs-directory`. --- Tags: org-mode, org-agenda, org-clock ---
thread-59814
https://emacs.stackexchange.com/questions/59814
Building Emacs from source doesn't generate a native application on macOS Catalina
2020-07-24T16:23:06.327
# Question Title: Building Emacs from source doesn't generate a native application on macOS Catalina I've been trying to build Emacs 28 from source on my MacBook Pro running macOS 10.15.5. I managed to get the `feature/native-comp` branch working, but I found it to be too unstable, so I deleted Emacs and tried rebuilding off of the `master` branch. Now when I build off of the master branch, I can't get the GUI'd Emacs to build. I've tried blowing away the source directory and rebuilding from scratch, but that didn't fix anything. Here's how I build: ``` $ ./autogen.sh $ ./configure --without-ns && make $ make install ``` I worry I might have bungled deleting the old app. Any suggestions on what I might try next? # Answer > 3 votes When using the flag `--without-ns`, that means do **not** build Emacs specifically for the MacOS platform. How about using `--with-ns` instead, or no flag at all? The build script should automatically build Emacs for MacOS when building on that platform -- i.e., when **not** using `--with-ns` or `--without-ns`. The package `Emacs.app` will be in the `nextstep` folder of the Emacs source code. Here is an excerpt from the `./configure --help` output: ``` Optional Packages: --without-PACKAGE do not use PACKAGE (same as --with-PACKAGE=no) --with-ns use Nextstep (macOS Cocoa or GNUstep) windowing system. On by default on macOS. ``` --- Tags: osx, gui-emacs, build ---
thread-59804
https://emacs.stackexchange.com/questions/59804
compilation-mode and next-error confusion
2020-07-23T18:07:45.997
# Question Title: compilation-mode and next-error confusion I'm going crazy trying to understand why compilation mode and next-error recognize some errors and not others. It appears as though we're long past the days of simple regexps for recognizing errors but I'm not finding anything that explains what is, or is not used now, much less how to debug it. Why is this recognized as an error: ``` /Users/kpixley/projects/src-head/cevo/junos/ui/tests/Makefile.inc:5:0 (41): no match found, expected: ":", [ \t] or [\p{Latin}-_.${}/%0123456789] ``` While this is not? ``` /Users/kpixley/projects/src-head/cevo/jdid/jdid-infra/build-files/evo/src/Makefile.inc:14:24 (268): rule include_dir: include ``` # Answer In the following *guess*-timated answer (tested with Emacs 26.3), I have changed the fourth line from the bottom; i.e., `(regexp "[0-9]?")` to `(regexp "[0-9]+?")`. This permits Emacs to match the number `14` following the filename and the first `:` (colon). To try out this answer, evaluate the Lisp code underneath section labeled **THE CODE**, and then paste the working data into a scratch buffer and type: `M-x compilation-mode` The following link provides other methods for changing an element of an alist: How to replace an element of an alist? I chose to use the solution provided by `Dan` to modify the alist at issue in this thread. **WORKING DATA**: ``` /Users/kpixley/projects/src-head/cevo/junos/ui/tests/Makefile.inc:5:0 (41): no match found, expected: ":", [ \t] or [\p{Latin}-_.${}/%0123456789] /Users/kpixley/projects/src-head/cevo/jdid/jdid-infra/build-files/evo/src/Makefile.inc:14:24 (268): rule include_dir: include ``` **THE CODE**: ``` ;;; Load the library before trying to change `compilation-error-regexp-alist-alist' (require 'compile) (setf (nth 1 (assoc 'gnu compilation-error-regexp-alist-alist)) (rx bol (? (| (regexp "[[:alpha:]][-[:alnum:].]+: ?") (regexp "[ \t]+\\(?:in \\|from\\)"))) (group-n 1 (: (regexp "[0-9]*[^0-9\n]") (*? (| (regexp "[^\n :]") (regexp " [^-/\n]") (regexp ":[^ \n]"))))) (regexp ": ?") (group-n 2 (regexp "[0-9]+")) (? (| (: "-" (group-n 4 (regexp "[0-9]+")) (? "." (group-n 5 (regexp "[0-9]+")))) (: (in ".:") (group-n 3 (regexp "[0-9]+")) (? "-" (? (group-n 4 (regexp "[0-9]+")) ".") (group-n 5 (regexp "[0-9]+")))))) ":" (| (: (* " ") (group-n 6 (| "FutureWarning" "RuntimeWarning" "Warning" "warning" "W:"))) (: (* " ") (group-n 7 (| (regexp "[Ii]nfo\\(?:\\>\\|rmationa?l?\\)") "I:" (: "[ skipping " (+ ".") " ]") "instantiated from" "required from" (regexp "[Nn]ote")))) (: (* " ") (regexp "[Ee]rror")) (: (regexp "[0-9]+?") ;; (regexp "[0-9]?") (| (regexp "[^0-9\n]") eol)) (regexp "[0-9][0-9][0-9]")))) ``` --- **SHOW YOUR WORK** One of my old math teachers used to say always "SHOW YOUR WORK". I came up with this *guess*-timated answer by first placing a message within the function `compilation-parse-errors`, with an eye towards extracting the regexp used to process the relevant components of the *working data*, which yielded the following regexp: ``` "^ *\\(?:[[:alpha:]][-[:alnum:].]+: ?\\|[ \t]+\\(?:in \\|from\\)\\)?\\(?1:\\(?:[0-9]*[^0-9\n]\\)\\(?:[^\n :]\\| [^-/\n]\\|:[^ \n]\\)*?\\)\\(?:: ?\\)\\(?2:[0-9]+\\)\\(?:-\\(?4:[0-9]+\\)\\(?:\.\\(?5:[0-9]+\\)\\)?\\|[.:]\\(?3:[0-9]+\\)\\(?:-\\(?:\\(?4:[0-9]+\\)\.\\)?\\(?5:[0-9]+\\)\\)?\\)?:\\(?: *\\(?6:\\(?:FutureWarning\\|RuntimeWarning\\|W\\(?::\\|arning\\)\\|warning\\)\\)\\| *\\(?7:[Ii]nfo\\(?:\>\\|rmationa?l?\\)\\|I:\\|\[ skipping \.+ ]\\|instantiated from\\|required from\\|[Nn]ote\\)\\| *\\(?:[Ee]rror\\)\\|[0-9]?\\(?:[^0-9\n]\\|$\\)\\|[0-9][0-9][0-9]\\)" ``` Then, I took the *working data* and used `M-x re-builder` to see what the above-mentioned regexp matched. I modified the second line of the *working data* by reducing the `14` to just one digit and that helped me zero in on the relevant section of the regexp at issue. From there, I looked at the `compilation-error-regexp-alist-alist` to locate the correspondenting section and found it in the `gnu` section of that variable. > 1 votes # Answer This isn't a complete answer, but it provides more context. As @lawlist has shown, this matching is determined by the `gnu` regexp in `compilation-error-regexp-alist-alist`, which is currently defined as follows: ``` (gnu ;; The first line matches the program name for ;; PROGRAM:SOURCE-FILE-NAME:LINENO: MESSAGE ;; format, which is used for non-interactive programs other than ;; compilers (e.g. the "jade:" entry in compilation.txt). ;; This first line makes things ambiguous with output such as ;; "foo:344:50:blabla" since the "foo" part can match this first ;; line (in which case the file name as "344"). To avoid this, ;; the second line disallows filenames exclusively composed of ;; digits. ;; Similarly, we get lots of false positives with messages including ;; times of the form "HH:MM:SS" where MM is taken as a line number, so ;; the last line tries to rule out message where the info after the ;; line number starts with "SS". --Stef ;; The core of the regexp is the one with *?. It says that a file name ;; can be composed of any non-newline char, but it also rules out some ;; valid but unlikely cases, such as a trailing space or a space ;; followed by a -, or a colon followed by a space. ;; ;; The "in \\|from " exception was added to handle messages from Ruby. ,(rx bol (? (| (regexp "[[:alpha:]][-[:alnum:].]+: ?") (regexp "[ \t]+\\(?:in \\|from\\)"))) (group-n 1 (: (regexp "[0-9]*[^0-9\n]") (*? (| (regexp "[^\n :]") (regexp " [^-/\n]") (regexp ":[^ \n]"))))) (regexp ": ?") (group-n 2 (regexp "[0-9]+")) (? (| (: "-" (group-n 4 (regexp "[0-9]+")) (? "." (group-n 5 (regexp "[0-9]+")))) (: (in ".:") (group-n 3 (regexp "[0-9]+")) (? "-" (? (group-n 4 (regexp "[0-9]+")) ".") (group-n 5 (regexp "[0-9]+")))))) ":" (| (: (* " ") (group-n 6 (| "FutureWarning" "RuntimeWarning" "Warning" "warning" "W:"))) (: (* " ") (group-n 7 (| (regexp "[Ii]nfo\\(?:\\>\\|rmationa?l?\\)") "I:" (: "[ skipping " (+ nonl) " ]") "instantiated from" "required from" (regexp "[Nn]ote")))) (: (* " ") (regexp "[Ee]rror")) (: (regexp "[0-9]?") (| (regexp "[^0-9\n]") eol)) (regexp "[0-9][0-9][0-9]"))) 1 (2 . 4) (3 . 5) (6 . 7)) ``` That alist is preceded with the comment: ``` ;; If you make any changes to `compilation-error-regexp-alist-alist', ;; be sure to run the ERT test in test/lisp/progmodes/compile-tests.el. ;; emacs -batch -l compile-tests.el -f ert-run-tests-batch-and-exit ``` The current `gnu` test cases from `compile-tests.el` are: ``` ;; gnu foo.c:88: message ../foo.c:88: W: message /tmp/foo.c:88:warning message foo/bar.py:8: FutureWarning message foo.py:88: RuntimeWarning message foo.c:88:I: message foo.c:88.23: note: message foo.c:88.23: info: message foo.c:88:23:information: message foo.c:88.23-45: Informational: message foo.c:88-23: message ;; The next one is not in the GNU standards AFAICS. ;; Here we seem to interpret it as LINE1-LINE2.COL2. foo.c:88-45.37: message foo.c:88.23-9.17: message jade:dbcommon.dsl:133:17:E: missing argument for function call G:/cygwin/dev/build-myproj.xml:54: Compiler Adapter 'javac' can't be found. file:G:/cygwin/dev/build-myproj.xml:54: Compiler Adapter 'javac' can't be found. {standard input}:27041: Warning: end of file not at end of a line; newline inserted boost/container/detail/flat_tree.hpp:589:25: [ skipping 5 instantiation contexts, use -ftemplate-backtrace-limit=0 to disable ] ``` to which we can add the two cases from this question (I've truncated the file paths, as that makes no difference). ``` Makefile.inc:5:0 (41): no match found, expected: ":", [ \t] or [\p{Latin}-_.${}/%0123456789] Makefile.inc:14:24 (268): rule include_dir: include ``` We can then test these with `M-x` `re-builder` either by switching it to `rx` mode to use the original form<sup>1</sup>, or for the default `read` mode using `(cadr (assoc 'gnu compilation-error-regexp-alist-alist))`: ``` "^\\(?:[[:alpha:]][-[:alnum:].]+: ?\\|[ \t]+\\(?:in \\|from\\)\\)?\\(?1:\\(?:[0-9]*[^0-9\n]\\)\\(?:[^\n :]\\| [^-/\n]\\|:[^ \n]\\)*?\\)\\(?:: ?\\)\\(?2:[0-9]+\\)\\(?:-\\(?4:[0-9]+\\)\\(?:\\.\\(?5:[0-9]+\\)\\)?\\|[.:]\\(?3:[0-9]+\\)\\(?:-\\(?:\\(?4:[0-9]+\\)\\.\\)?\\(?5:[0-9]+\\)\\)?\\)?:\\(?: *\\(?6:\\(?:FutureWarning\\|RuntimeWarning\\|W\\(?::\\|arning\\)\\|warning\\)\\)\\| *\\(?7:[Ii]nfo\\(?:\\>\\|rmationa?l?\\)\\|I:\\|\\[ skipping \\.+ ]\\|instantiated from\\|required from\\|[Nn]ote\\)\\| *\\(?:[Ee]rror\\)\\|[0-9]?\\(?:[^0-9\n]\\|$\\)\\|[0-9][0-9][0-9]\\)" ``` This confirms the issue: All of the original test cases match, but only one of the new cases matches. As @lawlist identified, changing that `[0-9]?` makes a difference. If we change that to `[0-9]*` then all of the cases are now matched; however there's so much going on in this pattern that it's currently unclear to me whether or not that's the *correct* fix. In the failure case: ``` Makefile.inc:14:24 (268): rule include_dir: include ``` The line number is 14, but it's the subsequent 24 which is failing to match the zero-or-one-digit `[0-9]?`. Reducing that to a single digit (as seen in the case which worked) means the original regexp matches the line. (Use `C-c``C-u` to ensure `re-builder` picks up the change, if necessary.) That `[0-9]?` dates back to commit 0ab31e4a9ff from 2006, and was part of a change intended to "rule out false positives due to time stamps": > we get lots of false positives with messages including times of the form "HH:MM:SS" where MM is taken as a line number, so the last line tries to rule out message where the info after the line number starts with "SS". --- <sup>1</sup> You'll need make the top-level sequence explicit. Refer to the discussion of this gotcha in https://emacs.stackexchange.com/a/5577/454 > 1 votes --- Tags: compilation-mode ---
thread-59752
https://emacs.stackexchange.com/questions/59752
View multiple emails at the same time with mu4e
2020-07-20T18:27:45.163
# Question Title: View multiple emails at the same time with mu4e I use `mu4e` to read my emails. I often find myself wanting to see the content of two or three emails at the same time, in different windows in the same frame. However, `mu4e` doesn't seem to allow for this. Specifically, what I'd like to do is: * from the Headers view, open a message. This will split the frame into two frames, the headers and the individual message view. * Then, I'd like to see a second email beside the first. I try moving point to the message view, splitting the window vertically, and then selecting the second message from the headers window * I'd like for one of the two windows showing the first email body to be replaced by the body of the second email * what happens instead is that the two message windows are both closed, and replaced by a single window showing the body of the second window. The exact details aren't crucial here. What I need is a way to simultaneously display the body of two emails at the same time, in different windows in a single Emacs frame. Is this possible? # Answer Display one email first and then run `M-x clone-buffer` to get an independent copy of the buffer. Then select the second email and display it. > 4 votes --- Tags: mu4e ---
thread-59664
https://emacs.stackexchange.com/questions/59664
Is it possible to disable suspend output when Ctrl-z pressed in Emacs?
2020-07-16T12:23:15.943
# Question Title: Is it possible to disable suspend output when Ctrl-z pressed in Emacs? When I suspend `emacs` (clicking `ctrl-z`) I get following output on the terminal: `[4] + 7317 suspended emacs -nw -q file.py`, I was wondering is it possible to prevent this output to printed. I tried `stty susp undef` but it didn't help. @disabling job control in bash (CTRL-Z) mentions emacs should be reconfigured individually for this. > `stty susp undef` will disable the keyboard-initiated suspend signal for most programs, however commands like vim and `emacs` that have specific bindings for `Ctrl-Z` will have to be reconfigured individually. --- Also I set `set +m` as advices in this answer, after pressing `CTRL+z` inside emacs, shell gets frozen and I cannot close it even using `CTRL+c` # Answer > 1 votes You cannot disable this message by configuring Emacs because it comes from your shell, not from Emacs. And zsh (which you appear to be using) doesn't have a way to disable this message. Neither does bash, nor I think any other common shell. Your attempts with `stty susp undef` and `set +m` cannot possibly help because they have no impact on this message. All they can do is prevent suspension from working properly. A way not to have this message is to invoke a single Emacs process. Typically, you do this by starting Emacs as a daemon with your session. Then, to open Emacs in a terminal, run `emacsclient -t` (you can of course make a shell alias for it). This opens a frame of the running Emacs instance in the current terminal. To go back to the shell, use `C-x C-c`, which closes the current frame (but doesn't kill Emacs since it was started as a daemon). To open Emacs again, run `emacsclient -t` again. --- Tags: suspend ---
thread-59824
https://emacs.stackexchange.com/questions/59824
How to map or iterate over a list of files and set the result to `org-agenda-files`?
2020-07-25T19:28:45.190
# Question Title: How to map or iterate over a list of files and set the result to `org-agenda-files`? looking for a little help with my function. I'm trying to create a loop-while that'll return a list of files back to org-agenda-files. It's just not working though and i keep getting errors. Any ideas how I can get this to work? Any using a loop-while could be completely wrong, i'm just looking for something that'll work. ``` (setq org-gtd-task-files '("next.org" "coding.org" "personal.org")) (setq org-gtd-folder '"~/.org/gtd/") (push (format "%s%s" org-gtd-folder (loop-while org-gtd-task-files (pop org-gtd-task-files))) org-agenda-files) ``` Another method I tried was: ``` (let ((files org-gtd-task-files) (dir org-gtd-folder)) (loop-while files (setq org-agenda-files (list (format "%s%s" org-gtd-folder (prog1 (car org-gtd-task-files) (setq org-gtd-task-files (cdr org-gtd-task-files))))))) (org-agenda nil "t") (print org-agenda-files)) ``` # Answer > 6 votes Without looking up any of the Org variables or functions you refer to, here's a guess at what you're trying to do. They both do the same thing: iterate over a list of file names, expanding them in directory `org-gtd-folder`, and setting the value of variable `org-agenda-files` to the resulting list of absolute file names. ``` ;; Use `mapcar' (setq org-agenda-files (mapcar (lambda (f) (expand-file-name file org-gtd-folder)) org-gtd-task-files)) ;; Use `dolist' (dolist (file org-agenda-files) (push (expand-file-name file org-gtd-folder) org-agenda-files) org-agenda-files) ``` See the Elisp manual, nodes Iteration and Mapping Functions. One other thing: Don't use `format` or `concat` etc. for file-name manipulations. Use the file-name manipulation functions that Emacs Lisp provides. In this case, `expand-file-name`. See the Elisp manual, node File Names. --- Tags: org-agenda, list, filenames, mapping, iteration ---
thread-12625
https://emacs.stackexchange.com/questions/12625
Global keybindings don't work in 'smex'
2015-05-22T18:22:13.057
# Question Title: Global keybindings don't work in 'smex' I've installed `smex` through MELPA as a replacement for the default `M-x` (`execute-extended-command`). The issue is that in `smex`, certain global keybindings don't work. For instance, `C-h` should work as backspace, yet in `smex` it's still bound to default `help`. ``` (global-set-key (kbd "C-h") 'delete-backward-char) ``` Any idea why the above `global-set-key` might not work in `smex`, while it does elsewhere (in minibuffer, eshell, etc.)? ## Addendum to Jesse's answer When using `ido-vertical-mode` one should also rebind `M-p`: ``` (defun ido-vertical-define-keys () (define-key ido-completion-map (kbd "C-n") 'ido-next-match) (define-key ido-completion-map (kbd "C-p") 'ido-prev-match) (define-key ido-completion-map (kbd "M-p") 'previous-history-element)) ``` # Answer > 3 votes I also had this problem and couldn't fix. My workaround was overriding the smex keybindings function: ``` (defun smex-prepare-ido-bindings () (define-key ido-completion-map (kbd "TAB") #'minibuffer-complete) (define-key ido-completion-map (kbd "M-p") #'previous-history-element) (define-key ido-completion-map (kbd "M-.") #'smex-find-function) (define-key ido-completion-map (kbd "C-h") #'delete-backward-char) (define-key ido-completion-map (kbd "C-a") #'move-beginning-of-line)) ``` # Answer > 0 votes I have used eval-after-load. I don't konw but @Jesse's solution was not changed the keybindings. > Code wrapped in `eval-after-load` will be executed only once. , so it is typically used to perform `one-time` setup such as setting default global values and behaviour. --- ``` (setq smex-save-file "~/.emacs.d/settings/smex-items") (global-set-key (kbd "M-x") 'smex) (global-set-key (kbd "M-X") 'smex-major-mode-commands) (eval-after-load 'smex `(defun smex-prepare-ido-bindings () (define-key ido-completion-map (kbd "TAB") 'minibuffer-complete) (define-key ido-completion-map (kbd "C-,") 'smex-describe-function) (define-key ido-completion-map (kbd "C-w") 'smex-where-is) (define-key ido-completion-map (kbd "C-.") 'smex-find-function) (define-key ido-completion-map (kbd "C-a") 'move-beginning-of-line) (define-key ido-completion-map (kbd "C-p") 'previous-history-element) )) ``` --- Tags: ido, flx-ido ---
thread-59838
https://emacs.stackexchange.com/questions/59838
How to ignore emtpy lines on the bottom of the buffer?
2020-07-27T00:52:34.370
# Question Title: How to ignore emtpy lines on the bottom of the buffer? When I jump to bottom part of the buffer using `vi` I does not show any empty lines. On `emacs` when I got to bottom of the buffer I see empty lines even there is no new lines exist. Is is possible to accomplish same behavior of `vim` on `emacs`? # Answer > 1 votes This answer uses following answer's code with a small change Can page-down clamp the last line to the bottom of the window?. I just replaced `(my-scroll-and-clamp--forward-line height)` with `(end-of-buffer)` that is followed by the `set-window-start` section. ``` (defun my-bottom () (interactive) (let* ((height (window-height))) (end-of-buffer) ;; Move window. (set-window-start (selected-window) (min (save-excursion ;; new point. (forward-line (- (/ height 2))) (point)) (save-excursion ;; max point. (goto-char (point-max)) (beginning-of-line) (forward-line (- (- height (+ 1 (* 2 scroll-margin))))) (point))))) (redisplay) (end-of-visual-line) (forward-line (/ (window-height (selected-window)) 2))) (global-set-key "\C-x\ ." 'my-bottom) ``` --- Tags: line-numbers, newlines, line-spacing ---
thread-59840
https://emacs.stackexchange.com/questions/59840
How to enable linum-mode only during I-search?
2020-07-27T01:28:05.930
# Question Title: How to enable linum-mode only during I-search? * `linum-line` it not enabled when emacs is started. I just want to enable linum-mode (see the line numbers) during `I-search` and disable it when `I-search:` is ended. Is it possible? # Answer Ideally, one would not have to worry about line numbers at all: the various tools would cooperate to put you in the right place. However, there are holes in the coverage, so you occasionally need to know on what line you are and how to get to a given line. As @lawlist points out, it would be preferable to use `display-line-number-mode` \- see the EmacsWiki page for details. That takes care of knowing where you are and, in my case, binding `goto-line` to a key takes cares of the second. AFAIK, this is *much* more efficient than `linum-mode` (which I am not using, but which, when I tried it out many years ago, was very unresponsive, although undoubtedly it is much better than it was). If you still want to turn it on and off in `isearch`, you can try using `isearch-mode-hook` and `isearch-mode-end-hook`. Something like this (minimally tested): ``` (add-hook 'isearch-mode-hook (lambda () (linum-mode 1))) (add-hook 'isearch-mode-end-hook (lambda () (linum-mode 0))) ``` This is bog-standard emacs customization: the only thing that you have to research is whether the appropriate hooks are available, which is generally easy to do by using `C-h v isearch--hook TAB` in this case, taking advantage on one hand of the universal convention of hook naming (`<prefix>-<type>-hook`) and on the other hand the standard completion mechanism (which will expand the `--` in the middle, giving you all the variables that start with `isearch-` and end with `-hook`). IMO, this is a very useful trick and is worth remembering. > 1 votes --- Tags: isearch, linum-mode ---
thread-59836
https://emacs.stackexchange.com/questions/59836
emacs grep eliminate suspects
2020-07-26T23:46:05.077
# Question Title: emacs grep eliminate suspects Typically, at the beginning of a coding/maintenance task, I usually start with a carefully worded grep, such as ``` M-x grep git --no-pager grep -n -e 'collect' -- ':!*spec*' ':!*.yml'<enter> ``` and suppose I got 200 grep results. Usually a task requires changing only 1 or 2 files, but figuring out which files that needs the edit is the hard part in the beginning. so I would essentially "eliminate suspects" from the grep results, until I come up with a "manageable" list of files I can focus on/dig in to. How can I effectively work with the grep results in emacs, do we have the ability to "eliminate" lines interactively ? # Answer You can always make the `*grep*` buffer writable with `C-x C-q` and delete lines the normal way (e.g. with `C-a C-k C-k`). When you are done, press `C-x C-q` again to make it read-only if you wish and use `TAB` and `ENTER` to navigate and visit files in the list. > 6 votes # Answer Just to add to what @NickD said, which is what I too recommend: After making buffer `*grep*` writable, use commands `flush-lines` and `keep-lines` to quickly remove lines you're uninterested in. * `M-x flush-lines` \- Remove all lines after point that *match* a regexp you provide. * `M-x keep-lines` \- Remove all lines after point that do ***not*** match a regexp you provide. This can save a lot of time visually checking lines and removing them by hand. You can obviously use these commands multiple times, with simple regexps, to get the effect of filtering out multiple things. That's typically much easier and quicker than trying to come up with complex regexps that filter multiple things at the same time. --- Note that the same thing applies to other listings of search hits and other things, in particular the output of `M-x occur`. > 2 votes # Answer I can recommend `double-saber` mode - https://github.com/dp12/double-saber for further filtering of grep results. > 0 votes --- Tags: grep, filtering ---
thread-59847
https://emacs.stackexchange.com/questions/59847
Does Emacs have a standard function to insert or overwrite text depending of the state of overwrite-mode?
2020-07-27T20:18:09.337
# Question Title: Does Emacs have a standard function to insert or overwrite text depending of the state of overwrite-mode? * Context: using Emacs 26.2 I would like to write Emacs Lisp code that inserts or over-types text depending of the state of the overwrite-mode. I would call this function to insert text instead of the standard `insert` function. When code uses the standard `insert` function while `overwrite-mode` is `t`, text is inserted and not overwritten. I could write and use the following function, but I would have thought that such functionality would already be built-in Emacs. I can't find it. Does Emacs already provide a similar function? ``` (defun insert-or-overwrite (text) "Insert or overwrite text depending of overwrite-mode status." (when overwrite-mode (delete-char (length text))) (insert text)) ``` # Answer The answer is almost yes. `self-insert-command` is the command that is run for those keys that simply insert a character into the current buffer, and it handles overwrite correctly (and it handles the edge cases that you have forgotten in the code you wrote; I recommend taking a look at it yourself). Of course it's not really very convenient to use, since it doesn't take a string of text as an argument. > 1 votes --- Tags: insert, overwrite ---
thread-59846
https://emacs.stackexchange.com/questions/59846
Recursion in char_charset?
2020-07-27T18:30:26.753
# Question Title: Recursion in char_charset? I am looking at the C code for Emacs as of Emacs 26.1, file `charset.c` , defun `char-charset` (around line 2040), and file `charset.h`, macro `CHAR_CHARSET` (around line 380). I don't understand how in the world this might work. How does this not recurse without bound if `ch >= 0x80` and `restriction == Qnil` ?? # Answer > 3 votes This isn't recursive, because there are actually three bits of code in play. First there is the Lisp function `char-charset`, then there is the CHAR\_CHARSET macro, and finally there is the C function `char_charset`. All three are distinct. The Lisp function `char-charset` is also given the name Fchar\_charset inside the Emacs binary's symbol table, although there are no calls to it by that name. (The metadata used by the Lisp interpreter when it examines this function is stored in the static global variable Schar\_charset.) It doesn't recurse because the macro calls the function `char_charset`, not `Fchar_charset`. But certainly the Hamming distance between these names is not very great, so it is an easy mistake to make. --- Tags: characters ---
thread-59852
https://emacs.stackexchange.com/questions/59852
Modify environment using a bash script of an already running emacs
2020-07-28T09:26:05.257
# Question Title: Modify environment using a bash script of an already running emacs I have Emacs open with lots of files. I want to compile within Emacs, but first I have to source some `setup.sh` bash script that modifies the environment. How do I do that? This post says it's impossible. This man page does not help. This ergoemacs page targets a single environmental variable only, which make me feel like it might be possible! I don't want to overload the Emacs compile function, as I just want to run the script once in a while, not for every compilation. # Answer > 1 votes There is some Elisp code below that I used for years in the framework of my personal Emacs configuration. I post it here to help you but I did only a rudimentary test in `emacs -Q`. After installing and running the code, the function `setenv-from-bashrc` should do what you want. You can call it interactively or from your Elisp code with the path of the shell script as single string argument. It parses the shell script for `export` statements and sets them with Elisp command `setenv`. It also does environment variable substitution and even calls subshells if it detects expansions like `$(...)` in the shell script. ``` (require 'cl-lib) (defun setenv-scan-string (&optional eval) "Scan shell-string evaluating embedded shell commands with non-nil EVAL." (let ((inString (looking-at "\"")) str-list) (if inString (forward-char)) (while (and (not (= (point) (point-max))) (or inString (not (looking-at "\n"))) (not (looking-at "\""))) (cond ((= (point) (point-max)) (error "Reached end of buffer while scanning escape character within bash-string")) ((looking-at "\\\\") (setq str-list (cons "\\" str-list)) (forward-char)) ((looking-at "\\$\\$") (setq str-list (cons "$$" str-list)) (forward-char 2)) ((looking-at "\\$(") (setq str-list (cons (if eval (substring (shell-command-to-string (progn (forward-char) (buffer-substring-no-properties (1+ (point)) (progn (forward-sexp) (1- (point)))))) nil -1) (buffer-substring-no-properties (point) (progn (forward-char) (forward-sexp) (point)))) str-list))) (t (setq str-list (cons (buffer-substring-no-properties (point) (progn (or (> (skip-syntax-forward "w ") 0) (forward-char)) (point))) str-list))))) (apply #'concat (nreverse str-list)))) (defvar setenv-from-bashrc-trafo nil "Filter for environment variables from shell script files (like ~/.bashrc). Should be (lambda (var val) val) for unix-like operating systems and maybe `setenv-from-bashrc-trafo-windows-nt' for windows-like operating systems.") (setq setenv-from-bashrc-trafo (cl-case system-type (windows-nt 'setenv-from-bashrc-trafo-winnt) (t (lambda (var val) val)))) (defvar setenv-from-bashrc-winnt-trafo-exceptions nil "Variables that are not transformed from cygwin-directories to winnt-directories.") (setq setenv-from-bashrc-winnt-trafo-exceptions '("DISPLAY" "CDHIST_SIZE" "CLIENT_NAME" "COLUMNS" "COMPUTERNAME" "EM_PARENT_PROCESS_ID" "G_SLICE" "LANG" "LC_LANG" "LINES" "LOCATION" "LOGONSERVER" "NO_AT_BRIDGE" "NUMBER_OF_PROCESSORS" "OS" "PAPERSIZE" "PROCESSOR_ARCHITECTURE" "PROCESSOR_IDENTIFIER" "PROCESSOR_LEVEL" "PROCESSOR_REVISION" "SESSIONNAME" "SHELL" "SYSTEMDRIVE" "SYSTEMROOT" "USERDNSDOMAIN" "USERDOMAIN" "USERNAME" "windows_tracing_flags")) (defun setenv-from-bashrc-trafo-winnt (var val) "Replace `:' with `;' and afterwards `/c/' after `;' with `c:'." (unless (member var setenv-from-bashrc-winnt-trafo-exceptions) (let ((pos 0)) (while (string-match "[^:;][a-zA-Z]:" val pos) (setq pos (match-end 0)) (aset val (1- pos) ?\;)) (setq pos 0) (while (string-match "\\(?:^\\|;\\)\\(/c/\\)" val pos) (setq pos (match-end 1)) (setq val (replace-match "c:/" t t val 1))))) val) ;; Get environment variables: (defun setenv-from-bashrc (filename) "Set environment variables from file FILENAME." (interactive "fFile name:") (and (file-exists-p filename) (set-buffer (find-file-noselect filename)) (save-excursion (goto-char (point-min)) (while (search-forward-regexp "^\\(export \\)?\\([[:alnum:]_]+\\)=" nil 'noErr) (let* ((var (match-string-no-properties 2)) (val (funcall setenv-from-bashrc-trafo var (setenv-scan-string t)))) (message "Set \"%s\" to \"%s\"." var val) (setenv var val 'substitute-env-vars))))) (let ((paths (split-string (getenv "PATH") ":" t))) (dolist (path paths) (add-to-list 'exec-path path)))) ``` ## Test: Emacs version: `GNU Emacs 28.0.50 (build 1, x86_64-pc-linux-gnu, GTK+ Version 3.22.30, cairo version 1.15.10) of 2020-06-22` Contents of the shell script file `/temp/test.sh`: ``` export some="thing of Tobias" export expanding="Some ${some}" export running="$(time)" ``` Test run: * Copy above Elisp code into buffer `<*scratch*>` and run it with `M-x` `eval-buffer` `RET` * `M-x` `setenv-from-bashrc` `RET` * Check the environment settings with + `M-x` `getenv` `RET` `some` `RET` Answer: `thing of Tobias` + `M-x` `getenv` `RET` `expanding` `RET` Answer: `some thing of Tobias` + `M-x` `getenv` `RET` `running` `RET` Answer: ``` real 0m0.000s user 0m0.000s sys 0m0.000s ``` Good luck with the code! Please comment if you encounter any problems. # Answer > 2 votes How about: ``` (setq compile-command "bash -c '. /path/to/setup.sh; make'") ``` --- Tags: bash ---
thread-59850
https://emacs.stackexchange.com/questions/59850
Specify what combinations shown as ligature while using FiraCode?
2020-07-28T05:15:06.203
# Question Title: Specify what combinations shown as ligature while using FiraCode? I'm using FiraCode in Emacs. Some ligature satisfies me and some don't. For example, I really dislike this: Is there any means to include or exclude specific ligatures? # Answer > 2 votes Most fonts have a built-in ligature table that controls when a glyph is used in place of other glyphs. For example, most fonts combine the 'f' and 'i' glyphs into an 'fi' glyph. For those fonts, you must either accept all the ligatures the font provides, turn all ligatures off, or edit the font to delete ligatures you don't like. FiraCode is a little unusual in that it includes no (or very few; I've never actually taken a look inside) ligatures within the font itself. Instead it relies on the application to pick ligatures without any support from the ligature table inside the font. When you set up Emacs to use FiraCode, you copied and pasted a big chunk of code into your init file. This is the code that tells Emacs how to use FiraCode's ligature glyphs. All you have to do is edit it to remove the one that you don't like. --- Tags: fonts ---
thread-59809
https://emacs.stackexchange.com/questions/59809
Cannot set the org-agenda to start my week on monday
2020-07-24T08:36:15.150
# Question Title: Cannot set the org-agenda to start my week on monday In `org-agenda` I am trying to change the start of my week to monday by adding this to my `.emacs` file: `(setq org-agenda-start-on-weekday 1)` Without success. The week (in the mini calendar, when I try to schedule a task) always starts with sunday). Also `M-x customize-variable [return] org-agenda-start-on-weekday` and setting it to `1` didn't help. What am I missing? # Answer > 3 votes (why are you asking this on both StackExchange and Reddit?) That's not the org-agenda, that's the calendar. Try ``` (setq calendar-week-start-day 1) ``` (btw, org-agenda-start-on-weekday is '1' by default) # Answer > 2 votes If that doesn't help, you can use the below to set the start day to today for org-agenda. `(setq org-agenda-start-day (org-today))` --- Tags: org-mode, org-agenda ---
thread-59867
https://emacs.stackexchange.com/questions/59867
Change $PATH once emacs is running
2020-07-29T07:49:43.807
# Question Title: Change $PATH once emacs is running In my shell (`Bash`), I can switch among several `LaTeX` distros setting the `$PATH` variable. E.g.: ``` export PATH=/usr/local/texlive/2016/bin/x86_64-linux:$PATH ``` or ``` export PATH=/usr/local/texlive/2018/bin/x86_64-linux:$PATH ``` This doesn't affect the `LaTeX` distro used by emacs when I call the function `tex-file`. Is there a way to set the `$PATH` variable used by emacs once it is running. I need it to test the `.pdf` file layout generated by different `LaTeX` distros while working on a document. # Answer Emacs initialises `C-h``v` `exec-path` based on `PATH` at start-up, and finds executables based upon that. > This doesn't affect the LaTeX distro used by emacs when I call the function `tex-file`. Try this: ``` (let ((exec-path (cons "/usr/local/texlive/2018/bin/x86_64-linux" exec-path))) (tex-file)) ``` --- Note that `exec-path` is not automatically copied into the environment inherited by other processes started by Emacs; so if the executable ultimately called by `tex-file` itself *also* required `PATH` to contain `/usr/local/texlive/2018/bin/x86_64-linux` then you would need to set `process-environment` as well: ``` (let* ((tex "/usr/local/texlive/2018/bin/x86_64-linux") (exec-path (cons tex exec-path)) (process-environment (cons (format "PATH=%s:%s" tex (getenv "PATH")) process-environment))) (tex-file)) ``` > 3 votes # Answer Using the `emacs` function `setenv` is a way to modify the environment of the running `emacs` process. For your particular use case, you'd want to evaluate: ``` (setenv PATH "modified-path-variable") ``` or simply `M-x` `setenv` and enter the value at the prompt. You can put together an `elisp` function following the answers here, to quickly toggle between your `texlive` distributions. Or you can probably do the same using the answer from @phils > 3 votes --- Tags: variables, environment ---
thread-59862
https://emacs.stackexchange.com/questions/59862
Unable to find files with ssh and environment variables
2020-07-29T03:02:32.400
# Question Title: Unable to find files with ssh and environment variables I have installed `exec-path-from-shell` as well as included the following in my `init.el` ``` (when (memq window-system '(mac ns x)) (exec-path-from-shell-initialize)) ``` within my `~/.bash_profile` I have defined an environment variable called `SOLARIS` which stores an IP address. I run the command `M-x exec-path-from-shell-copy-env (RET) SOLARIS (RET)` to 'import' the environment variable. But when I run `C-x C-f /ssh:user@$SOLARIS:` it throws out the error: ``` Error running timerL (error "In 'Find Files' source: 'helm-find-files-get-candidates' (user-error \"Not a Tramp file name: \\\"/ssh:user@$SOLARIS:\\\"\")") ``` When I run the `find-file` command using the explicit IP address instead of the environment variable, it works fine # Answer There is no expansion of shell variables there, either before or after it looks for the TRAMP filename syntax. I recommend configuring your ssh config file (`~/.ssh/config`) to have aliases that you can use. Something like, perhaps: ``` Host solaris Hostname w.x.y.z ``` Then, when you open the file `/ssh:user@solaris:…` in Emacs, ssh will use the correct ip address for the short host name 'solaris'. If you also specify the `IdentityFile` option, then it will automatically use the correct ssh key as well. That will save you time since you won't have to type in a password. You can shorten it even more by specifying the `User` option as well, so that you don't have to type your username every time. > 1 votes # Answer I believe it is a problem in helm, which doesn't expand environment variables. I have tried to reproduce the problem: 1. Download `exec-path-from-shell.el` from github (melpa doesn't work ATM) 2. `# emacs -Q -l ~/Downloads/exec-path-from-shell.el` 3. Evaluate `(when (memq window-system '(mac ns x)) (exec-path-from-shell-initialize))`. This results in `(("MANPATH" . "/usr/share/man:") ("PATH" . "/usr/share/Modules/bin:/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin"))`. No problem, I can use any environment variable for my test. 4. Evaluate `M-x exec-path-from-shell-copy-env (RET) MANPATH (RET)`. 5. Open the file `C-x C-f /ssh:user@$MANPATH:`. Obviously an error, but it tries to open `/ssh:user@/usr/share/man::` as expected. I recommend to check, what helm does. > 1 votes --- Tags: tramp, find-file, bash, environment ---
thread-59875
https://emacs.stackexchange.com/questions/59875
Org Src Block does not return any output
2020-07-29T16:05:01.103
# Question Title: Org Src Block does not return any output TL;DR: How do I get the stderr of my source block to be part of the #+RESULTS block, without changing the contents of the block? I can only get stdout to appear. --- \[Long and winding explanation\] While writing this question I found a solution/reason to it not working. Since I spent quite some time on it, I thought I'd still post it. Hey there! I'm relatively new to emacs and org mode especially. Last month, I started writing my bachelor's thesis for applied computer science using org mode (based on dangom's template). In the thesis, I use `org-src` blocks to demonstrate stuff. In this case, I've set up an example to demonstrate warnings from a `C` Compiler: ``` #+CAPTION: A simple C-Program without errors, but with a Code Smell #+NAME: qc:c-code #+ATTR_LATEX: :placement [H] #+BEGIN_SRC C :tangle ../sourcecodes/foo.c // foo.c #include <stdio.h> int main() { int i=10; } #+END_SRC ``` As you can see, this *program* is stored in a seperate `sourcecodes` folder: ``` ├── backmatter ├── frontmatter ├── images ├── library.bib ├── literatur ├── mainmatter │ └── 03-analysis.org <- This is where I am ├── sourcecodes │ ├── foo │ └── foo.c <- and here goes the program └── thesis ``` Now, I wish to build that file. ``` #+CAPTION: ... #+NAME: qc:c-code-build #+ATTR_LATEX: :placement [H] #+BEGIN_SRC sh :results output :dir ../sourcecodes gcc foo.c -Wall -o foo #+END_SRC ``` In this example, I use the `dir` header to change the directory for execution of the code. When run in a terminal, this results to this: ``` foo.c: In function 'main': foo.c:5:9: warning: unused variable 'i' [-Wunused-variable] 5 | int i=10; | ^ ``` This is what I would expect. In emacs, it results to this: ``` #+RESULTS: qc:c-code-build ``` Whereas this ``` #+CAPTION: ... #+NAME: qc:c-code-build #+ATTR_LATEX: :placement [H] #+BEGIN_SRC sh :results output :dir ../sourcecodes ls gcc --version gcc foo.c -Wall -o foo ls #+END_SRC ``` returns that: ``` #+RESULTS: qc:c-code-build : foo.c : gcc (GCC) 9.3.0 : Copyright (C) 2019 Free Software Foundation, Inc. : This is free software; see the source for copying conditions. There is NO : warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. : : foo : foo.c ``` Now, obviously this is not a real problem - just copy and paste the desired output into a `src` block your own. I would just like to know if I'm missing something super obvious. Other stuff I've tried/noticed: * Using `shell` instead of `sh` * `results: output replace` * `:exports both` * created a minimal example, which does not load anything from the template * tried to use scimax (and failed, since by default it doesn't contain the org-babel-execute function for sh/shell) * some Buffer once gave me errors (`Error Output` or something) Now, as promised, the reason: Org-mode shell source blocks do not capture stderr My solution for the problem: I don't have a good solution for this as of yet. The solution of John Kitchin suggests use of `2>&1` which writes all stderr to stdout, for example: ``` #+BEGIN_SRC sh :results output replace :dir ../sourcecodes :exports both gcc foo.c -Wall -o foo 2>&1 #+END_SRC ``` But that adds some unnecessary logic to the eye for the reader of the thesis, which is why I'm probably staying with copy-pasting stderr into src-blocks (except someone has a better solution) # Answer > 12 votes Rephrasing and shortening, I guess the question is roughly: "how to obtain stderr output without changing the source block content?" By skimming the comments section of the John Kitchin's post, adding ``` #+PROPERTY: header-args:sh :prologue "exec 2>&1" :epilogue ":" ``` globally, at the top of the file, should do the job (it works in my side). --- Tags: org-mode, org-babel, shell ---
thread-30653
https://emacs.stackexchange.com/questions/30653
flyspell's highlight cleared after a "save word" action
2017-02-12T10:06:17.693
# Question Title: flyspell's highlight cleared after a "save word" action After running `flyspell-buffer`, all misspelled words are highlighted. However, after saving a word, all of the highlighting is gone. How can I avoid that? My `flyspell-persistent-highlight` is set `t`. # Answer > 0 votes Via https://www.emacswiki.org/emacs/FlySpell#toc9 and https://www.reddit.com/r/emacs/comments/4oc7pg/spellcheck\_flyspellmode\_underlines\_disappear\_when/d5l9vtt/ I found this solution: ``` (defun flyspell-buffer-after-pdict-save (&rest _) (flyspell-buffer)) (advice-add 'ispell-pdict-save :after #'flyspell-buffer-after-pdict-save) ``` Unfortunately this seems to trigger a bit too often: `flyspell-buffer` now also runs after correcting a word or even after dismissing the `mouse-2` menu without any action. --- Tags: flyspell ---
thread-59657
https://emacs.stackexchange.com/questions/59657
How to bulk mark agenda items based on file name?
2020-07-15T22:32:15.730
# Question Title: How to bulk mark agenda items based on file name? my `org-agenda` todo list looks something like this: ``` inbox: TODO learn how to process the inbox inbox: TODO learn how to create a useful org agenda foo: TODO start the project ``` I want to use `org-agenda-bulk-mark-regexp` to mark all the items residing in my inbox. I'm invoking the function like `(org-agenda-bulk-mark-regexp "inbox:")`. However, this doesn't select the items in the inbox. It only works on items that contain `inbox:` in their header. How can I select these items? # Answer > 1 votes Was having the exact same problem. ## Issue: If you take a look at the source for `org-agenda-bulk-mark-regexp`: ``` (defun org-agenda-bulk-mark-regexp (regexp) "Mark entries matching REGEXP for future agenda bulk action." (interactive "sMark entries matching regexp: ") (let ((entries-marked 0) txt-at-point) (save-excursion (goto-char (point-min)) (goto-char (next-single-property-change (point) 'org-hd-marker)) (while (and (re-search-forward regexp nil t) (setq txt-at-point (get-text-property (match-beginning 0) 'txt))) (if (get-char-property (point) 'invisible) (beginning-of-line 2) (when (string-match-p regexp txt-at-point) (setq entries-marked (1+ entries-marked)) (call-interactively 'org-agenda-bulk-mark))))) (unless entries-marked (message "No entry matching this regexp.")))) ``` The issue comes when the `txt` text property is saved as `txt-at-point` and used for matching the regex with `string-match-p` later on. As the comments to your question stated, `inbox` is the category (which is usually the same as the filename) and doesn't appear with a colon (`inbox:`) in the `txt` property. ## Solution: I made an edited version of the same function which matches based on the category but not based on any of the text of the item: ``` (defun custom/org-agenda-bulk-mark-regexp-category (regexp) "Mark entries whose category matches REGEXP for future agenda bulk action." (interactive "sMark entries with category matching regexp: ") (let ((entries-marked 0) txt-at-point) (save-excursion (goto-char (point-min)) (goto-char (next-single-property-change (point) 'org-hd-marker)) (while (and (re-search-forward regexp nil t) (setq category-at-point (get-text-property (match-beginning 0) 'org-category))) (if (get-char-property (point) 'invisible) (beginning-of-line 2) (when (string-match-p regexp category-at-point) (setq entries-marked (1+ entries-marked)) (call-interactively 'org-agenda-bulk-mark))))) (unless entries-marked (message "No entry matching this regexp.")))) ``` This can now be used as such: ``` (defun custom/org-process-inbox () "Called in org-agenda-mode, processes all inbox items." (interactive) (custom/org-agenda-bulk-mark-regexp-category "inbox") (custom/bulk-process-entries)) ``` While this still doesn't allow you to match the `inbox:` pattern directly as you still have to remove the colon, I think it likely accomplishes what you're looking for in trying to bulk mark based on the category (file name). --- Tags: org-mode, org-agenda ---
thread-59866
https://emacs.stackexchange.com/questions/59866
url-(https)-file-exists-p: ignore interactive behaviour when called programmatically (insecure TLS connection)
2020-07-29T06:33:44.963
# Question Title: url-(https)-file-exists-p: ignore interactive behaviour when called programmatically (insecure TLS connection) I want to use `url-file-exists-p` (or more precisely, the underlying `url-https-file-exists-p`) to detect possible broken links. However, some `https` link makes `url-file-exists-p` require interaction (This even happens when `url-file-exists-p` is called programmatically): 1. when the TLS connection is insecure: a buffer named `*Network Security Manager*` pop up to show certificate information and a prompt is waiting for input as below; (below is the result of the help). 2. ask for user-name and password. I'm looking for a way to 1. prevent the buffer `*Network Security Manager*` pop up 2. send input to the prompt whenever is needed 3. return different values/symbols depending on the context * `t`: secure connection, no prompt showed up * `nil`: connection failure * TLS: `'always`, `'session` and `'no`: depending on the input (2.) sent whenever a prompt requires one * username/password: `'ignored` if username/password are not sent to the prompt causing failure. # Answer I list below several attempts I tried. 1. Associate `display-buffer-no-window` to the buffer `*Network Security Manager*`. This prevent the buffer to pop up, and since `url-file-exists-p` fails to receive input, an error is throw. Finally, intepret the "pop up" as `'no`. ``` (let ((display-buffer-alist (cons display-buffer-alist (cons "\\*Network Security Manager\\*" (cons #'display-buffer-no-window nil))))) (condition-case nil (url-file-exists-p url) (error 'no))) ``` 2. Bound `(minibuffer-message-timeout 0)` in a let-in form. For whatever reason, the two first attempts fail to deal with the prompt asking for authentification. By inspecting the source code of `url-*` packages, I found a workaround: > Send a `GET` request instead of a `HEAD` request as `url-http-file-exists-p` do (`url-http-head`). 3. Strangely, the website requiring authentification doesn't require one when is a `GET` request in contrast to `HEAD` request. Obviously, this is just a workaround as a `GET` request may take much more resource than a `HEAD` one. ``` (defun my/url-http-file-exists-p (url) (let ((buffer (url-retrieve-synchronously url t t))) (when buffer (let ((status (url-http-symbol-value-in-buffer 'url-http-response-status buffer 500))) (prog1 (and (integerp status) (>= status 200) (< status 300)) (kill-buffer buffer)))))) ``` 4. Use the auto-answer package where it is illustrated in this answer. To do this, we need to enhance it so that it supports `read-multiple-choice` (the function called when there is an insecure TLS connection). ``` (defun rmc-auto-answer (oldfun &rest args) (let ((prompt (car args))) (let* ((matcher-answer (and (stringp prompt) (--first (string-match (car it) prompt) auto-answer))) (dontask (and matcher-answer (cdr matcher-answer)))) (if dontask (--first (eq (car it) dontask) (cadr args)) (apply oldfun args))))) (advice-add #'read-multiple-choice :around #'rmc-auto-answer) ``` Finally, by binding the variable `auto-answer`, we can feed the input automatically whenever there is an insecure TLS connection asking for input ``` (let ((auto-answer (list (cons "Continue connecting\\?" ?s)))) (url-http-file-exists-p url)) ``` However, the authentification prompt occurs in an endless loop which means that this attempt is not sufficient (even if we can `auto-answer` username/password). 5. TODO Use Request.el instead of `url.el`. > 0 votes --- Tags: url ---
thread-59884
https://emacs.stackexchange.com/questions/59884
Create new key binding for command mode in evil mode
2020-07-29T23:27:29.970
# Question Title: Create new key binding for command mode in evil mode I am using doom emacs and would like to create a key binding to run the following line so that I don't need to write it every time I want to run a block of code of python ``` :w !python ``` The above line runs python code highlighted in visual mode in the terminal. # Answer > 1 votes The cleanest way is to not reuse Evil-specific commands or keystrokes unless absolutely necessary. Looking at the definition of `:w`, which happens to be the `evil-write` command, one can see that it parses the file name argument and calls `shell-command-on-region` if it starts with a bang. Here's the equivalent specialized command: ``` (defun my-evil-run-python-region (beg end) (interactive "r") (if (region-active-p) (shell-command-on-region beg end "python") (shell-command-on-region (point-min) (point-max) "python"))) (global-set-key (kbd "<F5>") 'my-evil-run-python-region) ``` --- Tags: key-bindings, evil, doom ---
thread-59878
https://emacs.stackexchange.com/questions/59878
Does declare-function recognize functions declared via cl-defun?
2020-07-29T20:13:37.843
# Question Title: Does declare-function recognize functions declared via cl-defun? It seems that `declare-function` \+ `check-declare-file` do not recognize functions defined via `cl-defun`. I was happy using `declare-function` because it comes with `check-declare-file` that actually checks whether the declaration is consistent with the actual code in some other source file. However, when I upgraded the code for one of my declared functions, adding some keyword arguments and relying on `cl-defun` for handling them, `check-declare-file` could not validate and said that the function was not to be found. Is there a workaround I could use? Or maybe `declare-function` is obsolete and there is some newer method I should use instead? # Answer > 1 votes At first note that `check-declare-verify` actually has a pattern for `cl-defun` in its regexp. So it should work. If it does not maybe you should double-check and report an error if your code is not the source of the problem. If it really turns out that you did not make any error and want to suppress the warning the doc string for `declare-function` answers your question: > `(declare-function FN FILE &optional ARGLIST FILEONLY)` > > Optional `FILEONLY` non-nil means that `check-declare` will check only that `FILE` exists, not that it defines `FN`. This is intended for function definitions that `check-declare` does not recognize, e.g., `defstruct`. So use a non-nil `FILEONLY` argument in `check-declare` for functions defined by `cl-defun`. --- Tags: declare, cl ---
thread-59853
https://emacs.stackexchange.com/questions/59853
Org task repeatable cycle state turn DEADLINE and SCHEDULED timestamp inactive/active
2020-07-28T09:47:19.767
# Question Title: Org task repeatable cycle state turn DEADLINE and SCHEDULED timestamp inactive/active I have a list of repeatable tasks. Sometimes I deactivate them by changing state to CANCELED. But when I do it the new SCHEDULE is created in the future. To prevent that from happening I change timestamp to inactive by hand, and when I want to bring this repeatable task back to TODO I have to remember to activate timestamp. I could remove timestamp from task before canceling it, and set it again if necessary, but I want to keep it as inactive in case I would like to return to it in the future, so I know repeatable setting from the past. How could I make task timestamp (DEADLINE and/or SCHEDULED) inactive while switching to CANCELED state, and active while changing it to TODO automatically? EDIT: I managed to put together something like this, but it doesn't work. ``` (defun jarfar/org-state-canceled-timestamp-toggle () "Toggle active/inactive SCHEDULED or DEADLINE timestamp when switching between CANCELED and TODO state." (save-excursion (let ((state (org-get-todo-state))) (cond ((equal state "CANCELED") (when (and (org-get-deadline-time (point)) (search-forward-regexp "DEADLINE: .*" nil t) (null (deactivate-mark)) (equal (char-to-string (char-after)) ">")) (org-toggle-timestamp-type)) (when (and (org-get-scheduled-time (point)) (search-forward-regexp "SCHEDULED: .*" nil t) (null (deactivate-mark)) (equal (char-to-string (char-after)) ">")) (org-toggle-timestamp-type))) ((equal state "TODO") (when (and (org-get-deadline-time (point)) (search-forward-regexp "DEADLINE: .*" nil t) (null (deactivate-mark)) (equal (char-to-string (char-after)) "]")) (org-toggle-timestamp-type)) (when (and (org-get-scheduled-time (point)) (search-forward-regexp "SCHEDULED: .*" nil t) (null (deactivate-mark)) (equal (char-to-string (char-after)) "]")) (org-toggle-timestamp-type))))) (when (equal (buffer-name (current-buffer)) "*Org Agenda*") (with-current-buffer "*Org Agenda*" (org-agenda-redo))))) (add-hook 'org-after-todo-state-change-hook 'jarfar/org-state-canceled-timestamp-toggle) ``` # Answer > 0 votes I figured this out. My solution is below. The problem was with `org-at-timestamp-p` function which takes only one parameter, so we can't tell that the timestamp is valid agenda like timestamp and it's inactive at the same time. So to change inactive timestamp to active I had to detect inactive state by checking the character at point if it match closing bracket. The good part is that `search-forward-regexp` places the point at the end of timestamp. It's a workaround that works. It would be ideal if `org-at-timestamp-p` would accept multiple parameters. Current implementation is quite limited. ``` (defun jarfar/org-state-canceled-timestamp-toggle () "Toggle active/inactive SCHEDULED or DEADLINE timestamp when switching between CANCELED and TODO state." (save-excursion (let ((state (org-get-todo-state))) (cond ((equal state "CANCELED") (when (and (org-get-deadline-time (point)) (search-forward-regexp "DEADLINE: .*" nil t) (org-at-timestamp-p 'agenda)) (org-toggle-timestamp-type)) (when (and (org-get-scheduled-time (point)) (search-forward-regexp "SCHEDULED: .*" nil t) (org-at-timestamp-p 'agenda)) (org-toggle-timestamp-type))) ((equal state "TODO") (when (and (org-get-deadline-time (point)) (search-forward-regexp "DEADLINE: .*" nil t) (equal (char-to-string (char-before)) "]")) (org-toggle-timestamp-type)) (when (and (org-get-scheduled-time (point)) (search-forward-regexp "SCHEDULED: .*" nil t) (equal (char-to-string (char-before)) "]")) (org-toggle-timestamp-type))))) (when (equal (buffer-name (current-buffer)) "*Org Agenda*") (with-current-buffer "*Org Agenda*" (org-agenda-redo))))) (add-hook 'org-after-todo-state-change-hook 'jarfar/org-state-canceled-timestamp-toggle) ``` --- Tags: org-mode ---
thread-59892
https://emacs.stackexchange.com/questions/59892
Narrow down refilling options to single sub-heading
2020-07-30T13:24:49.490
# Question Title: Narrow down refilling options to single sub-heading I have a single file `tasks.org` that contains all the tasks for agenda and I have separate projects files with a tasks related to specific project. I try to setup a configuration that will let me refile tasks from project files under the heading `* Projects` in `tasks.org` file and from the `tasks.org` file back to specific project file under heading `** Tasks`. I try to use `:regexp` to narrow down refilling options to specific heading, but it doesn't work at all, it works only when I use `:level` parameter - maybe there is a bug in "regexp" parameter implementation or I use it wrong way. Global `org-refile-targets`: ``` (setq org-refile-targets `( (,my/project-1 :level . 1) (,my/project-2 :regexp . "Projects$"))) ``` The example project file: ``` # -*- mode: org -*- # Local Variables: # eval: (setq-local org-refile-targets `((,my/org-tasks-file-path :regexp . "Projects$"))) # End: * Project 1 ** Tasks *** TODO bar ** Resources ``` Example `tasks.org` file: ``` # -*- mode: org -*- * Tasks ** TODO foo * Projects ``` --- EDIT: I managed to succesfully refile task from tasks.org to project file. The problem was that there were different heading depths. The tasks.org have 2 levels and project file had 3. I changed project file to match number of heading levels with tasks file and now it works. The project.org file look like this now: ``` # -*- mode: org -*- * Project 1 ** Tasks *** TODO bar ** Resources ``` The only problem that left is to narrow down local refiling options for project file to just tasks.org `* Projects`. Local Variables with eval doesn't work. When I eval `(setq-local org-refile-targets` ((,my/org-tasks-file-path :regexp . "Projects$")))\` by hand it works though. Any idea how can I set `org-refile-targets` on file level? # Answer Solved! I created `.dir-locals.el` file to set local `org-refile-targets` for all the files in the `projects` folder. `.dir-locals.el`: ``` ((nil . ( (eval . (progn (jarfar/org-projects-set-refile-targets-local))) ))) ``` I defined `jarfar/org-projects-set-refile-targets-local` to set local variable, because `.dir-locals.el` syntax is quite limited, but we can call functions inside of it so we are all good. The function looks like this: ``` (defun jarfar/org-projects-set-refile-targets-local () "Set local 'org-refile-targets for project org files." (setq-local org-refile-targets `((,jarfar/org-tasks-file-path :regexp . "Projects$")))) ``` Read first post EDIT together with this one for complete solution. --- EDIT: I decided to move local folder config from `.dir-locals.el` to general config: ``` (setq jarfar/org-projects-folder "~/Documents/emacs/projects) (dir-locals-set-class-variables 'jarfar/projects-directory '((nil . ( (eval . (progn (jarfar/org-projects-set-refile-targets-local))) )))) (dir-locals-set-directory-class jarfar/org-projects-folder 'jarfar/projects-directory) ``` > 1 votes --- Tags: org-mode ---
thread-59896
https://emacs.stackexchange.com/questions/59896
Refresh org statistics cookies automatically
2020-07-30T15:22:57.750
# Question Title: Refresh org statistics cookies automatically I try to automatically refresh statistics cookies while changing buffer to org buffer, saving buffer, showing agenda and refreshing agenda. I know it's possible to update entire file by calling `org-update-statistics-cookies` with prefix. Any ideas? # Answer This did the trick. ``` (defun jarfar/org-update-all-statistics-cookies () "Update all statistics cookies in org buffer." (when (string-equal major-mode "org-mode") (org-update-statistics-cookies t))) (add-hook 'buffer-list-update-hook 'jarfar/org-update-all-statistics-cookies) (advice-add 'save-buffer :before (lambda (&rest args) (jarfar/org-update-all-statistics-cookies))) ``` --- EDIT Sadly this messes things up. When cookies get updated the file is marked as modified even if there were no changes, so it cause constant problems with unsaved changes. It turned out that it's better to refresh cookies manually. > 0 votes --- Tags: org-mode ---
thread-59895
https://emacs.stackexchange.com/questions/59895
How to refresh org file programatically
2020-07-30T14:28:28.863
# Question Title: How to refresh org file programatically I am using `spacemacs-light` theme in Emacs and love it. In my spacemacs-light theme, some org-files open with bullets not hidden though. In those cases I go to the top of the file and hit `C-c C-c` to refresh my org-file. And then I go back to where I was via `C-u C-SPC`. Now I would like to create an elisp function that does this in a single step and map it to a key.\[^1\] Here is my approach in Elisp: ``` (defun my-refresh-org-fle () (interactive) (progn (set-mark-command nil) (beginning-of-buffer) (org-ctrl-c-ctrl-c) (pop-mark))) ``` But it does not work. It won't go back to where I was. I guess I haven't quite understood the functions `set-mark-command` and `pop-mark`. Although I do understand the concept of the mark-ring, and I enjoy using it (love jumping back to where I was prior to jumping to other files). --- \[^1\]: Of course I could start debugging as to why I have this behaviour in spacemacs-theme in Emacs 26.x, but I don't have the time to. # Answer > 6 votes You're on the right track, but the standard elisp idiom for "go somewhere else in the buffer, do some stuff, and then go back to where you came from" is to use `save-excursion`. You can rewrite (and simplify!) your command as follows: ``` (defun my-refresh-org-fle () (interactive) (save-excursion (goto-char (point-min)) (org-ctrl-c-ctrl-c))) ``` As an aside, the docstring for `beginning-of-buffer` says: > This function is for interactive use only; in Lisp code use `(goto-char (point-min))` instead. --- Tags: org-mode, save-excursion ---
thread-59900
https://emacs.stackexchange.com/questions/59900
Change emacs generated image size in org-mode export
2020-07-30T17:55:56.830
# Question Title: Change emacs generated image size in org-mode export I'm using PlantUML to generate a UML diagram inside an orgmode file. I've looked everywhere, and either I'm using the wrong terms (likely) or I'm missing something (also likely). When I view the raw tex file generated by C-c C-e l p, I get the following: ``` \includegraphics[width=.9\linewidth]{test.png} ``` What I need to know is how to change the width that is in the generated tex file. I *could* do it by manually changing the source image size, and then rerunning latex, but there *must* be a way that I'm missing to control it from within the orgmode file itself. Any ideas? Edit: this is the relevant section of the org-mode file: ``` #+BEGIN_SRC plantuml :file test.png Bob->Alice : hello #+END_SRC ``` # Answer You can give to an image an `atrribute` of `:width` to specify its width. For example: ``` #+ATTR_LATEX: :width 0.3\linewidth [[file:test.png]] ``` would do the job. But there is the additional complication here that the image file is generated by a source block. The easiest solution IME is as follows: * Give the source block a name. * Generate the results with `C-c C-c` -- the results block is now decorated with the name you gave to the block. * Add the `#+ATTR_LATEX:` line *before* the `#+RESULTS:` line. The effect is that the attribute applies to the image, despite the intervening `#+RESULTS:` line. When you regenerate the image file, the link ends up in the right place, after the named `#+RESULTS:` line. The final result looks like this: ``` #+name: bob-and-alice #+BEGIN_SRC plantuml :file test.png Bob->Alice : hello #+END_SRC #+ATTR_LATEX: :width 0.3\linewidth #+RESULTS: bob-and-alice [[file:test.png]] ``` > 3 votes --- Tags: org-mode, latex ---
thread-59903
https://emacs.stackexchange.com/questions/59903
list-packages hangs when contacting melpa
2020-07-30T19:10:07.503
# Question Title: list-packages hangs when contacting melpa I'm running Emacs 26.3 on Linux Mint 20. I am using paradox, but this also happens when I use the vanilla Emacs packages interface. When I call `list-packages`, the Paradox Menu section of the mode line just says "Loading', and the little progress indicator keeps going, but it never completes. I have a bunch of different package archives enabled, but I commented them all out and re-enabled them one by one, and it's only melpa that causes the problem. Even melpa-stable works. Anybody encountered this? Any troubleshooting steps to try? # Answer > 5 votes Figured it out two minutes after posting. In case it helps somebody else, the problem was that I had an outdated URL for the melpa package archive in my `init.el`. Perhaps there had been a redirect in place that caused it to function up until recently. For posterity, the correct value was available here: Melpa: Getting Started. As of July 2020, it was `https://melpa.org/packages/`. (For the curious, I had `http://melpa.milkbox.net/packages/`.) --- Tags: package, package-repositories, list-packages ---
thread-22390
https://emacs.stackexchange.com/questions/22390
Is there org-mode gantt view feature/package?
2016-05-20T18:15:59.363
# Question Title: Is there org-mode gantt view feature/package? Is there some sort of gantt chart view package/feature for org-mode? I want to view my headings in the gantt chart (rather then as we see it in agenda), and at least interactively modify those schedule by following operations: 1. change the start or end date. 2. shift the time range by not changing its length. # Answer > 5 votes org-gantt.el may be the project which you seek. It seems to be in early development, so let's give it a try :) https://github.com/HeyFlash/emacs-stuff/tree/master/experiments http://comments.gmane.org/gmane.emacs.orgmode/98012 # Answer > 3 votes You can export Org to TaskJuggler and do the Gantt chart there. Other alternative is python-gantt, but I never tried it. # Answer > 1 votes It may be worth checking out this project which has recently been announced: https://www.reddit.com/r/emacs/comments/hve0dy/ann\_elgantt\_gantt\_chartcalendar\_for\_orgmode/ --- Tags: org-mode ---
thread-59857
https://emacs.stackexchange.com/questions/59857
how to advance one whole virtual window in follow-mode?
2020-07-28T16:16:11.980
# Question Title: how to advance one whole virtual window in follow-mode? Is there a command for Emacs's `follow-mode` that will advance the text by a whole 'virtual window' rather than just the height of a column? Desired effect: Upon reaching the end of column 4, press `PgDn` (aka `next`), continue reading the next lines at the start of column one. Compare with and without `follow-mode`: When not in `follow-mode` I would use `PgDn`, but in `follow-mode` this only advances the text by the height of one column rather than the full height of the 'virtual window' Is there a command other than `PgDn` that will manage this in `follow-mode`? > Follow mode is a minor mode that makes two windows, both showing the same buffer, scroll as a single tall virtual window. ### update individually pressing `PgDn` four times OR individually pressing `C-v` four times does scroll the column of text 4 times and so the whole virtual window (assuming there are 4 columns in follow-mode). manually counting the lines tells me that the text has been scrolled forward by 57 lines. `C-u 57 C-v` scrolls the same number of lines ### still seeking a single command that will, regardless of column height or number of columns, scroll a full 'virtual window'. # Answer > 1 votes thankyou Lindydancer for the clue, and the editors for helping shape my text I had a look at the available `M-x follow-` completions and checked their descriptions with `C-h f` before running the ones that seemed about right. The ones below achieve what I wanted :) ``` M-x follow-scroll-up ``` Scroll text in a Follow mode window chain up. ``` M-x follow-scroll-down ``` Scroll text in a Follow mode window chain down. --- Tags: follow-mode ---
thread-31830
https://emacs.stackexchange.com/questions/31830
how can I get Emacs kill-ring to behave like a simple clipboard buffer?
2017-03-31T17:07:34.940
# Question Title: how can I get Emacs kill-ring to behave like a simple clipboard buffer? How can I get Emacs to behave the same as other programs for copy/paste (i.e. OpenOffice, Microsoft Word, etc.)? I want to simplify the `kill-ring` so that it behaves like a simple clipboard. I find it complex that the kill-ring contains multiple items. In my understanding I don't lose any of my work by doing this, since I have `undo-tree` to help me keep a history. Quote from Emacs tour: > Recall that most commands which delete a large amount of text in fact kill it (i.e. place it in the kill ring) so you can restore it later. Emacs makes it very difficult to lose a lot of text permanently: in editors with only a single clipboard, one can easily accidentally delete a large chunk of text or clobber the contents of the clipboard (by cutting two items in succession). But in Emacs, in either of those cases, the lost text can easily be retrieved from the kill ring. Please tell me how to do this. You can also add your reasoning why I shouldn't do this, or under what (infrequent) circumstances this scenario occurs. # Answer From the various comments so far, it sounds like you are in the process of learning about Emacs (welcome!). There are many things in Emacs that are unlike other editors, and as you go through the tutorials and read about things you might come across concepts like the kill ring that seem confusing and/or unnecessary. Emacs is endlessly configurable so you can bend it to your workflow, but I would always recommend you experiment with its features before trying the change something. You might find something that seemed weird is actually really useful -- or that it isn't, but now you've got enough experience to know exactly how you would like it to work. In this particular case it seems like you are worried about the complexity of managing the kill ring, but perhaps have not used Emacs kill/yank commands frequently enough to see that it does not gets in the way or require any specific workflow: this is a feature that is invisible until you ask for it. If there are specific problems you've encountered (such as accidentally hitting `M-y` and yanking the wrong text) then add those to the question and they can be addressed directly. You can change or remove the binding for `yank-pop` if it gets in the way of something else. **Updated** Based on the comment threads, it sounds like the real concern here is not the kill-ring but rather the various kill commands. In many editors: `C-x` will cut the selected text, and `C-v` will paste the most recently cut text. In Emacs: `C-w` will cut the selected text, and `C-y` will paste the most recently cut text -- same thing. In many editors, you can select some text and hit backspace to delete that text without saving it anywhere. In Emacs you can do the same thing. The difference is that most editors have only one command to cut text. Emacs has that, but also has commands to cut things *without* having to select them first: the rest of the line (`C-k`), the next word (`M-d`), a sentence, an expression, and so on. These are variations of the cut command: use any one of them, then use `C-y` to paste the most recently cut bit of text. For every cut (`kill-`) command in Emacs you could define another command to do the same thing without saving to a clipboard. For example you could have `delete-line`, `delete-word`, `delete-sentence`, `delete-sexp`, etc. Then you have the choice to delete or cut anything you want -- but you double the number of commands and key bindings, and every time you want to remove some chunk of text you need to decide whether you want to save it for later. The Emacs approach is to provide the "cut" versions of all these commands, but to maintain a longer history. You can freely cut text in many places and will be able to find it and paste it again if needed. Otherwise you can ignore the history and always paste the most recently cut text using `C-y`, as usual. Other editors I'm aware of don't (ok, ignoring vi\[m\]) have commands to delete up to the end of the line or sentence, delete the next expression or next 3 words, etc. You would do that by highlighting the text and then either hitting cut or backspace -- which you can do in Emacs too. So asking for these special commands to behave as they do in other editors is confusing: they don't exist elsewhere. If you want to use them, it's worth trying out the default behavior before deciding it is too complicated. If you end up deciding this is really not what you want, it is fairly easy to define new delete-xxx commands that are similar to the kill-xxx commands you actually find useful. > 7 votes # Answer > I want to simplify the kill-ring so that it behaves like a simple clipboard. I find it complex that the kill-ring contains multiple items. You can *completely ignore* the fact that the kill ring contains multiple items if you want. If you only ever use `yank` (`C-y`) to paste, then you will only ever paste the most recently-killed text. Unless you actively tell Emacs to yank text from elsewhere in the kill-ring, it won't do that, and so you needn't care that the rest of the kill ring exists. i.e. In systems with a single-item clipboard, the paste command always pastes the most recent copy/cut text, because that is all that it *can* do. In Emacs the yank command *also* pastes the most recent killed text, *but if you explicitly ask it to* it can give you something different. I think the only thing which could trip you up is the variety of commands that kill text (therefore changing what is on the front of the kill ring). There isn't just a single 'cut' command in Emacs, but a whole array of `kill-*` commands with standard key bindings. Hence you might manage to add some text to the kill ring *inadvertently* after an intentional kill, and then be surprised that your next `yank` didn't give you the text you were expecting to get. I really would urge you to familiarise yourself with the kill ring concept, rather than trying to limit it. I've heard plenty of people bemoaning the lack of a kill ring outside of Emacs, but I think this is the first time I've ever heard of a person wishing that Emacs didn't have one either. I genuinely think you're doing yourself a disservice if you try to avoid it. > 6 votes # Answer Have you tried using Emacs' `cua-mode`? This sets up key bindings that are compatible with the Common User Access (CUA) system, so C-x, C-c, and C-v behave as they do in those other applications. I believe it should give you the behaviour that you're after. > 0 votes # Answer In summary: To "enable" a Windows clipboard-like behavior is to disable the ability to retrieve previous deletes up to N-level deep (ie. set the **kill-ring-max** value to 1). To do this, add the following line to your Emacs init file... ``` (setq kill-ring-max 1) ;; Note: Set to (eg.) 60 to re-enable this feature ``` > 0 votes --- Tags: kill-ring, undo, undo-tree-mode ---
thread-59916
https://emacs.stackexchange.com/questions/59916
Only edit visible lines in sparse tree view
2020-08-01T15:34:36.703
# Question Title: Only edit visible lines in sparse tree view Consider the following org-mode document ``` * Foo ** bar1 :g1: ** bar2 :g2: ** bar3 :g1: ** bar4 :g2: ** bar5 :g2: ** bar6 :g1: ``` Now I do `C-c / m` and search for `g1`. The view will then be ``` * Foo ** bar1 :g1: ** bar3 :g1: ** bar6 :g1: ``` as desired. I would wish to be able to edit those three lines, e.g. by creating a selection and doing `C-x r t` in order to add `foo` to all three headings. If I do that, `foo` will also be added to the hidden headings. Furthermore, for some strange reasons, automatic newlines are inserted, the lines will look like ``` ** foo bar1 :g1: ``` My questions are: * How can I edit several headings at the same time? * Where does that line break come from? # Answer > 2 votes I found a solution: 1. `M-s o` for occur-mode, search for `g1` 2. `C-x o` to change to the other window 3. `e` to enable editing 4. Edit by rectangle tagging or similar 5. `C-c C-c` to switch back to occur-mode However, I am still interested in a better or more elegant solution. --- Tags: org-mode, search ---
thread-59882
https://emacs.stackexchange.com/questions/59882
How to change color of "font-lock-add-keywords"?
2020-07-29T22:30:33.837
# Question Title: How to change color of "font-lock-add-keywords"? I found this piece of code to change org-mode list elements from dashes (-) to circles (•): ``` (font-lock-add-keywords 'org-mode '(("^ *\\([-]\\) " (0 (prog1 () (compose-region (match-beginning 1) (match-end 1) "•")))))) ``` It works wonderfully, but I cannot figure out how to change the color of the circle to red. I tried reading the documentation of font-lock-add-keywords, but the syntax seems quite cryptic to me. Any help, pointers towards more information, or suggestions on how to achieve what I want would be most welcome. **EDIT:** Based on NickD's comment and on a blog post by Kitchin on colorizing strings, I ended up with the following: ``` (font-lock-add-keywords 'org-mode '(("^ *\\([-]\\) " (0 (prog1 () (compose-region (match-beginning 1) (match-end 1) (propertize "•" 'font-lock-face '(:foreground "red")))))))) ``` But that doesn't seem to do the trick. I guess the `compose-region` function must be ignoring any text properties, as inserting the propertized string directly in the buffer does work. Any help is highly appreciated. # Answer The Elisp code below shows how it can be done. First, some notes: 1. You can use the `display` text property to replace characters visually with other text. 2. If you want to display the bullet in red, propertize the replacement text. You can use text properties in strings for that purpose. 3. Use the `OVERRIDE` flag `prepend` or `append` for the font lock keyword. This is the most sensible choice if you modify an existing mode through personal configuration. It ensures that the fontification of the original mode and your own fontification is combined and none of the two overrides the other completely. If you do not add this `OVERRIDE` flag and prepend your own fontification to that one of the original mode your fontification prevents tweaks by the original mode. If you append your fontification without `OVERRIDE` it has no effect if the original mode fontifies the same stretch of text. 4. Add the keyword at the end of `font-lock-keywords` so that your fontification is not overridden by other rules (`HOW` argument of `font-lock-add-keywords`). 5. Note, a regexp as matcher is not sufficient since it also gives false positives. For an example, matches in source blocks are also highlighted. That is the reason why I introduced the matcher function `org+-match-item-marker`. ``` (require 'org-element) (defun org+-match-item-marker (bound) "Match the bullet of itemizations." (and (re-search-forward "^ *\\(-\\) " bound t) (save-match-data (save-excursion (goto-char (match-end 1)) (eq (org-element-type (org-element-at-point)) 'item))))) (font-lock-add-keywords 'org-mode '((org+-match-item-marker ;; matcher (1 ;; subexpression '(face default display #("•" 0 1 (face (:foreground "red")))) ;; face append ;; override ))) t) ;; how ``` > 2 votes # Answer This is a complementary answer to the one posted by Tobias. I noticed that the following worked for me too: ``` (setq red-unicode-dot (propertize "•" 'font-lock-face '(:foreground "red"))) (font-lock-add-keywords 'org-mode '(("^ *\\([-]\\) " (0 (prog1 () (put-text-property (match-beginning 1) (match-end 1) 'display red-unicode-dot)))))) ``` > 1 votes --- Tags: font-lock ---
thread-59667
https://emacs.stackexchange.com/questions/59667
Emacs insane CPU load caused by org-superstar-mode
2020-07-16T13:39:05.737
# Question Title: Emacs insane CPU load caused by org-superstar-mode if I try to open a fairly large file in emacs with org-mode enabled (loads of bullets and babel snippets), emacs uses an insane amount of cpu - my cpu is maxed out for 30 sec or so. I am running a spacemacs instance which I have extensively modified over the years. I have found the culprit via `profiler-report` (see below). org-superstar-mode seems to use a lot of resources. however, I find no way of disabling it. i also do not remember installing or enabling it (does it ship with org-mode?) So, 3 questions: * has someone else experienced this behaviour * any hints on exploring the cause of high cpu load further? * hints on disabling superstar-mode? ``` - funcall-interactively 49485 97% - #<lambda 0x14898bcabbc69a1a> 48160 94% - find-file 48160 94% - find-file-noselect 48157 94% - find-file-noselect-1 48150 94% - after-find-file 48140 94% - normal-mode 48014 94% - set-auto-mode 47994 94% - set-auto-mode-0 47991 94% - org-mode 47991 94% - run-mode-hooks 44502 87% - apply 44502 87% - run-hooks 44502 87% - org-superstar-mode 40013 78% - org-superstar--fontify-buffer 39993 78% - font-lock-ensure 39973 78% - jit-lock-fontify-now 39973 78% - jit-lock--run-functions 39973 78% - run-hook-wrapped 39973 78% - #<compiled 0x4010f3d> 39973 78% - font-lock-fontify-region 39973 78% - font-lock-default-fontify-region 39973 78% - font-lock-fontify-keywords-region 39932 78% + eval 21488 42% + org-fontify-meta-lines-and-blocks 16664 32% + org-activate-links 510 1% + org-do-emphasis-faces 458 0% org-fontify-drawers 116 0% org-activate-code 16 0% org-activate-dates 13 0% org-activate-tags 10 0% + org-activate-footnote-links 6 0% org-font-lock-add-priority-faces 6 0% font-lock-prepend-text-property 4 0% org-fontify-macros 3 0% ``` # Answer In the org-superstar-mode readme FAQ, they say slowdown can happen with this mode on because of "a deeper rooted issue involving fonts and font-lock reliant packages" and they recommend adding this to your init file if that's happening: ``` (setq inhibit-compacting-font-caches t) ``` > 2 votes # Answer That's a package available from melpa, so you can just uninstall it. Type `M-x list-packages` to list all available and installed packages. Search for org-superstar (`C-s`), hit `d` to mark the package for deletion, then `x` to execute the actions for all marked packages. > 0 votes --- Tags: org-mode, spacemacs ---
thread-36244
https://emacs.stackexchange.com/questions/36244
Show inactive timestamps in Agenda
2017-10-18T09:52:19.713
# Question Title: Show inactive timestamps in Agenda **SCHEDULED** or **DEADLINE** **TODO** items with *active* timestamps correctly appear in my Agenda View (day/week/fortnight) under Org 9.0.4. After making a timestamp *inactive*, such entries do not appear in the Agenda, as expected. Pressing `[` in Agenda View should display inactive timestamps. However, pressing this does not change the View. A message is displayed indicating that inactive timestamps are now included, but none are included. I have tested this in day, week and fortnight views, both pressing `[` before and after changing the view. I tested with a DEADLINE item for today. How can I display inactive timestamps in the Agenda? # Answer > 2 votes Using the hint by krishnab a possible function would be: ``` (defun org-agenda-inactive () (interactive) (let ((org-agenda-include-inactive-timestamps t)) (org-agenda))) ``` And using `M-x org-agenda-inactive` for the new function. # Answer > 0 votes Just to build on top of the excellent solution from Slaven, I did it one step further. I use `C-c a` to call the normal org-agenda. And I use `C-c b` to call the org-agenda that show inactive timestamps. ``` (defun org-agenda-inactive () (interactive) (let ((org-agenda-include-inactive-timestamps t)) (org-agenda)) ) (global-set-key (kbd "C-c a") 'org-agenda) (global-set-key (kbd "C-c b") 'org-agenda-inactive) ``` --- Tags: org-mode, org-agenda ---
thread-59922
https://emacs.stackexchange.com/questions/59922
How can I create a frame and open two files split vertically in it?
2020-08-02T01:31:40.490
# Question Title: How can I create a frame and open two files split vertically in it? I am trying to write an Elisp function that will create a new frame and in that new frame open two files split vertically. I have been unable to find anything about this in the Elisp manual, node Creating Frames How can I do this? # Answer You can try this function: ``` (defun my/open-files-vert-in-new-frame (file1 file2) (interactive "f\nf") (select-frame-set-input-focus (make-frame)) (find-file file1) (split-window-below) (find-file file2)) ``` The key is `select-frame-set-input-focus` which makes subsequent functions operating on windows of the new frame and set input focus on it. > 1 votes --- Tags: frames, window-splitting ---
thread-59918
https://emacs.stackexchange.com/questions/59918
just todays agenda for just the current buffer
2020-08-01T18:24:29.633
# Question Title: just todays agenda for just the current buffer I would like to make a quick access agenda for today and just for the current buffer. So my approach looks like this, but it does not work. ``` (setq org-agenda-custom-commands '( ("o" ;; Key "todays agenda for current buffer" ;; Description agenda ;; Type agenda ((org-agenda-files `(,(buffer-file-name))) (org-agenda-span 1)) ;; Options ))) ``` I found some inspiration here but it does not really work here atm. I know you can narrow the agenda to current buffer with \< but if it is possible I would prefer to use a custom agenda. An explanation why this approach does not work would be appreciated. # Answer The only problem is that you have forgotten a mandatory piece in the command. `C-h v org-agenda-custom-commands` says in part: ``` Each entry is a list like this: (key desc type match settings files) ... type The command type, any of the following symbols: agenda The daily/weekly agenda. ... match What to search for: ... For all other commands, this should be the empty string. settings A list of option settings, similar to that in a let form, so like this: ((opt1 val1) (opt2 val2) ...). The values will be evaluated at the moment of execution, so quote them when needed. ... ``` Since you are not using a match you just omitted it, but that's not correct: **For all other commands, this** (i.e. the match expression) **should be the empty string.** So it is looking for a match expression and since there is no empty string there, it goes after the settings instead and tries to interpret them as a match expression, with predictably chaotic results. Try this: ``` (setq org-agenda-custom-commands '( ("o" ;; Key "todays agenda for current buffer" ;; Description agenda ;; Type agenda "" ;; Match expression ((org-agenda-files `(,(buffer-file-name))) (org-agenda-span 1)) ;; Options ))) ``` That seems to have worked in my (rather superficial) experiment. > 1 votes --- Tags: org-mode, org-agenda ---
thread-37570
https://emacs.stackexchange.com/questions/37570
Elpy starts Python processes at the root of my git tree, not the module's actual location
2017-12-17T15:40:03.807
# Question Title: Elpy starts Python processes at the root of my git tree, not the module's actual location **(I now submitted this as an issue in GitHub: https://github.com/jorgenschaefer/elpy/issues/1249)** I'm using Emacs 25.3.1, Elpy v20171212.850, and Python 3.6.3 on MacOS 10.13.2 . I have a project tracked with Git in `~/MyProject`, with the usual git data in `~/MyProject/.git` and `~/MyProject/.gitignore`. I have some Python modules in `~/MyProject/Python`. If, for example, I open one of these modules and, from that buffer, call `elpy-shell-switch-to-shell`, or `elpy-shell-send-region-or-buffer`, then Elpy starts a new Python process in `~/MyProject` instead of `~/MyProject/Python`. This odd behaviour has only started occurring recently (might be since the last Elpy upgrade, but not sure - I upgrade fairly frequently). Interestingly, if I delete the Git data *and* kill/reopen the Python module (simply killing the Python REPL buffer is insufficient), then Elpy behaves properly, starting the Python process in `~/MyProject/Python`. Any idea how I can debug this? # Answer > 1 votes (I'm posting a slightly modified version of the comment I left on the GitHub issue Elpy starts Python processes at the root of my git tree, not the module's directory.) The solution described in another answer here ``` (setq elpy-shell-use-project-root nil) ``` isn't working for me with elpy 1.34. It used to work, but no longer does. I checked, and the following text appears in customize, in the `elpy-shell-use-project-root` section. > elpy-shell-use-project-root is a variable defined in ‘elpy-shell.el’. Its value is nil Original value was t > > This variable is obsolete since 1.32.0; use ‘elpy-shell-starting-directory’ instead. But `elpy-shell-use-project-root` still appears in customize. If it's obsolete (and apparently not working, in any case), it should just be removed. Anyway, I set `elpy-shell-starting-directory` via customize, and the correct syntax, per customize, is ``` (setq elpy-shell-starting-directory (quote current-directory)) ``` which works. # Answer > 2 votes Answered at github: > You can set `elpy-shell-use-project-root` to `nil` to start the shell in the directory of the Python file as before. Alternatively, modify your MyProject/Python directory so that it is detected as a project root; see `elpy-project-root-finder-functions`. The `elpy-project-root-finder-functions` have the options: > * Projectile project root > * Python project (setup.py, setup.cfg) > * Git repository root (.git) > * Mercurial project root (.hg) > * Subversion project root (.svn) --- Tags: git, elpy ---
thread-19231
https://emacs.stackexchange.com/questions/19231
ESS ignores R_LIBS_USER environment variable
2016-01-03T18:01:10.893
# Question Title: ESS ignores R_LIBS_USER environment variable I have the following in my `.bashrc` ``` export R_LIBS_USER="/home/wdkrnls/R/lib/3.2" ``` When I start `R` from the shell I see (even in Emacs `M-x shell`): ``` .libPaths() [1] "/home/wdkrnls/R/lib/3.2" "/usr/lib/R/library" ``` When I start an `R` process with `M-x R`, I see: ``` .libPaths() [1] "/usr/lib/R/library" ``` How do I make `ESS` know about and use official R environment variables instead of ignoring them? # Answer > 1 votes Following, @wvxvw's comment: I was starting Emacs from an environment which wasn't executing my .bashrc. --- Tags: ess, r ---
thread-26476
https://emacs.stackexchange.com/questions/26476
smartparens strict mode insert single quote before variable
2016-08-22T23:50:38.557
# Question Title: smartparens strict mode insert single quote before variable I'm using `smartparens-global-strict-mode`and having issues quoting variables. How do I get something like `'varname`? My current strategy, which seems ridiculous, is to do: `'|'` (sp inserts both pairs) `'varname'` (write the varname) at this point, I do `M-x smartparens-strict-mode`, which toggles it off, delete the right `'`, then do `M-x smartparens-strict-mode` again to turn it back on. But there's got to be a better way, right? Am I missing something simple? # Answer > 4 votes Specific answer: The default configuration for smartparens should cover this, but perhaps you aren't loading the default config. Make sure that ``` (require 'smartparens-config) ``` is in your `.emacs.d` instead of just `(require 'smartparens)`. More generally, to see the delimiters that smartparens is currently tracking, inspect variable `sp-pair-list`. You can use the functions `sp-pair` and `sp-local-pair` to configure it. For example to globally disable autoinsertion of closing single quotes you can write: ``` (sp-pair "'" "'" :actions nil) ``` Or to disable for specific modes: ``` (sp-local-pair '(emacs-lisp-mode) "'" "'" :actions nil) ``` # Answer > 2 votes What major mode are you using? In `emacs-lisp-mode`, Smartparens does not automatically close single quotes. To insert a single character, use `C-q`, `quoted-insert`, followed by the character. E.g. `C-q '` to insert a single quote. # Answer > 0 votes Eval `(sp-pair "'" "'" :actions :rem)` to disable any cleverness with the apostrophe. This removes the entry for `'` from sp-pairs. You can get the right arguments to pass into `sp-pair` by evaling `(sp-get-pair "'")`. --- Tags: smartparens ---
thread-58189
https://emacs.stackexchange.com/questions/58189
Long running jobs in emacs org mode
2020-04-30T22:59:47.787
# Question Title: Long running jobs in emacs org mode When I execute a long running script within the org mode, emacs freezes. Is there a way to see the (running) output of the script? Alternatively, is there a way to run script asynchronously, and then get the output back into the org buffer? I run my shell scripts the following way: ``` #+BEGIN_SRC shell ls #+END_SRC ``` Thank you! Edit: May be there is a way to run the command in a separate buffer, to observe output, and the put truncated output back to the main buffer? # Answer > Alternatively, is there a way to run script asynchronously, and then get the output back into the org buffer? There is a great package for that: ob-async Just add `:async` to your header (or in a drawer, etc.). Unfortunately I don't know of any way to monitor the process as it runs, though. > 1 votes --- Tags: org-mode, org-babel ---
thread-58875
https://emacs.stackexchange.com/questions/58875
How do I add appointments to effort sum?
2020-06-03T04:58:54.550
# Question Title: How do I add appointments to effort sum? I have set up my appointments as below in my `work.org`. ``` * Work :work: ** Client 1 Work <2020-06-03 Wed 09:00-10:00> ** Client 2 Work <2020-06-03 Wed 18:00-19:00> ``` And this is my org-agenda ``` Day-agenda (W23): Wednesday 3 June 2020 8:00...... ---------------- work: 9:00-10:00 Client 1 Work :work:: 10:00...... ---------------- 10:14...... now - - - - - - - - - - - - - - - - - - - - - - - - - 12:00...... ---------------- 14:00...... ---------------- 16:00...... ---------------- work: 18:00-19:00 Client 2 Work :work:: 20:00...... ---------------- ``` But when I go for my column view `C-c C-x C-c` in my agenda view, I notice that it my 1 hour appointments do not get added to my estimated effort or Actual effort. I have setup the following in my `.emacs` ``` ;; under custom-set-variables '(org-agenda-time-grid (quote ((daily today require-timed remove-match) (800 1000 1200 1400 1600 1800 2000) "......" "----------------"))) '(org-columns-default-format "%25ITEM(Task) %TODO %TAGS %Effort(Estim){:} %CLOCKSUM(ActTime)") '(org-agenda-columns-add-appointments-to-effort-sum t) ``` I was hoping that setting `org-agenda-columns-add-appointments-to-effort-sum` as non-nil would help. The help shows the below ``` org-agenda-columns-add-appointments-to-effort-sum is a variable defined in ‘org-agenda.el’. Its value is t Original value was nil Documentation: Non-nil means the duration of an appointment will add to day effort. The property to which appointment durations will be added is the one given in the option ‘org-effort-property’. If an appointment does not have an end time, ‘org-agenda-default-appointment-duration’ will be used. If that is not set, an appointment without end time will not contribute to the time estimate. ``` Quoting from the manual - https://orgmode.org/manual/Effort-Estimates.html > If you switch to column view in the daily/weekly agenda, the effort column summarizes the estimated work effort for each day81, and you can use this to find space in your schedule. To get an overview of the entire part of the day that is committed, you can set the option org-agenda-columns-add-appointments-to-effort-sum. The appointments on a day that take place over a specified time interval are then also added to the load estimate of the day. My requirement is that my appointments get added up in some way to my column view in agenda mode, so that I know how much time (effort) is already allocated and thus will give me an idea how much more time I can allocate for myself during the day. Org mode - 9.3.6 Emacs - 26.3 # Answer It seems that this is a bug in org-mode. Looking at the `org-colview.el` code I think that the reason why column view in org agenda can not add entry duration to efforts (even when `org-agenda-columns-add-appointments-to-effort-sum` is set to `t`) is because the function `org-columns--collect-values` which is called on each org entry by `org-agenda-columns` cannot actually get the text property called `duration` at the point where it tries to do that. The fix below: * treats property keys starting with `AGENDA_*` (e.g., `AGENDA_TIME`, `AGENDA_DURATION`) in your `org-columns-default-format-for-agenda` as special properties that will query text properties in agenda buffer instead of org properties * if text properties in agenda buffer does not have `duration` value (`AGENDA_DURATION` key) it queries `Effort` property of the entry instead. This is the opposite behavior compared to what setting `org-agenda-columns-add-appointments-to-effort-sum` to `t` should do (i.e., `duration` overwrites the `Effort` instead of `Effort` overwrites `duration`) * if the `duration` of the entry is negative (e.g. when you have a entry that spans the midnight `<2020-08-03 Mon 23:00-7:00>`) it adds 24h to the duration so time sums are calculated correctly Add the following to your init.el: ``` (with-eval-after-load 'org-colview ;; adjusted org-agenda-columns function that now calls ;; org-agenda-columns--collect-values (see below) instead ;; of org-columns--collect-values (defun org-agenda-columns () "Turn on or update column view in the agenda." (interactive) (org-columns-remove-overlays) (if (markerp org-columns-begin-marker) (move-marker org-columns-begin-marker (point)) (setq org-columns-begin-marker (point-marker))) (let* ((org-columns--time (float-time)) (fmt (cond ((bound-and-true-p org-overriding-columns-format)) ((bound-and-true-p org-local-columns-format)) ((bound-and-true-p org-columns-default-format-for-agenda)) ((let ((m (org-get-at-bol 'org-hd-marker))) (and m (or (org-entry-get m "COLUMNS" t) (with-current-buffer (marker-buffer m) org-columns-default-format))))) ((and (local-variable-p 'org-columns-current-fmt) org-columns-current-fmt)) ((let ((m (next-single-property-change (point-min) 'org-hd-marker))) (and m (let ((m (get-text-property m 'org-hd-marker))) (or (org-entry-get m "COLUMNS" t) (with-current-buffer (marker-buffer m) org-columns-default-format)))))) (t org-columns-default-format))) (compiled-fmt (org-columns-compile-format fmt))) (setq org-columns-current-fmt fmt) (when org-agenda-columns-compute-summary-properties (org-agenda-colview-compute org-columns-current-fmt-compiled)) (save-excursion ;; Collect properties for each headline in current view. (goto-char (point-min)) (let (cache) (while (not (eobp)) (let ((m (org-get-at-bol 'org-hd-marker))) (when m (push (cons (line-beginning-position) ;; `org-columns-current-fmt-compiled' is ;; initialized but only set locally to the ;; agenda buffer. Since current buffer is ;; changing, we need to force the original ;; compiled-fmt there. ;; clavis (org-agenda-columns--collect-values compiled-fmt m)) cache))) (forward-line)) (when cache (org-columns--set-widths cache) (org-columns--display-here-title) (when (setq-local org-columns-flyspell-was-active (bound-and-true-p flyspell-mode)) (flyspell-mode 0)) (dolist (entry cache) (goto-char (car entry)) (org-columns--display-here (cdr entry))) (setq-local org-agenda-columns-active t) (when org-agenda-columns-show-summaries (org-agenda-colview-summarize cache))))))) ;; new function that substitutes org-columns--collect-values (defun org-agenda-columns--collect-values (&optional compiled-fmt m) "Collect values for columns on the current line. Return a list of triplets (SPEC VALUE DISPLAYED) suitable for `org-columns--display-here'. This function assumes `org-columns-current-fmt-compiled' is initialized is set in the current buffer. However, it is possible to override it with optional argument COMPILED-FMT." (let ((summaries (get-text-property (point) 'org-summaries))) (mapcar (lambda (spec) (pcase spec (`(,p . ,_) (let* ((v (or (cdr (assoc spec summaries)) ;; first check if p is a special agenda (text) property (when-let* ((prop-p (string-match "^AGENDA_\\(.+\\)" p)) (prop-name (downcase (match-string 1 p)))) ;; if property is duration consider effort if it is not set (if (string= prop-name "duration") (if-let ((dur (org-get-at-bol (intern prop-name)))) ;; if duration is negatie (i.e. time range crossess ;; midnight) then add 24h to duration (if (> dur 0.0) (propertize (org-duration-from-minutes dur) 'face 'org-scheduled) (propertize (org-duration-from-minutes (+ dur (* 24 60))) 'face 'org-scheduled)) (org-with-point-at m (org-entry-get (point) org-effort-property 'selective t))) (org-get-at-bol (intern prop-name)))) (org-with-point-at m (org-entry-get (point) p 'selective t)) ""))) ;; A non-nil COMPILED-FMT means we're calling from Org ;; Agenda mode, where we do not want leading stars for ;; ITEM. Hence the optional argument for ;; `org-columns--displayed-value'. (list spec v (org-columns--displayed-value spec v compiled-fmt)))))) (or compiled-fmt org-columns-current-fmt-compiled))))) ``` Adding the following setup in `org-agenda-custom-commands` ``` (add-to-list 'org-agenda-custom-commands '("j" "Planning Table" agenda "" ((org-agenda-overriding-header "") (org-agenda-span 1) (org-agenda-use-time-grid nil) (org-agenda-view-columns-initially t) (org-columns-default-format-for-agenda "%11AGENDA_TIME(When) %4TODO(Type) %40ITEM(What) %5AGENDA_DURATION(Takes){:}") ;; do not show wardings, overdue and overscheduled (org-scheduled-past-days 0) (org-deadline-past-days 0) (org-deadline-warning-days 0) ;; skip finished entries (org-agenda-skip-deadline-if-done t) (org-agenda-skip-scheduled-if-done t)))) ``` and with this org file ``` * TODO Buy last minute spaceship tickets :PROPERTIES: :Effort: 1:00 :END: <2020-08-03 Mon> * TODO Take up space suit from dry cleaning :PROPERTIES: :Effort: 1:00 :END: <2020-08-03 Mon 14:00-14:30> * Rest well before space flight <2020-08-03 Mon 22:00-06:00> * Taxi to space port <2020-08-04 Tue 07:00-07:30> * Trip to Mars <2020-08-04 Tue 08:30>--<2021-01-13 Wed> ``` You should be able to get the following agenda: Hope this will help for now. Please, mind that this is not a sustainable solution as it will likely break if new versions of org will change org-columns code. Org 9.3.7. Emacs 26.3 > 1 votes --- Tags: org-mode, org-agenda ---
thread-59946
https://emacs.stackexchange.com/questions/59946
Show one todo tree with two different states
2020-08-03T14:49:46.457
# Question Title: Show one todo tree with two different states Hi I would like to make this function show a tree with headings in `NEXT` and `WAITING` status. ``` (defun show-NEXT-in-subtree () "Narrow to a subtree and show only headings with NEXT and WAITING keywords" (interactive) (org-narrow-to-subtree) (org-show-todo-tree '(3 4)) ;; NEXT|WAITING (org-ctrl-c-ctrl-c)) ``` I don't understand how to do it in the correct way according to help. > With a prefix argument (or by using C-c / T), search for a specific TODO. You will be prompted for the keyword, and you can also give a list of keywords like KWD1|KWD2|... to list entries that match any one of these keywords. With a numeric prefix argument N, show the tree for the Nth keyword in the option org-todo-keywords. # Answer `org-show-todo-tree` is incorrigibly interactive, so we go under the covers and see that it uses `org-occur` to find what it wants. That allows us to bypass it altogether and write your function like this: ``` (defun show-NEXT-in-subtree () "Narrow to a subtree and show only headings with NEXT and WAITING keywords" (interactive) (org-narrow-to-subtree) (org-occur (concat "^" org-outline-regexp " *" "\\(NEXT\\|WAITING\\)")) (org-ctrl-c-ctrl-c)) ``` That constructs the regexp that we give to `org-occur` explicitly: beginning of line, stars, spaces and then either `NEXT` or `WAITING`. There are easier ways to do the regexp perhaps, but these are new tricks and I am an old dog. > 2 votes --- Tags: org-mode ---
thread-59942
https://emacs.stackexchange.com/questions/59942
Is it possible suppress save message for undo-tree?
2020-08-03T13:02:36.633
# Question Title: Is it possible suppress save message for undo-tree? When I save my any file I am working on I always see following message, I believe this is related to my `unto-tree` configuration. `Wrote /home/alper/.emacs.d/undo/.!home!alper!current_folder!__init__.py.~undo-tree~` --- **\[Q\]** Is it possible suppress this message (saving `undo-tree`) somehow? My config file: ``` (global-undo-tree-mode 1) (setq undo-tree-auto-save-history t) (setq undo-tree-history-directory-alist '(("." . "~/.emacs.d/undo"))) (defmacro with-suppressed-message (&rest body) "Suppress new messages temporarily in the echo area and the `*Messages*' buffer while BODY is evaluated." (declare (indent 0)) (let ((message-log-max nil)) `(with-temp-message (or (current-message) "") ,@body))) (defun save-all () (interactive) ;(save-some-buffers t) ;(recentf-save-list) (with-suppressed-message (save-some-buffers t)) (message "") ``` # Answer `undo-tree-save-history` calls `write-region`. In this example, we suppress the `Wrote ...` message entirely using an `:around` advice. Here are the steps used to verify the answer works as advertised: **STEP 1**: Launch a recent public release of Emacs 26.3 -- without any user-configuration, aka `emacs -Q` **STEP 2**: Download the library undo-tree, which was last updated 01/29/2020 from the following link: https://elpa.gnu.org/packages/undo-tree-0.7.4.el **STEP 3**: From within Emacs, open the newly downloaded und-tree library file and then type `M-x eval-buffer` **STEP 4**: Create a **new** file-visiting-buffer by typing `M-x find-file` or its keyboard shortcut equivalent `C-x C-f` and give it a filename using a path to a working directory (where there is nothing of critical importance); e.g., `~/Desktop/scratch.el`. Assuming that the file was new, there will be a message in the echo-area as follows: `(New file)`. Now, write the file to the hard-drive by typing `M-x save-buffer` or use the keyboard shortcut equivalent of `C-x C-s`. The message in the echo area at this point will be something similar to: `Wrote /Users/HOME/Desktop/scratch.el` **Step 5**: Copy the following snippets in the code-block directly below and paste them into the file-visiting-buffer described in the step immediately above; e.g., paste everything into the file-visiting-buffer `~/Desktop/scratch.el`. Now, type `M-x eval-buffer`. Do **NOT** save the file at this time -- i.e., leave the file-visiting-buffer in a *modified* state. ``` (global-undo-tree-mode 1) (setq undo-tree-auto-save-history t) (setq undo-tree-history-directory-alist '(("." . "~/.emacs.d/undo"))) (defun my-undo-tree-save-history (undo-tree-save-history &rest args) (let ((message-log-max nil) (inhibit-message t)) (apply undo-tree-save-history args))) (advice-add 'undo-tree-save-history :around 'my-undo-tree-save-history) (global-set-key [f5] (lambda () (interactive) (let ((message-log-max nil) (inhibit-message t)) (save-some-buffers t)))) ``` **STEP 6**: At this point in time, the file-visiting-buffer (e.g., `~/Desktop/scratch.el`) should still be in a *modified* state. Now, let us test out the newly defined keyboard shortcut by pressing the `f5` key. Watch the mode-line closely -- i.e., when we press the `f5` key, the far-left of the mode-line will change from *modified* `-:**-` to *unmodified* `-:---`. However, we should not have seen anything appearing in the echo area related to pressing the above-mentioned key. **STEP 7**: Switch to the `*Messages*` buffer and see what is there: ``` For information about GNU Emacs and the GNU system, type C-h C-a. You can run the command ‘eval-buffer’ with M-x ev-b RET (New file) Wrote /Users/HOME/Desktop/scratch.el Mark set You can run the command ‘eval-buffer’ with M-x ev-b RET ``` > 5 votes --- Tags: message, undo-tree-mode ---
thread-59905
https://emacs.stackexchange.com/questions/59905
How can I start IPython from emacs
2020-07-30T20:43:49.307
# Question Title: How can I start IPython from emacs I deleted my old Python installation, so the only Python installation remaining is the one inside Anaconda. when I start Spyder I get: ``` Python 3.7.4 (default, Aug 9 2019, 18:34:13) [MSC v.1915 64 bit (AMD64)] Type "copyright", "credits" or "license" for more information. IPython 7.8.0 -- An enhanced Interactive Python. ``` Within a shell: ``` d:\docs\ML\scox>which ipython which ipython C:\anaconda3\Scripts\ipython.EXE ``` Inside my C:/emacs there is only python.el and no python-mode.el. I made the following changes in python.el: ``` (setq python-shell-interpreter "ipython" python-shell-interpreter-args "-i") (setq python-shell-virtualenv-root "C:/anaconda3/Scripts/") ``` Still, it does not start IPython (it does not start anything). Here is the output from the Messages buffer: ``` Source file ‘c:/emacs/emacs26/share/emacs/26.1/lisp/progmodes/python.el’ newer than byte-compiled file apply: Searching for program: No such file or directory, python ``` What do I need to do to start the same process as the one, above, in Spyder? # Answer Some observations for your problem: a) FIY: There is only a `python` mode, and should be as it is because someone else wrote a `python-mode` package here:https://gitlab.com/python-mode-devs/python-mode, which is a totally different thing. b) You should not do modifications in package's files - at the first update you will loose them. Instead, use an `init.el` file, where you make all needed configurations. But, since you already opened/modified the file `python.el`, read the comments at the beginning, since there you will find out answer(s) to your question (excerpt from file): ``` (setq python-shell-interpreter "C:/Python27/python.exe" python-shell-interpreter-args "-i C:/Python27/Scripts/ipython-script.py") ``` Take the above as example and modify paths according to your windows system. c) You may still have trouble with ipython due to readline and rlcompleter - I do not know the status of that in Windows - but for unix/linux many users set python as inferior shell interpreter instead ipython. d) To start an inferior Python process use the command `M-x run-python` or enable the menu and see what is set and use from there, at least until you get more experienced. e) In Emacs there are an environment path and an execution path - both should be in sync to work correctly - a small trick to do that is as below: ``` (setenv "PATH" (concat "your-path-to/anaconda3/bin:" (getenv "PATH"))) (add-to-list 'exec-path "your-path-to/anaconda3/bin") ``` Use this at the beginning of python configuration in your init.el file. f) Try to update your iPpython, mine is version 7.13.0 EDIT g) It is useful to use `use-package` package to configure everything in your Emacs. Example for Python: ``` (use-package python :ensure nil :mode ("\\.py\\'" . python-mode) :init (setq-default indent-tabs-mode nil) :hook ((python-mode . smartparens-mode) (python-mode . company-mode) (python-mode . flycheck-mode) (inferior-python-mode . smartparens-mode)) :config (setq python-indent-offset 4 python-indent-guess-indent-offset-verbose nil python-shell-interpreter "python" ;; python-shell-interpreter-args "-i --simple-prompt" )) ``` Note: The function `python-shell-calculate...` is not accessed directly by the user. > 1 votes --- Tags: python ---
thread-59345
https://emacs.stackexchange.com/questions/59345
Elfeed - how to change database location?
2020-06-30T09:15:46.770
# Question Title: Elfeed - how to change database location? I found in elfeed-db.el code: ``` (defcustom elfeed-db-directory "~/.elfeed" "Directory where elfeed will store its database." :group 'elfeed :type 'directory) ``` but I don't know how/where to customize it. I need this, because i synchronize Emacs between computers. Cheers Kuba # Answer > 1 votes I found the answer: variable `elfeed-db-directory` is responsible for location of database and I set this via `setq` in `init.el` to my own location. --- Tags: elfeed ---
thread-59945
https://emacs.stackexchange.com/questions/59945
Magit Move Submodule
2020-08-03T14:24:58.703
# Question Title: Magit Move Submodule In git bash I can use `git mv home/subdir_1/my_submod home/subdir_2/my_submod` to move a submodule between directories. Git handles changing `.gitmodules` and stages the change to be committed. Is there a way to do this cleanly with magit? I've tried using `R` in dired and then staging things in magit but magit runs into an error where it's looking for the original directory and can't find it since its been renamed. I've checked the submodule transient docs but I don't see anything related to moving the submodule. thanks for all suggestions/solutions. # Answer It helps to remember that a submodule is just a regular file to the parent repo. I was able to do this using `magit-file-rename`. The `magit-process` buffer shows the actual `git` actions performed The test sequence was: * `magit-submodule-add` ``` 0 git … submodule add --name extern/hugo-debugprint --force -- https\://github.com/kaushalmodi/hugo-debugprint.git extern/hugo-debugprint Cloning into '/tmp/testrepo/extern/hugo-debugprint'... remote: Compressing objects: 100% (5/5), done. Resolving deltas: 100% (68/68), done. 0 git … submodule absorbgitdirs extern/hugo-debugprint 0 git … commit -- hint: Waiting for your editor to close the file... Waiting for Emacs... [master 547557c] [add test submodule] 2 files changed, 4 insertions(+) create mode 100644 .gitmodules create mode 160000 extern/hugo-debugprint ``` * `magit-file-rename` ``` 0 git … mv /tmp/testrepo/extern/hugo-debugprint /tmp/testrepo/extern/debugprint 0 git … commit -- hint: Waiting for your editor to close the file... Waiting for Emacs... [master a6ce6d4] [moved submodule] 2 files changed, 1 insertion(+), 1 deletion(-) rename extern/{hugo-debugprint => debugprint} (100%) ``` > 1 votes --- Tags: magit, git ---