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-66315 | https://emacs.stackexchange.com/questions/66315 | lsp-mode How to suppress function definitions for specific functions in python | 2021-06-15T12:48:03.273 | # Question
Title: lsp-mode How to suppress function definitions for specific functions in python
I am using `lsp` under Python. I have followed: https://emacs-lsp.github.io/lsp-mode/page/installation/ for its installation.
```
(require 'lsp-mode)
(add-hook 'python-mode-hook 'lsp)
(add-hook 'python-mode-hook #'lsp-deferred)
```
When I type `print(` automatically its description shown as below window:
Would it be possible to disable this option for selected functions such as `print()`, hence I do not want to see its definition automatically.
# Answer
> 1 votes
I am no expert on lsp and its options, but the following answer works for Spacemacs, where the popup window is created via `lsp-signature`.
In that case you could add a hook as follows:
```
(defun lsp-signature-hook-function ()
(setq lsp-signature-doc-lines
(when (and lsp-signature-mode
(member (python-eldoc--get-symbol-at-point) '("print")))
(lsp-signature-stop))))
(add-hook 'lsp-signature-mode-hook #'lsp-signature-hook-function)
```
And you can add more symbols to the list in the `member` form.
However, you might be interested to just set `lsp-signature-doc-lines` to 1 (see this reddit post). Subsequently, you can toggle between full and small size doc using `M-x lsp-signature-toggle-full-docs` (or by setting a value for `lsp-signature-doc-lines` by modifying the hook just mentioned).
---
Tags: lsp-mode
--- |
thread-59724 | https://emacs.stackexchange.com/questions/59724 | Automatically activating python virtual environments with pyvenv | 2020-07-19T16:27:26.987 | # Question
Title: Automatically activating python virtual environments with pyvenv
I am using pyvenv with doom and am trying to have my python virtual environments automatically loaded when I enter a certain project.
I saw this relevant issue on pyvenv and have added the following code to my `config.el`
```
;; autoload python virtual environments
;; https://github.com/jorgenschaefer/pyvenv/issues/51#issuecomment-474785730
(defun pyvenv-autoload ()
"Activates pyvenv version if .venv directory exists."
(f-traverse-upwards
(lambda (path)
(let ((venv-path (f-expand ".venv" path)))
(if (f-exists? venv-path)
(progn
(pyvenv-workon venv-path))
t)))))
(add-hook 'python-mode-hook 'pyvenv-autoload)
```
I expect that whenever I enter a python file inside a project with a .venv directory, it would automatically activate the appropriate virtual environment. However, running `M-x shell-command` RET `which python` returns `/usr/bin/python` when I would expect it to return something like `/home/jacob/src/beets/.venv/bin/python`
**Some debugging:**
`python-mode-hook`'s value is
```
(er/add-python-mode-expansions
doom--setq-tab-width-for-python-mode-h
+python-use-correct-flycheck-executables-h
evil-collection-python-set-evil-shift-width
doom-modeline-env-setup-python
pyvenv-autoload
pipenv-mode)
```
Which looks good to me.
However, `pyvenv-workon`'s value is `nil` which could be the issue.
Activating and deactivating the virtual environment through `pyvenv-activate` and `pyvenv-deactivate` works as normal. If I use this method, `which python` returns the expected `/home/jacob/src/beets/.venv/bin/python`
# Answer
> 1 votes
I've found that using **'projectile-after-switch-project-hook** with the following function works well. The downside is that you do have to add conditional statements to the `autoload-venv` function as you add new projects and virtual environments. The upside is that you don't need to have a completely consistent approach to storing and naming virtual environments, i.e. you could have some in your home directory and others in the project itself.
```
(defun autoload-venv()
(cond
((string= (projectile-project-name) "project_one")
(pyvenv-activate "~/.virtualenvs/proj1_venv"))
((string= (projectile-project-name) "project_two")
(pyvenv-activate "~/project_two/proj2_venv"))))
(add-hook 'projectile-after-switch-project-hook #'autoload-venv)
```
---
Tags: python, doom
--- |
thread-68014 | https://emacs.stackexchange.com/questions/68014 | Touchpad vertical scroll gesture scrolls too much lines in GUI on Windows 10 | 2021-08-08T09:10:52.117 | # Question
Title: Touchpad vertical scroll gesture scrolls too much lines in GUI on Windows 10
How can I change that? I probably need something like fractional scrolling?
Look at that video https://streamable.com/lfic9h
# Answer
> 0 votes
You can try to set the amount of scroll:
```
(setq mouse-wheel-scroll-amount '(1))
```
or just for the touchpad:
Try two finger scroll while pressing the `left shift key`, it should slow down a bit the scroll in some touchpads.
**Update:**
If that doesn't work you could try changing this value on the registry on this solution:
https://superuser.com/a/1414458/53778
---
Tags: microsoft-windows, scrolling
--- |
thread-68017 | https://emacs.stackexchange.com/questions/68017 | How can I unbind (C-M-x) globally? | 2021-08-08T10:53:32.533 | # Question
Title: How can I unbind (C-M-x) globally?
I was trying to bind `(C-M-x)` to `er/expand-region` but I checked the key combination with `(C-h k)` and noticed that it was binded to `eval-defun`. So I tried to unbind it with any of the following commands:
```
(global-set-key (kbd "C-M-x") nil)
(global-unset-key (kbd "C-M-x"))
```
But even using any of those won't unbind the key and `(C-M-x)` still will be running `eval-defun`
This is the result after running both commands:
# Answer
`eval-defun` is bound to `C-M-x` in `lisp-interaction-mode-map` while `global-set-key` and friends operate on `global-map` which has lower priority than any local key-map.
One way to bind `C-M-x` unconditionally is to use the bind-key package which provides `bind-key*` for this purpose:
```
(bind-key* "C-M-x" 'er/expand-region)
```
> 8 votes
---
Tags: key-bindings
--- |
thread-68016 | https://emacs.stackexchange.com/questions/68016 | Creating buttons/input fields | 2021-08-08T10:22:09.670 | # Question
Title: Creating buttons/input fields
The options/customization as well as the install packages buffers demonstrate that it is possible to have buttons, links and input fields.
Is this something one could fairly easily duplicate to create a form?
Currently I use a mixture of `read-string`, `completing-read` and ORG capture templates to generate a "form" where one can use `C-c C-c` to check off items done. The problems with this approach are:
* all questions are asked in the message bar, which is easy to miss
* once an option was given, you cannot review and/or return/adjust the information you entered without having to start over
* since I start with the ORG capture template, the time recorded is the time this task started (not so important to me), but not when it was completed (much more important).
My goal is to replace the `read-string` and `completing-read` items with a form where people can more naturally move fore and aft to fill in the information using `TAB` and `RET` or even use the mouse to check off items they completed (like one can click to enable/disable a color theme).
While I am currently using ORG mode, it is not a requirement if buttons would need a different mode to work.
# Answer
I think you are looking for the widget library (https://www.gnu.org/software/emacs/manual/html\_mono/widget.html). See https://www.gnu.org/software/emacs/manual/html\_mono/widget.html#Programming-Example for an example use that has several features you describe in your question (multiple choice, select multiple, text fields, etc.
> 1 votes
---
Tags: buttons
--- |
thread-68012 | https://emacs.stackexchange.com/questions/68012 | Flatten parallel nested window trees | 2021-08-08T05:10:23.050 | # Question
Title: Flatten parallel nested window trees
Sometimes when moving windows around in emacs, it will get to a state where there is a horizontal or vertical stack of windows which appears to be a single list, but is actually made up of multiple nested window lists.
For example, what appears on the screen is a single horizontal line of windows:
`A B C D`
but what is stored in emacs is
`(A (B C) D)`
Is there a function that will remove this unnecessary nesting? I couldn't figure out any good way to do it.
# Answer
> 0 votes
I would use -flatten from the dash library.
---
Tags: window, list
--- |
thread-68015 | https://emacs.stackexchange.com/questions/68015 | How can I load Dired+ only if I actually use Dired? | 2021-08-08T09:53:34.770 | # Question
Title: How can I load Dired+ only if I actually use Dired?
I'm loading dired+ from a file ( as it has been removed from Melpa ), but it won't load when I try to make it conditional of opening a dired buffer.
```
;; ---- Dired + --------
;; Loads Dired+
(use-package dired+
:load-path "~/.emacs.d/elpa-offline/dired+"
:after dired
:config
(require 'dired+)
(print "Dired + package Loaded")
)
```
Also I tried making it depending of using a binding key but it doesn't load that way either:
```
;; ---- Dired + --------
;; Loads Dired+ Manually
(use-package dired+
:load-path "~/.emacs.d/elpa-offline/dired+"
:bind ( "C-x d" . dired)
:config
(require 'dired+)
(print "Dired + package Loaded")
)
```
The `(print "Dired + package Loaded")` is just so I can check if is properly loading on the message buffer.
# Answer
Use one of the hooks (`dired-before-readin-hook` or `dired-mode-hook`) that's used each time Dired is used, but have your hook function do just `(require 'dired+)`, so it does nothing once Dired+ has been loaded.
I would probably put it on **`dired-before-readin-hook`**. Use `M-x customize-variable` and add this hook function:
```
(defun my-require-dired+ ()
"Require Dired+."
(require 'dired+))
(add-hook 'dired-before-readin-hook 'my-require-dired+)
```
> 4 votes
---
Tags: dired, use-package
--- |
thread-68020 | https://emacs.stackexchange.com/questions/68020 | How to set key binding to `C-c C-t` in `sh-mode`? | 2021-08-08T14:49:10.987 | # Question
Title: How to set key binding to `C-c C-t` in `sh-mode`?
By default `C-c C-t` has `sh-tmp-file` binding in `sh-mode`, which I want to change.:
```
C-c C-t runs the command sh-tmp-file (found in sh-mode-map), which is an
interactive compiled Lisp function in ‘sh-script.el’.
It is bound to C-c C-t.
```
I have tried to bind the key binding as follows:
```
(defun insert-todo ()
(interactive "*")
(insert comment-start "TODO: "))
(define-key shell-mode-map (kbd "C-c C-t") 'insert-todo)
(define-key sh-mode-map (kbd "C-c C-t") 'insert-todo)
```
---
I am having following error message:
```
Debugger entered--Lisp error: (void-variable sh-mode-map)
(define-key sh-mode-map (kbd "C-c C-t") 'insert-todo)
eval-buffer(#<buffer *load*> nil "/home/alper/.emacs" nil t) ; Reading at
buffer position 100039
load-with-code-conversion("/home/alper/.emacs" "/home/alper/.emacs" t t)
load("~/.emacs" noerror nomessage)
startup--load-user-init-file(#f(compiled-function () #<bytecode
0x15948fd477f1>) #f(compiled-function () #<bytecode
0x15948fd46d41>) t)
command-line()
normal-top-level()
```
How could I resolve this error?
# Answer
Mode keymaps aren't defined until the defining library has been loaded, so you just need to defer binding the key until that happens.
```
(with-eval-after-load "sh-script"
(define-key sh-mode-map (kbd "C-c C-t") 'insert-todo))
```
> 2 votes
---
Tags: key-bindings, sh-mode
--- |
thread-67969 | https://emacs.stackexchange.com/questions/67969 | Set a property when changing to specific TODO state | 2021-08-05T09:09:47.750 | # Question
Title: Set a property when changing to specific TODO state
I would like to set/unset a property when entering a certain `TODO` state.
Example: Set the property `:COOKIE_DATA: todo recursive` automatically when the state is set to `PROJ`. So all the `TODO`s in project headings would be counted recursively, and not only `TODO`s which are direct children of the current tree (default).
How could this be done?
I do *not* want to set `org-hierarchical-todo-statistics` to activate recursive counting for every `TODO` globally.
# Answer
> 2 votes
# Table of Contents
1. The answer
2. A minimal working example
# The answer
As mentioned by @NickD, you can accomplish by writing a hook.
```
(defun my/org-set-cookie-data-when-state-changes-to-proj ()
(interactive)
(when (equal (org-get-todo-state) "PROJ")
(org-set-property "COOKIE_DATA" "todo recursive")))
```
```
(add-hook 'org-after-todo-state-change-hook 'my/org-set-cookie-data-when-state-changes-to-proj)
```
# A minimal working example
Consider the following minimal working exmaple
```
#+TODO: TODO(t) | DONE(d)
#+TODO: NOTPROJ(n) | PROJ(p)
* This is a heading
* This is another heading
```
After changing the states of the headings with `org-todo` (by default, bound to `C-c C-t`) , we get the following
```
#+TODO: TODO(t) | DONE(d)
#+TODO: NOTPROJ(n) | PROJ(p)
* PROJ This is a heading
:PROPERTIES:
:COOKIE_DATA: todo recursive
:END:
* DONE This is another heading
```
---
Tags: org-mode
--- |
thread-68013 | https://emacs.stackexchange.com/questions/68013 | org-link to the exact page-position in a pdf file | 2021-08-08T08:12:10.653 | # Question
Title: org-link to the exact page-position in a pdf file
*Newest EDIT*
I think my question wasn't very clear, so I'm trying to put some details.
1. With `pdf-tools` opening pdf files withing Emacs (`PDFview` buffers) works great. What I like is to get an org-link to a precise position (of the pointer on a page): Just a link that I can copy and paste into any org-file to use is it later to go directly (without activating org-noter) to that position.
("precise position": I'd like to get the x- and y-values of the pointer. But the y-value alone (scroll position) is ok.)
2. The PDF file shouldn't be changed. Neither at producing the link nor at a later opening of the link (from an org file).
I just need a temporary icon at the position, like the arrow in `org-noter` which you get with `org-noter-sync-current-note`.
Unfortunately this function only works in an "`org-noter` buffer" and I need a "globally" valid link.
---
I often use in org-files pdf-links like this: `[[pdf:~/book.pdf::5++2.13]]` After clicking I get the pdf file buffer on the right page: 5. And `PDFview` seems to go to the right exact position at that page: I can see in status bar: 10% an when I change the y-value from 2.13 to 10.13 (5++10.13), I see 'Bot'(Bottom) there.
My problem is that I don't get any pointer/icon at that specific position. Any idea to solve it? Should I change some variables?
I've installed `org-pdftools` as described: https://github.com/fuxialexander/org-pdftools
Note: I don't have at that position a real annotation in the pdf file. So it's maybe not the default use of the link function.
---
EDIT: I've deleted my old code here, it was wrong.
# Answer
> 2 votes
SECOND EDIT (incl. 'main' answer)
As mentioned in the comments, this feature has already been implemented into `org-pdftools`. However, `org-pdftools` does insert a *permanent* text annotation, but I guess that is not too much of a problem for you.
To get it to work (currently, until https://github.com/fuxialexander/org-pdftools/pull/75 gets merged), just replace the `org-pdftools-use-freestyle-annot` with `org-pdftools-use-freepointer-annot` in the installation code as given in the org-pdftools README. Afterwards you can insert the pointer/text annotation using `M-x org-noter-pdftools-insert-precise-note`. The pointer is customizable also. Just do `M-x customize-variable` and type `org pointer` to find the relevant variables.
And just to come back to the translation of the y-position, you could translate it as follows, but it is probably not what you desire as it only represents the scrolling position:
```
(defun my-pointer-function (orig-func &rest args)
(apply orig-func args)
(let ((height (round
(/
(*
(string-to-number (match-string 4 (car args)))
(cdr (pdf-view-image-size)))
(frame-char-height)))))
(pdf-annot-add-text-annotation (cons 10 height) "Circle")))
```
(THIRD EDIT)
You could delete these pointers again for example when you are changing the page using e.g.:
```
(defvar my-pointers nil)
(add-hook 'pdf-view-before-change-page-hook #'pdf-pointer-delete-hook-function)
(defun pdf-pointer-delete-hook-function ()
(while my-pointers
(pdf-annot-delete (pop my-pointers))))
```
I am not sure about the robustness of this code, but you can modify/improve it whenever it seems not to work.
FIRST EDIT
It looks like, if you do not have `pdf-tools` installed (i.e. the feature available), then you can use `org-pdftools-open-custom-open` to define a custom function for opening the link.
However, this feature appears not to be available when you have pdf-tools installed. So then you could advise the function `org-pdftools-open-pdftools`, e.g. as follows:
```
(defun my-pointer-function (orig-func &rest args)
(apply orig-func args)
(pdf-annot-add-text-annotation '(100 . 200) "Circle")
(print args))
(advice-add 'org-pdftools-open-pdftools :around #'my-pointer-function)
```
This advice (i.e. the `my-pointer-function`) will also print the args. I'll leave it to you to translate the args to some actual position where you would like to have the pointer inserted.
END EDIT
I guess there is no straightforward/default way to achieve this, because it is not possible to draw on .png images in Emacs.
If you still want it, then there are multiple hacks possible, of which probably the easiest option is to draw an icon (text annotation) with `pdf-annot-add-text-annotation`, e.g.: `(pdf-annot-add-text-annotation '(100 . 200) "Circle")`.
To preview (or just for fun) the possible icons (in `pdf-annot-standard-text-icons`), you can evaluate the following lines in a pdf buffer:
```
(let ((pos 0))
(dolist (type pdf-annot-standard-text-icons)
(pdf-annot-add-text-annotation (cons pos 0) type)
(setq pos (+ pos 100))))
```
These annotations will only get saved if you save the document. Or you could additionally add another hack to delete it again when you start scrolling, which should not be too difficult if you know some emacs-lisp.
---
Tags: org-mode, pdf, org-link, pdf-tools
--- |
thread-2423 | https://emacs.stackexchange.com/questions/2423 | How to choose between nil and 0, or t and 1 when setting variables or enabling modes | 2014-10-22T02:06:48.410 | # Question
Title: How to choose between nil and 0, or t and 1 when setting variables or enabling modes
I understand that `nil`, `0` and/or `-1` are used for disabling some features and `t`, `1` and/or `+1` are used for enabling some features. When assigning variables or enabling/disabling minor modes, which should I choose?
I have seen all of these variations used at one point or another. It leads me to wonder if there's actually a difference between them. I have seen that sometimes using `0` doesn't work for me, while `nil` does. Are there differences of where they are used?
# Answer
> 20 votes
## TL;DR
Before you set any variable, you must know how that variable is to be interpreted. Similarly, before you call any function (inluding those used to toggle minor modes), you must know how the arguments of that function are interpreted.
Use `C-h``f` and `C-h``v` to look at the documentation for the function or variable in question. It should specify the values that are expected.
"Non-nil" means *literally anything* that is not `nil`. This includes `0` and negative numbers.
---
## Minor Modes
Let's take a specific example. Type `C-h``f``blink-cursor-mode` and hit `RET` to see the function documentation for `blink-cursor-mode`:
> (blink-cursor-mode &optional ARG)
>
> Toggle cursor blinking (Blink Cursor mode). With a prefix argument ARG, enable Blink Cursor mode if ARG is positive, and disable it otherwise. If called from Lisp, enable the mode if ARG is omitted or nil.
We can enable Blink Cursor mode in any of the following ways:
```
(blink-cursor-mode) ; Omitted argument
(blink-cursor-mode 1) ; Positive argument
(blink-cursor-mode t) ; True argument
(blink-cursor-mode nil) ; nil argument (don't use this)
```
Notice that an argument of `t` will work, even though the doc string didn't specifically mention it. While this is often the case, your safest bet is to use what the doc string tells you to use, which in this case is a positive value.
Also, notice that an argument of `nil` will work. I would strongly recommend against `nil` in this way because it makes your intention unclear. If I were skimming over your lisp code and I saw a `nil` argument, I would assume that you wanted to disable the minor mode.
We can also disable `blink-cursor-mode` in the following ways:
```
(blink-cursor-mode 0) ; Non-positive argument
(blink-cursor-mode -1) ; Negative argument
```
Notice again that `nil` is **not** one of the ways to disable this minor mode. This is true of almost any minor mode you will encounter.
---
## Variables
Now let's look at an example of a variable. Type `C-h``v``truncate-lines` and hit `RET` to look at the documentation for the variable `truncate-lines`:
> truncate-lines is a variable defined in \`C source code'.
>
> Non-nil means do not display continuation lines. Instead, give each line of text just one screen line.
You can turn on truncation in any of the following ways:
```
(setq truncate-lines t) ; Boolean true value (non-nil)
(setq truncate-lines 1) ; Positive value (non-nil)
(setq truncate-lines 0) ; Zero value (non-nil)
(setq truncate-lines -1) ; Negative value (non-nil)
```
It may surprise you that the `0` and the `-1` will work. Again, I would recommend against using them because it makes your intentions unclear.
The only way to disable truncation is this:
```
(setq truncate-lines nil) ; nil value
```
In other words you can set `truncate-lines` equal to numbers, letters, strings, lists, or anything else you want, as long as it does not evaluate to `nil` it will **enable** truncation. (But you should really stick with `t` or `1`).
# Answer
> 0 votes
These are all different things. 0, 1, and -1 are different numbers; `nil` is a symbol.
They are each used all over the place, for many different things. To find out what each is used for **in a particular context**, *consult the doc for that context*. And that includes contexts of turning different modes on or off, enabling and disabling different things using variables, and lots of other contexts.
In sum:
* Your question is far too broad to be useful.
* You need to consult the doc: (a) in general, to learn a little about Emacs Lisp, and (b) in particular contexts (e.g., the doc for a particular mode).
The doc for a given mode generally tells you how to turn it on and off. If it tells you to use 1 or -1 or `nil` or non-`nil` for something, then that's what it means. There are some general rules for turning modes on and off (interactively and from Lisp code). But it sounds like you really need to start by getting some general background.
Consult the Emacs doc to learn how to **ask for help and other information from Emacs itself**: how to check the value of a variable, how to see the doc of a variable or a function (including a function that turns a mode on/off), and so on.
You can *start by using* **`C-h C-h`** (`Ctrl-h` `Ctrl-h`), to learn about the Emacs help system. And build from there.
**`C-h r`** puts you into the Emacs manual. Try the Emacs tutorial: `C-h t`. And check the Emacs Wiki Newbie page and the page about LearningEmacs.
To start learning about Emacs Lisp: **`C-h i`**, then choose the manual named `Emacs Lisp Intro`, and start reading. And check the Emacs Wiki page about Learning Emacs Lisp.
# Answer
> 0 votes
It seems that in most cases you should use `1` and `-1`. But sometimes this doesn't work and you need to use `t` and `nil` instead. Your safest bet is to use what the docstring, which is available by typing `C-h f` for a function and `C-h v` for a variable, tells you to use.
Just in case, here are quotes from other Emacs users that I found most helpful:
> "As with any mode defined using `define-global-minor-mode`, the only valid values are numbers, `nil`, and `toggle`. The fact that `t` works is only due to the fact that `prefix-numeric-value` doesn't choke on it and treats it like `1`." - Lindydancer
>
> \- global-auto-revert-mode doesn't seem to work?
> "I've run into some modes where you have to pass `t` or `nil` instead of numbers." - Joseph Garvin
>
> "@JosephGarvin It might be worthwhile to find out which those modes are... and may be file a bug report to fix that inconsistency." - Kaushal Modi
>
> \- global-auto-revert-mode doesn't seem to work?
> "Your safest bet is to use what the docstring tells you to use." - nispio
>
> \- How to choose between nil and 0, or t and 1 when setting variables or enabling modes
And here is an example:
> (global-auto-revert-mode &optional ARG)
>
> If called interactively, enable Global Auto-Revert mode if ARG is positive, and disable it if ARG is zero or negative. If called from Lisp, also enable the mode if ARG is omitted or nil, and toggle it if ARG is ‘toggle’; disable the mode otherwise.
```
;; So, to put in other words,
;; t, 1, nil, or if used without argument - enables global-auto-revert-mode
;; 0, -1 - disables it
(global-auto-revert-mode 1)
```
See also: https://stackoverflow.com/q/49370733
---
Tags: boolean
--- |
thread-57505 | https://emacs.stackexchange.com/questions/57505 | How to fix docker command prompt | 2020-04-01T05:57:00.220 | # Question
Title: How to fix docker command prompt
When I start `emacs -q` and run `M-x shell` there is formatting error when connecting to docker container as follows,
```
$ docker container exec -it b3c85fd9c5eaa2e64fc5aac9025d1f9c3b3fe47ca39008f40ddd436338d755f5 bash
]0;root@b3c85fd9c5ea: /root@b3c85fd9c5ea:/# ls
ls
bin dev home lib64 mnt proc run srv tmp var
boot etc lib media opt root sbin sys usr
]0;root@b3c85fd9c5ea: /root@b3c85fd9c5ea:/#
```
Here is its screenshot
# Answer
Your value of `PS1` contains ANSI escape codes that can only be processed correctly by a terminal emulator (like the built-in term.el or vterm), not by `M-x shell` or `M-x eshell`. Set it to something simpler like `\u@\h:\w\$`, this could be done with the `-e` switch for the `docker-container-exec` command.
> 1 votes
# Answer
Use `cd` instead of `docker attach`. So, at the eshell prompt, instead of attaching to a running container with
```
$ docker attach <container_id>
```
cd into it with
```
$ cd /docker:<container_id>:/
```
You'll get the full eshell experience with this method.
> 0 votes
---
Tags: shell, docker
--- |
thread-68035 | https://emacs.stackexchange.com/questions/68035 | Can't overwrite compile-command | 2021-08-09T10:48:05.957 | # Question
Title: Can't overwrite compile-command
I am having this in my init file to reset the compile command in the C mode, but when I run the `C-c C-c` inside C mode I will get the old command `make ...` meaning my new command hasn't been set. Why? Here is the code:
```
(add-hook 'c-mode-hook
(lambda ()
(set 'compile-command
(let* ((file (file-name-nondirectory buffer-file-name))
(fname (file-name-sans-extension file)))
(format "gcc -c -g -Wall -Wextra -Werror -std=c99 -pedantic -o %s.o %s"
fname fname))))
0 t)
(add-hook 'c-mode-hook
(lambda ()
(local-set-key (kbd "C-c C-c") #'compile)))
```
# Answer
> 2 votes
When you call `(add-hook … 0 t)` the `t` means to add the hook *locally* to the current buffer. When you load a C file, it creates a new buffer, and that hook isn't active in the new buffer.
I believe you can solve the problem by removing the `0 t` from the first `add-hook` call. That ways it will add the hook globally, and it will run in new buffers.
---
Tags: compile
--- |
thread-61692 | https://emacs.stackexchange.com/questions/61692 | JetBrains Mono font settings | 2020-11-12T05:07:00.097 | # Question
Title: JetBrains Mono font settings
I have been trying to configure emacs to use JetBrains Mono font, unfortunately i can hardly understand the way emacs handles font settings, there are way too many options and stuffs going on. So i got lost and here is my current font settings -
```
(set-face-attribute 'default nil
:family "JetBrains Mono"
:height 110
:weight 'light)
(set-face-attribute 'variable-pitch nil
:family "JetBrains Mono"
:height 1.0)
(set-face-attribute 'fixed-pitch nil
:family "JetBrains Mono"
:height 1.0)
```
But this seems not as per recommended settings from the jetbrains's site -
```
Size: 13
Line spacing: 1.2
```
I don't know to relate `:height` with `Size: 13`, couldn't figure that out. I also failed to match the line spacing 1.2. If i use `(setq line-spacing 1.2)` emacs renders lines way too separated vertically.
I am using emacs 27.1 with harfbuzz.
So if anyone has been using this font with emacs, please share your configuration or point me to some place where i can get/understand how to configure and match the recommended settings.
Thanks in advance.
# Answer
Here is a snippet from my `custom.el`:
```
'(default-frame-alist
'((fullscreen . fullscreen)
(font . "JetBrains Mono-13")
(line-spacing . 0.2)))
```
The JetBrains website doesn't specify the unit for their recommendation of "13", but inspecting the CSS reveals that their examples have a CSS `font-size` of 13px.
Emacs documentation on fonts specifies that the sizes point sizes.<sup>\[\]</sup>
Emacs on my macOS machine reports the value of `display-pixels-per-inch` as "72" whereas CSS specifies that a pixel is 1/96th of 1 inch.<sup>\[\]</sup> Nevertheless, the value of 13 points in Emacs seems to be the same height in real display pixels as the 13 pixels on the JetBrains website in Chrome and Firefox and I can't understand why that would be.
The `line-spacing` property is set as a height spec and refers to the amount of space added below each line. Therefore, you only want the *extra* space more than a default, single line height. The value should be `0.2`.
> 1 votes
---
Tags: fonts
--- |
thread-68041 | https://emacs.stackexchange.com/questions/68041 | How to list all the code blocks in the current buffer with no #+NAME? | 2021-08-09T22:59:39.297 | # Question
Title: How to list all the code blocks in the current buffer with no #+NAME?
Let's say I have a buffer with some code blocks, but I want to know the location of those code blocks that doesn't have `#+NAME` set.
# Answer
> 2 votes
# Table of contents
1. The answer
2. Minimal working example
# The answer
Use `org-babel-map-src-blocks`.
# Minimal working example
Consider the following Org Mode file
```
01 | * This is the first heading
02 |
03 | #+NAME: foo
04 | #+BEGIN_SRC bash
05 | echo 2
06 | #+END_SRC
07 |
08 | * This is the second heading
09 |
10 | #+BEGIN_SRC bash
11 | echo 1
12 | #+END_SRC
```
You can use the following sexp to show a message whenever a code block with no name is found
```
(org-babel-map-src-blocks nil
(let ((name (org-element-property :name (org-element-context))))
(unless name
(message "Code block with no name found in line %s" (line-number-at-pos))))))
```
If we evaluate the sexp in the Org Mode file, we would get
```
Code block with no name found in line 10
```
---
Tags: org-mode, org-babel
--- |
thread-36676 | https://emacs.stackexchange.com/questions/36676 | How to change fringe background color for current line only? | 2017-11-07T08:18:57.870 | # Question
Title: How to change fringe background color for current line only?
We can change current line background using `global-hl-line-mode`. How about fringe background of the current line?
# Answer
> 2 votes
The left and right fringe have one color that can be customized by the user; however, coloring only certain portions would need to be done with fringe bitmap images. Fringe bitmap images can be up to 8 pixels wide and up to frame-char-height in height. Emacs has about 10 to 15 built-in fringe bitmap images, and the user can customize his/her own. I like to use fringe-helper to create my own bitmap images https://github.com/nschum/fringe-helper.el. Emacs wiki has an example: https://www.emacswiki.org/emacs/FringeMark
Here is an example that runs every command loop on the `post-command-hook` that is **local** to the current-buffer only. You can use `fringe-helper` to create a rectangle the size and color of your liking.
```
(defface +-left-fringe-cursor-face
'((t (:foreground "firebrick")))
"Face for `+-left-fringe-cursor-face'."
:group '+-mode)
(defun set-fringe-cursor ()
"Doc-string"
(if (not (and (eobp) (bolp)))
(setq +-left-fringe-overlay-position (copy-marker (line-beginning-position)))
(setq +-left-fringe-overlay-position nil)))
(define-fringe-bitmap '+-cursor-left-fringe-bitmap [128 192 96 48 24 48 96 192 128] 9 8 'center)
(set-fringe-bitmap-face '+-cursor-left-fringe-bitmap '+-left-fringe-cursor-face)
;;; `overlay-arrow-bitmap' is a special SYMBOL defined in xdisp.c.
(defvar +-left-fringe-overlay-position nil
"Doc-string.")
(make-variable-buffer-local '+-left-fringe-overlay-position)
(add-to-list 'overlay-arrow-variable-list '+-left-fringe-overlay-position)
(put '+-left-fringe-overlay-position 'overlay-arrow-bitmap '+-cursor-left-fringe-bitmap)
(add-hook 'post-command-hook 'set-fringe-cursor 'append 'local)
```
---
Here is an example of a filled square bitmap image created using `fringe-helper` cited above, which is 8 pixels wide by 13 pixels high. \[I just counted the number of `x` and see that it is only 7 and the pixel to the right is empty. The last pixel does not have to be empty -- I probably copied that bitmap from the Emacs source code. Feel free to place an `x` in lieu of the `.`\]
```
;; AUTHOR: Nikolaj Schumacher -- https://github.com/nschum/fringe-helper.el
(defun +-fringe-helper (&rest strings)
"Convert STRINGS into a vector usable for `define-fringe-bitmap'.
Each string in STRINGS represents a line of the fringe bitmap.
Periods (.) are background-colored pixel; Xs are foreground-colored. The
fringe bitmap always is aligned to the right. If the fringe has half
width, only the left 4 pixels of an 8 pixel bitmap will be shown.
For example, the following code defines a diagonal line.
\(+-fringe-helper
\"XX......\"
\"..XX....\"
\"....XX..\"
\"......XX\"\)"
(unless (cdr strings)
(setq strings (split-string (car strings) "\n")))
(apply 'vector
(mapcar
(lambda (str)
(let ((num 0))
(dolist (c (string-to-list str))
(setq num (+ (* num 2) (if (eq c ?.) 0 1))))
num))
strings)))
(define-fringe-bitmap '+-fringe-filled-rectangle (+-fringe-helper
"xxxxxxx."
"xxxxxxx."
"xxxxxxx."
"xxxxxxx."
"xxxxxxx."
"xxxxxxx."
"xxxxxxx."
"xxxxxxx."
"xxxxxxx."
"xxxxxxx."
"xxxxxxx."
"xxxxxxx."
"xxxxxxx.") nil nil 'center)
(defface +-fringe-filled-square-face
'((t (:foreground "chartreuse")))
"Face for `+-fringe-filled-square-face'."
:group '+-mode)
(set-fringe-bitmap-face '+-fringe-filled-square '+-fringe-filled-square-face)
```
---
The built-in overflow cursor in fringe indicator (that appears if the user is on a line that is exactly the window-width) takes on the color of the `cursor-color` in the `frame-parameters`, and its image can be controlled as well. \[See `fringe-cursor-alist`.\] Other fringe bitmaps can be changed with `fringe-indicator-alist`.
Be aware that Emacs can also place fringe bitmap images using the built-in overlay mechanisms.
As indicated in a comment above, the user can also customize the line numbers to take on a foreground/background coloration of the user specifications -- this applies to the current line and to non-current lines.
# Answer
> 0 votes
Since `Emacs 26.1`, it is possible to enable `display-line-numbers` and configure `line-number-current-line` face.
Example configuration:
```
(setq-default display-line-numbers t)
(custom-theme-set-faces
'misterioso
'(line-number-current-line ((t (:background "SkyBlue4"))) t))
(enable-theme 'misterioso)
```
---
Tags: fringe
--- |
thread-68044 | https://emacs.stackexchange.com/questions/68044 | How to toggle the visibility of the PROPERTIES drawer programmatically? | 2021-08-10T06:22:03.550 | # Question
Title: How to toggle the visibility of the PROPERTIES drawer programmatically?
# Prologue
I heavily use the `:PROPERTIES:` drawer. Because of this, I want to create a function that would allow me to toggle the visibility of the `:PROPERTIES:` of the current subtree. I want the function to also work at the top level of the document (recall that a `:PROPERTIES:` drawer can be used in the top level of the document to set a property for all the subtrees in the current document).
I could use `org-cycle`, but in order to use this function, I need the cursor to be on the drawer, and I want the function to work regardless of the position of the cursor.
# The question
1. Is there any native function that accomplishes this behavior?
2. If that's not the case, what functions could I use to accomplish this desired behavior?
# Answer
> 1 votes
I don't think there is a native function for doing that, but you can define your custom function.
```
(defun my/org-toggle-properties-drawer-current-subtree ()
"Toggles the visibility of the PROPERTIES drawer of the current subtree."
(interactive)
(cond
;; If the cursor is on the top level of the document
((null (org-current-level))
(save-excursion
(beginning-of-buffer)
(unless (org-at-property-drawer-p)
(error "The top level of the document doesn't have a PROPERTIES drawer."))
(org-hide-drawer-toggle)))
;; If the cursor is on a headline
((eq (car (org-element-at-point)) 'headline)
(save-excursion
(next-line)
(unless (org-at-property-drawer-p)
(error "This heading doesn't have a PROPERTIES drawer."))
(org-hide-drawer-toggle)))
;; If the cursor is not on a headline and is not in the top level
;; of the document, then it is inside a subtree.
(t (save-excursion
(org-previous-visible-heading 1)
(next-line)
(unless (org-at-property-drawer-p)
(error "This heading doesn't have a PROPERTIES drawer."))
(org-hide-drawer-toggle)))))
```
```
(define-key org-mode-map (kbd "C-c t p") 'my/org-toggle-properties-drawer-current-subtree)
```
---
Tags: org-mode
--- |
thread-68046 | https://emacs.stackexchange.com/questions/68046 | How to insert the result of evaluating a sexp in a string? | 2021-08-10T09:07:15.173 | # Question
Title: How to insert the result of evaluating a sexp in a string?
I am new to Emacs and I am reading Elisp guide inside Emacs. I am at the *Args as Variable or list* chapter. There is listed below code-
```
(concat "The " (number-to-string (+ 2 value)) "red foxes.")
```
`value` here is an integer set by some function.
Now I want to print `fox` instead of `foxes` if the list argument to the concat function returns 1. How can I do that?
# Answer
I would use `format` instead of `concat`. For example:
```
(let* ((n (+ 2 value))
(f (if (= 1 n) "fox" "foxes")))
(format "The %d red %s" n f))
```
You can check the documentation of `format` (`C-h f format RET`) to understand the meaning of `%d` and `%s` and know more about this function. Check also `C-h f let* RET` to know more about let bindings.
> 4 votes
---
Tags: string, format
--- |
thread-38008 | https://emacs.stackexchange.com/questions/38008 | Adding many items to a list | 2018-01-10T14:56:04.870 | # Question
Title: Adding many items to a list
What is the proper way to add many items to a list? I assume just using many `add-to-list`s is not the normal way?
# Answer
> 7 votes
There are many different ways. Not sure if there's a particularly "proper" way. There are considerations you should take depending on how you want to add it (destructively, non-destructively) or if you care a lot about efficiency.
original list `(1)` things you want to add `(2 3 4)`
There are many different ways of adding. Things can be added destructively, meaning the original set of numbers is modified or non-destructively, just generating a new list. To see more look at list modification.
This is non-destructive. `(append '(1) '(2 3 4)) ;=> '(1 2 3 4)`
This is destructive and more indirect (more of a replacement than addition), here it replaces the last element of the list `2` with `2 3 4`. Which has the net effect of adding to the list.
If your list is in a variable: `(setq my-list '(1 2))`
`(setcdr my-list '(2 3 4)) ;=> '(2 3 4)`
`my-list ;=> '(1 2 3 4)`.
You could also just do a loop with `add-to-list` or `cons`. Note I'm assuming you don't care about order.
`(dolist (thing things) (add-to-list 'list-var thing))`
`(dolist (thing things) (cons thing list-var))`
I usually use the `append` as it is short to write and more direct. It also is probably among the fastest because it is written in C code whereas `add-to-list` is in elisp.
# Answer
> 3 votes
The proper way to add many items to a list is *consing* in a loop.
If `l` is the list variable you add an item `i` by
```
(setq l (cons i l))
```
for which you can use the shorthand
```
(push i l)
```
The computational cost of this operation is independent of the length of the list `l`.
After collecting the items in this way they are in reverse order. If it is important to retain the order you can call
```
(setq l (nreverse l))
```
as the last action or just return `(nreverse l)`. The cost of `nreverse` grows just linearly with the length of the list.
The costs of adding all elements with `add-to-list` grow quadratically with the length of the list (even without `append` set to `t`).
If you want to add an item to a list only if it is not already present. You have to search for that item. In that case you could consider using a hashmap (search the elisp info files for `make-hash-table`) or a sorted list to reduce the computational costs. Note that a single hash access is costly but the read/write access time is essentially independent on the number of elements in the hash.
# Answer
> 3 votes
I figured this question lacks an actual practical example that a person can copy-paste into their config, so here it is:
```
(defun merge-list-to-list (dst src)
"Merges content of the 2nd list with the 1st one"
(set dst
(append (eval dst) src)))
```
It combines the non-destructive `append` function that merges two lists, and a destructive `set`.
Now, let's say your config had this code:
```
(add-to-list 'company-dabbrev-code-modes 'c++-mode)
(add-to-list 'company-dabbrev-code-modes 'c-mode)
(add-to-list 'company-dabbrev-code-modes 'php-mode)
(add-to-list 'auto-mode-alist '("\\.mzn\\'" . minizinc-mode))
(add-to-list 'auto-mode-alist '("\\.glade$\\'" . xml-mode))
(add-to-list 'auto-mode-alist '("\\PKGBUILD\\'" . sh-mode))
(add-to-list 'auto-mode-alist '("\\.service\\'" . conf-mode))
(add-to-list 'auto-mode-alist '("\\.m$" . octave-mode))
```
You replace it with this:
```
(merge-list-to-list 'company-dabbrev-code-modes
'(c++-mode c-mode php-mode))
(merge-list-to-list 'auto-mode-alist
'(("\\.mzn\\'" . minizinc-mode)
("\\.glade$\\'" . xml-mode)
("\\PKGBUILD\\'" . sh-mode)
("\\.service\\'" . conf-mode)
("\\.m$" . octave-mode)))
```
---
Tags: list
--- |
thread-26251 | https://emacs.stackexchange.com/questions/26251 | One-time advice | 2016-08-13T21:48:12.107 | # Question
Title: One-time advice
I've been trying to a macro to **put one-time advice on a function**.
What I mean by one-time advice is **advice which removes itself after it is called** – so that when you add the advice and run the original function, the advice runs, but if you run the function again, the advice is gone.
My current (non-working) definition is
```
(defmacro add-one-time-advice (symbol where function &optional props)
`(let ((ad-sym (make-symbol "advice")))
(fset ad-sym (symbol-function ,function))
(advice-add ad-sym :after (lambda () (advice-remove ,symbol ad-sym)))
(advice-add ,symbol ,where ad-sym ,props)))
```
This throws no errors, but the advice doesn't remove itself.
If my approach is okay, **how can I fix it**, and if it's not, **what's the cleanest way to implement this?**
# Answer
> 7 votes
You don't need a macro for this. And you don't need (but you can certainly use) lexical binding.
```
;; Without lexical binding:
;;
(defun advise-once (symbol where function &optional props)
(advice-add symbol :after `(lambda (&rest _) (advice-remove ',symbol ',function)))
(advice-add symbol where function props))
;; With lexical binding:
;;
(defun advise-once (symbol where function &optional props)
(advice-add symbol :after (lambda (&rest _) (advice-remove symbol function)))
(advice-add symbol where function props))
(advise-once 'backward-word :before (lambda (_) (message "Eureka!")))
```
The reason you do not need lexical binding is that you are interested, when the function (lambda form) is used, only in the **values** of `symbol` and `function`, such as they were at the time the lambda-form list was created. You do not need **variables** `symbol` and `function` when the lambda form is used.
The use of the backquote syntax *constructs a list* that is a lambda form, where the **values** of `symbol` and `function` have been substituted in place of those variables.
Using lexical binding has the advantage that the lambda form can be compiled, because it is recognized by the compiler as a function, whereas in the case of using the backquote syntax all the compiler sees is code that constructs a list.
# Answer
> 1 votes
The code looks OK, actually (I would get rid of the call to `symbol-function`, tho).
My crystal ball tells me that maybe you get bitten by dynamic scoping: your code relies on lexical-scoping for its use of `ad-sym` from within the `lambda`, so it's indispensable that `lexical-binding` be non-nil in the code that *uses* this macro.
# Answer
> 0 votes
As far as I understand, the proposed solution lets the function advised. The `:after` advice to remove the original advice is not removed, so `(advice-remove ...)` remains being executed.
Here is an alternative solution "modifying the advice". Now, no advice is left, but it just works for interactive advises. Hopefully someone would fix it :)
```
(defun advice-once (symbol where function &optional props)
(let ((new-function (intern (concat (symbol-name function) "-advice-once"))))
(fset new-function `(lambda (&rest _)
;; (,function)
;; (funcall ',function)
;; (command-execute ',function)
(call-interactively ',function)
(advice-remove ',symbol #',new-function)))
(advice-add symbol where new-function props)))
(defun eureka nil
(interactive)
(message "Eureka!"))
(advice-once 'backward-word :before #'eureka)
```
Following OP code, here is a version "advising the advice". The code is more simple, `symbol` does not remains advised and it works for pretty much any advising function. But, the advising function `function` remains advised, which can not be solved.
```
(defun advice-once (symbol where function &optional props)
(advice-add function :after `(lambda (&rest _) (advice-remove ',symbol #',function)))
(advice-add symbol where function props))
```
---
Tags: elisp, elisp-macros, advice
--- |
thread-63883 | https://emacs.stackexchange.com/questions/63883 | Underline issue with Inconsolata font | 2021-03-13T14:13:59.563 | # Question
Title: Underline issue with Inconsolata font
I'm using `Inconsolata` font in emacs. The setting looks like
```
(set-face-attribute
'default nil
:font (font-spec :name "-*-Inconsolata-bold-italic-normal-*-*-*-*-*-m-0-iso10646-1"
:weight 'normal
:slant 'normal
:size 12.0))
```
But the wave style underline has some issue like
The bottom of the underline is strip by the next line. Using `Iosevka` everything is just fine
How can I fixed this without changing to another font? Changing the font size doesn't help. Thanks.
# Answer
This is not really a problem with Emacs. All that is happening is that the font metrics for the font you've chosen don't leave quite enough room for the wavy underlines (the descenders are not quite as tall as the wavy underline). You could increase the line spacing of the face to compensate. I suppose it would be a little nicer if Emacs drew the wavy underline in a second pass after it had drawn all of the text, but that's a lot of complications for a very minor graphical difference.
> 0 votes
# Answer
I think doing `(setq-default line-spacing 0.25)` might solve your problem (`0.25` is just an dummy number, you'll need to adjust this). There's more information about line-height at https://www.gnu.org/software/emacs/manual/html\_node/elisp/Line-Height.html (or directly in Emacs, of course: `M-x info-emacs-manual`).
> 0 votes
---
Tags: fonts, display
--- |
thread-68052 | https://emacs.stackexchange.com/questions/68052 | Display the header that a TODO item belongs to? | 2021-08-10T20:37:12.743 | # Question
Title: Display the header that a TODO item belongs to?
In org mode, I'll have a file pertaining to some topic, and a few top level headings pertaining to instances of that topic, which may contain TODOs (also potentially nested). In the global TODO list, TODOs show up like this:
```
<file-name>: <state> <name>
```
Would it be possible to instead display them like this (potentially with a custom format string):
```
<header> (<file-name>): <state> <name>
```
Thanks!
# Answer
> 3 votes
Customize the `todo` part of `org-agenda-prefix-format` and add the breadcrumbs placeholder `%b`. For example, by default `org-agenda-prefix-format` has the value
```
((agenda . " %i %-12:c%?-12t% s")
(todo . " %i %-12:c")
(tags . " %i %-12:c")
(search . " %i %-12:c"))
```
and a `TODO` entry for a second-level `Home` headline under a top-level `Tasks` headline, looks like this:
> Home: TODO Work on music DB
If you change the `todo` entry in `org-agenda-prefix-format` from `" %i %-12:c"` to `" %b %i %-12:c"`, the same entry is shown as
> Tasks-\> Home: TODO Work on music DB
Breadcrumbs include *all* the higher level headlines.
In order to do the above change, first do `C-h v org-agenda-prefix-format`, and click on the `customize` link. In the resulting display, the values can be edited directly: find the `todo` entry and its format and change it as above. Then click `Apply` to try it out or `Apply and Save` to save it for future sessions as well.
---
Tags: org-mode, formatting
--- |
thread-68057 | https://emacs.stackexchange.com/questions/68057 | Setup ox-extra in an elisp script to be run without init file | 2021-08-11T07:32:41.160 | # Question
Title: Setup ox-extra in an elisp script to be run without init file
I'm new to Emacs and I am trying to write an elisp script to automate the org-mode export for GitLab CI. The idea is that on the worker I simply run `emacs --batch --no-init-file --load build.el --funcall org-publish-all` to export my org project.
Since I use the `:ignore:` tag I need the `(ox-extras-activate '(ignore-headlines))` line in my `build.el`. This obviously reports `Symbol’s function definition is void: ox-extras-activate`, but with (`ox-extra` is part of `org-plus-contrib`):
```
(require 'package)
(package-initialize)
(add-to-list 'package-archives '("org" . "https://orgmode.org/elpa/") t)
(add-to-list 'package-archives '("org-plus-contrib" . "https://orgmode.org/elpa/") t)
(package-refresh-contents)
(require 'org)
(require 'ox-extra)
(ox-extras-activate '(ignore-headlines))
```
I got this error: `Cannot open load file: File o directory non esistente, ox-extra`.
I tried also with
```
(require 'package)
(package-initialize)
(add-to-list 'package-archives '("org" . "https://orgmode.org/elpa/") t)
(add-to-list 'package-archives '("org-plus-contrib" . "https://orgmode.org/elpa/") t)
(package-refresh-contents)
(package-install 'org)
(package-install 'ox-extra)
(require 'org)
(require 'ox-extra)
(ox-extras-activate '(ignore-headlines))
```
which causes `Package ‘ox-extra-’ is unavailable`.
So I cannot find a way to setup `ox-extra`.
Full `build.el`:
```
;; build.el --- Build orgmode book
;;; Commentary:
;; This script will export the book
;;; Code:
(require 'package)
(package-initialize)
(add-to-list 'package-archives '("org" . "https://orgmode.org/elpa/") t)
(add-to-list 'package-archives '("org-plus-contrib" . "https://orgmode.org/elpa/") t)
(package-refresh-contents)
(package-install 'org)
(package-install 'ox-extra)
(require 'org)
(require 'ox-extra)
(ox-extras-activate '(ignore-headlines))
(setq ; org-export-with-section-numbers nil
org-export-with-smart-quotes t
; org-export-with-toc nil
)
;; Minted
(setq org-export-latex-listings 'minted
org-latex-packages-alist '(("" "minted"))
org-latex-minted-options
'(("autogobble=true") ("breaklines=true"))
org-latex-pdf-process
(mapcar
(lambda (s)
(replace-regexp-in-string "%latex " "%latex -shell-escape " s))
org-latex-pdf-process))
;; Prepare to export
(setq org-html-divs '((preamble "header" "top")
(content "main" "content")
(postamble "footer" "postamble"))
org-html-container-element "section"
org-html-metadata-timestamp-format "%d/%m/%Y"
org-html-checkbox-type 'html
org-html-html5-fancy t
; org-html-validation-link nil
org-html-doctype "html5")
(defvar site-attachments
(regexp-opt '("jpg" "jpeg" "gif" "png" "svg"
"ico" "cur" "css" "js" "woff" "woff2" "html"
; "pdf"
))
"File types that are published as static files.")
(setq
common (list
:base-directory "."
:base-extension "org"
:recursive nil
:exclude (regexp-opt '("README" "LICENSE"))
)
)
;; Export
(setq org-publish-project-alist
(list
(append '("latex-org") common (list
:publishing-function '(org-latex-export-to-pdf)
:publishing-directory "."
))
(append '("html-org") common (list
:publishing-function '(org-html-export-to-html)
:publishing-directory "./public"
;; :auto-sitemap t
;; :sitemap-filename "index.org"
;; :sitemap-file-entry-format "%d *%t*"
;; :html-head-extra "<link rel=\"icon\" type=\"image/x-icon\" href=\"/favicon.ico\"/>"
;; :sitemap-style 'list
;; :sitemap-sort-files 'anti-chronologically
))
(list "site-static"
:base-directory "."
:exclude "public/"
:base-extension site-attachments
:publishing-directory "./public"
:publishing-function 'org-publish-attachment
:recursive t)
(list "site" :components '("html-org" "site-static"))
))
(add-to-list 'org-latex-classes
'("elegantbook"
"\\documentclass{elegantbook}"
("\\part{%s}" . "\\part*{%s}")
("\\chapter{%s}" . "\\chapter*{%s}")
("\\section{%s}" . "\\section*{%s}")
("\\subsection{%s}" . "\\subsection*{%s}")
("\\subsubsection{%s}" . "\\subsubsection*{%s}")))
(provide 'build)
;;; build.el ends here
```
# Answer
> 1 votes
As pointed out by @dalanicolai the solution was simply to install `org-plus-contrib` instead of `ox-extra`:
```
(require 'package)
(package-initialize)
(add-to-list 'package-archives '("org" . "https://orgmode.org/elpa/") t)
(add-to-list 'package-archives '("org-plus-contrib" . "https://orgmode.org/elpa/") t)
(package-refresh-contents)
(package-install 'org)
(package-install 'org-plus-contrib)
(require 'org)
(require 'ox-extra)
(ox-extras-activate '(ignore-headlines))
```
---
Tags: org-mode, org-export, package
--- |
thread-68056 | https://emacs.stackexchange.com/questions/68056 | Searching in Dired for content in files while filtering files | 2021-08-11T02:23:43.073 | # Question
Title: Searching in Dired for content in files while filtering files
From Dired, I'd like to be able to search for content pretty much like I do on my MAC Finder, while showing the files that match the criteria/regular expression (and no other files). I don't want the matching files to be marked, but rather filtered from the rest of the files in the folder. Is there a good online source where to find possibilities? I want something simple (if it's done inside the Dired menu, even better, rather than relying on other packages).
# Answer
You can try the built in `find-grep-dired`. From the documentation:
> Find files in DIR that contain matches for REGEXP and start Dired on output.
Try `C-h f find-grep-dired RET` to know more.
> 1 votes
---
Tags: dired, search, find-dired, find
--- |
thread-64007 | https://emacs.stackexchange.com/questions/64007 | Can't hide leading stars on selected row in org mode | 2021-03-20T23:51:34.587 | # Question
Title: Can't hide leading stars on selected row in org mode
Emacs 26.3
or this
As you can see it shows leading stars on selected row.
I want to hide them. I try this:
```
'(org-hide-leading-stars t)
```
But it does not help: stars are not hidden.
# Answer
> 0 votes
```
#+STARTUP: hidestars
```
You may need to reset with `M-x org-mode`.
---
Tags: org-mode
--- |
thread-66587 | https://emacs.stackexchange.com/questions/66587 | How to define global key binding for `C-c >` and `C-c <` using `defhydra` | 2021-07-04T12:23:08.747 | # Question
Title: How to define global key binding for `C-c >` and `C-c <` using `defhydra`
I am trying to apply following solutions's key binding to overwrite all mode's key bindings for `C-c >` and `C-c <`.
---
From the answer for Can we do `C-c >` and `>` and `>` to continue indentation:
```
(defhydra python-indent (global-map "C-c")
"Adjust python indentation."
(">" python-indent-shift-right "right")
("<" python-indent-shift-left "left"))
```
which works for the `python-mode`; but it does not overwrite into the global bindings and such as in `shell-mode`, its bind remain as to `sh-learn-line-indent`.
Is there any way to force to overwrite the key binding for `C-c >` and `C-c <`?
---
I have also tried following with the help of (https://emacs.stackexchange.com/a/68029/18414), which did not work:
```
(with-eval-after-load "sh-script"
(defhydra python-indent (sh-mode-map "C-c")
(">" python-indent-shift-right "right")
("<" python-indent-shift-left "left"))
```
# Answer
Update:
Since you're using a Hydra, I think the best way to do this is to create a minor mode, and then define the hydra in that minor-mode.
Start by creating your minor mode as described in this answer.
Then you just need to define the hydra in the mode-map for that mode:
```
(defhydra python-indent (my-mode-map "C-c")
"Adjust python indentation."
(">" python-indent-shift-right "right")
("<" python-indent-shift-left "left"))
```
Once you've run all this code, you can turn on `my-mode`, and you should have access to your keybinding in all buffers.
> 1 votes
---
Tags: key-bindings, python, indentation, shell
--- |
thread-68062 | https://emacs.stackexchange.com/questions/68062 | Can't send/receive OSC messages to/from other processes | 2021-08-11T09:54:53.600 | # Question
Title: Can't send/receive OSC messages to/from other processes
I made my first attempt at OSC with (Doom) Emacs. I got the example in osc.el working, but I couldn't make it either send or receive messages to/from other processes, even if they are running in Emacs itself (I tried SuperCollider both with Emacs and SCide). I can send OSC with SuperCollider in Emacs to a Python OSC server running in a terminal, but not to the elisp script, or from the elisp script to the Python server.
Here's my code:
```
(require 'osc)
(setq tkt-osc-client (osc-make-client "localhost" 7770))
(setq tkt-osc-server (osc-make-server
"localhost" 7770
(lambda (path &rest args)
(message "Unhandled: %s %S" path args))))
(osc-server-set-handler tkt-osc-server "/tkt" (lambda (path &rest args) (message "Received: %s %S" path args)))
(osc-send-message tkt-osc-client "/tkt" 1.5 1.0 5 "alo")
;; (delete-process tkt-osc-client)
(provide 'tkt-osc)
```
What am I missing?
Thanks,
EDIT: I managed to send messages to another process with:
```
(require 'osc)
(setq tkt-osc-client nil)
(setq tkt-osc-server nil)
(setq tkt-osc-server (osc-make-server
"localhost" 7770
(lambda (path &rest args)
(message "Unhandled: %s %S" path args))))
(osc-server-set-handler tkt-osc-server "/tkt" (lambda (path &rest args) (message "Received: %s %S" path args)))
(defun tkt-make-client (host port)
(make-network-process
:name "OSC client"
:host host
:service port
:type 'datagram
:family 'ipv4))
(defun tkt-osc-connect (host port)
"Connect to a remote HOST with PORT."
(if tkt-osc-server (delete-process tkt-osc-server))
(if tkt-osc-client (delete-process tkt-osc-client))
(setq tkt-osc-client (tkt-make-client host port)))
(defun tkt-osc-close ()
(delete-process tkt-osc-client)
(delete-process tkt-osc-server))
(provide 'tkt-osc)
```
But the server part still doesn't receive anything, not even the messages sent from this script's client, which was working before...
Any ideas?
# Answer
There seems to be a problem with the default `osc-make-server` function. By adding the property `:familiy 'ipv4` to the `(make-network-process)` function it seems to work.
Here's the full working code:
```
(require 'osc)
(setq tkt-osc-client nil)
(setq tkt-osc-server nil)
(defun tkt-make-osc-server (port default-handler)
"Listen to OSC messages on PORT."
(make-network-process
:name "OSCserver"
:coding 'binary
:filter #'osc-filter
:host "localhost"
:service port
:server t
:type 'datagram
:family 'ipv4 // <--------------------------- this makes it work
:plist (list :generic default-handler)))
(defun tkt-make-osc-client (host port)
(make-network-process
:name "OSC client"
:host host
:service port
:type 'datagram
:family 'ipv4))
(defun tkt-osc-connect (host port)
"Connect to a remote HOST with PORT."
(if tkt-osc-server (delete-process tkt-osc-server))
(if tkt-osc-client (delete-process tkt-osc-client))
(setq tkt-osc-client (tkt-make-osc-client host port))
(setq tkt-osc-server (tkt-make-osc-server 7770
(lambda (path &rest args)
(message "Unhandled: %s %S" path args)))))
(defun tkt-osc-close ()
(delete-process tkt-osc-client)
(delete-process tkt-osc-server))
(provide 'tkt-osc)
```
> 1 votes
---
Tags: process
--- |
thread-68064 | https://emacs.stackexchange.com/questions/68064 | Smart quotes for Italian language | 2021-08-11T12:03:02.087 | # Question
Title: Smart quotes for Italian language
With the language set to English the smart quotes work out of the box:
```
#+LANGUAGE: en
#+OPTIONS: ':t
This is a "test".
```
LaTeX: `This is a ``test''.`
HTML: `This is a “test”.`
Also with other languages (e.g. German, French, Spanish, ...) they work, but not with **Italian**:
```
#+LANGUAGE: it
#+OPTIONS: ':t
This is a "test".
```
LaTeX: `This is a "test".`
HTML: `This is a "test".`
Is there a way to add support for Italian smart quotes? Or otherwise a way to add custom support for smart quotes.
Since Italian smart quotes are indeed equal to English smart quotes another solution could be, if possible, to use English smart quotes with Italian language.
# Answer
This is the patch:
```
[PATCH] ox: Italian smart quotes
* ox.el (org-export-smart-quotes-alist): Added support for italian smart quotes.
---
lisp/ox.el | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/lisp/ox.el b/lisp/ox.el
index eb12b68d7..5fe894569 100644
--- a/lisp/ox.el
+++ b/lisp/ox.el
@@ -5476,6 +5476,12 @@ transcoding it."
(secondary-closing
:utf-8 "‘" :html "‘" :latex "\\grq{}" :texinfo "@quoteleft{}")
(apostrophe :utf-8 "’" :html "’"))
+ ("it"
+ (primary-opening :utf-8 "“" :html "“" :latex "``" :texinfo "``")
+ (primary-closing :utf-8 "”" :html "”" :latex "''" :texinfo "''")
+ (secondary-opening :utf-8 "‘" :html "‘" :latex "`" :texinfo "`")
+ (secondary-closing :utf-8 "’" :html "’" :latex "'" :texinfo "'")
+ (apostrophe :utf-8 "’" :html "’"))
("no"
;; https://nn.wikipedia.org/wiki/Sitatteikn
(primary-opening
--
2.32.0
```
I sent it to the mailing list, but I don't see it in https://orgmode.org/list/, maybe I have done something wrong.
**EDIT**
Finally is here: https://orgmode.org/list/MgqQyHa--3-2@tuta.io/T/#u
> 2 votes
---
Tags: org-mode, org-export
--- |
thread-58566 | https://emacs.stackexchange.com/questions/58566 | How to use doom-modeline in spacemacs? | 2020-05-17T18:29:56.650 | # Question
Title: How to use doom-modeline in spacemacs?
This might be a fairly stupid question but I simply can't figure it out.
I've been trying to install doom-modeline for spacemacs: https://seagle0128.github.io/doom-modeline/#install
I've added the `use-package` stuff to the configuration file like this:
```
...
;; configuration in `dotspacemacs/user-config'.
dotspacemacs-additional-packages '((use-package doom-modeline
:ensure t
:init (doom-modeline-mode 1))
(use-package all-the-icons))
;; A list of packages that cannot be updated.
dotspacemacs-frozen-packages '()
...
```
Then I restarted spacemacs and it did install something. However, the modeline didn't change:
It doesn't look like in the screenshots here: https://seagle0128.github.io/doom-modeline/#screenshots
Do I somehow have to activate it or something?
# Answer
**Disclaimer**: I did not find a way to integrate it into the Spacemacs intended use of packages.
# Solution
Adding this snippet to my `dotspacemacs/user-config`:
```
(use-package doom-modeline
:ensure t
:init (doom-modeline-mode 1)
:config
;; Enable flashing mode-line on errors
(doom-themes-visual-bell-config)
;; Corrects (and improves) org-mode's native fontification.
(doom-themes-org-config)
)
```
# Drawback
* The packages `doom-modeline`is going to be delete and reinstalled at every Emacs startup when `dotspacemacs-install-packages 'used-only)` this option is set ( which I would recommend to avoid garbage ).
It seems Spacemacs does not support constructs like this`(use-package <package> :ensure t)`.
# Things tried
* Putting `doom-modeline` into `dotspacemacs-additional-packages`.
+ Including trying to add the configuration block I put into the `dotspacemacs/user-config` section.
+ Result: Configuration is not applied.
* Writing a custom layer and initializing `doom-modeline` in this layer.
+ Result: Configuration is not applied.
# References
> 1 votes
# Answer
i've been all over the place with this , the issue with doom-modeline is that it gets removed as orphan caue if you require or use-package it duplicates it , look at the spacemacs-modeling layer..grep for doom-modeline. The trick is this tell spacemacs modeline to use doom-modeline:
`dotspacemacs-mode-line-theme '(doom :separator-scale 1.5)`
and then just simply
`(doom-modeline-mode 1)` in `(defun dotspacemacs/user-config ()`
and it will never get removed again. here's he doc:
```
;; Set the theme for the Spaceline. Supported themes are `spacemacs',
;; `all-the-icons', `custom', `doom', `vim-powerline' and `vanilla'. The
;; first three are spaceline themes. `doom' is the doom-emacs mode-line.
;; `vanilla' is default Emacs mode-line. `custom' is a user defined themes,
;; refer to the DOCUMENTATION.org for more info on how to create your own
;; spaceline theme. Value can be a symbol or list with additional properties.
;; (default '(spacemacs :separator wave :separator-scale 1.5))
```
> 0 votes
---
Tags: spacemacs, mode-line
--- |
thread-68030 | https://emacs.stackexchange.com/questions/68030 | Doom Emacs Slowing Down because of Autocomplete | 2021-08-09T03:55:23.447 | # Question
Title: Doom Emacs Slowing Down because of Autocomplete
Whenever I start typing a word, Emacs tries to autocomplete it, and it slows down the app a lot.
I know the problem is the autocomplete because Emacs works fine normally.
Is there a way to remove the autocomplete suggestions? Its suggestions are not useful even if it did not slow down the app.
I tried turning off auto-complete-mode, but it did not fix the problem.
# Answer
To turn off auto completions you need to disable `company` in your `~/.doom.d/init.el`
```
:completion
company ; the ultimate code completion backend
```
> 1 votes
---
Tags: auto-complete-mode, doom
--- |
thread-63638 | https://emacs.stackexchange.com/questions/63638 | Portacle Emacs C-c C-c stopped working | 2021-02-28T13:50:32.387 | # Question
Title: Portacle Emacs C-c C-c stopped working
I am a beginner Lisp programmer and new to Emacs. I work on Portacle. I must have done something because when I press `C-c C-c` to compile a function in a buffer I get: `C-c C-c is undefined`. This worked until about an hour before. I restarted Portacle a few times but it's the same all the time.
Here is the content of the message buffer:
```
Loading portacle...
Loading iso-transl...done
ad-handle-definition: ‘er/expand-region’ got redefined
Loading g:/Lisp/Portacle/portacle/config/user.el (source)...done
Loading portacle...done
Starting new Ispell process G:/Lisp/Portacle/portacle/win/bin/hunspell.exe with en_GB dictionary...
For information about GNU Emacs and the GNU system, type C-h C-a.
Polling "c:/Users/frmau/AppData/Local/Temp/slime.12988" .. 1 (Abort with ‘M-x slime-abort-connection’.)
Loading g:/Lisp/Portacle/portacle/config/.frame.el (source)...done
Polling "c:/Users/frmau/AppData/Local/Temp/slime.12988" .. 2 (Abort with ‘M-x slime-abort-connection’.)
Connecting to Swank on port 49981..
Connected. Are we consing yet?
Mark set
File mode specification error: (user-error Unmatched bracket or quote)
mwheel-scroll: Beginning of buffer [3 times]
C-c C-c is undefined
mwheel-scroll: Beginning of buffer [7 times]
C-c C-c is undefined
```
I work on Windows. I can't do any work until this is resolved.
# Answer
At least in my case, when I encountered the same problem, my inferior lisp process hadn't started for whatever reason. By left-clicking 'lisp' at the bottom right of the buffer, it gave me the option to 'Run inferior lisp process' (I'm sure there are many ways to do this).
This restored lisp editing commands such as C-c C-c.
> 1 votes
---
Tags: debugging
--- |
thread-68083 | https://emacs.stackexchange.com/questions/68083 | How to programmatically install packages from init.el (using emacs27)? | 2021-08-12T10:06:22.823 | # Question
Title: How to programmatically install packages from init.el (using emacs27)?
I have this in my init.el file
```
(when (not (package-installed-p 'geiser))
(package-install 'geiser))
```
But when I start emacs, I get the error
```
Warning (initialization): An error occurred while loading '/home/ykp/.emacs.d/init.el':
error: Package 'geiser-' is unavailable.
```
How do I fix this? I just want to avoid manually installing my package and do it through my initialization script.
# Answer
> 2 votes
You have to use `package-refresh-contents` before trying to install a package. From `C-h f package-refresh-contents`:
> Download descriptions of all configured ELPA packages. For each archive configured in the variable \`package-archives', inform Emacs about the latest versions of all packages it offers, and make them available for download.
So you could try something like this somewhere near the beginning of your `init.el`, at least before you try to install the packages you want:
```
(require 'package)
(package-refresh-contents)
```
---
Tags: package
--- |
thread-68080 | https://emacs.stackexchange.com/questions/68080 | Replace regex in string elisp for emphasis like strings | 2021-08-12T08:11:38.107 | # Question
Title: Replace regex in string elisp for emphasis like strings
I'm fairly new to Emacs and Elisp, and am tinkering around to customize to my liking. I'd like to be able to highlight some text in Emacs and also have it displayed when exporting to html, just like how emphasis such as `bold` `italics` etc. are exported.
For the same, when a text is preceded by `!`, I'd like it to be highlighted in red and when exporting to html, highlight it, perhaps using a `<mark>` tag. For eg. `!sometext!` would be converted to `<mark>sometext</mark>` in html.
I have been able to get highlighting within `org-mode` to work through a solution I found: apply the `org-habits` styles, to the regex expressions `("\\(!\\)\\([^\n\r\t]+\\)\\(!\\)`. The entire piece of code is:
```
(add-to-list 'org-font-lock-extra-keywords '("\\(!\\)\\([^\n\r\t]+\\)\\(!\\)" (1 '(face org-habit-overdue-face invisible t)) (2 'org-habit-overdue-face t) (3 '(face org-habit-overdue-face invisible t))) t))
```
This works well, and my text is highlighted in red whenever I precede it with `!`. But I've been unsuccessful in getting it to export to HTML.
Since I do not know enough Elisp for such a complicated task, (but have a good understanding of regexps with other programming languages), I've been trying to edit this block of code I found online
```
(defun my-html-mark-tag (text backend info)
"Transcode :blah: into <mark>blah</mark> in body text."
(when (org-export-derived-backend-p backend 'html)
(let ((text (replace-regexp-in-string "\\(!\\)\\([^\n\r\t]+\\)\\(!\\)" "<mark>" text nil nil 1 nil)))
(replace-regexp-in-string "\\(<mark>\\)\\([^\n\r\t]+\\)\\(!\\)" "</mark>" text nil nil 2 nil))))
(add-to-list 'org-export-filter-plain-text-functions 'my-html-mark-tag)
```
I'm not sure why this is not working since the regexp part seems fairly straightforward: I replace occurrences of `!text!` with `<mark>` followed by `</mark>`. But this code only produces `<mark></mark>` instead of `<mark>text</mark>`.
How can I fix this?
# Answer
> 1 votes
Two things:
1. `[^\n\r\t]` matches `!`
2. You don't need two replacements.
```
(replace-regexp-in-string
"!\\([^!\n\r\t]+\\)!" "<mark>\\1</mark>"
"Hello !world!, how !are! you?")
```
=\> `"Hello <mark>world</mark>, how <mark>are</mark> you?"`
---
Tags: org-mode, org-export, regular-expressions
--- |
thread-68070 | https://emacs.stackexchange.com/questions/68070 | Why do I need to restart emacs to reload configuation in spacemacs? | 2021-08-11T18:37:00.347 | # Question
Title: Why do I need to restart emacs to reload configuation in spacemacs?
Anytime I modify the spacemacs dotfile, I need to restart emacs in order for my modification to take effect. I have tried `spc`+`f`+`e`+`R`, but this does not work. Am I misunderstanding what `spc`+`f`+`e`+`R` (Reload configuration) does, or if not, has anybody else encountered this problem?
Sorry, I am new to emacs/spacemacs.
Edit: `spc`+`f`+`e`+`R` in my configuration corresponds to "Reload configuration". When I say that it does not work, I mean that whatever I changed does not take effect until I restart emacs. As an example, I tested remapping my `9` key to `(`. When I reload the configuration (without restarting emacs), the keys are not remapped. However, when I restart emacs, the keys are now remapped.
# Answer
There are lots of ways to re-evaluate elisp without restarting Emacs.
https://www.masteringemacs.org/article/evaluating-elisp-emacs is a nice article to read on the subject.
`eval-last-sexp`, `eval-region`, `eval-defun`, and `eval-buffer` are go-tos, and you can always `load-file`.
What will that do? Who knows? Your config is a software program written in the Emacs Lisp programming language, so re-evaluating your config in part or in whole is executing a program that you can see and we can't, so we can't tell you what the outcome will be.
Most elisp files are (expected to be) written such that loading them twice is no different to loading them once, but whether or not that is true depends entirely on the author of the code.
> 3 votes
---
Tags: spacemacs
--- |
thread-53129 | https://emacs.stackexchange.com/questions/53129 | Getting operation not permitted when trying to open projects or use integrated terminal in emacs-doom | 2019-10-13T19:58:34.187 | # Question
Title: Getting operation not permitted when trying to open projects or use integrated terminal in emacs-doom
While using MacOS Catalina (which is suspect is the problem) I recently decided to try emacs, as a recommendation from a friend. I finally get it working and generally figure it out and now when trying to open a project or even trying to ls my Downloads or Documents folder I get an operation not permitted error. I have checked my user (whoami) which the user has permission to run the commands, and I have granted full disk access to all emacs applications I could find, yet to no avail.
UPDATE:
Got it working by running `csrutil disable` in recovery mode (yes I understand what the effects of this are), however I still have this error: Any idea how to resolve this? The only way I can add files to the current project is by using `:edit FILENAME` however I can edit the files just fine, and can run `find .` in any folder using the integrated terminal.
# Answer
Try running emacs from a terminal:
```
$ emacs -nw
```
If it works this way, it means the permissions restrictions is applied only to Emacs.app and can be solved giving permissions to `ruby`, as explained here.
It sounds weird, but it works like a charm. It is because the desktop app is launched using `ruby`.
> 3 votes
---
Tags: osx
--- |
thread-68090 | https://emacs.stackexchange.com/questions/68090 | nconc does not seem to update first parameter when its value is nil | 2021-08-12T17:16:39.250 | # Question
Title: nconc does not seem to update first parameter when its value is nil
I’m trying to add several values at once to a given list, which may be nil or already contain some other values.
After some research, I found the two following versions are working well:
```
(let ((x '(a)))
(setq x (append x '(b c)))
x)
⇒ (a b c)
(let ((x '(a)))
(nconc x '(b c))
x)
⇒ (a b c)
```
However, if the "main" list is nil at the beginning, `nconc` does not seem to work as expected:
```
(let (x)
(setq x (append x '(b c)))
x)
⇒ (b c)
(let (x)
(nconc x '(b c))
x)
⇒ nil
```
Is someone able to explain the last exemple? I would have expected it to return `(b c)`. Did I miss something?
Just in case, I also tested with an empty list, same result:
```
(let ((x '()))
(nconc x '(b c))
x)
⇒ nil
```
However, the following is working, but in that case I don’t see added value compared to `append`:
```
(let (x) ;; work with an empty list too
(setq x (nconc x '(b c)))
x)
⇒ (b c)
```
Thank you very much to any explanation on this.
# Answer
For some existing explanations on this, see:
> ```
> (let ((x '(a)))
> (nconc x '(b c))
> x)
>
> ```
**Don't do this.** `nconc` works by destructively modifying all but its last argument, but `x` in this case is a quoted list literal, which is not safe to modify; see `(info "(elisp) Mutability")`.
It is okay to use `nconc` if you know for sure that `x` is safe to modify, as in the following example:
```
(let ((x (list 'a)))
(nconc x '(b c))
x)
```
If you are not sure whether `x` is safe to modify, use `append` instead, or make a copy of `x` first, e.g. using `copy-sequence`.
> Is someone able to explain the last exemple? I would have expect it to return `(b c)`. Did I miss something?
Yes. What `nconc` does is link all of its arguments together, by modifying each argument (except the last) in-place to point to the next argument.
How would this work for a `nil` argument? The answer is it doesn't: appending an empty list to any other list is the same as not appending the empty list at all!
For example, `(nconc (list 1) () (list 2))` is equivalent to `(nconc (list 1) (list 2))`, which is `(1 2)` \- the empty list is skipped.
Besides, even if it did make sense to link `nil` like any other list, then Emacs would complain, because `nil` is a protected constant that can't be modified.
> However, the following is working
Yes, that is the correct way to use `nconc` if you don't know ahead of time whether `x` will be empty. If `x` is guaranteed to be non-`nil`, then using `nconc` without assigning the result back to same variable is fine. If, OTOH, `x` might be `nil`, then you must assign the result back to some variable, otherwise the result will be lost.
> but in that case I don’t see added value compared to `append`
`append` makes a copy of all but its last argument. It can also concatenate sequences of other types, like strings and vectors, in addition to lists.
By contrast, `nconc` is intended for a very specific purpose: linking mutable lists in-place and fast, without any extra memory allocations due to copying. It is effectively a generalisation of `setcdr` that operates on the last link of any number of cons cells.
If you're not sure which of the two to use, it's safer to go with `append`.
> 0 votes
---
Tags: list
--- |
thread-68092 | https://emacs.stackexchange.com/questions/68092 | With side-by-side windows how to slide the middle vertical bar? | 2021-08-12T17:51:09.237 | # Question
Title: With side-by-side windows how to slide the middle vertical bar?
I often have two buffers open side by side and I'd like to be able to slide the central vertical bar to the left or to the right, in order to make either buffer wider or narrower.
Is this supported in emacs 26.3?
Here's what I get:
The vertical bar in the middle won't move.
I looked at this other question, but `M-x xterm-mouse-mode` didn't help.
# Answer
> 1 votes
You can drag the vertical split with your mouse. And you can use `C-x }` and `C-x {` to enlarge or shrink a window horizontally. And you can use `C-x ^` to enlarge a window vertically.
---
Tags: window-splitting
--- |
thread-58883 | https://emacs.stackexchange.com/questions/58883 | Ispell + Hunspell recognizes everything after the apostrophe a different word | 2020-06-03T11:22:32.473 | # Question
Title: Ispell + Hunspell recognizes everything after the apostrophe a different word
I'm using `flyspell-mode` with `ispell` and `hunspell` \- as the dictionary backend, the problem is: if I type a word, for example `you've` or `you're` it recognizes `ve` and `re` as individual words. I want to fix that so it recognizes apostrophes as part of words.
# Answer
> 3 votes
This can stem from using Unicode apostrophes (U+2019, ) instead of ASCII single quotes (`'`), which certain Emacs major/minor modes might substitute automatically.
Have a look at http://www.pertinentdetail.org/IspellCharacterMapsError for one user's detailed solution to this problem using `hunspell`. The gist is that both Emacs and the dictionary back end need to be told what extra characters can count as parts of words. I use `aspell`, which already handles U+2019, so I just have to tell Emacs to accept the character by adding
```
(setq ispell-local-dictionary-alist
'((nil "[[:alpha:]]" "[^[:alpha:]]" "['’]" t nil nil utf-8))))
```
to my `.emacs` configuration file. Depending on which dictionary you use, the above arguments may need to be adjusted; see the documentation for `ispell-dictionary-alist` for their explanation.
---
Tags: flyspell, ispell, hunspell
--- |
thread-68079 | https://emacs.stackexchange.com/questions/68079 | Org-mode question: Evaluating lisp in property | 2021-08-12T07:16:26.507 | # Question
Title: Org-mode question: Evaluating lisp in property
Is there a way to evaluate (during an export) lisp code inside a property? If yes, what’s the syntax?
For instance, like in this dummy example:
```
* Header
:PROPERTIES:
:EXPORT_FILE_NAME: (print “filename.txt”)
:END:
```
I tried this but it doesn’t work.
# Answer
> 4 votes
Here is a way to do what you want. I took the liberty of expanding the export\_file\_name to resemble what I think you implied in the comments above. I don't think this is the best way to do what you want though. It isn't necessary to put the code in the properties, and it would be simpler to just put it in the list code that I put in the build section. If you do this a lot, e.g. for a blog post, I would wrap that into an interactive command you could use.
Anyway, the idea is to wrap this in a copy of the buffer, modify the buffer (here with org-map entries, but you could find other ways to do it) with that property, and then call the export in the copy. I use this code block by simply executing it, and a new buffer opens up to the file name "Header-for-something.txt".
```
* Header for something
:PROPERTIES:
:EXPORT_FILE_NAME: (concat (string-join (split-string (cl-fifth (org-heading-components))) "-") ".txt")
:END:
** build :noexport:
#+BEGIN_SRC emacs-lisp :results none
(org-export-with-buffer-copy
(org-map-entries
(lambda ()
(let ((efn (org-entry-get (point) "EXPORT_FILE_NAME")))
(when (stringp efn)
(org-entry-put (point) "EXPORT_FILE_NAME" (eval (read (string-trim efn))))))))
(org-open-file (org-ascii-export-to-ascii nil t)))
#+END_SRC
#+RESULTS:
```
---
Tags: org-mode, text-properties
--- |
thread-68096 | https://emacs.stackexchange.com/questions/68096 | How to control the resulting sizes when splitting a window? | 2021-08-12T23:11:45.243 | # Question
Title: How to control the resulting sizes when splitting a window?
I often split my windows into two with `C-x 2`. The window in the bottom tends to be the SLIME's REPL or Magit and the one at the top is usually the common lisp file being edited.
I like to have more space for the file to be edited. Thus, every time, I keep doing:
(i) - `C-x 2`; (ii) - Put the cursor on the window at the top (it is the default position); (iii) - `C-x ^` enlarges the window. In order to do it multiple times, I use `C-u 7` to repeat it 7 times. Thus, I press `C-u 7 C-x ^`
Is there a way to automate this? Maybe adding a hook to my config files so that every time I press `C-X 2` then `C-u 7 C-x ^` happens?
# Answer
This old answer in stackoverflow pointed out by @phils really helped me.
The following code in my init file did the trick:
```
(defun my-split-window-below (&optional arg)
"Split the current window 70/30 rather than 50/50.
A single-digit prefix argument gives the top window arg*10%."
(interactive "P")
(let ((proportion (* (or arg 7) 0.1)))
(split-window-below (round (* proportion (window-height))))))
(global-set-key (kbd "C-x 2") 'my-split-window-below)
```
> 1 votes
---
Tags: window-splitting
--- |
thread-68107 | https://emacs.stackexchange.com/questions/68107 | How to custom-set-faces with one of the named faces? | 2021-08-14T18:15:29.387 | # Question
Title: How to custom-set-faces with one of the named faces?
I can do this:
```
(custom-set-faces
'(j-verb-face ((t (:foreground "Red")))))
```
But what I want is to set the color to one that is theme-dependent.
I tried the following, which causes a "wrong argument type" error:
```
(custom-set-faces
'(j-verb-face ((t (font-lock-function-name-face)))))
```
How can I set the color of `j-verb-face` to be `font-lock-function-name-face`?
# Answer
> 0 votes
Found a simpler solution!
```
(setq j-verb-face font-lock-function-name-face)
```
---
Tags: font-lock, custom
--- |
thread-68110 | https://emacs.stackexchange.com/questions/68110 | How to get a character's face if one cannot move point to it? | 2021-08-14T22:50:15.467 | # Question
Title: How to get a character's face if one cannot move point to it?
When I want to find out a character's face, I usually move point to it, and run `M-x describe-face`.
This approach requires being able to move point to the character of interest, which is not always possible.
(For example, I don't know how to move point so that it sits on a character right on the mode-line; therefore, the anything on the mode-line is off-limits to the technique described above.)
Is there a more general way to determine conclusively a character's face, irrespective of where it is?
# Answer
There’s no universal method (though perhaps there ought to be, perhaps based on the mouse cursor rather than moving point), but you can definitely find out for the mode line. Just run `(format-mode-line mode-line-format t)` in the scratch buffer. The result will be a big string with text properties that tell Emacs which font(s) to use, which parts are buttons, any images that need to be displayed in it, etc.
This will get you the mode line for the scratch buffer, of course, so if you want the mode line for a specific buffer you need to specify it as the fourth argument. For example:
```
(format-mode-line mode-line-format
t
nil
(get-buffer "main.rs"))
```
Since header lines use the same format as the mode line, you can also call it with `header-line-format`, although for most buffers that will just be an empty string.
```
(format-mode-line header-line-format t)
```
> 2 votes
---
Tags: faces, point
--- |
thread-56064 | https://emacs.stackexchange.com/questions/56064 | Cannot enable org-roam mode - No EmacSQL SQLite binary avaiable | 2020-03-11T11:45:33.840 | # Question
Title: Cannot enable org-roam mode - No EmacSQL SQLite binary avaiable
I've installed org-roam (Windows 10, 26.3 x86\_64-w64-mingw32) but when I try to call org-roam... then Emacs show:
```
Loading d:/MEGAsync/Emacs/config/init.el (source)...done
Could not find C compiler, skipping SQLite build
Org-roam initialization: (error "No EmacSQL SQLite binary available, aborting")
Could not find C compiler, skipping SQLite build
emacsql-sqlite-ensure-binary: No EmacSQL SQLite binary available, aborting
```
Please help :-)
# Answer
The error originates from https://github.com/skeeto/emacsql/blob/master/emacsql-sqlite.el which checks whether there's a binary created from a previous compilation, then attempts to build it on your system. You haven't built one yet and don't have a toolchain set up, so it errors out early.
https://github.com/skeeto/emacsql/issues/55#issuecomment-515704368 gives a short introduction into the many possible ways of compiling C programs on Windows. I second the recommendation of setting up a mingw-w64 environment, be it with or without msys2.
> 0 votes
# Answer
I solved this issue by doing the following steps:
1. Install Chocolatey package manager
2. Install `emacs`, `sqlite`, `mingw` and `msys2` using `chocolatey`
```
choco install emacs sqlite msys2 mingw -y
```
3. Open your configuration file or your `init.el` file in your `.emacs.d` directory and copy paste the following code and save it. For more details, visit org-roam user manual
```
(use-package org-roam :ensure t)
```
4. Open `emacs` to force it to download the `org-roam` packages
5. Open `msys2` and execute the following commands (These steps may not be necessary, however it is recommended based on the MSYS2 Website):
```
pacman -Syu
pacman -Su
pacman -S --needed base-devel mingw-w64-x86_64-toolchain
```
6. Open `msys2` and execute the following command:
```
pacman -S gcc
```
7. While still inside `msys2`, navigate to your downloaded `emacs-sqlite` package located in your `.emacs.d`. In my case, it is located here: `C:\Users\User\AppData\Roaming\.emacs.d\elpa\emacsql-sqlite-20190727.1710\sqlite`. Therefore, the command was:
```
cd C:/Users/User/AppData/Roaming/.emacs.d/elpa/emacsql-sqlite-20190727.1710/sqlite
```
if you're using **Spacemacs**, then sqlite will be in a different folder like:
```
C:/Users/User/AppData/Roaming/.emacs.d/elpa/27.2/develop/emacsql-sqlite-20190727.1710
```
8. In your `emacsql-sqlite/sqlite` directory, you should have these four files:
* emacsql.c
* Makefile
* sqlite3.c
* sqlite3.h
9. While inside `emacsql-sqlite/sqlite` directory, execute the following command:
```
make emacsql-sqlite CC=gcc LDLIBS=
```
10. Now you should have an additional file called `emacsql-sqlite.exe`.
11. Lastly, just restart your `emacs` and you are good to go.
Hope this help anybody in the future.
> 6 votes
# Answer
I solved this issue, and a similar one (`org-roam cannot find executable sqlite3`) by downloading manually the binary of SQLite for Windows.
Download, unzip, and put the executable at a location known by Windows PATH (or set its location in the PATH variable, in the Environment Variables). Reload Emacs, and it works!
> 1 votes
---
Tags: org-mode, sqlite
--- |
thread-46484 | https://emacs.stackexchange.com/questions/46484 | Error on list-colors-display | 2018-12-08T16:27:40.770 | # Question
Title: Error on list-colors-display
When running this function:
```
M-x list-colors-display
```
I always get the following error:
```
Wrong number of arguments: #<subr max>, 0
```
If I try to use edebug in the function I get:
```
edebug-signal: Wrong number of arguments: #<subr max>, 0
```
The same happens starting emacs -q, I'm using: This is GNU Emacs 27.0.50 (build 1, x86\_64-apple-darwin16.7.0, NS appkit-1504.83 Version 10.12.6 (Build 16G1408)) of 2018-06-21
As pointed in the comments this was bug for the emacs that I installed with homebrew and --HEAD option. now with this version or \< 26.1 works well:
```
This is GNU Emacs 27.0.50 (build 1, x86_64-apple-darwin18.2.0, NS appkit-1671.10 Version 10.14.1 (Build 18B75))
of 2018-12-08
```
# Answer
> 7 votes
I think the error comes from list-colors-print, which seems to have a nil at the end, and that gives you the error you see. This doesn't seem to happen in earlier versions of emacs and is probably a bug.
# Answer
> 0 votes
I have a hacky fix for this for Emacs 26.3 at https://github.com/simon-katz/nomis-emacs-configuration/blob/933d6330ff642bca184671efd5df2dd2fa8a580e/emacs-installation/emacs-init-files/nomis-list-colors-print-hacks.el
It replaces the definition of `list-colors-print` to fix the bug.
EDIT:
I reported this bug at https://debbugs.gnu.org/cgi/bugreport.cgi?bug=50094
The fix for me (on my Mac) was:
rm $HOME/Library/Colors/Emacs.clr After that, things worked properly.
---
Tags: colors
--- |
thread-68127 | https://emacs.stackexchange.com/questions/68127 | locally stored package not found | 2021-08-16T09:42:58.113 | # Question
Title: locally stored package not found
I am trying to use the setup of `org-cite` and `org-ref-cite` described on jkitchin’s org-ref-cite repository (https://github.com/jkitchin/org-ref-cite) but I keep getting the error
> Cannot open load file: No such file or directory, org-cite.
My adjusted setup is:
```
(add-to-list 'load-path "/Users/XXX/github/org-mode/lisp/")
(use-package org-cite
:load-path "/Users/XXX/github/org-mode/lisp/"
:config
(require 'oc-csl)
)
```
The folder `org-mode` is the git-repo from https://code.orgmode.org/bzg/org-mode
Using Emacs 27.2 and `use-package` is also installed.
I cannot find any difference to the setup of the repo above. Any guidance would be appreciated.
# Answer
The problem has also been discussed elsewhere: https://github.com/jkitchin/org-ref-cite/issues/20
To make it short:
For `org-cite` the name for the package has been changed to `oc`.
Loading `org-cite` with
```
(use-package oc
:load-path "/Users/xxx/github/org-mode/lisp/"
:config
(require 'oc-csl))
```
works fine.
**But** if you load `org` before-hand, load it also with this specific path:
```
(use-package org
:load-path "/Users/xxx/github/org-mode/lisp/"
:ensure nil
.
.
.
```
> 0 votes
---
Tags: org-mode, load-path
--- |
thread-68129 | https://emacs.stackexchange.com/questions/68129 | Org mode how to apply 4 spaces for tab without initial indent inside source-code-block? | 2021-08-16T12:36:03.053 | # Question
Title: Org mode how to apply 4 spaces for tab without initial indent inside source-code-block?
On this example, cursor is at beginning of `if` when I press `tab` 2 space indent is added beginning of `if` block, which is aligned.
```
** TODO help | ** TODO help
#+begin_src python | #+begin_src python
if True | if True # 2 space added to beginning
print(True) | print(True) #
if True: | if True: #
print("World") | print("World") #
#+end_src | #+end_src
```
Would it be possible to apply `(setq org-adapt-indentation nil)` into `#+begin_src...#+end_src` region as well where pressing `TAB` will no do initial tab alignment.
Also would it be possible to set the indent as four spaces instead of two?
---
Wanted behaviour:
```
** TODO help
#+begin_src python
if True # Indent does not added
print(True) # Four spcace added at the beginning
if True:
print("World")
#+end_src
```
init.el:
```
(setq org-adapt-indentation nil)
(require 'org-tempo)
(defun my-tab-related-stuff ()
(setq tab-width 4))
```
Related:
# Answer
> 1 votes
Customize the variable `org-edit-src-content-indentation` and set it to 0. The doc string of the variable says:
```
org-edit-src-content-indentation is a variable defined in ‘org-src.el’.
Its value is 2
This variable is safe as a file local variable if its value
satisfies the predicate ‘wholenump’.
You can customize this variable.
Documentation:
Indentation for the content of a source code block.
This should be the number of spaces added to the indentation of the #+begin
line in order to compute the indentation of the block content after
editing it with ‘M-x org-edit-src-code’.
It has no effect if ‘org-src-preserve-indentation’ is non-nil.
```
As a corollary, you should also make sure that `org-src-preserve-indentation` is `nil`.
---
Tags: org-mode, indentation
--- |
thread-68123 | https://emacs.stackexchange.com/questions/68123 | async org-agenda | 2021-08-16T06:37:40.537 | # Question
Title: async org-agenda
I have a lot of org files in emacs 27.1 so when I do an agenda listing for the week it takes about 20seconds. Is there a nice way to do this in the background? I've put together the following function and it sort of works. The *Org Agenda* buffer that it shows in the finish lambda is blank, but the agenda.org file is correct but it's just an org file not the special Org Agenda buffer.
```
(defun async-org-agenda-list()
(interactive)
(async-start
;; start
(lambda ()
(setq org-agenda-files '("~/org/" "~/org/projects"))
(org-agenda-list)
(switch-to-buffer "*Org Agenda*")
(append-to-file (point-min) (point-max) "~/agenda.org")
)
;; finish
(lambda (msg)
(message "done")
)
)
)
```
Is there a way to do the Agenda in the background and display it in the Org Agenda buffer in the correct mode?
# Answer
SECOND EDIT
A solution that also fixes the links has been posted/implemented here.
Thanks Thierry!
EDIT
Okay, so you can fix it by adding the following two lines before just before the `(goto-char (point-max))` in the `async-when-done` function (see the comment to this answer also):
```
(goto-char (point-min))
(replace-string "#" "")
```
I will send a mail about it to the emacs-devel mailing list.
END EDIT
Nice idea!
The following answer works for simple org files. However, the `async` API seems to error on some more complex org files (bug?). Anyway, would be nice to hear back how it works on your files.
Okay, then here follows the code:
```
(defun map-text-properties (props)
(let ((plist (caddr props)))
(while plist
(put-text-property (1+ (nth 0 props))
(1+ (nth 1 props))
(car plist)
(cadr plist))
(setq plist (cddr plist)))
(when props
(map-text-properties (nthcdr 3 props)))))
(async-start
;; What to do in the child process
(lambda ()
(setq org-agenda-files '("~/spacemacs/diary.org"))
(org-agenda-list)
(buffer-string))
;; What to do when it finishes
(lambda (result)
(switch-to-buffer-other-window "*Org Agenda*")
(insert (car result))
(map-text-properties (cdr result))
(org-agenda-mode)))
```
The `map-text-properties` properties function is required because the *async API* returns the text object as a list. There is probably an easier way to convert the list back into a text object (but I did not look very much into that).
> 1 votes
---
Tags: org-mode, org-agenda, async
--- |
thread-20240 | https://emacs.stackexchange.com/questions/20240 | How to distinguish C-m from RETURN? | 2016-02-12T06:09:03.413 | # Question
Title: How to distinguish C-m from RETURN?
When in javascript mode trying to use `C-c C-m i` get an error saying "`C-c RET` is undefined?"
What makes Emacs believe I am pressing `RET`?
How can i properly make this keybinding work?
# Answer
Emacs "thinks" that `C-m` is `RET` because "Control M" is the ASCII control character "carriage return". Even though this reason is "historical" Emacs can run in a terminal and so it needs to support the way terminals *still* work now.
Try opening a terminal window, typing "`ls`", and pressing `C-m`. You will see that it is interpreted as "return", even though you are **not** in Emacs.
See Control character on Wikipedia for details about control characters.
To distinguish `C-m` from `RET` in a GUI Emacs, one could change `C-i` to `C-m` in **@nispio**'s answer:
```
(define-key input-decode-map [?\C-m] [C-m])
;; now we can do this:
(defun my-command ()
(interactive)
(message "C-m is not the same as RET any more!"))
(global-set-key (kbd "<C-m>") #'my-command)
```
See also
> 25 votes
# Answer
I have no idea why, but the accepted answer did not work for me. Maybe it is because of how I declare my key bindings.
I use `bind-keys` like this...
```
(bind-keys :map my-mode-map ...)
```
to bind keys, then I activate my-mode so that my key declarations always have precedence. Using my own mode is new, but I always used `bind-keys`.
In bind-keys I include the following:
```
([return] . newline) ;; needed to distinguish from C-m
```
Looking at key declaration help, I do not believe that assigning `[return]` to `newline` changes the function of the return key, but declaring `[return]` causes the `Return` key to become different than `Control-M`, allowing me to declare `[C-m]` later in the same bind-keys command and the two declaratoins are unique.
I use the same technique to separate `[tab]` from `[C-i]`, first binding `[tab]`, then binding `[C-i]` in the same `bind-keys` statement.
> 0 votes
---
Tags: key-bindings
--- |
thread-68134 | https://emacs.stackexchange.com/questions/68134 | org-protocol URLs with UTF-8 (URL-encoded) characters aren't properly captured | 2021-08-16T18:49:00.407 | # Question
Title: org-protocol URLs with UTF-8 (URL-encoded) characters aren't properly captured
When using org-protocol capture URLs on Windows, pages with non-ASCII titles or captured text results in a capture with incorrect values applied in the template. Despite such characters being properly URL-encoded in the capture URL, Emacs does not decode them back to valid Unicode characters. Despite this, the file to which the captures are sent is properly UTF-8 encoded, and doing a copy/paste of the text that gets mangled via the capture URL into the buffer works as expected.
A couple examples that I whipped up to demonstrate:
* Example 1
+ URL: https://www.branah.com/japanese
+ Capture URL: `org-protocol://capture?template=L&url=https%3A%2F%2Fwww.branah.com%2Fjapanese&title=Japanese%20Keyboard%20-%20%E6%97%A5%E6%9C%AC%E8%AA%9E%E3%81%AE%E3%82%AD%E3%83%BC%E3%83%9C%E3%83%BC%E3%83%89%20-%20Type%20Japanese%20Online&body=`
+ Title: *Japanese Keyboard - 日本語のキーボード - Type Japanese Online*
+ Captured as: *Japanese Keyboard - ????????? - Type Japanese Online*
* Example 2
+ URL: https://www.washingtonpost.com/history/2021/05/03/dominos-pizza-noid-returns/
+ Capture URL: `org-protocol://capture?template=L&url=https%3A%2F%2Fwww.washingtonpost.com%2Fhistory%2F2021%2F05%2F03%2Fdominos-pizza-noid-returns%2F&title=Domino%E2%80%99s%20Pizza%20Noid%3A%20Return%20of%20the%20mascot%20that%20drove%20a%20man%20to%20take%20hostages%20in%201989%20-%20The%20Washington%20Post&body=`
+ Title: *Domino’s Pizza Noid: Return of the mascot that drove a man to take hostages in 1989 - The Washington Post*
+ Captured as: *Domino**\222**s Pizza Noid: Return of the mascot that drove a man to take hostages in 1989 - The Washington Post*
I am running 27.2 on Windows 10, with Org 9.4 via ELPA.
**Update:** Calling emacsclientw or emacsclient directly with such org-protocol URLs seems to work just fine. Windows appears to be passing the decoded URL to emacsclientw.
# Answer
> 0 votes
Because Windows itself decodes the URL, emacsclient gets in its arguments something that it can't really make heads or tails of. The solution (at least for now) is a wrapper application that re-encodes the URL and passes that in to emacsclient.
I just created such a program, and it seems to work: org-protocol-w32-handler
---
Tags: microsoft-windows, emacsclient, org-capture, utf-8, org-protocol
--- |
thread-10707 | https://emacs.stackexchange.com/questions/10707 | in org-mode, how to remove a link? | 2015-04-15T19:41:53.523 | # Question
Title: in org-mode, how to remove a link?
How do I remove an existing hyperlink without having to wade in and manually delete a bunch of brackets? When I try to `org-insert-link` and just delete the existing link, I get `Lisp error: (error "Empty link")`.
I want to remove the link and preserve the text (i.e. the description).
# Answer
The following elisp function will take a link around the current point as recognised by `org-bracket-link-regexp`, so either `[[Link][Description]]` or `[[Link]]`, and replace it by `Description` in the first case or `Link` in the second case.
New version: for org 9.3 or newer (also added `save-excursion` as in the answer of @Chris)
```
(defun afs/org-replace-link-by-link-description ()
"Replace an org link by its description or if empty its address"
(interactive)
(if (org-in-regexp org-link-bracket-re 1)
(save-excursion
(let ((remove (list (match-beginning 0) (match-end 0)))
(description
(if (match-end 2)
(org-match-string-no-properties 2)
(org-match-string-no-properties 1))))
(apply 'delete-region remove)
(insert description)))))
```
Alternatively the following elisp function will do such a replacement on all links in the buffer or region:
```
(defun afs/org-replace-all-links-by-description (&optional start end)
"Find all org links and replace by their descriptions."
(interactive
(if (use-region-p) (list (region-beginning) (region-end))
(list (point-min) (point-max))))
(save-excursion
(save-restriction
(narrow-to-region start end)
(goto-char (point-min))
(while (re-search-forward org-link-bracket-re nil t)
(replace-match (match-string-no-properties
(if (match-end 2) 2 1)))))))
```
The above is for org 9.4, where `org-match-string-no-properities` has been obseleted in favour of `match-string-no-properties`.
Old version: before org 9.3
```
(defun afs/org-replace-link-by-link-description ()
"Replace an org link by its description or if empty its address"
(interactive)
(if (org-in-regexp org-bracket-link-regexp 1)
(let ((remove (list (match-beginning 0) (match-end 0)))
(description (if (match-end 3)
(org-match-string-no-properties 3)
(org-match-string-no-properties 1))))
(apply 'delete-region remove)
(insert description))))
```
In org version 9.3 `org-bracket-link-regexp` was obsoleted, but aliased to the new `org-link-bracket-re`. The new regexp is documented in `ol.el` as
```
org-link-bracket-re
(rx (seq "[["
;; URI part: match group 1.
(group
(one-or-more
(or (not (any "[]\\"))
(and "\\" (zero-or-more "\\\\") (any "[]"))
(and (one-or-more "\\") (not (any "[]"))))))
"]"
;; Description (optional): match group 2.
(opt "[" (group (+? anything)) "]")
"]"))
```
so the second group now matches the description of the link if present.
> 14 votes
# Answer
I tried to add this to the answer from @Andrew, but it was too long for a comment...
I really liked his solution, except that it moved the cursor. (Technically I guess it moved the point. Anyway...) Fortunately, it was easy to add `save-excursion` to avoid that:
```
(defun afs/org-replace-link-by-link-description ()
"Replace an org link by its description or if empty its address"
(interactive)
(if (org-in-regexp org-bracket-link-regexp 1)
(save-excursion
(let ((remove (list (match-beginning 0) (match-end 0)))
(description (if (match-end 3)
(org-match-string-no-properties 3)
(org-match-string-no-properties 1))))
(apply 'delete-region remove)
(insert description)))))
```
> 7 votes
# Answer
There is a solution which avoids using custom parsing with regexes and directly uses the built-in `org-element` API:
```
(defun org-link-delete-link ()
"Remove the link part of an org-mode link at point and keep
only the description"
(interactive)
(let ((elem (org-element-context)))
(if (eq (car elem) 'link)
(let* ((content-begin (org-element-property :contents-begin elem))
(content-end (org-element-property :contents-end elem))
(link-begin (org-element-property :begin elem))
(link-end (org-element-property :end elem)))
(if (and content-begin content-end)
(let ((content (buffer-substring-no-properties content-begin content-end)))
(delete-region link-begin link-end)
(insert content)))))))
```
> 7 votes
# Answer
The quickest may be to place the cursor before the link, then type `C-M-space` (`mark-sexp`), which will mark the entire link. Then delete it by typing a backspace (if you use `delete-selection-mode`) or `C-w`.
> 4 votes
# Answer
Call this command when the point is anywhere after the first `[[` brackets of an org-link (or anywhere on/after an hyper-linked org-link).
An org link will be deleted if it is of the format `[[LINK][DESCRIPTION]]` or `[[LINK]]` in an `org-mode` buffer; else nothing will happen.
For safety, the discarded LINK from org-link is saved to the `kill-ring` in the event a need arises to use that link elsewhere.
```
(defun my/org-delete-link ()
"Replace an org link of the format [[LINK][DESCRIPTION]] with DESCRIPTION.
If the link is of the format [[LINK]], delete the whole org link.
In both the cases, save the LINK to the kill-ring.
Execute this command while the point is on or after the hyper-linked org link."
(interactive)
(when (derived-mode-p 'org-mode)
(let ((search-invisible t) start end)
(save-excursion
(when (re-search-backward "\\[\\[" nil :noerror)
(when (re-search-forward "\\[\\[\\(.*?\\)\\(\\]\\[.*?\\)*\\]\\]" nil :noerror)
(setq start (match-beginning 0))
(setq end (match-end 0))
(kill-new (match-string-no-properties 1)) ; Save the link to kill-ring
(replace-regexp "\\[\\[.*?\\(\\]\\[\\(.*?\\)\\)*\\]\\]" "\\2" nil start end)))))))
```
> 4 votes
# Answer
To remove all links in the selection:
```
(defun night/org-remove-link-to-desc-at-point ()
"Replace an org link by its description or if empty its address"
(interactive)
(if (org-in-regexp org-link-bracket-re 1)
(save-excursion
(let ((remove (list (match-beginning 0) (match-end 0)))
(description
(if (match-end 2)
(org-match-string-no-properties 2)
(org-match-string-no-properties 1))))
(apply 'delete-region remove)
(insert description)))))
(defun night/org-remove-link-to-desc (beg end)
(interactive "r")
(save-mark-and-excursion
(goto-char beg)
(while (re-search-forward org-link-bracket-re end t)
(goto-char (match-beginning 0))
(night/org-remove-link-to-desc-at-point))))
```
> 2 votes
# Answer
This very quick and very dirty macro would be one way, not the best way:
```
(fset 'my/org-remove-link
[?\M-a delete delete ?\M-x ?z ?a ?p ?- ?t ?o ?- ?c ?h ?a ?r return ?\[ ?\C-e backspace backspace ?\C-x])
```
> 1 votes
---
Tags: org-mode
--- |
thread-22078 | https://emacs.stackexchange.com/questions/22078 | How to split a long org file into separate org files? | 2016-05-05T17:18:19.300 | # Question
Title: How to split a long org file into separate org files?
I've an huge org file `HUGE.org` with this structure:
```
* ID-HEAD-1 Title1 :TAG:
bla bla bla
* ID-HEAD-2 Title2 :TAG:
bla bla bla
...
* ID-HEAD-N TitleN :TAG:
bla bla bla
```
and I want to split `HUGE.org` into:
```
ID-HEAD-1.org
ID-HEAD-2.org
...
ID-HEAD-N.org
```
where the content of each `ID-HEAD-i.org` is:
```
* ID-HEAD-i Titlei :TAG:
bla bla bla
```
Suggestions?
# Answer
I use a function of my own. It moves a subtree to a new org file, and replaces it with a link to this new file. Specify the name of the file through the parameter or interactively at the prompt.
```
(defun org-move-tree (filename)
"move the sub-tree which contains the point to a file,
and replace it with a link to the newly created file"
(interactive "F")
(org-mark-subtree)
(let
((name (buffer-substring (region-beginning)
(save-excursion (end-of-line) (point))))
(xxx (buffer-substring (region-beginning) (region-end))))
(setq name (replace-regexp-in-string "^[*]+ *" "" name))
(delete-region (region-beginning) (region-end))
(insert (format "[[file:%s][%s]]\n" filename name))
(find-file-other-window filename)
(insert xxx)
(save-buffer)))
(provide 'org-move-tree)
```
> 7 votes
# Answer
I tried to use the previous answer as is but I had to tweak it a bit to make it work as I would expect. I think this version might be slightly safer too because it should handle tags correctly.
```
(defun y/org-move-tree (buffer-file-name)
"move the sub-tree which contains the point to a file,
and replace it with a link to the newly created file"
(interactive "F")
(org-mark-subtree)
(let*
((title (car (last (org-get-outline-path t))))
(dir (file-name-directory buffer-file-name))
(filename (concat dir title ".org"))
(content (buffer-substring (region-beginning) (region-end))))
(delete-region (region-beginning) (region-end))
(insert (format "** [[file:%s][%s]]\n" filename title))
(with-temp-buffer
(insert content)
(write-file filename))))
```
> 1 votes
---
Tags: org-mode, files
--- |
thread-68152 | https://emacs.stackexchange.com/questions/68152 | jumping to a directory in speedbar | 2021-08-17T20:46:52.853 | # Question
Title: jumping to a directory in speedbar
Is there a way to jump to a given directory in speedbar?
For example, when I open up emacs and speedbar, it begins in `~/`. Which is fine most of the time, but sometimes I'll want to jump to a remote system using tramp such as `/sshx:raspberrypi:/home/raspberry`. I'd like to make it easy to jump there.
One possible solution is to use a variation of the solution that Ren Wenshan proposed and add a hook to the start of speedbar-mode, but that only solves if I want to go to the same directory every time I start speedbar:
```
(add-hook 'speedbar-mode-hook
(lambda ()
(cd "/sshx:raspberrypi:/home/raspberry")))
```
Ideally there'd be a function I can call to just change the visible directory in speedbar.
# Answer
The following function will update an open speedbar file/folder buffer with DIRECTORY being the top level. \[At some point, it may be a good idea to add support to programmatically check to verify the speedbar buffer is in files mode ... at this time, there is no such check.\]
```
(defun speedbar-jump-to-directory (&optional directory)
"Update the speedbar directory."
(interactive)
(let ((default-directory (if directory
(file-name-as-directory directory)
(file-name-as-directory
(read-directory-name "DIRECTORY: ")))))
(speedbar-update-contents)))
```
> 2 votes
---
Tags: tramp, speedbar
--- |
thread-68102 | https://emacs.stackexchange.com/questions/68102 | Ruby+imenu not showing private methods | 2021-08-13T13:12:23.843 | # Question
Title: Ruby+imenu not showing private methods
I'm a little surprised that I haven't found anything on the web about this, but I've got a Ruby file and its private methods aren't listed by imenu.
Given the following class:
```
class Blub
def hi
"Hi!"
end
def bye
"Bye!"
end
private
def hiding
"You can't see me"
end
end
```
you can reproduce this by running `M-x` `imenu`, which doesn't show `hiding`, while `hi` and `bye` are there.
This is the case whether I start emacs normally or with `--no-init`.
Any ideas?
In larger buffers where I want to navigate within it, this would be a valuable fix.
Here's the version info my emacs. I'm on arch linux.
```
$ emacs --version
GNU Emacs 27.2
Copyright (C) 2021 Free Software Foundation, Inc.
GNU Emacs comes with ABSOLUTELY NO WARRANTY.
You may redistribute copies of GNU Emacs
under the terms of the GNU General Public License.
For more information about these matters, see the file named COPYING.
```
## Update
I've gotten a bit further. The original version of my sample class was incorrect, which is why @Dmitry and @Étienne weren't able to reproduce the problem.
When we use inline access modifiers, as in the example below, the problem should be reproducible when emacs is started with either the -q or -Q option.
```
class Blub
def hi
"Hi!"
end
def bye
"Bye!"
end
private def hiding
"You can't see me"
end
end
```
I'm still not sure how to fix this though. A quick look into the imenu source makes me think it has to do with the `imenu-create-index-function`, which I'd guess has to be defined for each language, but that's as far as I've gotten at this point.
# Answer
> 0 votes
This is now fixed in `ruby-mode` on master, for the upcoming Emacs 28.
If you are staying on a release version, you can apply this patch locally: https://git.savannah.gnu.org/cgit/emacs.git/commit/?id=9e2cc406d3bc1a1f2f6008059091b9c1b8f12acf
---
Tags: imenu, ruby
--- |
thread-68130 | https://emacs.stackexchange.com/questions/68130 | How to navigate to last headline in a tree? | 2021-08-16T13:24:58.823 | # Question
Title: How to navigate to last headline in a tree?
In large org trees, it would be useful to jump
* from a heading to the last (direct) subheading
* to the last or first heading on the same level
Are there functions in org-mode that accomplish this?
# Answer
> 0 votes
You don't need special functions for this:
* from a heading to the last direct subheading, `C-c C-n` will get you to the first direct subheading, and then `C-u 10000 C-c C-f` will get you to the last one (I assume there are fewer than 10000 headings at this level - feel free to add one or more 0's if that's not enough).
* `C-u 10000 C-c C-b` similarly will take you to the first heading at this level and as described above `C-u 10000 C-c c-f` will take you to the last one (both with the same caveat).
If you need to do this often, create `keyboard macros` to do each, save them and bind them to keys. Do `C-h i g(emacs)Keyboard macros` for more info.
BTW, you can do `C-h c C-c C-b` to find out what command is bound to `C-c C-b` and similarly for the others. Check the `Motion` section of the manual with `C-h i g(org)Motion`.
# Answer
> 0 votes
In addition to using keyboard macros, you can also write your own command. Here's one that moves the cursor to the last heading of the subtree, or to the first sibling when called with a prefix argument.
```
(defun org-tree-goto-last (arg)
(interactive "P")
(if arg (while (org-goto-sibling 'previous))
(org-up-heading-safe)
(org-end-of-subtree)
(re-search-backward org-complex-heading-regexp nil t)))
```
---
Tags: org-mode
--- |
thread-68156 | https://emacs.stackexchange.com/questions/68156 | How to start a background process from Org? | 2021-08-18T02:23:13.427 | # Question
Title: How to start a background process from Org?
The following code waits until process is finished, which is unexpected
```
#+begin_src shell
perl -wE 'sleep(3)' & disown
#+end_src
```
The work-around for that is to close `STDIN` and `STDOUT` explicitly
```
#+begin_src shell
perl -wE 'STDIN->close(); STDOUT->close(); sleep(3)' & disown
#+end_src
```
But what should I do if it's impossible to change the code inside src block? I.e
```
#+begin_src shell
./readonly-deamon-script start # has & and disown inside
#+end_src
```
# Answer
You can close the file descriptors for `stdin`, `stdout` and `stderr` using a `:prologue` header arg. Of course, if the script opens other file descriptors, you will have to close those too, but in the simplest case, the three standard ones will be enough:
```
#+begin_src shell :prologue exec 0>&- 1>&- 2>&-
sleep 10 & disown
#+end_src
```
> 4 votes
---
Tags: org-mode, org-babel
--- |
thread-10611 | https://emacs.stackexchange.com/questions/10611 | How to easily cherry pick with magit? | 2015-04-10T13:48:39.883 | # Question
Title: How to easily cherry pick with magit?
I've been using magit for a few months now and I like it a lot. But one thing I still do it in a terminal is cherry picking.
What is a simple way to do this?
# Answer
Everywhere you see a commit in a Magit buffer, you can cherry-pick it by moving point there and then typing `A A`. You can also cherry-pick multiple commits at once: just select some commits using the region and then press `A A`.
> 51 votes
# Answer
## Magit version \>= 2.1.0
For both methods, first start up `magit-status`.
**Method A**: *Cherry Pick changes from another branch one by one, or by ranges*
1. Press `l` and then `o` to get a list of other branches.
2. Select the branch you want to cherry pick from.
3. Move to the commit you need and press `A` followed by `A` again. You can also select the lines with the commit range you want with `C-space` and press `A` followed by `A` again.
4. The status line will show you which commit you selected
e.g. `feature/ABC~4`
Press `Enter` to apply changes.
**Method B**: *Cherry Pick all changes from another branch*
1. Press `A` to choose the cherry pick mode.
2. Press `A` again to apply and commit changes. Press `a` to only apply changes.
3. Choose a branch to cherry pick changes from and press `Enter`.
I personally prefer method A as you can handle merge conflicts better.
## Magit version \<= 1.4.2
The workflow was different in earlier versions:
1. Enter overview `magit-status`
2. Check out (press `b b`) the branch you want to cherry pick into.
3. Do a log range (press `l r l`) to find the commits that you want to cherry pick. Here you select the 2 branches you want to compare.
4. Scroll to the commit you want to pick and press `A` to apply the changes and also stage them togeteher with the commit message. If you press `a` it will not stage the changes but only apply them.
You don't need to do a log range to cherry pick. Whenever you see a commit log you can press `A` to cherry pick it.
> 84 votes
# Answer
I don't use cherry picking, but hitting `?` in `magit-status` shows `y: Cherry`. This runs the command `magit-cherry`, which lets you pick a head and an upstream. It sounds like this is what you want.
You can type `C-h r d m Magit RET` to read the Magit manual. You can use `C-s cherry` and repeated hit `C-s` to search through the manual. Looks like the info is in section 23:
> One of the comforts of `git` is that it can tell you which commits have been merged upstream but not locally and vice versa. Git's sub-command for this is `cherry` (not to be confused with `cherry-pick`). Magit has support for this by invoking `magit-cherry` which is bound to `y` by default.
>
> Magit will then ask you first for the upstream revision (which defaults to the currently tracked remote branch if any) and the head revision (which defaults to the current branch) to use in the comparison. You will then see a new buffer in which all commits are listed with a directional marker, their revision and the commit message's first line. The directional marker is either `+` indicating a commit that's present in upstream but not in head or `-` which indicates a commit present in head but not in upstream.
>
> **From this list you can use the usual key bindings for cherry-picking individual commits (`a` for cherry-picking without committing and `A` for the same plus the automatic commit).** The buffer is refreshed automatically after each cherry-pick.
> 9 votes
# Answer
Using `Cherry` to better narrow down candidate commits:
Usually you want to pick some commits which are on `feature-a` but not on `released`, you can:
* create/checkout the branch you want to save the cherries to (name like `feature-a-subset`)
* `Cherry` in magit status buffer
* select `feature-a` as cherry head, `released` as upstream, to get some log of commits `feature-a` differ from `released`
* `Apply`-\>`Pick` (`A`-\>`A`) on some single commits or a region (*see more detail in tarsius and other's answers*)
> 0 votes
---
Tags: magit
--- |
thread-68140 | https://emacs.stackexchange.com/questions/68140 | Unrestricted movement of lines Alt-Up/Down | 2021-08-17T05:34:35.550 | # Question
Title: Unrestricted movement of lines Alt-Up/Down
I'm learning Orgmode and moving lines (headers, checkbox items) up and down. These movement are restrited to a tree part of the line (header section, checkbox list):
```
* Here is a list
- Item 1
- Item 2
- Item 3 - Alt-down stops here
* Another list
- Here is where I want to move the line Item 3
```
Is there a simple way to move line without restriction in orgmode?
The closest I learned is C-k on a line -\> move cursor -\> C-y on other line.
Ideally is htere some modifier like Alt-Shift-Arrow?
# Answer
> 1 votes
Name and documentation of this function says it all:
```
Signature
(org-shiftmetaup &optional ARG)
Documentation
Drag the line at point up.
In a table, kill the current row.
On a clock timestamp, update the value of the timestamp like S-<up>
but also adjust the previous clocked item in the clock history.
Everywhere else, drag the line at point up.
```
The name says that this function is bound to `S-M-<up>`.
You can look up the documentation of any function with `M-x describe-function` which is bound to `C-h f`.
---
Tags: org-mode, text-editing, lines
--- |
thread-68139 | https://emacs.stackexchange.com/questions/68139 | Editing Thunderbird 78+ messages in Emacs | 2021-08-17T03:19:39.857 | # Question
Title: Editing Thunderbird 78+ messages in Emacs
It used to be possible to use an **external editor**, such as Emacs, to edit **Thunderbird** mail messages, but now I haven't found a way to do it. The solution to this question posted 7 years ago doesn't work on the more modern versions of Thunderbird (I'm running v. 78.13.0). I also tried using the code offered here, but unsuccessfully.
Does anyone knows if there's another solution for editing Thunderbird messages in Emacs or if someone's working on updating previous hacks?
# Answer
> 1 votes
You can use Emacs Everywhere which allows you to enter text into any text field.
---
Tags: email
--- |
thread-68167 | https://emacs.stackexchange.com/questions/68167 | yaml: How to set indentation width? | 2021-08-18T13:10:30.963 | # Question
Title: yaml: How to set indentation width?
I'm new to editing yaml with emacs. I currently use `yaml-mode` 20210808.1122 installed like so :
```
(use-package yaml-mode)
(add-to-list 'auto-mode-alist '("\\.yml\\'" . yaml-mode))
```
I would like to configure how many spaces `TAB` indents because I work in a codebase that uses 4 spaces, and package default seems to be 2 spaces.
How can I do it? If not possible, are there other yaml editing options available?
# Answer
> 4 votes
Customize `yaml-indent-offset`. Its doc says:
```
yaml-indent-offset is a variable defined in ‘yaml-mode.el’.
Its value is 2
This variable is safe as a file local variable if its value
satisfies the predicate ‘natnump’.
You can customize this variable.
Documentation:
*Amount of offset per level of indentation.
```
BTW, I didn't know about this variable before I saw your question, but I found it using some simple methods which you may find useful in the future when you are in a similar situation. The methods involve the awesome help system that emacs provides. If you don't know about it already, then type `C-h ?` and start exploring. Any effort you make to learn how to use the help system will repay you with a huge dividend in the future.
The first component is that emacs packages use a prefix to distinguish the names that the package uses (variables and functions mainly) from those of other packages. For `yaml-mode` as you would expect, the prefix is `yaml-`. The help system allows you to start looking for something, using the prefix, and then ask for `completions`: all the things that emacs knows about that start with that prefix. There are two main roads: if it is a variable (which clearly would be the case here), then the help invocation you want is `C-h v yaml-TAB`. The other road is for functions: `C-h f yaml-TAB`.
`C-h v yaml-TAB` gave me a completion buffer with two dozen entries: giving them the once over, I saw the above variable and clicked on it.
This is a particularly simple case, but I use this method (and its sibling for functions: `C-h f <some prefix>TAB`) all the time. You can also get at the manuals for emacs itself, and many of its larger packages, using the Info system which you can get to with `C-h i`.
Happy exploring!
---
Tags: indentation
--- |
thread-68149 | https://emacs.stackexchange.com/questions/68149 | rainbow-delimiters does not properly highlight unmatched parenthesis | 2021-08-17T16:19:26.117 | # Question
Title: rainbow-delimiters does not properly highlight unmatched parenthesis
Would it be possible to highlight unmatched parenthesis if they are at the beginning of a function like `func((((()`?
Related: How can I find missing or mismatched braces / parens in emacs?
**minimal.el** //example is taken from the link above
```
(require 'package)
(setq user-init-file (or load-file-name (buffer-file-name)))
(setq user-emacs-directory (file-name-directory user-init-file))
(add-to-list 'package-archives
'("melpa" . "https://melpa.org/packages/") t)
(package-initialize)
(setq frame-background-mode 'dark)
(require 'rainbow-delimiters)
(add-hook 'prog-mode-hook 'rainbow-delimiters-mode)
(set-face-attribute 'rainbow-delimiters-unmatched-face nil
:foreground "red"
:background "yellow"
:inherit 'error
:box t)
```
It find unmatcing parenthesis for `print("Hello"))` when parenthesis at the end. Find error:
But it does not do anything for if unmatched parenthesis are at the beginning: `print(((((((((((((((((("Hello")`
# Answer
Issue:
> Not easily, no. In the worst case it would require going through the entire buffer to determine that an opening parenthesis has no matching closing one, which is slow and doesn't play well with how font-lock works.
---
My goal was to detect any mismatching parenthesis in `python-mode`. The only smart way I come up was to do `check-parens` after each save. It jumps the mismatched parenthesis in the buffer.
I have following function:
```
(defun save-all ()
(interactive)
(let ((message-log-max nil)
(inhibit-message t))
(save-some-buffers t)
(check-parens)))
(global-set-key (kbd "C-x C-s") 'save-all)
;; could be set for a specific mode
(define-key python-mode-map (kbd "C-x C-s") 'save-all-check-paren)
```
> 1 votes
---
Tags: balanced-parentheses, parentheses
--- |
thread-68172 | https://emacs.stackexchange.com/questions/68172 | How to match the car of alist elements with a regexp? | 2021-08-18T17:06:17.470 | # Question
Title: How to match the car of alist elements with a regexp?
I've spent a good amount of hours trying to solve this one but without success. I have an alist with strings
```
(setq trees '(("pine" . "cones") ("oak" . "acorns") ("maple" . "seeds")))
```
and I want to obtain the `assoc` of it using a regexp as key. That is
```
(assoc ".ine" trees)
```
always returns `nil` instead of `("pine" . "cones")`. I've tried to use the assoc-default function instead, using string-match but it also did not work. I know that this is pretty basic, but I cannot really understand what I am doing wrong. Thank you in advance.
# Answer
Pass a `TESTFN` arg to `assoc`. It needs to use `string-match-p` with the args reversed. That is, `assoc` passes `TESTFN` the pattern arg second, but `string-match-p` expects the pattern as its first arg.
```
(assoc ".*ine" trees (lambda (x regexp) (string-match-p regexp x)))
```
---
I filed doc bug report #50110 for this, asking that the arg order for optional arg `TESTFN` be specified. And that bug has now been fixed!
> 4 votes
---
Tags: regular-expressions, association-lists, alists
--- |
thread-64158 | https://emacs.stackexchange.com/questions/64158 | Evaluate JavaScript source block in org-mode | 2021-03-27T17:41:21.580 | # Question
Title: Evaluate JavaScript source block in org-mode
If I attempt to evaluate a JavaScript source block then I have to `return` a value to get a result. For example:
```
#+begin_src js
return 1 + 2;
#+end_src
#+RESULTS:
: 3
```
That's a bit unusual. I guess that the code block is treated as the body of a function. Should I have to use `return` to get the result of this expression?
# Answer
For future passengers, `:results value` (the default option) requires an explicit `return` statement to display its value. On the other hand, `:results output` displays everything from the standard output.
#### Examples
In both cases, `1+2` is not enough.
```
#+begin_src js :results value
return 1 + 2;
#+end_src
#+RESULTS:
: 3
```
```
#+begin_src js :results output
console.log(1 + 2);
#+end_src
#+RESULTS:
: 3
```
#### Documentation
> ‘value’
>
> **Default** for most Babel libraries. **Functional mode**. Org gets the value by wrapping the code in a function definition in the language of the source block. That is why when using ‘:results value’, code should execute like a function and return a value. For languages like Python, **an explicit return statement is mandatory** when using ‘:results value’. **Result is the value returned** by the last statement in the code block.
>
> ...
> ‘output’
>
> **Scripting mode**. Org passes the code to an external process running the interpreter. Org **returns the contents of the standard output stream as text results**.
>
> ...
> 4 votes
---
Tags: org-babel, javascript
--- |
thread-68147 | https://emacs.stackexchange.com/questions/68147 | How can Elisp code determine the previously selected window? | 2021-08-17T14:19:48.163 | # Question
Title: How can Elisp code determine the previously selected window?
I would like to implement an interactive function that, in the "canonical" case, selects the window that was selected before the currently selected one<sup>1</sup>.
But my plan founders immediately on this question: how can my future function find out, to begin with, what the previously selected window is???
---
<sup><sup>1</sup> There are a few edge cases, e.g. when no other window was previously selected, that I won't get into.</sup>
# Answer
Since Emacs 27.1, the previously selected window is recorded and can be obtained with `old-selected-window`. The previously selected window in each frame can be obtained with `frame-old-selected-window`. If you want older information, you can record it with a hook in `window-selection-change-functions`.
In older versions of Emacs, I don't think Emacs remembers any historical information about window selections by default, and there's no hook for window selection. You would have to advise at least `select-window`, and quite possibly other built-in functions that change the window selection.
> 4 votes
---
Tags: window, selected-window
--- |
thread-2096 | https://emacs.stackexchange.com/questions/2096 | Different themes for terminal and graphical frames when using Emacs daemon | 2014-10-12T11:27:51.247 | # Question
Title: Different themes for terminal and graphical frames when using Emacs daemon
I'm trying to achieve the following behavior in Emacs24:
I like to use a different theme (solarized-dark vs. solarized-light) depending on whether I connect to the running server with a terminal frame
```
% emacsclient -t
```
or with a gtk frame
```
% emacsclient -c
```
This seems to have worked in older Emacs, but the current Emacs I couldn't find a way. I alreday checked SO (e.g., https://stackoverflow.com/q/18904529/152439 and answers) and the mailing lists (e.g., https://lists.gnu.org/archive/html/help-gnu-emacs/2012-02/msg00227.html and https://lists.gnu.org/archive/html/help-gnu-emacs/2012-02/msg00237.html).
My current setup looks like this:
```
(add-to-list 'custom-theme-load-path "~/.emacs.d/themes/solarized")
(if (daemonp)
(add-hook 'after-make-frame-functions
(lambda (frame)
(select-frame frame)
(if (display-graphic-p frame)
(load-theme 'solarized-light t)
(load-theme 'solarized-dark t)
)
)
)
(load-theme 'solarized-light t)
)
```
The problem with this is that if I have a graphical frame open and then open a terminal frame with `emacsclient -t`, the theme solarized-dark gets applied to both the new terminal frame (which is correct) and the already open graphical frame (which should be left untouched, ideally). The equivalent happens when a terminal frame is already open and I open a new graphical frame with `emacsclient -c`.
**EDIT:** In case this is not possible with current Emacs24, are there any plans to make it possible again?
# Answer
You cannot do this using different themes. The solution is to create a theme that has different face definitions depending on the terminal. If you look at an example like `font-lock-comment-face`, you'll see how it works. Instead of specifying `((class color) (min-colors 88) (background dark))` you could also specifcy `(type tty)` or `(type graphic)` etc. The manual has more info.
```
(defface font-lock-comment-face
'((((class grayscale) (background light))
:foreground "DimGray" :weight bold :slant italic)
(((class grayscale) (background dark))
:foreground "LightGray" :weight bold :slant italic)
(((class color) (min-colors 88) (background light))
:foreground "Firebrick")
(((class color) (min-colors 88) (background dark))
:foreground "chocolate1")
(((class color) (min-colors 16) (background light))
:foreground "red")
(((class color) (min-colors 16) (background dark))
:foreground "red1")
(((class color) (min-colors 8) (background light))
:foreground "red")
(((class color) (min-colors 8) (background dark))
:foreground "yellow")
(t :weight bold :slant italic))
"Font Lock mode face used to highlight comments."
:group 'font-lock-faces)
```
I guess you could write a function that takes two themes and produces a merged theme, with faces from one theme being assigned `(type tty)` and faces from the other theme being assigned `(type graphic)` where both of the original themes use `t`.
> 9 votes
# Answer
color-theme-buffer-local provides buffer-local theme support for both color-theme and the Emacs 24 theme systems. My version of the solarized theme also supports *both* systems, if you decide to go this route.
> 7 votes
# Answer
You can define conditions for face customizations, like "terminal mode" or "minimal colors" in the customization editor:
When customizing a face, click the \[State\] button and select "Show all display specs". Then you can set up the conditions for further specialization of the face.
Here's a minimal variant to set the background color to **black** when the frame is a tty:
```
(custom-set-faces
'(default (
(((type tty) (min-colors 256))
(:background "black"))
(t
(:background "#181a26")))
))
```
> 3 votes
# Answer
Here is a (somewhat hacky) function that creates a copy of a given theme that applies only to TTY terminals (as suggested in Alex' answer). This theme can then be enabled on top of your default theme but will only affect TTY frames.
```
(defun rgmacs/copy-theme-tty (from-theme to-theme)
"Copies all faces from from-theme to to-theme but restricts to TTY frames only."
(dolist (entry (get from-theme 'theme-settings))
(when (eq (car entry) 'theme-face)
(let ((face (nth 1 entry))
(face-specs (nth 3 entry))
(new-specs))
(dolist (face-spec face-specs)
(let ((display (car face-spec))
(rest (cdr face-spec)))
(cond
((listp display)
(progn
(setq display (cl-copy-seq display))
(add-to-list 'display '(type tty))))
((eq display t)
(setq display '((type tty)))))
(add-to-list 'new-specs (append `(,display) rest))))
(custom-theme-set-faces to-theme `(,face ,new-specs))))))
```
I use it as follows:
```
(load-theme 'leuven) ;; load and enable default theme
(load-theme 'spacemacs-dark t t) ;; load but do not enable desired theme for TTY frames
;; create a copy of the latter theme, but restrict it to TTYs
(deftheme spacemacs-dark-tty)
(rgmacs/copy-theme-tty 'spacemacs-dark 'spacemacs-dark-tty)
;; now enable it (on top of currently active themes)
(enable-theme 'spacemacs-dark-tty)
```
> 0 votes
---
Tags: frames, daemon, themes
--- |
thread-63749 | https://emacs.stackexchange.com/questions/63749 | How to turn off R help document popup when using ESS? | 2021-03-05T16:38:45.107 | # Question
Title: How to turn off R help document popup when using ESS?
When I input a function, the R help document pops up automatically. It's very annoying. How to turn it off?
# Answer
This is an interaction of `company-mode` with ESS. You can fix this issue like this:
`(setq ess-use-company 'script-only)`
This disables use of `company-mode` in the R terminal, but makes it available in R scripts. To disable it entirely in ESS, just use
`(setq ess-use-company nil)`
More useful information about `company-mode` with ESS can be found here:
https://www.emacswiki.org/emacs/ESS-company
> 2 votes
---
Tags: company-mode, ess, company
--- |
thread-68182 | https://emacs.stackexchange.com/questions/68182 | lsp-mode Golang build tags | 2021-08-19T21:12:18.817 | # Question
Title: lsp-mode Golang build tags
I am using lsp-mode with Gopls as my coding environment. But I have one file with
```
// +build tagthis
```
at beginning of the file. Then my emacs lsp-mode cannot work well in this file. How can I change custom of go build flag for letting lsp-mode works well in this file?
I have make
```
(setq
lsp-go-build-flags (vector "tagthis")
)
```
in my configuration. But it doesn't work.
# Answer
I figure out the solution. Just change `lsp-go-env` with
```
(setq
lsp-go-env '((GOFLAGS . "-tags=tagthis"))
)
```
make it works.
> 1 votes
---
Tags: customize, lsp-mode
--- |
thread-68181 | https://emacs.stackexchange.com/questions/68181 | Why jshell doesn't work in comint-mode? | 2021-08-19T18:26:57.210 | # Question
Title: Why jshell doesn't work in comint-mode?
When I try to run jshell using `(comint-run "/usr/bin/jshell")`, it presents me with the prompt but when I give it some input, the buffer gets frozen and I get no output.
Conversely when I try to run python using `(comint-run "/usr/bin/python")`, it presents me with the prompt and it works fine with whatever input I give.
Why is this happening? What is the difference here? I thought comint just redirects the stdin and stdout. What underlying mechanism makes it so that comint treats python and jshell differently?
# Answer
Comint doesn't provide a fully-functional terminal replacement. It passes input from the user to the shell, and prints the output back to the screen. It can handle some escape sequences, but that's about it. Programs that require more sophisticated control of the terminal will not work properly under these conditions.
I don't have access to `jshell` locally, but from your description it sounds like it requires full terminal emulation, rather than the 'dumb terminal' features of `M-x shell`. You can test this by running it in `M-x term` instead.
See further pointers on the Emacs Wiki.
> 2 votes
---
Tags: comint, repl
--- |
thread-68028 | https://emacs.stackexchange.com/questions/68028 | What libraries are available for working with Apache Avro IDL? | 2021-08-09T00:18:04.043 | # Question
Title: What libraries are available for working with Apache Avro IDL?
I noticed there is no library listed in `melpa` for highlighting and working with Apache Avro IDL schemata. Is there any, or else how people who work with Avro have set up their configuration to ease their work?
# Answer
I couldn't find anything, so I made it myself.
```
;;; avro-mode.el -- major mode for editing Avro IDL files. -*- coding: utf-8; lexical-binding: t; -*-
;;; Copyright © by Daniel Vianna
;;; Version: 0.0.1
;;; Created: 19 Aug 2021
;;; Keywords: languages
;;; This file is not part of GNU Emacs.
;;; License:
;;; You can redistribute this program and/or modify it under the terms of the GNU General Public License version 2.
;;; Package --- summary
;;; Commentary:
;;;
;;; Avro interface description language mode (.avdl)
;;; Code:
(require 'generic-x)
(define-generic-mode
'avro-mode
'("//") ;; comments
'("protocol" "namespace") ;; reserved words
'(("\\<[[:alnum:]]+\\>" (0 font-lock-builtin-face) ("\\<[[:alnum:]]+\\>;?\\( {\\)?" nil nil (0 nil))) ;; type
("\\<\\(?:namespace\\|protocol\\)\\>" . font-lock-keyword-face)
("{\\|}\\|;\\|<\\|>" . font-lock-constant-face)) ;; separators
'("\\.avdl$") ;; file extension
nil
"Major mode for editing Avro IDL files."
)
(provide 'avro-mode)
;;; avro-mode.el ends here
```
> 1 votes
---
Tags: syntax-highlighting
--- |
thread-68143 | https://emacs.stackexchange.com/questions/68143 | Would it be possible apply different font/background color for `<code_sample>` in org mode? | 2021-08-17T10:31:16.407 | # Question
Title: Would it be possible apply different font/background color for `<code_sample>` in org mode?
In `markdownmode`, or while asking questions in stackoverflow, when we do,
```
`<code>`
```
or
<pre><code>```<code>```
</code></pre>
The background become changes into gray.
Would it be possible to apply same in `orgmode`, where it also change background color or change its forecolor?
---
Example:
# Answer
> 1 votes
You can add support to highlight fenced code blocks exactly like in Markdown mode, as several comments have already suggested. However, if you're using orgmode already, you have far more powerful and flexible features already built in.
Orgmode comes with markup for code blocks:
```
* My Org File
** Code blocks
#+begin_src elisp
(defun my-function ()
"This is my special function."
(interactive)
(message "Hello from Emacs"))
#+end_src
```
By default, the text in the src block has syntax highlighting applied according the code language of the block, in this case it's elisp:
You can modify the way this appears with themes, or by directly modifying the faces (`org-block` being one of the basic ones).
Similarly, inline code snippets in org mode are marked up as:
```
Here's a bit of inline code: ~x = x + 1~
```
The default colouring for this is:
This just scratches the surface. Org-mode provides a lot of features for working with inline code, and especially code blocks. If you're writing documents with included code snippets, you should consider using the features org mode already provides.
Working with Source Code (org manual)
Markup for inline code (org manual)
---
Tags: org-mode, font-lock, colors
--- |
thread-68189 | https://emacs.stackexchange.com/questions/68189 | Why is code indentation in the current codebase of Emacs so difficult to read? | 2021-08-20T09:04:42.523 | # Question
Title: Why is code indentation in the current codebase of Emacs so difficult to read?
I'm looking at the codebase of Emacs (for example `gnus` codebase) and see that the code indentation style is so weird.
For example, here is source code of the functions `gnus-sort-threads-recursive` in module `gnus-sum.el.gz` of Emacs 27.2. It's difficult to read the `if` statement in line 3 since the condition and the body in next lines are totally unaligned and unordered.
```
(defun gnus-sort-threads-recursive (threads func)
;; Responsible for sorting the root articles of threads.
(let ((subthread-sort-func (if (eq gnus-subthread-sort-functions ;; why is
'gnus-thread-sort-functions) ;; this
func ;; if-expr
(gnus-make-sort-function ;; so difficult
gnus-subthread-sort-functions)))) ;; to read ???
(sort (mapcar (lambda (thread)
(cons (car thread)
(and (cdr thread)
(gnus-sort-subthreads-recursive
(cdr thread) subthread-sort-func))))
threads)
func)))
```
If I call `indent-region` by Emacs itself to indent this function, then it's much clearer to read.
```
(defun gnus-sort-threads-recursive (threads func)
;; Responsible for sorting the root articles of threads.
(let ((subthread-sort-func (if (eq gnus-subthread-sort-functions
'gnus-thread-sort-functions)
func
(gnus-make-sort-function
gnus-subthread-sort-functions))))
(sort (mapcar (lambda (thread)
(cons (car thread)
(and (cdr thread)
(gnus-sort-subthreads-recursive
(cdr thread) subthread-sort-func))))
threads)
func)))
```
I guess it might be due to a historical reason. But I'm curious if anybody can explain why code indentation of the original codebase is so difficult to read?
# Answer
> 3 votes
It has mixed tabs and spaces for indentation, and assumes that tabs are 8 characters wide. You’ve probably configured your Emacs to display tabs as a different width.
---
Tags: indentation
--- |
thread-68187 | https://emacs.stackexchange.com/questions/68187 | org-babel pass bibtex sample to python code block | 2021-08-20T07:38:08.693 | # Question
Title: org-babel pass bibtex sample to python code block
Is it possible to pass a sample `bibtex` document into a python source code block to be evaluated?
```
:PROPERTIES:
:ID: d7154890-6d45-44c0-9b0c-9c0f6533c11e
:header-args: :session bibtex
:END:
#+NAME: sample_bib
#+BEGIN_SRC bibtex
@book{崔光宙_先秦儒家禮樂敎化思想在現代敎育上的涵義與實施_1985,
title = {先秦儒家禮樂敎化思想在現代敎育上的涵義與實施},
author = {{崔光宙}},
date = {1985},
series = {私立東吳大學中國學術著作獎助委員會叢書},
edition = {初版},
number = {94},
publisher = {{私立東吳大學中國學術著作獎助委員會}},
location = {{台北市}},
langid = {chi}
}
@article{李平_中國古代樂論的易學淵源_1996,
title = {中國古代樂論的《易》學淵源},
author = {{李平}},
date = {1996},
journaltitle = {音樂藝術.上海音樂學院學報},
number = {01},
pages = {11-16+27},
issn = {1000-4270},
url = {https://kns.cnki.net/kcms/detail/detail.aspx?dbcode=CJFD&dbname=CJFD9697&filename=SHYB199601002&v=IRe2C4LIBXc2dm%25mmd2FCtYiLuYcL8BGh6BOP9B5FiG59mEXb4llLOFZuq17u9CBg6yGt},
urldate = {2021-07-26},
langid = {中文;},
keywords = {《乐论》,《周易》,《易》,《易》学,十二律,吕氏春秋,天地万物,音乐本体}
#+END_SRC
#+BEGIN_SRC python :results output :noweb yes
import bibtexparser
from bibtexparser.bwriter import BibTexWriter
from bibtexparser.bibdatabase import BibDatabase
with open(<<sample_bib>>) as bibtex_file:
bibtex_str = bibtex_file.read()
db = bibtexparser.loads(bibtex_str)
print(db)
#+END_SRC
#+RESULTS:
```
The python source block above returns no results. And there is `No org-babel-execute` function for bibtex\`.
# Answer
> 1 votes
You can make a simple bibtex execute function like this:
```
#+BEGIN_SRC emacs-lisp
(defun org-babel-execute:bibtex (body params)
body)
#+END_SRC
```
Then use a variable instead of noweb like this:
```
#+BEGIN_SRC python :results output :var bibdata=sample_bib
import bibtexparser
from bibtexparser.bwriter import BibTexWriter
from bibtexparser.bibdatabase import BibDatabase
db = bibtexparser.loads(bibdata)
print(db)
#+END_SRC
#+RESULTS:
: <bibtexparser.bibdatabase.BibDatabase object at 0x7f87201f8910>
```
---
Tags: org-babel, python, bibtex
--- |
thread-68193 | https://emacs.stackexchange.com/questions/68193 | How to tell, with Elisp, whether a command is running as part of a keyboard macro? | 2021-08-20T15:26:06.123 | # Question
Title: How to tell, with Elisp, whether a command is running as part of a keyboard macro?
In some situations a command will use timers or hooks in a way that doesn't work when repeating as a keyboard macro.
How can I detect if a function is running as part of a keyboard macro that is being repeated?
# Answer
> 0 votes
This can be checked using `(not (or executing-kbd-macro noninteractive))`
---
The documentation for `called-interactively-p` states:
```
Instead of using this function, it is cleaner and more reliable to give your
function an extra optional argument whose `interactive' spec specifies
non-nil unconditionally (\"p\" is a good way to do this), or via
\(not (or executing-kbd-macro noninteractive)).
```
However I couldn't figure out how that was supposed to work.
---
Tags: keyboard-macros
--- |
thread-68175 | https://emacs.stackexchange.com/questions/68175 | bug in the CTAN version of aux-renum.el | 2021-08-18T20:32:09.340 | # Question
Title: bug in the CTAN version of aux-renum.el
Emacs has been my LaTex editor for several years. Along with AucTex, I have been using the label/ref management utility for emacs supplied by aux-renum.el. It's available on the CTAN archive at
aux-renum.el
However, when I fired it the other day I ran into an error:
invalid read sytax: "#"
If anyone has updated the aux-renum package to work with the current version of emacs, I would greatly appreciate knowing how to get a copy of a working version. Thanks in advance.
# Answer
Short answer: your TeX document is using the `hyperref` package. Simply turn it off by commenting out the
```
\usepackage{hyperref}
```
line and try to use `aux-renum.el` again.
Longer answer: `aux-renum.el`parses the LaTeX document's `.aux` file and writes what it finds into a temporary buffer on which it runs `eval-buffer`. Meanwhile, `hyperref` completely subverts the `.aux`, redefining `\newlabel` among other things. Put the two together and `aux-renum` writes garbage into the temporary buffer and then tries to `read` it. Hence the error.
It is hard to blame `aux-renum` for this: it was written in 1995 before PDF took off and `hyperref` became almost mandatory.
> 2 votes
---
Tags: latex
--- |
thread-36980 | https://emacs.stackexchange.com/questions/36980 | How to change the current working directory? | 2017-11-20T11:34:11.110 | # Question
Title: How to change the current working directory?
how to change the current working directory of emacs?
set `default-directory` doesn't not affect the emacs process's current working directory, which can be verified via `lsof -p pid`.
# Answer
> 7 votes
I think the only way Emacs offers to control the `cwd` of the process is the `--chdir` command line argument. Once the process is started, there is currently no way to modify it.
# Answer
> 38 votes
`M-x cd`
This should solve your problem.
# Answer
> 9 votes
`C-h f cd`:
> **`cd`** is an interactive compiled Lisp function in `files.el`.
>
> `(cd DIR)`
>
> Make `DIR` become the current buffer’s default directory.
>
> If your environment includes a `CDPATH` variable, try each one of that list of directories (separated by occurrences of `path-separator`) when resolving a relative directory name. The path separator is colon in GNU and GNU-like systems.
And please explain why changing `default-directory` does not also change the "current directory" for you: `(setq default-directory "/my/favorite/dir")`.
# Answer
> 1 votes
Maybe not an answer to the question but I had a similar issue. The setup was emacsclient over **tmux** session and had to split the window horizontally and open a new tmux tab with **the current Emacs' working directory**. Here is a workaround:
init.el:
```
;;; Tmux integration (See tmux.conf for details).
(defun id/tmux-split-horisontal ()
"Split tmux pane horisontally."
(interactive)
(ignore-errors (call-process "tmux" nil nil nil "split-window" "-h" "-c"
default-directory)))
(global-set-key (kbd "C-q %") #'id/tmux-split-horisontal)
(defun id/tmux-new-tab ()
"Create new tmux tab."
(interactive)
(ignore-errors (call-process "tmux" nil nil nil "new-window" "-c"
default-directory)))
(global-set-key (kbd "C-q c") #'id/tmux-new-tab)
```
tmux.conf:
```
## Use C-q as a prefix key.
unbind C-b
set -g prefix C-q
bind C-q send-prefix
## Handle [C-q %] and [C-q c].
is_emacs='echo "#{pane_current_command}" | grep -iqE "emacs"'
# Let Emacs handle [C-q %] if active.
bind-key -T prefix % if-shell "$is_emacs" "send-prefix ; send-keys %" "split-window -h -c \"#{pane_current_path}\""
# Let Emacs handle [C-q c] if active.
bind-key -T prefix c if-shell "$is_emacs" "send-prefix ; send-keys c" "new-window -c \"#{pane_current_path}\""
```
In this way, if you're under emacs or emacsclient the control is passing to Emacs, thus Emacs sends tmux command with default-directory argument. Otherwise, tmux handles it directly, so the user doesn't see the difference.
---
Tags: config
--- |
thread-68199 | https://emacs.stackexchange.com/questions/68199 | Is it possible my Windows Emacs install was compromised by a virus? | 2021-08-21T06:23:51.150 | # Question
Title: Is it possible my Windows Emacs install was compromised by a virus?
I recently downloaded Emacs 27.2 from one of the mirrors linked from the homepage of Emacs at gnu.org. After extracting the files and running runemacs.exe, Windows warned me that this was an unrecognized app and that running the file could put my computer at risk. Thinking not too much of it, I ran the file anyway. No, I did not verify the signature.
What tipped me off that there might be a problem was the title of the window Emacs ran in: it said "emacs@DESKTOP-2LURKID". 2LURKID is not a name I recognize, and has a rather sinister sound to it (lurking?). As an experiment I downloaded Emacs 27.1 and ran that. Windows did not warn me about running that exe (although the title of the window was still "emacs@DESKTOP-2LURKID"), which makes me think there was something in the 27.2 build.
I've shut off my computer for now until I can figure out if there's a virus or not. Is my concern valid? What is the title of the Emacs window normally? What are some further steps I can take to determine if this was a virus?
# Answer
You’re fine. Believe it or not, `DESKTOP-2LURKID` is actually your computer’s host name. Windows chooses that host name in a pretty odd way that results in unique names but not very usable ones. Since most people don’t know what a host name is for or why they might need one, this keeps them from encountering problems due to duplicate names.
Search elsewhere for information about changing that host name. You can just set it to whatever you want, and it’ll probably never effect you one way or the other. Emacs puts the host name in the window title because on Linux it is very common to log into a remote computer, and in that case you would want to know which computer each Emacs window represents.
> 3 votes
---
Tags: microsoft-windows, install
--- |
thread-68205 | https://emacs.stackexchange.com/questions/68205 | How to use Org KEYWORD values within exported body? | 2021-08-21T19:09:26.577 | # Question
Title: How to use Org KEYWORD values within exported body?
How can I get the author's name, the date, or other `#+KEYWORD: value` variables to appear within the exported body?
This is my org-mode file:
```
#+TITLE: Some Title
#+AUTHOR: Foo Bar
#+DATE: 2021-08-21
* some headline
This does not work:
- author's name: %a
- date: %d
```
Note: I'm exporting to HTML.
# Answer
> 5 votes
Org mode defines macros for these things. Try:
```
#+TITLE: Some Title
#+AUTHOR: Foo Bar
#+DATE: 2021-08-21
* some headline
This works:
- author's name: {{{author}}}
- date: {{{date}}}
```
See the "Macro Replacement" section of the manual with `C-h i g(org)macro replacement` for more info.
EDIT: as the OP points out in the comment, the section I pointed to above describes the general mechanism, as well as the specific cases (`author` and `date`) in the text above.
For *any* keyword `FOO`, the value of that keyword can be inserted into the exported output by using the macro call `{{{keyword(FOO)}}}`. The `author` macro e.g. is just a shortcut for the `keyword(AUTHOR)` macro.
---
Tags: org-export, html
--- |
thread-9560 | https://emacs.stackexchange.com/questions/9560 | Org-mode: org-export-as-html is detected as XML, not HTML | 2015-02-25T07:34:05.240 | # Question
Title: Org-mode: org-export-as-html is detected as XML, not HTML
I am exporting my org-mode file via `org-export-as-html`, but when I check the file type via `file my/file.html`, it is XML. I notice the first three lines in my HTML exported file is the following:
```
<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
```
which is a reasonable explanation. If I manually re-order these lines to the following:
```
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<?xml version="1.0" encoding="iso-8859-1"?>
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
```
then the file is correctly identified as HTML. How do I correct this issue in my export function? I checked the org-mode docs here but they seem out of date:
http://orgmode.org/manual/HTML-Export-commands.html#HTML-Export-commands
because I do not have their listed commands, but `org-export-to-html` and `org-export-as-html-to-buffer`.
Any suggestions would be very helpful.
BTW I am on Emacs 24.3 with Ubuntu 14.04. Here are the first few lines of my org file:
```
Flatsheet Project Mgmt -*- mode: org -*-
#+TODO: TODO IN-PROGRESS WAITING DONE
#+INFOJS_OPT: view:overview toc:true
* project stuff...
* more project stuff...
```
**UPDATE**
I found this link potentially helpful, but their suggestion is not working:
http://doc.norang.ca/org-mode.html
There is a section called `16.8.2 Export HTML without XML header`, but their solution below does not work for me:
```
(setq org-html-xml-declaration (quote (("html" . "")
("was-html" . "<?xml version=\"1.0\" encoding=\"%s\"?>")
("php" . "<?php echo \"<?xml version=\\\"1.0\\\" encoding=\\\"%s\\\" ?>\"; ?>"))))
```
# Answer
> 1 votes
This was resolved by upgrading to the latest version of org-mode, detailed here
I did it through the ELPA package manager, with marmalade packages, to upgrade org-mode from 7.9 to 8.2. Org-mode seems to be under heavy development, and it has a new export engine, which was probably the cause of my error.
When re-installing a package, just be sure to delete any existing org package directory under `.emacs/elpa/org...` and restart emacs with `emacs -q` and THEN install the latest package to avoid conflicts! YMMV but it worked for me.
After that, it exported fine, with a DOCTYPE html declaration at the top of the file. Now the file is recognized as HTML instead of XML.
# Answer
> 1 votes
XML export is still the default as of org 9.4, but you can override in several ways. For example, I export as html5 by putting this in my init file:
```
(setq org-html-doctype "html5")
```
You can also set this per-file with this at the top:
```
#+HTML_DOCTYPE: html5
```
Using either of these methods generates this html:
```
<!DOCTYPE html>
<html lang="en">
<head>
```
---
Tags: org-mode, org-export, html
--- |
thread-61904 | https://emacs.stackexchange.com/questions/61904 | quick way to restore backups | 2020-11-23T21:13:20.167 | # Question
Title: quick way to restore backups
The following happens fairly often to me:
* I do `emacs note-xyz` in the terminal to create a new note
* I write something in the note
* I forget to save before logging out
Now I'm left with a file `#note-xyz#` in my directory, without corresponding `note-xyz`.
What's the fastest way to open `#note-xyz#` as `note-xyz`, so that from then on `C+x C+s` saves to the intended filename? Ideally I'm looking for a single command that I can put in an alias.
# Answer
> 3 votes
Try `recover-file` for one specific file. If you call it with a filename it will prompt if the auto-save data exists e.g. `(recover-file "note-xyz")` otherwise, you could use `recover-session` if there are multiple files with unsaved changes.
You can also avoid the problem by adjusting the autosave settings to save more frequently. To save after every change for example `(setq auto-save-interval 1)` or `(setq auto-save-timeout 1)` to save whenever you stop typing for more than a second...
# Answer
> 2 votes
I believe `M-x recover-session` *should* be all you need.
However... I've just tested your scenario, and for some reason the session file is deleted if I kill emacs externally, which means that there is no record of what to recover.
This seems like a bug. Certainly it seems like undesirable default behaviour. Could you please `M-x` `report-emacs-bug` to follow this up?
I can reproduce the behaviour just by running `emacs` in the foreground in a terminal and then killing it with `C-c` once I've verified the presence of the session file listing the autosaved files.
---
Tags: auto-save
--- |
thread-52572 | https://emacs.stackexchange.com/questions/52572 | use-package org-mode :hook is being ignored | 2019-09-08T16:49:04.373 | # Question
Title: use-package org-mode :hook is being ignored
I'm currently running this version of Emacs:
```
GNU Emacs 26.1 (build 2, x86_64-pc-linux-gnu, GTK+ Version 3.24.7) of 2019-04-11, modified by Debian
```
I'm attempting to use use-package to configure the latest version of org-mode, and not the one that comes with Emacs. My initial attempt at configuration used `:hook` directive (commented out in the elisp code below) does not work, as the resulting value of `org-mode-hook` does not have `my-org-mode-hook` at all (the actual value is shown later on):
```
;; Define org and melpa as package sources, and install `use-package' if it's
;; not already there. Origination:
;; https://www.reddit.com/r/emacs/comments/5sx7j0/how_do_i_get_usepackage_to_ignore_the_bundled/
;; Here, I *DO* actually desire automatic updating of the latest packages in this
;; case (specifically org-mode which receives frequent updates.
(require 'package)
(add-to-list 'package-archives '("melpa" . "https://melpa.org/packages/") t)
(add-to-list 'package-archives '("org" . "https://orgmode.org/elpa/") t)
;; Ensure that "org" and "melpa" are found first in this order (higher numbers are higher priority):
(when (>= emacs-major-version 25) (setq package-archive-priorities '(("org" . 3)
("melpa" . 2)
("gnu" . 1))))
;; This is the key!! --> " The symbol ‘all’ says to load the latest installed
;; versions of all packages not specified by other elements." and for org-mode,
;; this means always get that latest version.
(setq package-load-list '(all))
(package-initialize)
;; Not sure why we need this:
(setq package-enable-at-startup nil)
;; Install use-package:
(unless (package-installed-p 'use-package)
(package-refresh-contents)
(package-install 'use-package))
(eval-when-compile
(require 'use-package))
;; Load org mode early to ensure that the orgmode ELPA version gets picked up, not the
;; shipped version.
;;
;; Reference https://github.com/jwiegley/use-package#package-installation
;;
(require 'use-package-ensure)
(setq use-package-always-ensure t)
;;
;; Now the configuration for org-mode:
;;
(use-package org
;; Install both org and "contrib"-uted org-related packages:
:ensure org-plus-contrib
:pin org
;;
;; This seems to be correct way to add my hook function to org-mode-hook, but
;; it does not show up in the value of org-mode-hook, so I commented it out in
;; favor of the forced use of add-hook inside :config, later:
;;
;; :hook #'my-org-mode-hook
;;
:config
;;
;; This seems to be the only way to get my hook function to be added, as the
;; :hook directive is ignored or obliterated by something else:
;;
(add-hook 'org-mode-hook 'my-org-mode-hook))
```
When try to use `:hook` that is commented out above (and of course also commenting out the call to `add-hook`), I get this for the final value after opening up a `.org` file:
```
org-mode-hook is a variable defined in ‘org.el’.
Its value is shown below.
This variable may be risky if used as a file-local variable.
Documentation:
Mode hook for Org mode, run after the mode was turned on.
You can customize this variable.
Value:
(#f(compiled-function
()
#<bytecode 0x1684c2d>)
#f(compiled-function
()
#<bytecode 0x1ab413d>)
org-babel-result-hide-spec org-babel-hide-all-hashes #f(compiled-function
()
#<bytecode 0x1ae75e1>)
org-eldoc-load)
Original value was nil
```
As seen above, the `my-org-mode-hook` function is not in the value. My understanding is that `use-package` should add it there (per use-package Hooks section) but does not, and I have to force it with the explicit call to `add-hook`.
What am I doing wrong here?
# Answer
> 1 votes
I have no clue why yours didn't work, maybe use-package is not correctly identifying that it should attach to the 'org-mode-hook. However, I managed to add my own hook to enable visual-line-mode, in the other alternative way documented to insert hooks:
```
(use-package org
;; Specify my hook to add to org-mode-hook (remove the -hook suffix):
:hook (org-mode . (lambda () (visual-line-mode)))
```
In your case it would be:
```
(use-package org
; again, remove `-hook` from org-mode-hook:
:hook (org-mode . '#my-org-mode-hook))
```
I think that way will work for you also, as the hook to which this is added is explicit.
---
Tags: org-mode, hooks, use-package
--- |
thread-68106 | https://emacs.stackexchange.com/questions/68106 | How to remove empty space on ido-find-file's completions minibuffer window | 2021-08-14T15:11:09.693 | # Question
Title: How to remove empty space on ido-find-file's completions minibuffer window
When I use `ido-find-file` and press `TAB` I see the found filenames in a half windows size. Instead could it be compact, where can emtpy space removed?
Ex:
---
minimal.el:
```
(ido-mode 1)
(require 'consult)
(require 'vertico)
(vertico-mode)
```
*Please note* that I am not able to use `icicles` due to consult does not properly work when I enable `ivy-mode`.
# Answer
> 2 votes
\[UPDATE\] The issue is reported to be fixed in Emacs 29 trunk.
I had this question myself and your post had stimulated me to finally research how to do it.
Here's the *current* solution (or rather a *fix*, because this behavior of the \*Ido Completions\* buffer *looks like* a bug to me) tested on `Emacs 28.0.50`:
```
(customize-set-variable
'display-buffer-alist
'(("\\*Ido Completions\\*"
(display-buffer-reuse-window display-buffer-at-bottom)
(window-height . fit-window-to-buffer))))
```
Additionally, try out `'one-column` output:
```
(setq completions-format 'one-column) ; or 'vertical / 'horizontal
```
Documentation on display-buffer-alist.
P.S. I probably should have also mentioned that typing `C-f` (after `C-x C-f` calling `ido-find-file`) allows to fallback to non-ido `find-file` with the currently more standard completions buffer behavior. `C-h f ido-magic-forward-char` lists all `C-f` initiated "magic actions".
---
Tags: minibuffer, ido
--- |
thread-68207 | https://emacs.stackexchange.com/questions/68207 | org-gcal: could not parse org.file when org-gcal-fetch | 2021-08-21T20:47:03.340 | # Question
Title: org-gcal: could not parse org.file when org-gcal-fetch
I checked, where the error comes from and it's:
```
(while (re-search-forward org-heading-regexp nil t)
```
where org-heading-regexp is:
```
"^\\(\\*+\\)\\(?: +\\(.*?\\)\\)?[ ]*$"
```
How does my org file have to look like in order to match this?
Currently the file looks like this:
```
* test
* Events was ist das
* hi
```
The error message is:
```
Org-gcal error: Couldn't parse /home/dave/Dropbox/org/events.org
```
and the backtrace looks like this:
# Answer
sounds weird, but after putting (see https://github.com/kidd/org-gcal.el/issues/96)
```
* one
* another
SCHEDULED: <2020-07-15 wed 09:15>
:PROPERTIES:
:calendar-id: jjjjjjjjjjjfuuuk842fdok134@group.calendar.google.com
:ETag: "7777777777980000"
:ID: xxxxxxxxxxa4jlcj0v998f4u18/jjjjjjjjjjjfuuuk842fdok134@group.calendar.google.com
:END:
:org-gcal:
:END:
```
and some fetching in my events.org, all appointments were strangely fetched. another was overwritten, so weird, but solved my problem.
> 0 votes
---
Tags: org-mode, org-gcal
--- |
thread-68219 | https://emacs.stackexchange.com/questions/68219 | How to create a horizontal table in org-mode | 2021-08-23T10:56:33.793 | # Question
Title: How to create a horizontal table in org-mode
I have a physical journaling setup that I want to move to Emacs/org-mode for better integration with the rest of my note-taking. I have a set of questions that I rate myself on. On paper, I was using one row for each question and one column for every day (mostly because my questions are relatively long, and I can fit everything on one page this way). See here for an example of what I mean.
Is there a way to do something similar in org-mode/Emacs? I tried doing this with tables, but I couldn't figure out how to expand the tables horizontally instead of vertically.
I tried searching for something like "org table by row", "vertical table org-mode" or "transpose org table" but haven't found what I was looking for.
# Answer
> 2 votes
Sorry, what do you mean by 'expand' the table horizontally?
Maybe this isn't what you meant, but you can add a column with `M-S-right`. If this is wrong maybe you could clarify? Nice journaling!
---
Tags: org-mode, org-table
--- |
thread-68198 | https://emacs.stackexchange.com/questions/68198 | Help window in ESS | 2021-08-21T02:33:19.887 | # Question
Title: Help window in ESS
I am using ESS for using R. When I use help in ESS, I have the screenshot like Picture 1. But, I want to get Picture 2. How do I manage my init.el? The following code is my init related to ESS.
```
(use-package ess
:ensure t
:init (require 'ess-site)
:config
(setq inferior-R-program-name "/usr/local/bin/R")
(setq ess-ask-for-ess-directory nil)
(defun forbid-vertical-split ()
(setq-local split-height-threshold nil)
(setq-local split-width-threshold 0))
(add-hook 'ess-mode-hook
'forbid-vertical-split))
```
# Answer
> 1 votes
Your function `forbid-vertical-split` sets some rather extreme settings for window splitting. If I remove this, I get the behaviour you want: calling help from R puts the help buffer in one of the existing windows, and doesn't create the funny split in your first figure.
You may need to tweak your settings to get this working exactly how you want it. Just removing the `(setq-local split-width-threshold 0)` appears to fix the problem for me.
---
Tags: ess, window-splitting
--- |
thread-2387 | https://emacs.stackexchange.com/questions/2387 | Browser not opening when exporting HTML from org-mode | 2014-10-20T20:41:35.383 | # Question
Title: Browser not opening when exporting HTML from org-mode
Org-mode can export as HTML and open on a browser with `C-c C-e h o` (`org-export-dispatch`), but the problem is that the generated html file opens in a buffer inside emacs. There is no error in the message buffer, either. How can I make it work?
When I click a link inside org-mode, the browser opens correctly.
I'm running org-mode 8.2.10, emacs 24.3.1 on manjaro linux 0.8.10. I checked preferred applications in KDE and it points web browsing to firefox.
# Answer
> 5 votes
I experienced the same problem after a new installation of ArchLinux with XFCE.
Although I didn't manage to understand the problem, a workaround was to configure 'org-file-apps' as described in the FAQ :
http://orgmode.org/worg/org-faq.html#external-application-launched-to-open-file-link
in my .emacs.d/init.el, I have now :
```
'(org-file-apps
(quote
((auto-mode . emacs)
("\\.mm\\'" . default)
("\\.x?html?\\'" . "/usr/bin/firefox %s")
("\\.pdf\\'" . default))))
```
# Answer
> 1 votes
```
(setq browse-url-generic-program
(cond
((eq window-system 'mac) "open") ; mac
((or (eq system-type 'gnu/linux) (eq system-type 'linux)) ; linux
(executable-find "firefox"))
))
```
# Answer
> 0 votes
```
emacs --version
GNU Emacs 25.1.1
```
It works for me:
```
(setq org-file-apps
(quote
((auto-mode . emacs)
("\\.mm\\'" . default)
("\\.x?html?\\'" . "/usr/bin/firefox %s")
("\\.pdf\\'" . default))))
```
REF from answer of @skizo
# Answer
> 0 votes
As documented on Worg (and mentioned in other answers), org-mode uses`org-file-apps` to determine how to open files. Moreover, `org-file-apps` can call emacs functions instead of specifying external applications. Especially for opening stuff in the web-browser, emacs ships with the `browse-url` package. This package provides a lot of functions to call a lot of different browsers (most of them are not really used anymore), and `M-x customize-group` `Enter` `browse-url` can help to give an overview. When `browse-url` is configured correctly, then the function `browse-url` will open a new browser (or a tab in an already running browser). This can be leveraged in `org-file-apps`:
```
(setq org-file-apps
(quote
(
("\\.x?html?\\'" . browse-url)
)
)
)
```
This configuration is more portable then specifying exact paths, and it also allows to have a different entry in the `.mailcap`, which org-mode normally uses if nothing is defined in `org-file-apps`.
# Answer
> -1 votes
I suspect that you have a mixed installation of org-mode. See the FAQ here:
http://orgmode.org/worg/org-faq.html#mixed-install
When this has happened to me what I have done is (assuming you install via ELPA):
1. uninstall org-mode
2. quit emacs
3. restart emacs using `emacs -q`
4. manually add `("org" . "http://orgmode.org/elpa/")` to `package-archives` and run `(package-initialize)` \`
5. install org-mode
6. restart emacs
Hope that helps.
---
Tags: org-mode, org-export
--- |
thread-68188 | https://emacs.stackexchange.com/questions/68188 | Org-mode do not inheriting Unnumbered property | 2021-08-20T08:59:48.913 | # Question
Title: Org-mode do not inheriting Unnumbered property
Is there a way to set the `UNNUMBERED` property only to the current heading but not to the children headings?
My desired headings are:
```
1 Part one
1.1 Chapter one
Appendixes (unnumbered)
A Appendix one (numbered)
B Appendix two (numbered)
```
leaving apart the letters for Appendixes (see "EXTRA" below), I can get this result with:
```
* Part one
** Chapter one
* Appendixes
:PROPERTIES:
:UNNUMBERED: t
:END:
** Appendix one
:PROPERTIES:
:UNNUMBERED: nil
:END:
** Appendix two
:PROPERTIES:
:UNNUMBERED: nil
:END:
```
but repeating the `UNNUMBERED: nil` for each appendix is boring and not so good for future changes, so I tried to group appendix in a phantom header (with `(ox-extras-activate '(ignore-headlines))`):
```
* Part one
** Chapter one
* Appendixes
:PROPERTIES:
:UNNUMBERED: t
:END:
** core :ignore:
:PROPERTIES:
:UNNUMBERED: nil
:END:
*** Appendix one
*** Appendix two
```
but with this I get:
```
1 Part one
1.1 Chapter one
Appendixes
Appendix one
Appendix two
```
so it does not ignore the heading only, but also its properties.
I am exporting both to LaTeX and HTML/ePub, so a solution involving LaTeX custom export is not possible.
**UPDATE**
As suggested by @NickD I checkd the variable `org-use-property-inheritance` was set to nil. It was, so maybe the `UNNUMBERED` property has forced inheritance like other properties.
```
* Part one
Lorem Ipsum
** Chapter one
Dolor sit amet
* Appendixes
:PROPERTIES:
:UNNUMBERED: t
:END:
Lorem Ipsum
** Appendix one
Dolor sit amet
** Appendix two
Lorem Ipsum
```
with `org-use-property-inheritance` equal to `nil` generates
```
% Created 2021-08-23 lun 09:46
% Intended LaTeX compiler: pdflatex
\documentclass[11pt]{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{graphicx}
\usepackage{grffile}
\usepackage{longtable}
\usepackage{wrapfig}
\usepackage{rotating}
\usepackage[normalem]{ulem}
\usepackage{amsmath}
\usepackage{textcomp}
\usepackage{amssymb}
\usepackage{capt-of}
\usepackage{hyperref}
\usepackage{minted}
\usepackage{tikz}
\usepackage{bookmark}
\author{Davide Peressoni}
\date{\today}
\title{}
\hypersetup{
pdfauthor={Davide Peressoni},
pdftitle={},
pdfkeywords={},
pdfsubject={},
pdfcreator={Emacs 27.2 (Org mode 9.5)},
pdflang={English}}
\begin{document}
\tableofcontents
\section{Part one}
\label{sec:orgd36625b}
Lorem Ipsum
\subsection{Chapter one}
\label{sec:orgc5dae8d}
Dolor sit amet
\section*{Appendixes}
\label{sec:orgf878691}
Lorem Ipsum
\subsection*{Appendix one}
\label{sec:org0d45b16}
Dolor sit amet
\subsection*{Appendix two}
\label{sec:org848be4e}
Lorem Ipsum
\end{document}
```
**EXTRA**
If someone is interested I'm using this function to achieve the same numbering of LaTeX in HTML (parts in roman, chapters continuous among parts and appendix chapters in alpha):
```
(defun org-export-get-headline-number (headline info)
"Return numbered HEADLINE numbering as a list of numbers.
INFO is a plist holding contextual information."
(and (org-export-numbered-headline-p headline info)
(let* (
(nums (cdr (assq headline (plist-get info :headline-numbering))))
(root-heading (let ((parent headline)(temp)) (while (and (setq temp (org-element-property :parent parent)) (eq 'headline (org-element-type temp))) (setq parent temp)) parent))
(appendix (member "appendix" (org-element-property :tags root-heading))))
(if (eq 1 (length nums))
;; if it's a part get roman numbers
(list (nth (car nums) '("Z" "I" "II" "III" "IV" "V" "VI" "VII" "VIII" "IX" "X")))
(let ((nums (cdr nums))) ; remove part number
(cons (if appendix
;; appendix chapters in alpha
(byte-to-string (- (+ ?A (car nums)) 1))
(+ (car nums) ; sum chapters of previous parts
(-count 'identity
(org-element-map (org-element-property :parent root-heading) 'headline
(lambda (el)
(and
(eq 2 (org-element-property :level el))
(< (org-element-property :begin el) (org-element-property :begin root-heading))))))))
(cdr nums))
)))))
(defun number-to-string (number)
(format "%s" number))
)
```
# Answer
> 1 votes
Following the suggestions of @NickD I figured out this hack to break the inheritance of `UNNUMBERED` property:
```
;; Break inheritance of UNNUMBERED
(defun org-export-numbered-headline-p (headline info)
"Return a non-nil value if HEADLINE element should be numbered.
INFO is a plist used as a communication channel."
(unless (org-not-nil (org-export-get-node-property :UNNUMBERED headline ))
; removing `t` here ↑
; removes inheritance
(let ((sec-num (plist-get info :section-numbers))
(level (org-export-get-relative-level headline info)))
(if (wholenump sec-num) (<= level sec-num) sec-num))))
```
With that the chapters in appendix are numbered continuing from previous part, to avoid this I changed the function to assign headlines numbering in this way (also including roman for parts and letters for appendix):
```
;; Numbering
(defun org-export-get-headline-number (headline info)
"Return numbered HEADLINE numbering as a list of numbers.
INFO is a plist holding contextual information."
(and (org-export-numbered-headline-p headline info)
(let* (
(nums (cdr (assq headline (plist-get info :headline-numbering))))
(root-heading (let ((parent headline)(temp)) (while (and (setq temp (org-element-property :parent parent)) (eq 'headline (org-element-type temp))) (setq parent temp)) parent))
(appendix (member "appendix" (org-element-property :tags root-heading))))
(if (eq 1 (length nums))
;; if it's a part get roman numbers
(list (nth (car nums) '("Z" "I" "II" "III" "IV" "V" "VI" "VII" "VIII" "IX" "X")))
(let ((nums (cdr nums))) ; remove part number
(cons (if appendix
;; appendix chapters in alpha
(byte-to-string
(-
(+ ?A (car nums))
(nth 1 (cdr (assq
(org-element-map root-heading 'headline (lambda (el) (when (org-export-numbered-headline-p el info) el)) nil t)
(plist-get info :headline-numbering)))) ; number of first appendix
))
(+ (car nums) ; sum chapters of previous parts
(-count 'identity
(org-element-map (org-element-property :parent root-heading) 'headline
(lambda (el)
(and
(eq 2 (org-element-property :level el))
(< (org-element-property :begin el) (org-element-property :begin root-heading))))))))
(cdr nums))
)))))
(defun number-to-string (number)
(format "%s" number))
)
```
---
Tags: org-mode, org-export
--- |
thread-51097 | https://emacs.stackexchange.com/questions/51097 | How to execute a shell script inside of emacs? | 2019-06-18T13:06:00.003 | # Question
Title: How to execute a shell script inside of emacs?
I simply want to execute the whole file I am editing right now in a small shell buffer just like I can run my python script. How can I do this?
# Answer
> 5 votes
You can execute the selected code snippet with `C-M-x` (`sh-execute-region`). (It's the same key binding as `eval-defun` when editing Lisp code, but in sh mode, it executes the region, not the defun around point.) This uses the shell in `sh-shell-file`, which is determined from the shebang line if there is one.
If the script is executable, you can execute it with `C-c C-x` (`executable-interpret`). You'll be given the opportunity to pass arguments. (This command works no matter what language the program is written in, by the way, as long as the file you're editing is executable.)
Neither command maintains a running interpreter in the background, like `run-python` and the associated eval commands do in Python mode. This functionality isn't built in for shell mode. If you want that, you can copy-paste into a `*shell*` buffer.
# Answer
> 2 votes
Here you can find a function that will send current line to the shell buffer: https://stackoverflow.com/questions/6286579/emacs-shell-mode-how-to-send-region-to-shell/7053298#7053298
Here is an adapted version that uses `comint-scroll-to-bottom-on-output`, so the shell buffer always scrolls to the last output: https://nistara.net/post/emacs-send-line-or-region-to-shell/
# Answer
> 1 votes
A possible workaround would be to select the entire buffer (`C-x h`) and then use the function to run a shell command on a region as explained on https://stackoverflow.com/questions/1871970/emacs-execute-code-in-shell-script-mode.
If I have a split window with the shell script on top and a session in bash below, it would indeed be nice to have a command to send the content of the upper buffer to the bash session and see the output without having to change to the buffer below.
---
Tags: shell
--- |
thread-68230 | https://emacs.stackexchange.com/questions/68230 | emacs 28.0.50 `sh-quoted-exec` has different coloring for `sh` and `bash` | 2021-08-23T21:34:11.190 | # Question
Title: emacs 28.0.50 `sh-quoted-exec` has different coloring for `sh` and `bash`
In `Shell-script[bash]` mode, coloring differs for `sh-quoted-exec` in `#!/bin/sh` and `#!/bin/bash`.
If `#!/bin/sh` is the first line: // I prefert this
If `#!/bin/bash` is the first line:
Would it be possible to have same coloring in `sh` for `bash`?
# Answer
> 2 votes
You can manually toggle which features Emacs will apply to your file via `M-x sh-set-shell`: pick `/bin/sh` to get the variant you prefer. You can set this automatically for a file by adding the following code at the end of the file:
```
# Local Variables:
# sh-shell: sh
# End:
```
To illustrate, with this file:
```
#!/bin/bash
alper=$(gdrive list --query "'$id' in parents" --no-header | grep "patch_")
# Local Variables:
# sh-shell: sh
# End:
```
I see this:
It doesn't change the `#!` directive on the first line, and I get the syntax highlighting of the `sh` style in a `bash` script. This is with Emacs 28.0.50, started with `emacs -Q`.
To enable this automatically for all bash scripts, you can use the following hook:
```
(defun my-set-shell ()
(sh-set-shell "sh"))
(add-hook 'sh-mode-hook 'my-set-shell)
```
---
Tags: shell, bash, shell-mode, customize-face
--- |
thread-68234 | https://emacs.stackexchange.com/questions/68234 | How to use yasnippets from js- and css- modes in html-mode? | 2021-08-24T11:44:23.417 | # Question
Title: How to use yasnippets from js- and css- modes in html-mode?
I have latest YASnippet package installed on GNU Emacs 27.2 via MELPA. Snippets work, for example in `*.js` files, `let` expands to snippet after hitting `TAB`. However, when I edit HTML file (in html-mode), the JS inside `<script>` tag does not use YAS. Also, CSS snippets don't work in `<style>`.
I tried web-mode, but it fixes only JS.
Are there other solutions?
# Answer
> 1 votes
The answer mentioned by @dalanicolai helped a lot: I just had to edit `~/.emacs.d/snippets/html-mode/.yas-parents` to contain `css-mode js-mode`.
---
Tags: yasnippet, html, web-mode
--- |
thread-68125 | https://emacs.stackexchange.com/questions/68125 | Insert json or XML blocks in org mode | 2021-08-16T07:52:02.893 | # Question
Title: Insert json or XML blocks in org mode
I often have to insert blocks of json or XML code into my org documents. What is the preferred way of doing so?
I see that for the standard:
```
#+BEGIN_SRC
...
#+END_SRC
```
... there is no json or xml in the list of supported languages: https://orgmode.org/manual/Languages.html
And the same goes for babel languages: https://orgmode.org/worg/org-contrib/babel/languages/index.html
Thanks!
# Answer
> 6 votes
Org babel "Supported languages" are languages that you can evaluate/execute directly from an orgmode code block. I don't think JSON and XML are executable languages anywhere, so you don't need special support for them. You can still use src blocks, and if there's an Emacs mode for editing the language, it will apply the formatting to the code.
If you have JSON mode installed, you could use that. I don't, but JSON is close enough to Javascript that it produces reasonable formatting:
```
#+begin_src js
{
"firstName": "John",
"lastName": "Smith",
"isAlive": true,
"age": 27,
"phoneNumbers": [
{
"type": "home",
"number": "212 555-1234"
},
{
"type": "office",
"number": "646 555-4567"
}
],
"children": [],
"spouse": null
}
#+end_src
```
Which appears like this:
xml files are edited in the built-in mode `nxml` by default, so you don't need to add anything to use it:
```
#+begin_src xml
<note>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
</note>
#+end_src
```
Which is formatted as:
---
Tags: org-mode, json, xml
--- |
thread-68201 | https://emacs.stackexchange.com/questions/68201 | Dailies Capture Template Org-Roam not unique headline | 2021-08-21T10:00:43.653 | # Question
Title: Dailies Capture Template Org-Roam not unique headline
I would like to get my org roam dailies capture template to work but it returns with an error saying that the heading is not unique on level 1. My dailies capture template is as below:
```
(org-roam-dailies-capture-templates
(let ((head
(concat
"#+title: %<%A, %d %B %Y>\n#+roam_tags: Dailies\n* Inbox\n* Log\n"
"* [/] Do Today\n- [ ] Morning pages\n- [ ] Go through inbox\n- [ ] Flashcards\n* [/] Possibly Do Today\n")))
`(("d" "default" entry
"* %?"
:if-new (file+head+olp "%<%Y>/%<%B>/%<%Y-%m-%d>" ,head ("Inbox"))
:unnarrowed t)
("D" "default + reference" entry
"* %?
%a"
:if-new (file+head+olp "%<%Y>/%<%B>/%<%Y-%m-%d>" ,head ("Inbox"))
:unnarrowed t)
("j" "journal" entry
"* %U: %?"
:if-new (file+head+olp "%<%Y>/%<%B>/%<%Y-%m-%d>" ,head ("Log")))
("J" "journal + refernce" entry
"* %U: %?
%a"
:if-new (file+head+olp "%<%Y>/%<%B>/%<%Y-%m-%d>" ,head ("Log")))
("t" "Do Today" item
"[ ] %a"
:if-new (file+head+olp "%<%Y>/%<%B>/%<%Y-%m-%d>" ,head ("Do Today"))
:immediate-finish t)
("p" "Possibly Do Today" item
"[ ] %a"
:if-new (file+head+olp "%<%Y>/%<%B>/%<%Y-%m-%d>" ,head ("Possibly Do Today"))
:immediate-finish t)
)))
```
I'm using org-roam v2 in Doom Emacs on Ubuntu 20.04
# Answer
> 1 votes
Your template is just fine. I copied it into my configuration and it worked. The problem is, you have one of your headings more than once in your daily journal. The easiest solution would probably be to remove the multiple(s). Seems like this is not specific to org-roam-templates. From org-capture:
> ‘(file+headline "filename" "node headline")’
>
> Fast configuration if the target heading is unique in the file.
>
> ‘(file+olp "filename" "Level 1 heading" "Level 2" ...)’
>
> For non-unique headings, the full path is safer.
Since your duplicate is on level 1 I don't see how you could differentiate them by path, thus deleting or renaming the heading in your journal should solve the issue. Let me know if this solves your problem.
---
Tags: doom, org-roam
--- |
thread-68232 | https://emacs.stackexchange.com/questions/68232 | Setting latex compiler | 2021-08-24T05:16:39.723 | # Question
Title: Setting latex compiler
I was happily running emacs with a locally installed texlive in ~/texlive/2021 on manjaro KDE. But I decided to switch to Gnome. So, installed necessary packages, removed the ones I did not need and am now using Gnome without any problem.
When I opened emacs to compile a tex file (something I have been doing for a very long time), it suddenly produced an error:
```
Suspicious state from syntax checker tex-chktex: Flycheck checker tex-chktex returned 1, but its output contained no errors: warning: kpathsea: configuration file texmf.cnf not found in these directories: /usr/bin:/usr/bin/share/texmf-local/web2c:/usr/bin/share/texmf-dist/web2c:/usr/bin/share/texmf/web2c:/usr/bin/texmf-local/web2c:/usr/bin/texmf-dist/web2c:/usr/bin/texmf/web2c:/usr:/usr/share/texmf-local/web2c:/usr/share/texmf-dist/web2c:/usr/share/texmf/web2c:/usr/texmf-local/web2c:/usr/texmf-dist/web2c:/usr/texmf/web2c://texmf-local/web2c:/://share/texmf-local/web2c://share/texmf-dist/web2c://share/texmf/web2c://texmf-local/web2c://texmf-dist/web2c://texmf/web2c.
chktex: WARNING -- Could not find global resource file.
chktex: ERROR -- Illegal verbosity level.
Try installing a more recent version of tex-chktex, and please open a bug report if the issue persists in the latest release. Thanks!
```
In my zsh shell, Output of `whereis xelatex` shows:
```
xelatex: /usr/bin/xelatex /home/sandip/texlive/2021/bin/x86_64-linux/xelatex
```
`echo $PATH` shows:
```
/home/sandip/.local/bin:/usr/local/bin:/usr/bin:/var/lib/snapd/snap/bin:/usr/local/sbin:/usr/lib/jvm/default/bin:/usr/bin/site_perl:/usr/bin/vendor_perl:/usr/bin/core_perl:/home/sandip/texlive/2021/bin/x86_64-linux/
```
In a terminal, if I run `~/texlive/2021/bin/x86_64-linux/xelatex test.tex` it compiles without error. But if I run `xelatex test.tex`, it produces an error.
So, I thought that the error is happening because emacs is looking at the files in /usr/bin whereas it should be looking at files in ~/texlive/2021/bin.
So, I tried the solution here. Now `M-x getenv PATH` shows:
```
/home/user/texlive/2021/bin/x86_64-linux:/home/sandip/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/bin:/usr/lib/jvm/default/bin:/usr/bin/site_perl:/usr/bin/vendor_perl:/usr/bin/core_perl:/var/lib/snapd/snap/bin:/home/sandip/texlive/2021/bin/x86_64-linux/
```
But the problem persists.
How do I tell emacs to look at the correct place?
# Answer
Make sure that your texlive installation directory comes first, both in `PATH` (presumably set in some shell initialization file) and also in `exec-path` which is what `emacs` uses to find executables. I'm pretty sure that at initialization, `exec-path` is set from `PATH`, but if you change the latter later, the change does not automatically propagate to `exec-path`. So you have to make sure that any changes to `PATH` are faithfully reflected in `exec-path` \- otherwise, you will get different versions of the program when you run it from a shell than when it gets executed in `emacs`, perhaps by AucTeX or something similar.
It is also true as @Rusi points out in a comment, that when you start emacs from a shell command line, you might get a different value of `PATH` than if you start it by clicking on a button in the DE. That's because `PATH` is passed from the parent process to the child process in the environment, so `emacs` might end up with different values of `PATH` when it is started from a shell than when it is started from the GUI.
The problem with the OP's (duct-tape as @Rusi called it) solution is that there are now *two* places where `PATH` needs to be set: once in the shell initialization file, so that the shell will pick up the right executable and once in the `emacs` initialization file so that `emacs` will do so. That's a recipe for future problems. It would be better to have a single place where `PATH` is defined, so that both the shell's environment *and* the GUI environment would be able to get it, so that when emacs is started (either way) from them, it would inherit the correct value of `PATH` without having to worry about it itself (N.B BTW that doing the `setenv` in the emacs init file is "wrong": when emacs is started from the shell, then the additional directory would be added to `PATH` twice: once when the shell is initialized and then once more when `emacs` is initialized. That should not cause problems in finding the correct executable but it is probably less efficient).
> 1 votes
---
Tags: latex, init-file, config, configuration-files
--- |
thread-68245 | https://emacs.stackexchange.com/questions/68245 | How to apply multiple actions to the same active region (using CUA-mode) | 2021-08-25T08:45:12.030 | # Question
Title: How to apply multiple actions to the same active region (using CUA-mode)
Imagine one wants to apply two functions (A and B, where A could be commenting the code with `M-;` and B convert the text to all-caps with `C-x C-u`) to the same active region. I would proceed as follows:
1. set the mark with `C-<SPC>`
2. move the cursor until the end of the region I want to modify
3. run function A
4. repeat 1. and 2.
5. run function B
How should I proceed to run both A and B (and potentially others) without repeating the selection step? It seems this behavior arises since most functions which work on an active region implicitly call `deactivate-mark` on completion.
---
The question above highlights one of the use cases described in this other post.
# Answer
At step 4, do `C-x C-x` (`exchange-point-and-mark`) which will reactivate the mark as it swaps point and mark (and so takes point back to where you started in Step 1).
> 3 votes
---
Tags: region, mark
--- |
thread-68246 | https://emacs.stackexchange.com/questions/68246 | Call random function from list | 2021-08-25T12:03:04.463 | # Question
Title: Call random function from list
I have a list of interactive functions and want to call a random one of them. In the end I expect to have a function that randomly changes the capitalization of the word at point (without moving the point).
I tried my best but did not get it to work.
### The functions
Here are three functions that change the word at point in different ways. (They might behave unexpectedly when point is at the beginning of the word, but we won't worry about that now)
```
(defun upcase-word-without-moving ()
"Convert the word at point to uppercase."
(interactive)
(save-excursion
(backward-word)
(upcase-word 1)
))
(defun downcase-word-without-moving ()
"Convert the word at point to lowercase."
(interactive)
(save-excursion
(backward-word)
(downcase-word 1)
))
(defun capitalize-word-without-moving ()
"Convert the word at point to be capitalized."
(interactive)
(save-excursion
(backward-word)
(capitalize-word 1)
))
```
### get a random element of a list
```
(defun random-element-of-list (items)
(let* ((size (length items))
(index (random size)))
(nth index items)))
```
I tried out this function and it works as expected:
```
(random-element-of-list '("a" "b" "c"))
(random-element-of-list '('upcase-word-without-moving 'downcase-word-without-moving 'capitalize-word-without-moving))
```
### Put it all together
That should be easy, right? Have a list of the functions, pick a random element of that list and call it as a function.
```
(defun change-capitalisation-of-word-1 ()
(interactive)
(funcall (random-element-of-list '('upcase-word-without-moving 'downcase-word-without-moving 'capitalize-word-without-moving)))
)
```
Trying this gives me one of three error messages:
* `Invalid function: 'upcase-word-without-moving`
* `Invalid function: 'downcase-word-without-moving`
* `Invalid function: 'capitalize-word-without-moving`
I don't understand why this is. The emacs-manual on invalid function is a bit heavy on the theory for a lisp-beginner. It also doesn't seem to offer a simple solution.
So I tried changing some things. For example I tried to bind the selected function to a variable:
```
(defun change-capitalisation-of-word-2 ()
(interactive)
(let ((fun-to-call (random-element-of-list '('upcase-word-without-moving 'downcase-word-without-moving 'capitalize-word-without-moving))))
(funcall fun-to-call)
)
)
```
This code has same problem with the same error messages.
I then tried to leave out the randomness and just use one of the three functions directly.
```
(defun change-capitalisation-of-word-3 ()
(interactive)
(let ((fun-to-call 'upcase-word-without-moving)) ;; constant
(funcall fun-to-call)
)
)
```
This works as expected (but obviously doesn't solve my problem, it is the random selection of the function that I am after).
So I would like to know:
* How I can make my function `change-capitalisation-of-word` work?
* Is there a fundamental mistake I made or a concept I was not aware of?
# Answer
> 3 votes
You have double-quoted your function symbols. The sexp `'(symbol1 symbol2)` is a list of two symbols: `symbol1` and `symbol2`. The sexp `'('symbol1 'symbol2)` is a list of two symbols `'symbol1` and `'symbol2`. Note that the error message you get, "Invalid function: 'upcase-word-without-moving" tells you that emacs is trying to call the function `'upcase-word-without-moving`, not `upcase-word-without-moving`.
---
Tags: quote
--- |
thread-68229 | https://emacs.stackexchange.com/questions/68229 | ido-find-file how to prevent `In this buffer, type RET to select the completion near point.` message to show up | 2021-08-23T20:56:31.053 | # Question
Title: ido-find-file how to prevent `In this buffer, type RET to select the completion near point.` message to show up
I keep seeing following at the top of the buffer when I do: `ido-find-file`.
```
In this buffer, type RET to select the completion near point.
Possible completions are:
```
Would it be possible to prevent this message to show up?
# Answer
This is controlled via the variable `completion-show-help`. Set that to `nil` and you won't see that message anymore.
> 1 votes
---
Tags: ido, ido-find-file
--- |
thread-68243 | https://emacs.stackexchange.com/questions/68243 | Who or what decides what gets put into `loaddefs.el`? | 2021-08-25T06:47:03.537 | # Question
Title: Who or what decides what gets put into `loaddefs.el`?
For context, I'm writing an extension.
I need to check if a particular symbol is an autoload symbol, such that `autoloadp` = `t`.
After doing some digging I found that the defined autoloads in `loaddefs.el` do not match up with every declared autoload in the repository.
Check these screenshots out for clarity:
---
---
---
As shown, symbol `org-capture-string` is declared to be an autoload, which is accurately reflected in the `loaddefs.el` file.
But symbols `orgtbl-exp-regexp` and `org-table-to-lisp` are also declared to be an autoload, which is inaccurately reflected in the `loaddefs.el` file, since they are no where to be found.
What gives?
# Answer
`loaddefs.el` is automatically generated at build time. See `src/Makefile.in` line 774 (in whatever version I happened to have checked out; it might be a different line in yours).
> 1 votes
# Answer
You'll find the org loaddefs in org-loaddefs.el, due to the file-local variable generated-autoload-file.
cl-macs is not a package, it is an internal component of cl-lib, which is in finder-inf.el.
> 1 votes
# Answer
In addition to what @db48x said, this is how it happens, and how you can yourself update `loaddefs.el` (or another file of autoloads). `C-h f batch-update-autoloads` tells us:
> **`batch-update-autoloads`** is an autoloaded Lisp function in `autoload.el`.
>
> `(batch-update-autoloads)`
>
> **Update `loaddefs.el` autoloads in batch mode.**
>
> Calls `update-directory-autoloads` on the command line arguments. Definitions are written to `generated-autoload-file` (which should be non-`nil`).
See also `update-directory-autoloads`, `update-file-autoloads`, and `w32-batch-update-autoloads`.
> 0 votes
---
Tags: autoload
--- |
thread-68254 | https://emacs.stackexchange.com/questions/68254 | Deleting words while preserving clipboard | 2021-08-25T16:32:03.947 | # Question
Title: Deleting words while preserving clipboard
Is there a way to keep the clipboard contents when deleting entire words with `M-DEL`?
For instance, I'd like to delete a word (`M-DEL`) and then paste (`C-y`) what I had previously copied (with `ctrl+c`) from a different application. Is this possible?
# Answer
> 2 votes
No. `M-DEL` is bound to the function `backward-kill-word`, which calls `kill-region`. Anything that calls `kill-region` puts the killed text into the `kill-ring`, and also into the system clipboard. This is what differentiates the “kill commands” from commands that merely delete text from the buffer.
You could call `delete-region` instead, or you could paste from the clipboard before killing any text.
I recommend the latter, though you may also want to know about the `exchange-point-and-mark` command. Yanking text will set the mark just before inserting the yanked text, so you can yank something, run `exchange-point-and-mark` (bound to `C-x C-x` by default) to go back to where you started, then call `backward-kill-word`. This should do what you want.
There is no `backward-delete-word`, but it is trivial to write it yourself if you really want it:
```
(defun backward-delete-word (arg)
"Delete characters backward until encountering the beginning of a word.
With argument ARG, do this that many times."
(interactive "p")
(delete-word (- arg)))
(defun delete-word (arg)
"Delete characters forward until encountering the end of a word.
With argument ARG, do this that many times."
(interactive "p")
(delete-region (point) (progn (forward-word arg) (point))))
```
# Answer
> 2 votes
In modern versions of Emacs, by default, `delete-backward-char` (`DEL`, i.e. `BackSpace`) deletes the region if it is active. So you can delete instead of killing by selecting, then pressing `DEL`. If you want `C-d` or `delete` (`Del`) to do that, bind them to `delete-forward-char` instead of the default `delete-char`.
If you enable `delete-selection-mode`, then most commands that insert something, including `yank`, delete the selection if it is active. This does what you want here, but may not be what you want in other circumstances.
Alternatively, call `rotate-yank-pointer` with the numeric argument 0 (i.e. `M-0 M-x r o - y RET` — you may need to type more characters depending on what other commands with a similar name are present in your Emacs instance). This saves the system clipboard in the kill ring. Then kill whatever you want (which clobbers the system clipboard), then access the next-to-last kill ring entry with `C-2 C-y` (`yank` with the numeric argument 2) or `C-y M-y` (`yank` then `yank-pop`).
---
Tags: copy-paste, clipboard, words, deletion
--- |
thread-68259 | https://emacs.stackexchange.com/questions/68259 | Is there a way to check if a symbol is a built-in variable? | 2021-08-25T22:45:01.787 | # Question
Title: Is there a way to check if a symbol is a built-in variable?
This is how you check if an object is a built-in function:
```
(subrp (symbol-function 'assoc))
=> t
```
Is there an equivalent way to do this for variables as well?
# Answer
> 0 votes
I assume that by "built-in" you mean a variable defined in C. This should do it:
```
(defun built-in-var-p (variable)
"Return non-nil if VARIABLE is defined in C source code."
(let ((file-name (find-lisp-object-file-name variable 'defvar)))
(and file-name (eq file-name 'C-source))))
```
---
Tags: variables, builtin
--- |
thread-45350 | https://emacs.stackexchange.com/questions/45350 | Cannot enable visual line mode globally | 2018-10-14T10:09:07.540 | # Question
Title: Cannot enable visual line mode globally
I would like `visual-line-mode` to be always on.
For this reason I put in the very end of my `init.el` file the following line of code `(global-visual-line-mode 1)` (as suggested here).
Anyway, the above code does not work and so. I still have to enable `visual-line-mode` for every buffer I need it.
How can I have it permanently on? Why is the above code not working?
# Answer
I have no experience with emacs.. I merely use it for just org mode. But I did manage to permanently enable visual-line mode (aka proper line wrapping) globally, here is what i did:
The website OP mentioned (http://ergoemacs.org/emacs/emacs\_long\_line\_wrap.html) instructs that the snippet
```
(global-visual-line-mode 1)
```
be written somewhere in the `.emacs` file (which is in the usually in `C:\Users\"your user name"\AppData\Roaming directory`). I don't know where exactly to put that snippet in `.emacs` file because, well, I am using Spacemacs so I edited the `.spacemacs` file. Towards the end of the text inside the `.spacemacs` file there is the following code, where I added the additional line `(global-visual-line-mode 1)` as shown:
```
(defun dotspacemacs/user-config ()
"Configuration function for user code.
This function is called at the very end of Spacemacs initialization after
layers configuration.
This is the place where most of your configurations should be done. Unless it is
explicitly specified that a variable should be set before a package is loaded,
you should place your code here."
(global-visual-line-mode 1))
```
> 1 votes
# Answer
All - I am new to EMACS but it is awesome. I have been adding things to my `~/.emacs` file I finally just put the `(global-linum-mode t)` and `(global-visual-line-mode 1)` at the top of the file and now it is working. I am on Linux Mint and have Emacs version 26.3. hope this helps
> 0 votes
---
Tags: init-file, visual-line-mode
--- |
thread-68264 | https://emacs.stackexchange.com/questions/68264 | How to get rid of "Compiling" message stuck on mode line? | 2021-08-26T05:32:14.630 | # Question
Title: How to get rid of "Compiling" message stuck on mode line?
For some reason it's always showing Compiling, even if there is no compilation.
*I found the answer, I post this question to record the solution for it*
# Answer
Set `compilation-in-progress` to `nil` to get rid of it:
```
(setq compilation-in-progress nil)
```
> 2 votes
---
Tags: mode-line
--- |
thread-68209 | https://emacs.stackexchange.com/questions/68209 | How to disable the buffer with completion options after hiting `tab` in Slime's REPL? | 2021-08-22T01:19:05.407 | # Question
Title: How to disable the buffer with completion options after hiting `tab` in Slime's REPL?
I have been using `company` for tab completion. It has been great while editing files.
Unfortunately, when I am using a buffer with the SLIME's REPL something annoying happens. As I start typing some function name, e.g.: `list-bookmarks`, Emacs creates a new buffer showing this info:
```
Click on a completion to select it.
In this buffer, type RET to select the completion near point.
Possible completions are:
list-bookmarks
list-bookmarks-after-hook
list-bookmarks-before-hook
```
Almost always, I will ignore this information. Thus, I would like to disable it.
I would like to have only `company` working on SLIME's REPL. It is already being shown in the status bar as an active mode.
Observation: this "problem" does **not** if I use `M-/`. It only happens if I use `tab`. Since I am a heavy user of `tab`, I would like to tweak it without chaning bindings on `M-\`·
My bet is that I need to disable some hook in my config. Is my instinct correct? What exactly should I do?
Thanks!
# Answer
There are lots of things to unpack here. Let me reframe what you're actually asking.
> I have been using company for tab completion.
You have been using *company for completion*. Company-mode is a minor mode. It can be enabled locally or globally. You don't press any key for the completion to start. You simply wait `company-idle-delay` seconds, and it starts completing (i.e. the drop-down menu appears). Notice, however, that there's a `company-active-map`. That's a set of keybindings enabled IF AND ONLY IF the completion has already started. Indeed, (by default) hitting `TAB` runs `company-complete-common`. Let me make this clear: hitting `TAB` BEFORE the completion runs `completion-at-point`, i.e. the built-in (extremely powerful and underrated) Emacs completion system.
Although company is part of emacs, there's no documentation (afaik). How did I study it? By reading the source code. If you're unsure where to start: visit its homepage; `M-x find-library RET company RET`; `C-h f company-mode RET`.
Now it should be clear that what you're really asking is: is there a way to disable the built-in Emacs completion? Well, yes. Do you really need that? No. Don't hit `TAB` before company starts doing its thing. If you'd like it to start faster, tweak `company-idle-delay`.
Notice that you don't need to use `M-/` when `company-mode` is active. What `M-/` suggests is part of company's completion. In proper terms, `dabbrev` is a company backend by default.
> 1 votes
---
Tags: auto-complete-mode, slime
--- |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.