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-633
|
https://emacs.stackexchange.com/questions/633
|
How to run a previous command in an Emacs shell?
|
2014-10-02T22:57:44.003
|
# Question
Title: How to run a previous command in an Emacs shell?
Of course when I am in Terminal and I press the up arrow key, it goes to the previous command. However, when I hit the `M-x` keys and type `shell` an integrated shell comes up in Emacs:
However, if I type a command and press up, this happens:
How do I get back to the last command I typed?
# Answer
The function that *cycles backwards through input history, saving input.* is `comint-previous-input`
It is bound to `C-up`, `M-p`.
> 23 votes
# Answer
Just found an answer on Super User:
How do you run the previous command in emacs shell?
`M-p` goes to the previous command.
> 7 votes
# Answer
You could use helm-eshell-history for interactive history selection, and replace the original `C-c C-l`:
```
(require 'helm-eshell)
(add-hook 'eshell-mode-hook
#'(lambda ()
(define-key eshell-mode-map (kbd "M-l") 'helm-eshell-history)))
;; for shell-mode
(define-key shell-mode-map (kbd "C-c C-l") 'helm-comint-input-ring)
```
> 5 votes
# Answer
My favorite commands for cycling through shell command history are `comint-previous-matching-input-from-input` and `comint-next-matching-input-from-input`. If the prompt is empty, they will behave exactly like `comint-previous-input` and `comint-next-input` cycling through all history items. Though if you have entered `rake`, for example, they will cycle through your shell command history of commands starting with `rake`.
By default these are bound to `C-c M-r` and `C-c M-s` respectively, but I find those not ideal. I'm personally binding them to `M-TAB` and `<M-S-tab>`.
> 3 votes
# Answer
Things have changed in Eshell a little.
The module `em-hist.el` is implemented based on the minor mode `eshell-hist-mode` since commit 1ee0192b79 in the Emacs git-repro. Currently, this commit is only in the `master` branch of Emacs (i.e., `28.0` as of today). It has been reverted in the Emacs `27.1` by the commit 478638e470 because of Bug#41370.
So here is my updated working solution for using helm-eshell-history
```
(use-package eshell
:config
(require 'em-hist)
(use-package eshell-git-prompt
:config
;; the powerline prompt is best but I've no idea how to shorten it to the last directory.
(eshell-git-prompt-use-theme 'powerline)
(define-advice eshell-git-prompt-powerline-dir (:override () short)
"Show only last directory."
(file-name-nondirectory (directory-file-name default-directory))))
:bind (:map eshell-hist-mode-map
;; ("<down>" . 'next-line)
;; ("<up>" . 'previous-line)
;; ([remap eshell-previous-matching-input-from-input] . helm-eshell-history)
([remap eshell-list-history] . helm-eshell-history)
))
```
> 2 votes
# Answer
Another possibility, if you use **Icicles**: Use `C-c TAB` (command `icicle-comint-command`) to choose a previously entered command with completion (or cycling).
> 1 votes
---
Tags: eshell
---
|
thread-54619
|
https://emacs.stackexchange.com/questions/54619
|
Skip flyspell checking of ~code~ and =verbatim= regions in Org mode
|
2020-01-01T21:41:32.833
|
# Question
Title: Skip flyspell checking of ~code~ and =verbatim= regions in Org mode
First some disambiguation:
* This Endless Parentheses page demonstrates how to use `ispell-skip-region-alist` to skip `=code=` and `=verbatim=` blocks with ispell…
```
(defun endless/org-ispell ()
"Configure `ispell-skip-region-alist' for `org-mode'."
(make-local-variable 'ispell-skip-region-alist)
(add-to-list 'ispell-skip-region-alist '(org-property-drawer-re))
(add-to-list 'ispell-skip-region-alist '("~" "~"))
(add-to-list 'ispell-skip-region-alist '("=" "="))
(add-to-list 'ispell-skip-region-alist '("^#\\+BEGIN_SRC" . "^#\\+END_SRC")))
(add-hook 'org-mode-hook #'endless/org-ispell)
```
…however, `flyspell` does not use `ispell-skip-region-alist`.
* This question on Emacs SX demonstrates how to skip flyspell checking for source blocks…
```
;; NO spell check for embedded snippets
(defadvice org-mode-flyspell-verify (after org-mode-flyspell-verify-hack activate)
(let* ((rlt ad-return-value)
(begin-regexp "^[ \t]*#\\+begin_\\(src\\|html\\|latex\\|example\\|quote\\)")
(end-regexp "^[ \t]*#\\+end_\\(src\\|html\\|latex\\|example\\|quote\\)")
(case-fold-search t)
b e)
(when ad-return-value
(save-excursion
(setq b (re-search-backward begin-regexp nil t))
(if b (setq e (re-search-forward end-regexp nil t))))
(if (and b e (< (point) e)) (setq rlt nil)))
(setq ad-return-value rlt)))
```
…but not for inline code and verbatim region.
How can I achieve the `ispell` solution for `flyspell`, where Flyspell skips any regions surrounded by `~` or `=`? Generally I use these for things like variable names, which naturally tend to fail spellchecking.
# Answer
> 3 votes
It looks like this works out-of-the box with Emacs 26.3 and Orgmode 9.1.9. Source blocks and code snippets are not highlighted by `flyspell` with that Orgmode version. Maybe, you should just update.
To address the general problem:
You can ignore corrections proposed by flyspell by adding a function to `flyspell-incorrect-hook`. This hook already exists since Emacs 21.1. So it should be available even if you use an Emacs that old (for whatever reason).
I cite here the doc-string of `flyspell-incorrect-hook`:
> List of functions to be called when incorrect words are encountered. Each function is given three arguments. The first two arguments are the beginning and the end of the incorrect region. The third is either the symbol ‘doublon’ or the list of possible corrections as returned by ‘ispell-parse-output’.
>
> If any of the functions return non-nil, the word is not highlighted as incorrect.
It is easy to detect source blocks and code snippets with `org-element-context`.
Here comes the code that skips flyspell on source blocks and code snippets:
```
(defun org+-flyspell-skip-code (b e _ignored)
"Returns non-nil if current word is code.
This function is intended for `flyspell-incorrect-hook'."
(save-excursion
(goto-char b)
(memq (org-element-type (org-element-context))
'(code src-block))))
(defun org+-config-flyspell ()
"Configure flyspell for org-mode."
(add-hook 'flyspell-incorrect-hook #'org+-flyspell-skip-code nil t))
(add-hook 'org-mode-hook #'org+-config-flyspell)
```
Tested on Emacs 26.3.
# Answer
> 1 votes
Check the current font face at point, if it's `org-verbatim` or `org-code`, then set the predicate's return value to nil. So Emacs knows the word at point is NOT a typo.
Here is the function to test font face at point,
```
(defun font-belongs-to (pos fonts)
"Current font at POS belongs to FONTS."
(let* ((fontfaces (get-text-property pos 'face)))
(when (not (listp fontfaces))
(setf fontfaces (list fontfaces)))
(delq nil
(mapcar (lambda (f)
(member f fonts))
fontfaces))))
```
To use this function, in https://emacs.stackexchange.com/a/9347/594 code, just below `(when ad-return-value`, insert one line,
```
(if (font-belongs-to (point) '(org-verbatim org-code)) (setq rlt nil))
```
BTW, you can check my org setup at https://github.com/redguardtoo/emacs.d/blob/98bef295ac515e5af43716d72a377494646653bf/lisp/init-org.el#L120 . The predicate there has more features and its code is more efficient.
**Please note `flyspell-incorrect-hook` is NOT the right place for per mode setup.** I explain the details in https://emacs.stackexchange.com/a/9347/594
---
Tags: org-mode, flyspell, spell-checking
---
|
thread-54900
|
https://emacs.stackexchange.com/questions/54900
|
Org-mode: use result from babel in another programming language
|
2020-01-14T01:01:56.650
|
# Question
Title: Org-mode: use result from babel in another programming language
Org and babel in emacs are awesome. Is it possible to have something like this:
Here is a C code
```
#+BEGIN_SRC C :output results
#include <stdio.h>
int main(){
int x = 5.00;
int i;
for (i = 0; i < 5; ++i) {
x = x+1;
}
printf("X = %d", x);
return 0;
}
#+END_SRC
```
Then I would like to use this X in another programming environment, say Python and do something else with this X.
```
#+BEGIN_SRC python :output resultPython
print(x+2)
#+END_SRC
```
It is not as simple as just directly use the variable X. Is it possible to do this in Babel?
# Answer
> 4 votes
That is one of the main pillars of babel.
Give the C source block a name if you want to use in the variable assignments of another source block.
You input the result of the C source block to another source block by the `:var` header argument.
The python source blocks are described at https://orgmode.org/worg/org-contrib/babel/languages/ob-doc-python.html. The output of a non-session python block is its `return` value.
```
#+NAME: myCSrcBlock
#+BEGIN_SRC C
#include <stdio.h>
int main(){
int x = 5.00;
int i;
for (i = 0; i < 5; ++i) {
x = x+1;
}
printf("%d", x);
return 0;
}
#+END_SRC
#+RESULTS: myCSrcBlock
: 10
#+RESULTS:
: X = 10
Then I would like to use this X in another programming environment, say Python and do something else with this X.
#+BEGIN_SRC python :var x=myCSrcBlock
return x+2;
#+END_SRC
#+RESULTS:
: 12
```
---
Tags: org-mode, org-babel
---
|
thread-4089
|
https://emacs.stackexchange.com/questions/4089
|
Can I configure eww to use pdf-view-mode (from pdf-tools) for PDFs instead of DocView?
|
2014-12-03T18:17:20.480
|
# Question
Title: Can I configure eww to use pdf-view-mode (from pdf-tools) for PDFs instead of DocView?
I use pdf-tools to read PDFs inside of Emacs and greatly prefer it to DocView. I just noticed that when I try to open a URL thar points to a PDF in eww, it uses DocView instead of the pdf-view-mode from pdf-tools. This is particularly annoying since DocView fails to display the PDF! Switching the buffer to pdf-view-mode manually then succesfully shows it. Can I configure things so that eww uses pdf-view-mode on the first try?
# Answer
> 7 votes
**Warning: dirty work-around ahead**
Since you "*greatly prefer \[pdf-tools\] to DocView*", is it safe to assume that using it to view all pdfs is acceptable?
The following code snippet will switch the document to `pdf-view-mode` anytime `doc-view`is entered with a `pdf` document.
```
(defvar tv/prefer-pdf-tools (fboundp 'pdf-view-mode))
(defun tv/start-pdf-tools-if-pdf ()
(when (and tv/prefer-pdf-tools
(eq doc-view-doc-type 'pdf))
(pdf-view-mode)))
(add-hook 'doc-view-mode-hook 'tv/start-pdf-tools-if-pdf)
```
The behavior can be enabled or disabled by `setq`-ing the variable `tv/prefer-pdf-tools` to t or nil.
# Answer
> 3 votes
You can use an advise around `eww-display-pdf` to override the definition of `doc-view-mode` temporarily. With the new `nadvice` library this is as easy as:
```
(advice-add 'eww-display-pdf
:around (lambda (orig &rest args)
(cl-letf (((symbol-function 'doc-view-mode) #'pdf-view-mode))
(apply orig args)))
'((name . eww-display-pdf-tools)))
```
To revert back to the original `doc-view-mode`, use `(advice-remove 'eww-display-pdf 'eww-display-pdf-tools)`.
I have opened Emacs bug 19270 to make the EWW PDF Mode customizable.
# Answer
> 1 votes
I use emacs-28, eww use mailcap to open pdf, custom it by open with pdf-tools:
```
(add-to-list 'mailcap-user-mime-data
'((type . "application/pdf")
(viewer . pdf-view-mode)))
```
See Emacs - Help - pdf viewer for more information.
---
Tags: eww, pdf
---
|
thread-52679
|
https://emacs.stackexchange.com/questions/52679
|
image-dired: Change thickness of cursor
|
2019-09-16T10:38:52.203
|
# Question
Title: image-dired: Change thickness of cursor
On a hires screen I find it really hard to see on which image the cursor currently is, because the rectangle around the image is very thin. *Is it possible to increase the line width of that rectangle?*
Already I looked through customization options, through `image-dired.el`, and using `what-cursor-position` I inspected what’s at on cursor position, all to no avail.
# Answer
> 1 votes
You might try customizing one or both of these image-dired options (the text is what you get with `C-h v`).
* **`image-dired-thumb-relief`** \- Size of button-like border around thumbnails.
* **`image-dired-thumb-margin`** \- Size of the margin around thumbnails. This is where you see the cursor.
There are many other image-dired options, some of which might also help you more easily see which choice is currently selected. Use `M-x customize-group RET image-dired RET` to see them all.
# Answer
> 0 votes
I agree with @feklee that this is a major problem for those who use Image-Dired. Finding the selected icon is like looking for a needle in a haystack. The solution provided by @Drew helps. My pragmatic solution is to hit RET and then DEL as I look for the thumbnail. The movement allows my eyes to find the right image.
---
Tags: dired, faces, images, style, image-dired
---
|
thread-54863
|
https://emacs.stackexchange.com/questions/54863
|
org-agenda not showing missed deadlines
|
2020-01-12T10:38:36.197
|
# Question
Title: org-agenda not showing missed deadlines
today I have to ask the community for some help. I used my `org-agenda` for a few years now. But since a few month my missed deadlines wont be shown in weekly agenda. Maybe I miss-configured something during continues cleanup but I dont find a bad configuration.
I already tried a clean only `org-mode` installed config but it also does not work, no warnings of missed deadlines :-(
Documentation for deadlines writes "*In addition, the agenda for today will carry a warning about the approaching or missed deadline, starting org-deadline-warning-days before the due date, and continuing until the entry is marked DONE.*" So actually no magic.
My Emacs-Version: GNU Emacs 26.3
My Org-Version: 9.3.1
My org-mode config:
```
(use-package
org
:mode
("\\.org\\'" . org-mode)
:commands
(org-agenda
org-capture-todo
org-capture-todo-context
org-capture-journal
org-capture-calendar)
:config
(setq
org-gtd-directory "~/.gtd/"
;; org-gtd-todos-file (expand-file-name "todos.org" org-gtd-directory)
;; org-gtd-journal-file (expand-file-name "journal.org" org-gtd-directory)
org-gtd-todos-file (expand-file-name "gtd.org" org-gtd-directory)
org-gtd-journal-file (expand-file-name "gtd.org" org-gtd-directory))
(setq
org-startup-indented t
org-M-RET-may-split-line t
org-default-notes-file org-gtd-todos-file
org-outline-path-complete-in-steps nil
org-refile-use-outline-path t
org-blank-before-new-entry '((heading . nil) (plain-list-item . nil))
org-agenda-files (list org-gtd-todos-file)
org-todo-keywords '((sequence "TODO(t)" "STARTED(s)" "BLOCKED(b)" "|" "DONE(d)" "DELEGATED(g)" "CANCELED(c)"))
org-tag-alist '(;; For exclusiv groups
;; (:startgroup . nil)
;; ("@work" . ?w) ("@home" . ?h)
;; ("@tennisclub" . ?t)
;; (:endgroup . nil)
("GENERAL" . ?g) ("EMACS" . ?e))
org-refile-targets '((org-agenda-files :maxlevel . 5)))
(setq
org-capture-templates
'(("t" "Todo (without context)" entry (file+headline org-gtd-todos-file "Inbox")
"* TODO %? %i %^g\n:PROPERTIES:\n:ADDED: %U\n:CONTEXT:\n:DEADLINE: %^t\n:END:")
("T" "Todo (with context)" entry (file+headline org-gtd-todos-file "Inbox")
"* TODO %? %i %^g\n:PROPERTIES:\n:ADDED: %U\n:CONTEXT: %a\n:DEADLINE: %^t\n:END:")
("j" "Journal" entry (file+headline org-gtd-journal-file "Journal")
"* %? %i %^g\n:PROPERTIES:\n:ADDED: %U\n:CONTEXT: %a\n:END:")
("c" "Calendar" entry (file+headline org-gtd-todos-file "Calendar")
"* TODO %? %i %^g\n:PROPERTIES:\n:ADDED: %U\n:CONTEXT: %a\n:SCHEDULED: %^T\n:DEADLINE: %^t\n:END:")))
(defun org-capture-todo ()
(interactive)
(org-capture nil "t"))
(defun org-capture-todo-context ()
(interactive)
(org-capture nil "T"))
(defun org-capture-journal ()
(interactive)
(org-capture nil "j"))
(defun org-capture-calendar ()
(interactive)
(org-capture nil "c"))
:bind*
(("C-M-- <RET>" . org-capture)
("C-M-- t" . org-capture-todo)
("C-M-- T" . org-capture-todo-context)
("C-M-- j" . org-capture-journal)
("C-M-- c" . org-capture-calendar)
("C-M-- a" . org-agenda)))
```
My example org-file:
```
* TODO TEST A :GENERAL:
:PROPERTIES:
:ADDED: [2020-01-05 Sun 16:47]
:DEADLINE: <2020-01-08 Wed>
:END:
* TODO TEST B :GENERAL:
:PROPERTIES:
:ADDED: [2020-01-05 Sun 16:47]
:DEADLINE: <2020-01-16 Thu>
:END:
```
My agenda output:
```
Week-agenda (W03):
Monday 13 January 2020 W03
Tuesday 14 January 2020
Wednesday 15 January 2020
Thursday 16 January 2020
gtd: TODO TEST B :GENERAL:
Friday 17 January 2020
Saturday 18 January 2020
Sunday 19 January 2020
```
Expectation: TEST A schould be shown as missed deadlined task.
Any ideas what I missed, hopefully someone can help me, thx.
# Answer
You are setting your deadline incorrectly. The normal way of setting a deadline is as follows:
```
* MY-TEST :GENERAL:
DEADLINE: <2020-01-13 Mon>
```
Your entry should thus look like this:
```
* TODO TEST :GENERAL:
DEADLINE: <2020-01-13 Fri>
:PROPERTIES:
:ADDED: [2020-01-14 Tue 16:47]
:END:
```
DEADLINE is not an ordinary org property.
> 3 votes
---
Tags: org-mode, org-agenda
---
|
thread-54916
|
https://emacs.stackexchange.com/questions/54916
|
Org is implemented on top of Outline mode
|
2020-01-14T15:31:25.573
|
# Question
Title: Org is implemented on top of Outline mode
Org manual states in its beginning
> Org is implemented on top of Outline mode, which makes it possible to keep the content of large files well structured.
I referenced 'outline-mode' by C-h f outline-mode, and curious about :
Is outline-mode is part of org, which was written by org team?
or it a emacs-builtin before Org?
How could I check it?
# Answer
> 8 votes
One option is to check the source.
`M-x find-library outline`
You'll find in the header comments:
> ;; Copyright (C) 1986, 1993-1995, 1997, 2000-2019 Free Software Foundation, Inc.
>
> ;; This file is part of GNU Emacs.
`M-x find-library org`
> ;; Copyright (C) 2004-2019 Free Software Foundation, Inc.
>
> ;; This file is part of GNU Emacs.
So, both are included with Emacs but outline-mode predates org-mode.
Poking further you can see that org-mode is actually implemented as a derived mode of outline:
> (define-derived-mode org-mode outline-mode "Org" ...
---
Tags: org-mode, outline
---
|
thread-54902
|
https://emacs.stackexchange.com/questions/54902
|
How to get date+interval? (revisited)
|
2020-01-14T02:06:26.240
|
# Question
Title: How to get date+interval? (revisited)
I have a deadline that is some date *in the past*(such as 12/26/2019) + interval (e.g. 15d). How would I get it in Emacs? In a previous post under the same title I posted *an example* with interval = the sum of the two subintervals (15d+1m). Someone answered that would have to be a feature request, but was able to do it with only one interval. Actually, that is all I need, but still don't know how to do it. Would someone be so kind as to give a step by step instruction to do it?
Bottom line: how to get '12/26/2019+15d'?
# Answer
> 0 votes
Given a timestamp of `2019-12-12`, you can specify `++15d` (note the double plus) to move forward to `2019-12-27`, then you can specify `++1m` to move forward to `2020-01-27`. See the section of the manual entitled The date/time prompt:
> With a single plus or minus, the date is always relative to today. With a double plus or minus, it is relative to the default date.
EDIT: Here's a more detailed workflow. The simplest method I know to do what you want is to use the date/time prompt and select your initial date from the calendar: e.g. for a SCHEDULE: date, say `C-c C-s` and click on 2019-12-12. That makes 2019-12-12 the default date, so you can say `C-c C-s` again and type `++15d` at the date/time prompt: that gets you to 2019-12-27 which is now the new default date. So you can do `C-c C-s` one more time and say `++1m` at the prompt to get you to 2020-01-27. Does that help?
Note that with `C-c .`, every time you modify the date, the cursor ends up *after* the date, so if you do it again, you end up with a date range. Just move the cursor back *into* the date before repeating it and you will not get a second date.
---
Tags: org-mode, calendar
---
|
thread-54912
|
https://emacs.stackexchange.com/questions/54912
|
How to cancel the minibuffer with M-x
|
2020-01-14T13:47:21.317
|
# Question
Title: How to cancel the minibuffer with M-x
I have M-x (and also my menu key) mapped to the command helm-M-x.
How to write an elisp function or how to configure emacs so that M-x (and the menu key) performs as C-g when the minibuffer is open.
the goal is then to make M-x (and the menu key) a toggle on/off feature.
# Answer
> 3 votes
For reasons @Drew pointed out, this is not necessarily a good idea. However, if you really want to do it, you can simply bind `exit-minibuffer` to `M-x` in the `minibuffer-local-map` which is the keymap used when in the minibuffer.
You can find information on minibuffer key maps here: https://www.gnu.org/software/emacs/manual/html\_node/emacs/Minibuffer-Maps.html
```
(define-key minibuffer-local-map (kbd "M-x") 'exit-minibuffer)
```
---
Tags: key-bindings, minibuffer
---
|
thread-54920
|
https://emacs.stackexchange.com/questions/54920
|
How can a list of fields be colored with different colors?
|
2020-01-14T18:42:36.630
|
# Question
Title: How can a list of fields be colored with different colors?
Here's a line from an SQL dump with randomized contents:
```
REPLACE INTO `drxneuleqtx` (`qd`, `mva`, `cuqtgwm`, `vatoj`, `mrfdgnaheui`, `pacc`, `aaqfjhkv`, `epue`, `kvaerg`, `xevtan`, `vmvwwgci`, `hhgvedhjv`, `omndbwf`, `butbjsjrey`, `nwyxtnox`, `aslfh`, `wvtkpyn`, `ywidifrf`, `uxvjfpamlhoa`, `qfmlpisc`, `hlpgj`, `hioplo`, `gebqth`, `bovhklyrphx`, `dijqxqxodwr`, `rdqynsve`, `loxcqfybkdm`, `sakpxfsyqkwi`, `pfypefxwfp`, `exuqiufco`, `kdprjngn`, `bnjfdcws`, `vumrbkeh`, `avgamdde`, `ceewufkv`, `xtvikcuw`, `jeswerey`, `ygqhghq`, `svygrhkw`)
VALUES (506,'xyjnm','rsrongvucegfcbnpqplcdbfef','kcgottkurypcathxiqte','tctwpmfwkhqojyatkrfbmwvsd',3094,NULL,56806,149,NULL,18.258930,10.362209,0,9,NULL,NULL,NULL,0,0,0,NULL,488,-422,0,0,NULL,NULL,NULL,0,NULL,'lbwyshaxdtpmvbkggwreaaqd','xiyunrgjvgxgwvmyhuuunjfr','wbkyuwaykgostnowratnjmov','mjxgjnbvadhckdmonouhkwgm','wefcoaehlbinlhejgjstfwtk','fnodw','chotb',NULL,'oqidxyqfhtksxbvmstiqlsgayntgveyymrdpbybdstdehhmyircimpexwoqaimrveuwtbvbxcqebgcpfandjpnoevsdkboqyrdxhjylfrrqakcfkwdhiovlensossbttufhvmyxugixmkcgwpvjddcgpdwmytmuhju');
```
As you can see the first line lists the field names and the VALUES line lists the values for the relevant fields, **but I only used two lines here for easier explanation, in the dump file the two lines above are on a single line**.
For easier reading of the dump I'd like it to be automatically colored when the dump file is opened, so that each field name has a different background color and each value has a different background color, but the value and the corresponding field has the same background color.
Note that the number of fields/values can change, depending on the database dump, so it's not fixed. Also, the string values are delimited with single quotes, but the strings can contain single quotes, in which case they are escaped with a backslash: `'stu\'ff'`
What is the simplest way to implement this?
# Answer
> 2 votes
First, define a major mode that treats single quotes like string delimiters, and backslash as escape character.
Secondly, define font-lock rules for REPLACE INTO and VALUES. You can use a so-called "anchored" rule (a two-layer rule) where the outer rule match the keyword and the inner each string. The inner rule decide which color to use for the strings, which is a generic lisp expression, so you can iterate over a list of predefined colors.
Having said this, font-lock rules are hard to get right. Start by looking at similar code and use good tools, like font-lock-studio. A good starting point is a presentation I held some years ago, font-lock-introduction, at an Emacs meetup in Stockholm.
---
Tags: font-lock
---
|
thread-54925
|
https://emacs.stackexchange.com/questions/54925
|
Source file ‘c:/Users/.../AppData/Local/emacs-26.1-x86_64/share/emacs/26.1/lisp/progmodes/python.el’ newer than byte-compiled file
|
2020-01-15T02:26:45.210
|
# Question
Title: Source file ‘c:/Users/.../AppData/Local/emacs-26.1-x86_64/share/emacs/26.1/lisp/progmodes/python.el’ newer than byte-compiled file
this message shows up on Emacs startup. what does it mean and how to get rid of it?
`Source file ‘c:/Users/jcao/AppData/Local/emacs-26.1-x86_64/share/emacs/26.1/lisp/progmodes/python.el’ newer than byte-compiled file`
btw, my setting folder is `C:\Users\...\AppData\Roaming\.emacs.d` and I recently made some changes there.
# Answer
In general, such a message appears when a user modifies a Lisp file after it has been byte-compiled. There might be as many as three types of files relating to the same library; e.g., `python.el.gz` (compressed archive), `python.el` (flat text file) and `python.elc` (byte-compiled file). Perhaps a user visits a library to look at how a function or variable is defined (e.g., with `find-library`, `find-function`, `find-variable`, `find-face`, etc.) and inadvertently modifies and saves the file.
If the modifications to the library are desired, then go ahead and re-byte-compile the file with `M-x byte-compile-file` and type in the absolute path to the file. Another way to accomplish this is to visit the directory in `dired-mode`, place the cursor on the file to be byte-compiled, and press the capital letter "B" which is bound to `dired-do-byte-compile`.
If the modifications to the library are *not* desired, then restore the original \*.el file by extracting a new one from the zipped archive, or obtaining the original from the source files used to build the executable. If the \*.el file is newer than the \*.elc file, then re-byte-compile as indicated above.
There are other likely reasons such a inadvertently touching the file with something like the `touch` command ... if no revisions to the file, then just re-byte-compile as indicated above.
> 1 votes
---
Tags: byte-compilation
---
|
thread-54887
|
https://emacs.stackexchange.com/questions/54887
|
make company-backends work in lisp files
|
2020-01-13T12:37:36.703
|
# Question
Title: make company-backends work in lisp files
I have a running Emacs on my gentoo, with doom configuration (with evil mode disabled). It works great. One issue i want to solve...
Some company-backends - for example like `company-files` in Lisp files, do not work.
When I run Emacs and try to enter a path to a load function - nothing happens. If I do `eval-buffer` on the file that I have the `company-backends` settings - it starts to work. So it seems that that piece of code runs too late.
Here's what i do: On my `.doom.d/config.el` file I load my custom el file. in that file I do
```
(after! company (setq company-backend '(company-files company-capf)) )
```
I also tried to add `(setq company-backends '(company-files))` to the `config.el` file.
None of the above worked.
# Answer
> 0 votes
Doom has its own function **`set-company-backend!`** to set the backends:
```
(defun set-company-backend! (modes &rest backends)
"Prepends BACKENDS (in order) to `company-backends' in MODES.
MODES should be one symbol or a list of them, representing major or minor modes.
This will overwrite backends for MODES on consecutive uses.
If the car of BACKENDS is nil, unset the backends for MODES.
Examples:
(set-company-backend! 'js2-mode
'company-tide 'company-yasnippet)
...
```
You can also change the default backends used. They are defined in `+company-backend-alist`:
```
(defvar +company-backend-alist
'((text-mode company-dabbrev company-yasnippet company-ispell)
(prog-mode company-capf company-yasnippet)
(conf-mode company-capf company-dabbrev-code company-yasnippet))
"An alist matching modes to company backends. The backends for any mode is
built from this.")
```
Those variables and functions are defined in https://github.com/hlissner/doom-emacs/blob/develop/modules/completion/company/autoload.el.
---
Tags: company-mode
---
|
thread-54896
|
https://emacs.stackexchange.com/questions/54896
|
Org entry found only from its own buffer
|
2020-01-13T22:19:59.157
|
# Question
Title: Org entry found only from its own buffer
I tried to detangle (`org-babel-detangle`) a latex file and got the error message
> Cannot find entry with ID "......."
with the ID of the subtree of the first block. But the entry does exist in the original org file. What's more puzzling is that this happens on one machine and not on another, with exactly the same files.
Moreover, if I minimalize the file, the problem persists, but, if I create a new file with the same structure, detangling works as expected.
Also, if evaluate `(org-id-find '452031425...)` in the org buffer, the entry is found, but, if I evaluate the same expression in the tangled buffer, it returns `nil`. What am I missing?
# Answer
> -1 votes
When first using an org file on a new system, containing IDs one wishes to track, one must evaluate
```
(org-id-update-id-locations '("file.org"))
```
---
Tags: org-babel
---
|
thread-54932
|
https://emacs.stackexchange.com/questions/54932
|
Is there a way to add some margin/padding above a line?
|
2020-01-15T16:08:08.623
|
# Question
Title: Is there a way to add some margin/padding above a line?
For example I have this text in a buffer:
```
aaa
bbb
ccc
```
and I want it displayed with some spacing above the bbb line:
```
aaa
bbb
ccc
```
Is there a face or something which I could add to the bbb line, so it has some margin above it (without modyfing the buffer contents, so not with a newline like here, which I added only for demonstration purposes).
# Answer
> 1 votes
I found a solution which is bit hackish, but not too much. I find the first space in the line and set it to a larger height. The line in my case always have a space somewhere (and it's generally true usually), the bigger height space forces the line height to be bigger which is effectively a top margin:
```
(let ((pos (1- (save-excursion (beginning-of-line) (search-forward " ")))))
(put-text-property pos (1+ pos) 'display '(height 1.5)))
```
In the comments @rpluim suggested an even simpler alternative: putting the text property on the newline, but note that this method does not work well if the line is long and spans multiple visual lines.
```
(put-text-property (line-end-position) (1+ (line-end-position)) 'display '(height 1.5))
```
---
Tags: text-properties
---
|
thread-54937
|
https://emacs.stackexchange.com/questions/54937
|
split every single org headline in a org file to separate md/org files
|
2020-01-15T22:47:28.580
|
# Question
Title: split every single org headline in a org file to separate md/org files
I want to be able to create a function that splits or exports **every** single headline in a org mode file (recursively) into a separate file.
Ideally that would be a .md file but I can also live with a .org file
Does anyone have any examples on how to achieve this? Previous answers found here/org forums were focused only on top level headers and had issues with looping over the file.
to illustrate this org file:
```
* Title of Heading 1
Text 1
** Sub-Heading 2
Text 2
* Title of Heading 2
Text 3
```
would result in the files
```
Title of Heading 1.md
Sub-Heading 2.md
Title for Heading 2.md
```
# Answer
> 9 votes
If a region is active `org-md-export-as-markdown` exports the region only.
So we have to
* loop through each headline
* set the active region
* export the region to a markdown buffer
* and finally use the title to save it
```
(defun my-org-export-each-headline-to-markdown (&optional max-level scope)
"Export each headline in the current buffer to a separate markdown file.
The title of each headline is used as the filename. Existing
files are overwritten.
With a prefix argument MAX-LEVEL, only headlines up to the specified level will
be exported.
If SCOPE is nil, the export will be performed on the entire buffer.
For other valid values of SCOPE, refer to `org-map-entries'."
(interactive "P")
(when max-level (setq max-level (format "LEVEL<=%s" max-level)))
;; Widen buffer temporarily as narrowing would affect the exporting.
(save-window-excursion
(org-with-wide-buffer
(save-mark-and-excursion
;; Loop through each headline.
(org-map-entries
(lambda ()
;; Get the plain headline text without statistics and make filename.
(let* ((title (car (last (org-get-outline-path t))))
(dir (file-name-directory buffer-file-name))
(filename (concat dir title ".md")))
;; Set the active region.
(set-mark (point))
(outline-next-preface)
(activate-mark)
;; Export the region to a markdown file.
(with-current-buffer (org-md-export-as-markdown)
;; Save the buffer to file and kill it.
(write-file filename)
(kill-current-buffer))))
max-level scope)))))
```
Then use `M-x my-org-export-each-headline-to-markdown` to export the headlines of the current buffer. If you want to export headlines up to a certain level call it with a prefix arg `C-u 1 M-x my-org-export-each-headline-to-markdown`.
You probably want to add this to the top of your org file to not get a table of contents:
```
#+OPTIONS: toc:nil
```
---
Tags: org-mode, org-export
---
|
thread-54763
|
https://emacs.stackexchange.com/questions/54763
|
Org Mobile staging area with a WebDAV: Unable to set 'org-mobile-directory' with TRAMP
|
2020-01-08T08:38:51.133
|
# Question
Title: Org Mobile staging area with a WebDAV: Unable to set 'org-mobile-directory' with TRAMP
I have a working Owncloud server, and I would like to use Org Mobile to sync my Org files with my phone.
Following "Setting up the staging area" in the info doc for Org Mobile, I have customized the variable `org-mobile-directory` to the directory where I want my files to be stored on the server. I have now the following in my `~/.emacs`:
```
'(org-mobile-directory
"/davs:MyUserName@MyIPaddress:/owncloud/remote.php/webdav/MyRemotePath/")
```
This syntax for the remote directory is what I understood from the TRAMP info docs.
When I run `org-mobile-push`, then after an expected message showing me the good certificate for my cloud and asking me if I am sure to connect, I always get "`Variable 'org-mobile-directory' must point to an existing directory`".
Is the syntax I am using correct? Am I missing something?
Notes:
* The path `/owncloud/remote.php/webdav/` is what I read in the settings of my Owncloud to specify the WebDAV address to applications.
* I have verified that `MyRemotePath` exists on my server.
* I have set `org-mobile-files` and I have verified that `org-directory` is set to an existing directory (if it matters, although the latter should only concern the pulling from the staging area).
* I eventually would like to use Mobileorg. I have managed to sync from the Mobileorg application to my Owncloud, but apparently I would need a file `index.org` in my server directory in order to sync from the server to the phone. And this file seems to be generated by `org-mobile-push`, which is what led me to this problem.
# Answer
> 1 votes
The recent Tramp versions support the `nextcloud` method, which is also good for OwnCloud servers. You might have better Tramp support if you use the latest Tramp (via GNU ELPA), create on your local machine a NextCloud GNOME Account, and try it.
If there are further problems on the Tramp side, I might be able to help; I have configured several OwnCloud and NextCloud servers via Tramp already.
---
Tags: tramp, mobileorg
---
|
thread-54947
|
https://emacs.stackexchange.com/questions/54947
|
Source C code of function 'apply'
|
2020-01-16T10:57:47.850
|
# Question
Title: Source C code of function 'apply'
I referenced `C-h f apply` for the source code of "apply", it prompts
```
References
C code is not yet loaded.
```
but does not hint the destination file.
Execute `grep-find` within Emacs repo thus return no results.
```
find . -type f -exec grep --color -nH --null -e 'int apply' \{\} +
Grep finished with no matches found at Thu Jan 16 18:47:40
```
How could locate the definition of apply in C code?
# Answer
> 1 votes
Your `C-h f` is not the standard `C-h f` (`M-x describe-function`), `describe-function` doesn't provide "References ..." information at all. To find the source of `apply`, use `C-h f apply`, it will say
> apply is a built-in function in \`src/eval.c'.
`src/eval.c` will be clickable, then click it to go to the source. If you didn't install Emacs from the source code by yourself, Emacs will ask you to input your "Emacs C source dir", you should enter the path of the Emacs git repo, alternatively, you also can set the variable `source-directory` or `find-function-C-source-directory` in your init file
```
(setq source-directory "/path/to/your-emacs-repo")
;; OR
(setq find-function-C-source-directory "/path/to/your-emacs-repo/src")
```
> find . -type f -exec grep --color -nH --null -e 'int apply' {} +
We can't know whether `apply` is defined as a plain C function and its return value must be an integer, thus try something different, for example, search `apply` in all \*.c files.
---
Tags: help
---
|
thread-54939
|
https://emacs.stackexchange.com/questions/54939
|
How do I get request.el to post the contents into the buffer
|
2020-01-16T01:28:51.923
|
# Question
Title: How do I get request.el to post the contents into the buffer
I'm trying to use `request.el` but have no clue what I'm doing. What I want to do is create a request to `Zotero` that uses their citation picker using the to get a 'Cite As You Write' capability using the `Better Bibtex For Zotero` backend.
I have gotten this working with a `do-applescript` function, but it sporadically just stops working, and I get the error `Emacs is not allows to send keystrokes`. I have gone and reset the security preferences numerous times, and ensured the the `Info.plist` has the proper permissions, but I still get this error sporadically.
Can anyone guide me through the process of what I need to do? The relevant url to call is `"/usr/bin/curl 'http://localhost:23119/better-bibtex/cayw?format=pandoc' 2>/dev/null; exit 0"`. I have tested it in the scratch buffer and got the popup citation picker once (see picture). However, when I selected the references it changed focus to the `Zotero` apps search box, and that's as far as I got.
Subsequent requests have failed, and I get the following error:
```
Debugger entered--Lisp error: (void-function request)
(request "http://localhost:23119/better-bibtex/cayw?format=pandoc 2>/dev/null; exit 0")
eval((request "http://localhost:23119/better-bibtex/cayw?format=pandoc 2>/dev/null; exit 0") nil)
elisp--eval-last-sexp(nil)
eval-last-sexp(nil)
funcall-interactively(eval-last-sexp nil)
#<subr call-interactively>(eval-last-sexp nil nil)
apply(#<subr call-interactively> eval-last-sexp (nil nil))
(let ((ido-cr+-current-command command)) (apply orig-fun command args))
call-interactively@ido-cr+-record-current-command(#<subr call-interactively> eval-last-sexp nil nil)
apply(call-interactively@ido-cr+-record-current-command #<subr call-interactively> (eval-last-sexp nil nil))
call-interactively(eval-last-sexp nil nil)
command-execute(eval-last-sexp)
```
I'm sorry, but this is coming across as very much a "can you do this for me" as I don't have a clue what I'm doing.
---
So I got it working again thanks to @lawlist, and the message I get is:
```
(fn &rest ARGS2)"] :url "http://localhost:23119/better-bibtex/cayw?format=pandoc 2>/dev/null; exit 0" :response #0 :encoding utf-8) #<buffer *request curl*> nil nil ...)
```
Any idea how to get this working?
# Answer
> /usr/bin/curl 'http://localhost:23119/better-bibtex/cayw?format=pandoc' 2\>/dev/null; exit 0
This is a shell command consisting two commands (`curl` and `exit`), here is another way to write it
```
/usr/bin/curl 'http://localhost:23119/better-bibtex/cayw?format=pandoc'
exit 0
```
thus the URL is `http://localhost:23119/better-bibtex/cayw?format=pandoc`, to fetch the URL and insert its contents into Emacs buffer, an easy way for new Emacs user is
```
(insert
(shell-command-to-string
"curl -s 'http://localhost:23119/better-bibtex/cayw?format=pandoc'"))
```
(The `-s` (or `--silent`) option tells curl not to print progress meter.) `shell-command-to-string` consumes a shell command and produces its output, for example,
```
(shell-command-to-string "date")
;; =>
"Thu Jan 16 20:03:09 CST 2020
"
```
`insert` consumes a string and insert it at current cursor.
If the above code works for you, then you can wrap it as an Emacs command, e.g.,
```
(defun zotero-cite ()
"Insert Zotero Cite at point."
(interactive)
(insert
(shell-command-to-string
"curl -s 'http://localhost:23119/better-bibtex/cayw?format=pandoc'")))
```
now you can use `M-x zotero-cite`, you can also assign a key binding if you prefer
```
(global-set-key (kbd "C-c C-c") 'zotero-cite)
```
---
Instead of `curl`, Emacs has built HTTP client library (that is, `url.el`) and third part package `request.el`, but you need to be familiar with Emacs Lisp and HTTP in order to use them.
> 1 votes
# Answer
Whenever an Emacs user receives an error message like `void-function request`, it generally means the function has not yet been defined because the library containing that function has not been loaded. If, for example, the function at issue is named `request` and it is defined in the library `request.el`, then before using the library, evaluate the following statement:
```
(require 'request)
```
That statement can also be placed inside the `.emacs` / `init.el` file if you will be using the library fairly frequently in the future.
The library `request.el` should be placed within a file folder in the Emacs `load-path` so that Emacs knows where to look for it.
> 1 votes
---
Tags: spacemacs, http
---
|
thread-29524
|
https://emacs.stackexchange.com/questions/29524
|
Bookmark Plus: Correct bookmark file after directory/file rename
|
2016-12-23T09:39:50.620
|
# Question
Title: Bookmark Plus: Correct bookmark file after directory/file rename
I had a couple of bookmarks for a given file, then I decided to rename the directory of the file. Now `list-bookmarks` ( I am using the `bookmark+` package) shows all the bookmarks for the given file in yellow (indicating that they are no longer valid).
How can I easily repair the bookmark file?
# Answer
The location (file) of a bookmark is in literal (string) form in the bookmark data, which is in variable `bookmark-list` and which is saved in your bookmark file.
You have these options, to change the file name of one or more bookmarks:
* You can use command `bmkp-edit-bookmark-name-and-location`, which is bound to **`C-x p r`** globally. (A similar command is bound to **`r`** in the bookmark-list display.) With no prefix arg you are prompted for a new bookmark name (just hit `RET` for the same name) and a new bookmark location (file). With a prefix arg an editing buffer opens for the full bookmark record (what you see in the bookmark file).
* You can use command `bmkp-edit-bookmark-record`, which is bound to **`C-x p E`** globally. (A similar command is bound to **`e`** in the bookmark-list display.) This is like `C-u C-x p r`: An editing buffer opens for the full bookmark record.
* In the bookmark-list display (buffer `*Bookmark List*`), you can use command `bmkp-bmenu-relocate-marked`, which is bound to **`M-R`**. It relocates the target files of all (visible) bookmarks that are marked `>`. You are prompted for the relocation target directory. Omitted bookmarks are excluded, by default (so you can hide some bookmarks from this operation without unmarking them). With a prefix arg, any omitted bookmarks that are marked are included.
* In the bookmark-list display (buffer `*Bookmark List*`), you can use command `bmkp-bmenu-edit-marked`, which is bound to **`E`**, to edit the full bookmark records of the bookmarks that are marked `>`. An editing buffer opens for all of the full bookmark records together. Omitted bookmarks are excluded, by default. With a negative prefix arg, any omitted bookmarks that are marked are included. With a non-negative prefix arg, the edit buffer includes *all* bookmarks.
* You can open your bookmark file as any file, and edit the text. You can use `query-replace` etc. However, it is probably a better idea to use `C-u E` in the bookmark list -- see previous (but be aware that `C-u E` works with the current `bookmark-list`, not the bookmark file, which is the last-saved `bookmark-list`).
There might be other possibilities, that I'm not thinking of at the moment. Use `C-h m` in the bookmark-list display for more information. Or check the **`Bookmark+`** menu in the bookmark-list display. Or check the **`Bookmarks`** menu anywhere (under `Edit` in vanilla Emacs). Or use `apropos-command`...
> 7 votes
# Answer
You can do this easily without using `bookmark+`
To upload a series of files in bulk, simply open the bookmark file (Typically `~/.emacs/emacs.bmk`) and do a `query-replace` where you search for the old path and replace it with the new one.
> 0 votes
---
Tags: bookmarks
---
|
thread-30597
|
https://emacs.stackexchange.com/questions/30597
|
how to make org-mode section numbers start counting from 0 instead of 1?
|
2017-02-10T00:18:05.357
|
# Question
Title: how to make org-mode section numbers start counting from 0 instead of 1?
org-mode section numbers (when exported to html) by default starts count from 1, however it is traditional in computer science to start counting from zero. How to make org-mode section numbers start counting from 0 instead of 1?
# Answer
Plain lists are turned into HTML by the function `org-html-plain-list`, which calls `org-html-begin-plain-list`. `org-html-begin-plain-list` outputs the `<ol>` tag, and has a provision for outputting a `start` attribute as well, but `org-html-plain-list` doesn't use it. Interestingly, in the version of `org-mode` that I happen to have (which is 6 months old), there's a commented out section of code that looks like someone was thinking about implementing this:
```
(defun org-html-plain-list (plain-list contents info)
"Transcode a PLAIN-LIST element from Org to HTML.
CONTENTS is the contents of the list. INFO is a plist holding
contextual information."
(let* (arg1 ;; (assoc :counter (org-element-map plain-list 'item
(type (org-element-property :type plain-list)))
(format "%s\n%s%s"
(org-html-begin-plain-list type)
contents (org-html-end-plain-list type))))
```
It looks like it would look for a `COUNTER` property nearby in the org file. Of course, that would still make you put something in for every single list you used, but it would be a start.
What you could do is use `add-advice` to override `org-html-begin-plain-list`, so that it always outputs a `start="0"` attribute on ordered lists. You might double-check what the latest version of `org-mode` does as well; perhaps they've improved it.
> 1 votes
# Answer
This is a hack, but you can *mostly* get the numbering right by making the first section unnumbered.
In other words, this source file:
```
* Foo
:PROPERTIES:
:UNNUMBERED: t
:END:
* Bar
* Baz
```
will result in this table of contents:
* Foo
* 1. Bar
* 2. Baz
It's not super ideal, but it's the best I've been able to do without hacking the org-mode source code.
> 1 votes
---
Tags: org-mode, org-export
---
|
thread-54924
|
https://emacs.stackexchange.com/questions/54924
|
Setting up the **second** leader key for Xah-Fly-Keys
|
2020-01-14T23:29:34.093
|
# Question
Title: Setting up the **second** leader key for Xah-Fly-Keys
Inspired by this post, I tried to set up a second leader key for my `Xah-Fly-Keys` for major mode commands (as suggested in the post). But I couldn't find how I can set up the **second** leader key for `Xah-Fly-Keys`. I also ask this question in Xah-Fly-Keys Reddit forum but didn't get any answer. Does anyone know how?
In case you wonder why I'm trying to that: The purpose is using a single key binding for similar actions in different major-modes. For example, running a unit of code (e.g. a source block in org-mode, a cell in matlab-mode and etc) with e.g. + RET (note that is the "second leader key" suggested by the post I mentioned). I propose a solution in Reddit forum, but with using the control key (rather a new leader key).
# Answer
First one needs introduce `<deletechar>` to command mode of xah-fly-keys (XFK):
```
(defun ss-xfk-addon-command()
"Modify keys for xah fly key command mode keys
To be added to `xah-fly-insert-mode-activate-hook'"
(interactive)
(define-key xah-fly-key-map (kbd "<deletechar>") 'ss-xfk-delchar-keymap)
;; more here
)
```
Then add the needed keybindings; For example this is a piece from my config:
```
(xah-fly--define-keys
(define-prefix-command 'ss-xfk-delchar-keymap)
'(
("a" . eshell-command)
("c" . increment-number-at-point) ; i
("t" . decrement-number-at-point) ; k
("." . org-edit-special) ; e
("RET" . ss-run-code-unit)
("n" . read-only-mode) ; l
("v" . flyspell-auto-correct-word) ; .
("w" . flyspell-goto-next-error) ; ,
("e" . goto-line) ; d
)
)
```
and then let then, let XFK add them to the command mode:
```
(add-hook 'xah-fly-command-mode-activate-hook 'ss-xfk-addon-command)
```
> 1 votes
---
Tags: key-bindings
---
|
thread-40519
|
https://emacs.stackexchange.com/questions/40519
|
How to count the number of lines in the region?
|
2018-03-19T18:00:33.987
|
# Question
Title: How to count the number of lines in the region?
Is there a command similar to `count-words-region` to count the total number of lines of a selected region?
# Answer
`M-=` (command `count-words-region`).
(The region does not even need to be activated, but activating it lets you see it.)
> 26 votes
# Answer
Count lines does the trick, it is defined in simple.el
```
(count-lines (point-min) (point-max))
```
> 5 votes
---
Tags: region, lines
---
|
thread-54961
|
https://emacs.stackexchange.com/questions/54961
|
How does one type <C-menu> or <next> on a keyboard (in Emacs)?
|
2020-01-16T21:10:38.813
|
# Question
Title: How does one type <C-menu> or <next> on a keyboard (in Emacs)?
I recently came across these two keybindings in someone else's config and haven't seen them before. I have a US qwerty keyboard, a Kinesis Freestyle Pro. I know where the control, `C`, key is, and I see a `Menu` key in the left auxilliary cluster of my keyboard, but when I ask Emacs, `C-h k`, to describe `C-menu` it says: `<C-linefeed>` is undefined. So the `Menu` key produces is `linefeed`? And, I don't know where the `<next>` key is, I can only assume it is the media next key?
Even better, how would I ask Emacs for these values? I know about `C-h k`, `describe-key`, but is there a way, something like `C-x 8` return that would show me all the keys I could use including odd ones like?
# Answer
Probably depends on your keyboard. I have a typical US PC keyboard. I don't know whether I have a `<menu>` key (for `C-<menu>`). But the `<next>` key is the key labeled **Page Down**.
To see how Emacs calls any given keyboard key, use `C-h k`. For example, if I use `C-h k` and hit the key labeled **Page Down**, Emacs describes what it calls key `<next>`.
> 1 votes
---
Tags: key-bindings, keyboard-layout, keyboard
---
|
thread-54959
|
https://emacs.stackexchange.com/questions/54959
|
Can you generate a tags table for CMD scripting?
|
2020-01-16T18:57:01.253
|
# Question
Title: Can you generate a tags table for CMD scripting?
I am working on an elaborate script for Windows using CMD.EXE scripting.
It walks a tree of files and folders and uses our specialized file transfer program to send the tree to a remote location. Successfully transmitted files (and empty folders) are moved to a SENT folder leaving behind only this that did not get transmitted in this pass.
In case you are wondering, it is a customer requirement to do it this way. This is actually a replacement for a Python version that is completely unacceptable for certification in this environment (military).
This has grown to a set of twenty \*.cmd files and includes both CALL to other scripts and CALL to :LABEL "subroutines".
I am mostly editing this with Emacs (on Windows) and got to wondering if I could generate a usable TAGS table.
Meta-. navigation would be nice but so would Meta-x tags-query-replace
Has anyone generated a TAGS table for this sort of thing?
# Answer
That's definitely doable. I use Emacs lisp to append content into TAGS (https://blog.binchen.org/posts/javascript-code-navigation-in-counsel-etags.html)
Create a simple `hello.c` with below content,
```
int hello() {
}
int bye() {
}
```
Use ctags to create TAGS. So run `ctags -e hello.c` in shell (see https://www.emacswiki.org/emacs/BuildTags if you prefer etags. I don't like etags. It's not actively maintained and has leass features than ctags).
A file named `TAGS` is created, here is its content displayed in Emacs,
`hello.c` is file name. the number after file name is file size. `^?` is one character whose ASCII code is 127. `^A` is one character whose code is 1. After `^A` is `line-numer,char-position-in-file`.
PowerShell script supports file IO and string (see https://docs.microsoft.com/en-us/powershell/scripting/samples/sample-scripts-for-administration?view=powershell-7) so you can use it to create TAGS. You can use any other programming language to create TAGS if and only if that language supports file IO and string manipulation.
If ctags is not restricted by your organization, you can customize the regular expression of ctags to parse the dos batch file,
Run `ctags -e --regex-DosBatch="/^:LABEL \"([a-zA-Z0-9]*)\"/\1/f/" hello.cmd` in shell
`hello.cmd` is like,
```
IF %1==12 GOTO specialcase
rem sub1
Echo the input was NOT 12
goto:eof
:LABEL "sub1"
:specialcase
Echo the input was 12
goto:eof
```
If you run the ctags without file name, it will scan the whole directory recursively.
DosBatch is the name of the language which ctags supports by default. Run `ctags --list-maps` to list all languages.
> 1 votes
---
Tags: microsoft-windows, search, etags
---
|
thread-54968
|
https://emacs.stackexchange.com/questions/54968
|
Emacs counts words incorrectly
|
2020-01-17T07:11:17.260
|
# Question
Title: Emacs counts words incorrectly
Here is an interesting discovery. Copy the following text into a buffer:
```
'hello world'
'नमस्कार नमस्कार'
```
One can see that there are four words, two on line 1 and two on line 2.
Emacs count these as six words! Two on line 1 and four on line 2!
In case if it matters, I am using Doom Emacs v 2.0.9, Emacs v 26.3.
How do I set things right?
# Answer
> 1 votes
The problem is with the second line which Emacs sometimes treats as four words. I can reproduce this in Vanilla Emacs 26.3 and 28.1. If I copy your text into the Emacs *scratch* buffer or into a .el file I get the correct count. If I copy the text into an org file or text file, the count is incorrect. This persuades me that this is likely a bug which has to do with the way Emacs treats the Hindi script, in which case I would file a bug report. First I would check my dot Emacs for language specific and environment settings and remove any you have specifically added.
---
Tags: words
---
|
thread-54951
|
https://emacs.stackexchange.com/questions/54951
|
Emacs 26.3 crash on network/process interaction on macOS
|
2020-01-16T12:23:31.187
|
# Question
Title: Emacs 26.3 crash on network/process interaction on macOS
Here's the story: I'm using macOS 10.15.1 and Emacs ver. 26.3 for macOSX from the eponymous site.
Some time ago, maybe after 10.15.2 update, I started to experience frequent Emacs crashes, occurring mainly in the start of the session, whenever I try to launch shell, use grep/ag from projectile, start sly/slime session, or fetch git repo information via magit. Crashes never occur when I just edit files, open and close them, save my changes and so on.
However, it doesn't always crash, and if it doesn't at the very first attempt, it won't crash at all and I can do as I please and just continue with my work.
Now the information about crash: as I see in the Console.app, crashes are quite consistent and reproduce nicely. For the process launch case:
```
Thread 0 Crashed:: Dispatch queue: com.apple.main-thread
0 libsystem_kernel.dylib 0x00007fff71dd149a __pthread_kill + 10
1 libsystem_pthread.dylib 0x00007fff71e8e6cb pthread_kill + 384
2 libsystem_c.dylib 0x00007fff71ce93a2 raise + 26
3 Emacs-x86_64-10_14 0x00000001000bb789 terminate_due_to_signal + 153
4 Emacs-x86_64-10_14 0x00000001000d8e03 emacs_abort + 19
5 Emacs-x86_64-10_14 0x00000001001c102a ns_term_shutdown + 122
6 Emacs-x86_64-10_14 0x00000001000bb976 shut_down_emacs + 262
7 Emacs-x86_64-10_14 0x00000001000bb756 terminate_due_to_signal + 102
8 Emacs-x86_64-10_14 0x00000001000dba0e handle_fatal_signal + 14
9 Emacs-x86_64-10_14 0x00000001000dba91 deliver_thread_signal + 129
10 Emacs-x86_64-10_14 0x00000001000da629 deliver_fatal_thread_signal + 9
11 Emacs-x86_64-10_14 0x00000001000dbb4b handle_sigsegv + 171
12 libsystem_platform.dylib 0x00007fff71e83b1d _sigtramp + 29
13 ??? 000000000000000000 0 + 0
14 Emacs-x86_64-10_14 0x0000000100187ba3 setup_process_coding_systems + 163
15 Emacs-x86_64-10_14 0x0000000100189e0b create_process + 555
16 Emacs-x86_64-10_14 0x00000001001891c8 Fmake_process + 2424
17 Emacs-x86_64-10_14 0x0000000100140b18 Ffuncall + 728
18 Emacs-x86_64-10_14 0x000000010014066f Fapply + 607
19 Emacs-x86_64-10_14 0x0000000100140b18 Ffuncall + 728
20 Emacs-x86_64-10_14 0x0000000100184d3e exec_byte_code + 1838
21 Emacs-x86_64-10_14 0x0000000100140ab9 Ffuncall + 633
22 Emacs-x86_64-10_14 0x0000000100184d3e exec_byte_code + 1838
23 Emacs-x86_64-10_14 0x0000000100141ae1 funcall_lambda + 897
24 Emacs-x86_64-10_14 0x0000000100140ab9 Ffuncall + 633
25 Emacs-x86_64-10_14 0x0000000100184d3e exec_byte_code + 1838
26 Emacs-x86_64-10_14 0x0000000100141ae1 funcall_lambda + 897
27 Emacs-x86_64-10_14 0x0000000100140ab9 Ffuncall + 633
28 Emacs-x86_64-10_14 0x000000010014121a call0 + 26
29 Emacs-x86_64-10_14 0x000000010013f540 internal_condition_case_n + 288
30 Emacs-x86_64-10_14 0x00000001000c2747 safe_run_hook_funcall + 55
31 Emacs-x86_64-10_14 0x0000000100140e3d run_hook_with_args + 317
32 Emacs-x86_64-10_14 0x00000001000c097c safe_run_hooks + 108
33 Emacs-x86_64-10_14 0x00000001000f8420 Fdo_auto_save + 224
34 Emacs-x86_64-10_14 0x00000001000c41e3 read_char + 5059
35 Emacs-x86_64-10_14 0x00000001000c106a read_key_sequence + 1722
36 Emacs-x86_64-10_14 0x00000001000bf872 command_loop_1 + 1234
37 Emacs-x86_64-10_14 0x000000010013f16c internal_condition_case + 268
38 Emacs-x86_64-10_14 0x00000001000cef60 command_loop_2 + 48
39 Emacs-x86_64-10_14 0x000000010013e760 internal_catch + 272
40 Emacs-x86_64-10_14 0x00000001000be81e command_loop + 158
41 Emacs-x86_64-10_14 0x00000001000be72f recursive_edit_1 + 111
42 Emacs-x86_64-10_14 0x00000001000bea16 Frecursive_edit + 406
43 Emacs-x86_64-10_14 0x00000001000bd32d main + 6477
44 libdyld.dylib 0x00007fff71c822e5 start + 1
```
When I try to fetch remotes from Magit:
```
Thread 0 Crashed:: Dispatch queue: com.apple.main-thread
0 libsystem_kernel.dylib 0x00007fff71dd149a __pthread_kill + 10
1 libsystem_pthread.dylib 0x00007fff71e8e6cb pthread_kill + 384
2 libsystem_c.dylib 0x00007fff71ce93a2 raise + 26
3 Emacs-x86_64-10_14 0x00000001000bb789 terminate_due_to_signal + 153
4 Emacs-x86_64-10_14 0x00000001000d8e03 emacs_abort + 19
5 Emacs-x86_64-10_14 0x00000001001c102a ns_term_shutdown + 122
6 Emacs-x86_64-10_14 0x00000001000bb976 shut_down_emacs + 262
7 Emacs-x86_64-10_14 0x00000001000bb756 terminate_due_to_signal + 102
8 Emacs-x86_64-10_14 0x00000001000dba0e handle_fatal_signal + 14
9 Emacs-x86_64-10_14 0x00000001000dba91 deliver_thread_signal + 129
10 Emacs-x86_64-10_14 0x00000001000da629 deliver_fatal_thread_signal + 9
11 Emacs-x86_64-10_14 0x00000001000dbb4b handle_sigsegv + 171
12 libsystem_platform.dylib 0x00007fff71e83b1d _sigtramp + 29
13 ??? 000000000000000000 0 + 0
14 Emacs-x86_64-10_14 0x000000010018ca0a connect_network_socket + 3130
15 Emacs-x86_64-10_14 0x000000010018b955 Fmake_network_process + 1973
16 Emacs-x86_64-10_14 0x0000000100140b18 Ffuncall + 728
17 Emacs-x86_64-10_14 0x0000000100184d3e exec_byte_code + 1838
18 Emacs-x86_64-10_14 0x0000000100140ab9 Ffuncall + 633
19 Emacs-x86_64-10_14 0x0000000100184d3e exec_byte_code + 1838
20 Emacs-x86_64-10_14 0x0000000100140ab9 Ffuncall + 633
21 Emacs-x86_64-10_14 0x0000000100184d3e exec_byte_code + 1838
22 Emacs-x86_64-10_14 0x0000000100140ab9 Ffuncall + 633
23 Emacs-x86_64-10_14 0x0000000100184d3e exec_byte_code + 1838
24 Emacs-x86_64-10_14 0x0000000100140ab9 Ffuncall + 633
25 Emacs-x86_64-10_14 0x0000000100139c26 Ffuncall_interactively + 70
26 Emacs-x86_64-10_14 0x0000000100140b18 Ffuncall + 728
27 Emacs-x86_64-10_14 0x0000000100139e92 Fcall_interactively + 594
28 Emacs-x86_64-10_14 0x000000010014166b funcall_subr + 299
29 Emacs-x86_64-10_14 0x0000000100140b18 Ffuncall + 728
30 Emacs-x86_64-10_14 0x0000000100184d3e exec_byte_code + 1838
31 Emacs-x86_64-10_14 0x0000000100140ab9 Ffuncall + 633
32 Emacs-x86_64-10_14 0x000000010014124c call1 + 44
33 Emacs-x86_64-10_14 0x00000001000bfb0c command_loop_1 + 1900
34 Emacs-x86_64-10_14 0x000000010013f16c internal_condition_case + 268
35 Emacs-x86_64-10_14 0x00000001000cef60 command_loop_2 + 48
36 Emacs-x86_64-10_14 0x000000010013e760 internal_catch + 272
37 Emacs-x86_64-10_14 0x00000001000be81e command_loop + 158
38 Emacs-x86_64-10_14 0x00000001000be72f recursive_edit_1 + 111
39 Emacs-x86_64-10_14 0x00000001000bea16 Frecursive_edit + 406
40 Emacs-x86_64-10_14 0x00000001000bd32d main + 6477
41 libdyld.dylib 0x00007fff71c822e5 start + 1
```
System log also contains suspicious lines, but I don't know if they have any connection to the crash:
```
09:15:39 com.apple.xpc.launchd[1] (org.gnu.Emacs.1528[75856]): Service exited due to SIGABRT
09:20:49 Emacs-x86_64-10_14[82907]: assertion failed: 19B88: libxpc.dylib + 86572 [99CC9436-D653-3762-ADBB-9054EBD1BA2B]: 0x89
09:28:52 com.apple.xpc.launchd[1] (org.gnu.Emacs.1528[82907]): Service exited due to SIGABRT
09:29:13 Emacs-x86_64-10_14[83715]: assertion failed: 19B88: libxpc.dylib + 86572 [99CC9436-D653-3762-ADBB-9054EBD1BA2B]: 0x89
09:30:59 com.apple.xpc.launchd[1] (org.gnu.Emacs.1528.5A034B74-38F9-4465-B8F3-EE4A7D6C3D04[83715]): Service exited due to SIGABRT
09:47:18 Emacs-x86_64-10_14[83519]: assertion failed: 19B88: libxpc.dylib + 86572 [99CC9436-D653-3762-ADBB-9054EBD1BA2B]: 0x89
10:00:33 Emacs-x86_64-10_14[85644]: assertion failed: 19B88: libxpc.dylib + 86572 [99CC9436-D653-3762-ADBB-9054EBD1BA2B]: 0x89
10:02:01 com.apple.xpc.launchd[1] (org.gnu.Emacs.1528.98532F72-A7CA-48C1-AB20-CA9BA40214C0[85644]): Service exited due to SIGABRT
10:02:15 Emacs-x86_64-10_14[86431]: assertion failed: 19B88: libxpc.dylib + 86572 [99CC9436-D653-3762-ADBB-9054EBD1BA2B]: 0x89
10:04:42 com.apple.xpc.launchd[1] (org.gnu.Emacs.1528.12F80E4E-3872-435C-82CD-91B51957B182[86431]): Service exited due to SIGABRT
10:04:51 Emacs-x86_64-10_14[87066]: assertion failed: 19B88: libxpc.dylib + 86572 [99CC9436-D653-3762-ADBB-9054EBD1BA2B]: 0x89
10:06:12 Emacs-x86_64-10_14[87586]: assertion failed: 19B88: libxpc.dylib + 86572 [99CC9436-D653-3762-ADBB-9054EBD1BA2B]: 0x89
10:06:38 com.apple.xpc.launchd[1] (org.gnu.Emacs.1528.C07B4B1E-4019-40AA-B049-C7BA6350DC7C[87586]): Service exited due to SIGABRT
12:47:25 Emacs[45383]: assertion failed: 19B88: libxpc.dylib + 86572 [99CC9436-D653-3762-ADBB-9054EBD1BA2B]: 0x89
12:48:24 com.apple.xpc.launchd[1] (org.gnu.Emacs.9828.64AFFA95-874F-4701-9DBF-64AE044CA82F[45383]): Service exited due to SIGABRT
12:53:46 Emacs[46033]: assertion failed: 19B88: libxpc.dylib + 86572 [99CC9436-D653-3762-ADBB-9054EBD1BA2B]: 0x89
12:55:14 com.apple.xpc.launchd[1] (org.gnu.Emacs.9828.2CD9EA36-8700-4AF8-A1AC-1EAA9FFE9100[46033]): Service exited due to SIGABRT
```
I also have an impression that if I don't touch "dangerous" functions (i.e. don't launch processes/access network) for a while, the probability of crash lowers. I haven't verified it though.
Also Emacs doesn't crash when run with `-q`, so I suppose it has to do with packages I use, but I have no idea what can cause this, since Emacs also crashes on built-in actions like `M-x shell` right after I start it.
I've been haunted by this issue for almost a month, actively trying to device a fix for a week and have run out of ideas, so any help or advice would be much appreciated!
# Answer
> 2 votes
Success! and eventually I found out what exactly happened and how to fix it.
Short version: I work on a large C++ project and use lsp + clls for code navigation. Emacs part of the lsp, `lsp-mode` has a number of variables, and one of them — `lsp-file-watch-threshold` was set to `nil` by me in order to silence its warning about a number of watched directories. This cause Emacs to exhaust all available file descriptors, and on the next attempt to get a descriptor Emacs crashed. That's what my lsp config looked like:
```
(use-package lsp-mode
:commands lsp
:config (setq lsp-file-watch-threshold nil
lsp-enable-snippet nil)
:init
(add-hook 'rust-mode-hook #'lsp))
```
I set `lsp-enable-file-watchers` to `nil` and this fixed the crash. It didn't impair lsp functionality in an observable way, since directory watching purpose is to add new files to lsp workspace when they appear on the filesystem (as I understand). Final version of the lsp-mode config:
```
(use-package lsp-mode
:commands lsp
:config (setq lsp-file-watch-threshold 512
lsp-enable-file-watchers nil
lsp-enable-snippet nil)
:init
(add-hook 'rust-mode-hook #'lsp))
```
---
Long version: @Stefan's mention of C code reminded me of the possibility to go low-level. So I decided to give it a try.
I. Compiling Emacs from source was surprisingly easy. I just checked out the official repo and did everything according to INSTALL file. I only encountered two issues: missing makeinfo and misplaced `libxml.h`. Also after initial ./configure and make I realised that I forgot to enable debug flags and asserts, so I had to reconfigure and recompile Emacs again. Glad that it took only three minutes or so. The final Emacs debug build for macOS Catalina 10.15.2 is here:
```
$ ./autogen.sh # generates ./configure script
$ CFLAGS='-I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk/usr/include/libxml2/ -ggdb3 -O0' ./configure --without-makeinfo --enable-checking
$ make -j8
```
II. Debugging After Emacs have successfully compiled, I launched `lldb` and reproduced the crash: `lldb ./src/emacs` was sufficient:
```
process.c:459: Emacs fatal error: assertion failed: fd >= 0 && fd < FD_SETSIZE
Process 54308 stopped
* thread #1, queue = 'com.apple.main-thread', stop reason = signal SIGABRT
frame #0: 0x00007fff71dd149a libsystem_kernel.dylib`__pthread_kill + 10
libsystem_kernel.dylib`__pthread_kill:
-> 0x7fff71dd149a <+10>: jae 0x7fff71dd14a4 ; <+20>
0x7fff71dd149c <+12>: movq %rax, %rdi
0x7fff71dd149f <+15>: jmp 0x7fff71dcb3b7 ; cerror_nocancel
0x7fff71dd14a4 <+20>: retq
Target 0: (emacs) stopped.
```
Thanks to enabled asserts, reason have become apparent. Just to be sure I checked also the frame with the assert itself:
```
(lldb) fr s 9
frame #9: 0x00000001003975bf emacs`add_non_keyboard_read_fd(fd=2534) at process.c:459:3
456 static void
457 add_non_keyboard_read_fd (int fd)
458 {
-> 459 eassert (fd >= 0 && fd < FD_SETSIZE);
460 eassert (fd_callback_info[fd].func == NULL);
461
462 fd_callback_info[fd].flags &= ~KEYBOARD_FD;
(lldb) p fd
(int) $2 = 2534
```
The `fd` is indeed greater than `FD_SETSIZE`, which is set to 1024 in macOS system headers. It's a great number of descriptors and I still have no idea, why Emacs would need such a large number.
So naturally I proceeded to the terminal and invoked `lsof` in order to reveal this secret:
```
$ lsof | awk '{print $1}' | uniq -c | sort -rn | grep -i emacs
2591 emacs
```
And after quick glance on a `lsof | grep emacs | less` it become apparent that all the file descriptors opened were the directory structure of that large C++ project I'm working on.
Hope that helps someone else! Also building and debugging Emacs turned out much more friendly that I anticipated.
---
Tags: osx, crash
---
|
thread-54901
|
https://emacs.stackexchange.com/questions/54901
|
How to override background to black after load-theme?
|
2020-01-14T01:59:14.313
|
# Question
Title: How to override background to black after load-theme?
I am using the monokai theme from https://github.com/oneKelvinSmith/monokai-emacs, and I would like to override the background to be black. Following the override instructions, I tried:
```
(setq monokai-background "#000000")
(load-theme 'monokai t)
```
However, this does not seem to work. What am I missing?
# Answer
Try the following
```
(setq customize-set-variable "#000000")
(load-theme 'monokai t)
```
or better see "How to change face in particular theme locally?"
> 0 votes
# Answer
You can add this to the end of your .emacs file:
```
(set-background-color "black")
```
I've tried it on my machine and you can read more here: http://ergoemacs.org/emacs/emacs\_playing\_with\_color\_theme.html
> 0 votes
# Answer
Try loading the theme, THEN changing the background color. Your existing code allows the theme to set the color after you've changed it.
```
(load-theme 'monokai t)
(set-background-color "black")
```
> 0 votes
---
Tags: colors
---
|
thread-54989
|
https://emacs.stackexchange.com/questions/54989
|
Byte compilation still happening when `no-byte-compile` is t on adding advice
|
2020-01-18T14:24:00.623
|
# Question
Title: Byte compilation still happening when `no-byte-compile` is t on adding advice
In org-mode, I have the following:
```
#+BEGIN_SRC emacs-lisp :results scalar
(setq no-byte-compile t)
(defun f ())
(defun g ())
(add-function :before (symbol-function 'f) 'g)
(symbol-function 'f)
#+END_SRC
#+RESULTS:
: #[128 "\300\301\"\210\300\302\"\207" [apply g (lambda nil nil) nil] 4 nil]
```
I wanted to see what adding advice did to the function. Why is byte compilation happening, despite `no-byte-compile` being t? How do I prevent byte compilation in this case?
# Answer
> Why is byte compilation happening...?
Strictly speaking no byte-compilation is happening, from the looks of it.
`advice--make-1` actually generates byte code directly via `make-byte-code`.
This is obviously a low-level approach, and offhand I'm surprised to see that going on outside of compilation; but perhaps it's more common than I imagine -- I have little knowledge in this area.
> 1 votes
---
Tags: byte-compilation, advice
---
|
thread-54982
|
https://emacs.stackexchange.com/questions/54982
|
Insert aligned multi-line text in current buffer regardless of position?
|
2020-01-17T23:16:47.233
|
# Question
Title: Insert aligned multi-line text in current buffer regardless of position?
I'm creating a function to easily insert `ditaa` boxes while drafting reports in org-mode. I have the meat of the function accomplished, but not sure how to implement it so that boxes can be inserted without losing formatting across new-lines.
Here is the current function:
```
(defun create-ditaa-box (x)
(interactive "sText: ")
(let* ((input x)
(input-list (s-split "\n" input))
(input-lengths (mapcar 'length input-list))
(max-len (+ 2 (seq-max input-lengths)))
(border (concat "+" (make-string max-len ?-) "+"))
(input-format (mapcar* '(lambda (x y)
(concat "| "
x
(make-string (- (- max-len y) 1) ? )
"|")) input-list input-lengths)))
(with-current-buffer (buffer-name)
(insert border)
(mapc '(lambda (x)
(newline-and-indent)
(insert x))
input-format)
(newline-and-indent)
(insert border))))
```
It currently works as expected when my cursor is at the beginning of a line:
```
+--------+
| Hello |
| World! |
+--------+
```
When creating diagrams I might have a box that needs to be in the center of the buffer. Currently, my function can't handle this:
**Output:**
```
<cursor-here>+--------+
| Hello |
| World! |
+--------+
```
**Expected Output:**
```
<cursor-here>+--------+
| Hello |
| World! |
+--------+
```
# Answer
You need to find the current column and then insert at column `COL` (see `lm-insert-at-column`).
```
(defun create-ditaa-box (x)
(interactive "sText: ")
(let* ((input x)
(col (current-column))
(input-list (split-string input "\n"))
(input-lengths (mapcar 'length input-list))
(max-len (+ 2 (seq-max input-lengths)))
(border (concat "+" (make-string max-len ?-) "+"))
(input-format (mapcar* (lambda (x y)
(concat "| "
x
(make-string (- (- max-len y) 1) ? )
"|"))
input-list input-lengths)))
(with-current-buffer (buffer-name)
(save-excursion
(insert border)
(mapc (lambda (x)
(unless (eobp)
(forward-line 1))
(lm-insert-at-column col x))
input-format)
(unless (eobp)
(forward-line 1))
(lm-insert-at-column col border)))))
```
> 0 votes
---
Tags: text-editing, insert
---
|
thread-54994
|
https://emacs.stackexchange.com/questions/54994
|
enable counsel-projectile by default
|
2020-01-18T17:48:01.220
|
# Question
Title: enable counsel-projectile by default
I want to enable `counsel-projectile-mode` by default.
I have added `(counsel-projectile-mode)` to `.emacs` file as per project's usage guide but it doesn't work; meaning `projectile` still uses `ido` for finding files and such) ...
But after the Emacs is open if i `M-x counsel-projectile-mode` twice to disable and re-enable it, from within emacs, it will start working. (meaning `projectile` will use `counsel` for finding files, instead of using `ido`)
Any idea what's wrong?
This is my `.emacs` file.
# Answer
I'm not sure why you have both `(counsel-projectile-mode)` and `(counsel-projectile-mode nil)` in your .emacs file. Have you tried simply adding a hook to start `(counsel-projectile-mode)` when loading projectile? Delete (or comment out) the lines you currently have for counsel-projectile-mode and try this:
```
(add-hook 'projectile-mode-hook 'counsel-projectile-mode)
```
> 1 votes
# Answer
Adding this to the `.emacs` file, solves the problem:
```
(add-hook 'emacs-startup-hook 'counsel-projectile-mode)
```
> 0 votes
---
Tags: init-file, projectile, ivy, counsel, multiple-modes
---
|
thread-54997
|
https://emacs.stackexchange.com/questions/54997
|
Which site-lisp file was loaded, default.el or default.elc?
|
2020-01-18T22:10:38.767
|
# Question
Title: Which site-lisp file was loaded, default.el or default.elc?
I'm setting up some site-wide default configuration in the site-lisp directory, and trying to figure out whether emacs is loading the byte-compiled `default.elc` or `default.el`. I haven't applied any other configuration, such as `load-prefer-newer`.
With the following `default.el`
```
(defvar foo nil)
```
and having compiled it so both the .el and .elc files are present, if I run `describe-symbol` on `foo` I'm shown:
> foo is a variable defined in 'default.el'
and the `*Messages*` buffer shows the path to `default.el` (as if it loaded it to look up the symbol, though I don't know if that's actually what it means).
If I remove the .el file leaving only the .elc file, then start emacs and again describe `foo` it shows:
> foo is a variable defined in 'default.elc'
and in the `*Messages*` buffer I see the path to `default.elc`.
I had expected it to load the byte-compiled .elc file when both were present, but can't tell if that's what's happening. How can I check?
# Answer
> 2 votes
`C-h v load-history`
Then search the variable value (in buffer `*Help*`) for the library you're interested in, e.g. `default.el` or `default.elc`.
---
Tags: byte-compilation, site-lisp
---
|
thread-54998
|
https://emacs.stackexchange.com/questions/54998
|
How to prevent undo steps being freed while undoing?
|
2020-01-18T22:14:31.557
|
# Question
Title: How to prevent undo steps being freed while undoing?
As I understand it, undo operations (namely `undo` and `undo-only`) are regular Emacs operations which add to the undo history.
An issue with this is undoing adds to the size of the undo data, which could cause some undo data to be freed.
Is there a way to reliably pause this while the user runs `undo` & `undo-only`, restoring the normal freeing behavior once a regular editing operation runs?
---
### Recipe that exemplifies the issue
Run the following command:
```
emacs -Q --eval "(setq undo-limit 1 undo-outer-limit 10 undo-strong-limit 10)" newfile.txt
```
Type in 8 characters over 6 lines, so the document reads.
```
AAAAAAAA
BBBBBBBB
CCCCCCCC
DDDDDDDD
EEEEEEEE
FFFFFFFF
```
Undo using `C-_` until only the first line is present.
```
AAAAAAAA
```
Now try redo by pressing `C-g`, `C-_` (keep pressing `C-_`).
The redo does not complete, it reaches 4 lines, then gives an error.
```
AAAAAAAA
BBBBBBBB
CCCCCCCC
DDDDDDDD
```
With the warning
```
Warning (undo): Buffer ‘newfile.txt’ undo info was 32 bytes long.
The undo info was discarded because it exceeded `undo-outer-limit'.
```
---
This is just to show that the undo history is freed while undoing.
# Answer
> 1 votes
This is an example implementation of a temporary lock which increases the limits while undoing.
This uses the `after-change-functions` to detect non-undo changes, releasing the lock.
Tested with emacs-27.
> *Note that I'm not all that happy with my own solution, I think the way it relies on hooks is fragile, although I didn't see a better way to do it either.*
```
;; Undo Locking: don't free undo state while undoing.
;; These functions don't clear the lock even when they modify the buffer.
;; Include 'save-buffer' so hooks to format on save don't release the lock.
(defvar-local myundo--lock-dont-unlock-fn (list 'save-buffer 'undo 'undo-only))
;; When non-nil we have a lock, store undo limits here while locked.
(defvar-local myundo--lock-alist nil)
;; Override with 'let' so undo functions don't release the lock.
(defconst myundo--lock-dont-unlock nil)
(defun myundo--lock-disable-after-change (_beg _end _len)
(unless myundo--lock-dont-unlock
;; Can be null since removing the 'after-change' doesn't happen immediately.
(when myundo--lock-alist
(myundo--lock-release))))
(defun myundo--without-lock-fn (old-function &rest args)
(let ((myundo--lock-dont-unlock t))
(apply old-function args)))
(defun myundo--lock-aquire ()
;; In case the lock was already enabled, re-enable.
(when myundo--lock-alist
(myundo--lock-release))
;; Prevent loss of undo data.
(setq myundo--lock-alist
(list
(cons 'undo-outer-limit undo-outer-limit)
(cons 'undo-limit undo-limit)
(cons 'undo-strong-limit undo-strong-limit)))
;; Don't truncate any undo data in the middle of this.
(setq undo-outer-limit nil)
(setq undo-limit most-positive-fixnum)
(setq undo-strong-limit most-positive-fixnum)
(dolist (elem myundo--lock-dont-unlock-fn)
(advice-add elem :around #'myundo--without-lock-fn '((name . "myundo--advice"))))
(add-hook 'after-change-functions #'myundo--lock-disable-after-change :local)
(message "Undo Lock Aquired"))
(defun myundo--lock-release ()
(dolist (elem myundo--lock-dont-unlock-fn) (advice-remove elem "myundo--advice"))
(remove-hook 'after-change-functions #'myundo--lock-disable-after-change :local)
(setq undo-outer-limit (alist-get 'undo-outer-limit myundo--lock-alist))
(setq undo-limit (alist-get 'undo-limit myundo--lock-alist))
(setq undo-strong-limit (alist-get 'undo-strong-limit myundo--lock-alist))
;; Clear to show we're not locked.
(setq myundo--lock-alist nil)
;; Account for reduced undo limits.
(garbage-collect)
(message "Undo Lock Released"))
(defun myundo--lock-aquire-advice (&rest _)
(unless myundo--lock-alist
(myundo--lock-aquire)))
(defun myundo--lock-install ()
(interactive)
(advice-add 'undo :after #'myundo--lock-aquire-advice '((name . "myundo--advice"))))
(defun myundo--lock-uninstall ()
(interactive)
(advice-remove 'undo "myundo--advice"))
;; Enable this now!
(myundo--lock-install)
```
---
Tags: undo
---
|
thread-54618
|
https://emacs.stackexchange.com/questions/54618
|
Prioritize color of emphasis faces in Org headers
|
2020-01-01T21:30:15.863
|
# Question
Title: Prioritize color of emphasis faces in Org headers
Observe the following Org buffer, tested on Emacs with no configuration (`emacs -q`):
Note that **bold**, **italic**, and **underline** are all distinctly fontified in the header. However **verbatim** and **code** are not.
This becomes more relevant when viewing Org-mode buffers with emphasis markers hidden, with `(setq org-hide-emphasis-markers t)`:
Now **code** and **verbatim** emphasis is not visible. I would rather that the foreground color of `org-code` and `org-verbatim` be given priority over the foreground color of `org-level-1`. How may I achieve this?
> *Version Information*:
> **Org**: Org mode version 9.2.3 (9.2.3-20-g31873e-elpa)
> **Emacs**: GNU Emacs 26.3 (build 1, x86\_64-pc-linux-gnu, GTK+ Version 3.24.10)
# Answer
> 1 votes
I have tested this in Emacs 28.0.50. Emacs displays the line you have given in the same colors regardless of whether `org-hide-emphasis-markers` is set to `t` or `nil`. Hence, `org-code` and `org-verbatim` are given priority over the foreground color of `org-level-1`. (They are shown in grey not blue.) With `org-hide-emphasis-markers` set to `t` what is not visible are the symbols `=` and `~`. But perhaps I am misunderstanding what you are asking.
---
Tags: org-mode, font-lock
---
|
thread-48723
|
https://emacs.stackexchange.com/questions/48723
|
Auctex autocomplete and physics.sty
|
2019-04-02T22:57:53.470
|
# Question
Title: Auctex autocomplete and physics.sty
I have autocomplete successfully working in auctex. It also works for included packages, so if I, for example, have `\usepackage{url}` in my preamble, I will get autocompletion while typing `\url`.
However, this is not the case for the physics package in latex.
One possible problem I can think of is that this package makes use of `xparse`, so there is no `\def` or `\newcommand` in physics.sty but instead commands like `\DeclareDocumentCommand`.
Is there a way to get autocomplete for physics.sty?
# Answer
> 1 votes
I ran into the same issue and asked on the mailing list.
Auctex uses elisp style files to know what symbols exist. For your own code, it auto generates these style files and stores them in the "auto" directory. For some libraries, it ships with style files (see the `TeX-style-path` variable to find where these are stored). But for other libraries it doesn't auto generate the style file.
You can manually generate the style file by running `TeX-auto-generate` on the `physics.sty` file that shipped with your TeX distribution. However, the parsing is very naive, so while you'll probably get all of the commands, they won't have the right arguments. You can modify the generated file yourself to set the number of arguments (and if you get a fully working style file feel free to commit it upstream).
---
Tags: auctex
---
|
thread-54884
|
https://emacs.stackexchange.com/questions/54884
|
Web-mode left arrow without the right closing angle bracket
|
2020-01-13T09:32:01.060
|
# Question
Title: Web-mode left arrow without the right closing angle bracket
When using Elixir html template (.eex) in web-mode, I sometimes need to type code like `<%= for bid <- @bids do %>` . At the moment because the opening left angled bracked is closed immediately with a matching right angled bracket, after I type `<-`, I'm left with a closing angled bracket that I don't need and have to delete.
I need help coming up with a way to prevent the left angled bracket from auto closing.
Below is my current web-mode and smartpatens configs:
**Web-mode**
```
(use-package web-mode
:ensure t
:mode (("\\.erb\\'" . web-mode)
("\\.mustache\\'" . web-mode)
("\\.html?\\'" . web-mode)
("\\.eex\\'" . web-mode)
("\\.php\\'" . web-mode)
("\\.jsx$" . web-mode))
:init
(setq web-mode-markup-indent-offset 2
web-mode-css-indent-offset 2
web-mode-code-indent-offset 2)
;; make web-mode play nice with smartparens
(setq web-mode-enable-auto-pairing nil)
;(setq web-mode-enable-auto-closing nil)
(setq web-mode-enable-current-element-highlight t)
(setq web-mode-enable-current-column-highlight t)
:config
(sp-with-modes '(web-mode)
(sp-local-pair "<" nil :actions nil)
(sp-local-pair "% " " %"
:unless '(sp-in-string-p)
:post-handlers '(((lambda (&rest _ignored)
(just-one-space)
(save-excursion (insert " ")))
"SPC" "=" "#")))
(sp-local-pair "<% " " %>" :insert "C-b %")
(sp-local-pair "<%= " " %>" :insert "C-b =")
(sp-local-pair "<%# " " %>" :insert "C-b #")
(sp-local-pair "<-" "")))
```
**Smartparens**
```
(use-package smartparens
:ensure t
:hook (prog-mode . smartparens-mode)
:init
;; https://stackoverflow.com/questions/23789962/how-to-disable-emacs-highlighting-whitespace-in-parenthesis
(setq sp-highlight-pair-overlay nil)
:bind
(:map smartparens-mode-map
("C-M-f" . sp-forward-sexp)
("C-M-b" . sp-backward-sexp)
("C-M-a" . sp-backward-down-sexp)
("C-M-e" . sp-up-sexp)
("C-M-w" . sp-copy-sexp)
("C-M-k" . sp-change-enclosing)
("M-k" . sp-kill-sexp)
("C-M-<backspace>" . sp-splice-sexp-killing-backward)
("C-S-<backspace>" . sp-splice-sexp-killing-around)
("C-]" . sp-select-next-thing-exchange))
:config
(require 'smartparens-config)
(sp-local-pair 'emacs-lisp-mode "'" nil :actions nil)
(sp-local-pair 'org-mode "[" nil :actions nil)
(sp-local-pair 'prog-mode "{" nil :post-handlers '((my-create-newline-and-enter-sexp "RET")))
(sp-local-pair 'prog-mode "(" nil :post-handlers '((my-create-newline-and-enter-sexp "RET"))))
```
Thanks.
# Answer
To remove pre-existing pairs, you have to use `:action :rem`, not `:action nil`. There is even an example in the documentation.
So this line:
```
(sp-local-pair "<" nil :actions nil)
```
needs to be changed to:
```
(sp-local-pair "<" nil :actions :rem)
```
> 0 votes
---
Tags: web-mode, smartparens
---
|
thread-54978
|
https://emacs.stackexchange.com/questions/54978
|
can one do math on :properties:?
|
2020-01-17T15:15:15.830
|
# Question
Title: can one do math on :properties:?
I would like to use column-mode to create a project rollup similar to MSProject, but much simpler and faster. I would like to have a column for :hours:, and a column for :materials\_cost:. Here's the core of my question: can I create a column for :total cost: which would be this math (I'm pretending I'd write it like this):
:total\_cost: = :hours: * 210 + :materials\_cost:.
this is sufficiently simple to do in excel or a org-table, but doesn't use the greatness of folding in outlines which column-mode allows, with the simplicity of sums {+}. I've searched everywhere for some mention about math with properties.
# Answer
Look at org-collector http://orgmode.org/worg/org-contrib/org-collector.html. This collects properties in a table, where you can then do calculations.
> 1 votes
---
Tags: org-mode
---
|
thread-54984
|
https://emacs.stackexchange.com/questions/54984
|
How can I add a name to prefixes?
|
2020-01-18T03:47:30.087
|
# Question
Title: How can I add a name to prefixes?
My current config looks like this:
```
(use-package general
:ensure t
:config (general-define-key
:states '(normal visual insert emacs)
:prefix "SPC"
:non-normal-prefix "C-SPC"
;; Buffer.
"b k" '(kill-this-buffer :which-key "Kill Buffer")
))
```
But when I press `SPC` it shows `+prefix` next to `b` instead of an actual name. How can I set a name there with :which-key?
# Answer
You can give SPC and SPC-b a description for which-key by using the `:ignore` keyword:
```
(general-define-key
:states '(normal visual insert emacs)
:keymaps 'override
:prefix "SPC"
:non-normal-prefix "C-SPC"
"" '(:ignore t :which-key "description for SPC") ; <<< added
;; Buffer.
"b" '(:ignore t :which-key "description for b") ; <<< added
"b k" '(kill-this-buffer :which-key "Kill Buffer"))
```
This is shown in the example in the Which Key Integration section on the github page.
> 3 votes
---
Tags: key-bindings
---
|
thread-54445
|
https://emacs.stackexchange.com/questions/54445
|
specify time of day for org-resolve-clocks, not number of minutes
|
2019-12-18T16:58:57.037
|
# Question
Title: specify time of day for org-resolve-clocks, not number of minutes
I can use `org-resolve-clocks` if I've been away from a task but kept the clock for the task running -- but when I do that and select `K` ("keeps however many minutes you request and then immediately clock out of that task."), I have to specify a number of *minutes*.
Instead, I want to specify a time, since usually that's what I remember ("my coworker stopped to ask a question at 10:45"). I'd like a way to get the `K` functionality, but instead of doing the math to figure out a number of minutes, I want to just type in a time of day.
What would I need to do for that?
# Answer
It seems there's no way for org to do this right now. But I've sent a patch to the org-mode mailing list; the change to `org-clock.el` is quite simple:
https://lists.gnu.org/archive/html/emacs-orgmode/2020-01/msg00175.html
> 1 votes
---
Tags: org-mode, org-clock
---
|
thread-54977
|
https://emacs.stackexchange.com/questions/54977
|
need help with very complex find and replace
|
2020-01-17T14:57:21.967
|
# Question
Title: need help with very complex find and replace
I have a very complex (at least to my mind) text replacement task. ideally this would be a function or macro I could run over every org header in a buffer.
I want to 1. move over any TODO state to a line beneath the header starting with `tags:` 2. then move over any org tags following that todo state into the tags line proceeded by a comma
the issue is that of course the org header changes in depth across the file and the header name changes of course.
this is for getting ready to use org export to markdown. since org markdown export cant convert org tags and states into markdown tags I want this step of pre proceesing. I would then export each changed heading to md and use the first line as meatadata.
the markdown app can the read these exported tags and thus keeping/"exporting" my org rating and todo state .
as an example this org section:
```
*** ✔ Kopitiam :3star:
pretty good malasyian food. Had a nice frothy tea, the nasi lamak and blue rice with pandan cream
all was ok but nothing outstanding
*** Brussels
**** ✔ Tonton Garby :3star:
very good sandwhices in brussels
```
would look like this after the find and replace
```
*** Kopitiam
tags: #✔ , #3star
pretty good malasyian food. Had a nice frothy tea, the nasi lamak and blue rice with pandan cream
all was ok but nothing outstanding
*** Brussels
**** Tonton Garby
tags: #✔ , #3star
very good sandwhices in brussels
```
is something like that even possible within emacs or do I need to some other tools like python?
EDIT:
someone helped me try a outside emacs solution using perl
```
#!/usr/bin/env perl
use strict;
use warnings;
sub fmt_tags {
return unless defined $+{tags};
map {q/#/ . $_} $+{tags} =~ /\w+/g
}
sub check_tag {
defined $+{checked}? q{#} . $+{checked} : q{}
}
while (<>) {
s/
(?<stars>[*]{2,4})
\s+
(?<checked>✔)?
\s+
(?<title>.+?)
\s+
((?<tags>:.+\n)?|\n)$
/$+{stars} $+{title}\ntags: @{[join ', ', check_tag(), fmt_tags()]}\n/x;
print;
}
```
this seems to work, yet docent really pick up the `TOVISIT` tags...
# Answer
This function maps through all headings with todo state ✔ and inserts the todo state and tags as described (as long as I have understood it correctly):
```
(defun my-org-prepare-for-markdown-export (&optional _backend)
"Insert a line below all headings with todo state ✔.
The line has the following format: tags: #✔ , #tag1 , #tag2 , ...
Existing org tags are removed."
(interactive)
;; Map through each heading that has a todo state ✔.
(org-map-entries
;; Function called at each heading.
(lambda ()
(let* ((todo (org-get-todo-state))
(tags (org-get-tags nil t))
;; Get list of todo and tags if non-nil.
(lst (if todo
(if tags
(append (list todo) tags)
(list todo))
tags))
;; Build the string to insert.
(str (mapconcat (lambda (x) (concat "#" x)) lst " , "))
(str (concat "tags: " (substring-no-properties str))))
;; Remove tags.
(org-set-tags nil)
;; Insert newline and insert text.
(end-of-line)
(newline-and-indent)
(insert str)))
;; Match for headings to map through.
"TODO=\"✔\""))
```
You should add this function to the `org-export-before-processing-hook` (that's why I added the backend argument). The following command adds it to the hook, exports the buffer to markdown and removes it from the hook afterwards. Like this the original buffer is not touched:
```
(defun my-org-special-markdown-export ()
(interactive)
(add-hook 'org-export-before-processing-hook #'my-org-prepare-for-markdown-export)
(org-md-export-as-markdown)
;; Or
;; (org-md-export-to-markdown)
(remove-hook 'org-export-before-processing-hook #'my-org-prepare-for-markdown-export))
```
Call it with `M-x my-org-special-markdown-export` while the buffer is active.
> 1 votes
---
Tags: org-mode, search, text-editing, replace
---
|
thread-55021
|
https://emacs.stackexchange.com/questions/55021
|
How to run a function when setting a 'defcustom' option?
|
2020-01-20T04:37:17.840
|
# Question
Title: How to run a function when setting a 'defcustom' option?
Is it possible to run code when setting an option defined by `defcustom`?
For example, I would like `(setq my-package-option t)` to install a hook.
While `defcustom` has a `:set` keyword, it's documented only to run in the user interface.
---
This is close to working, it has an error about a recursive function call.
```
(defcustom my-boolean-example nil
"Docs."
:set
#'(lambda (var value)
(if (set-default var value)
(turn-thing-on)
(turn-thing-off)))
:initialize 'custom-initialize-changed
:type 'boolean)
```
# Answer
In a comment to @Drew's answer you've said:
> Doesn't this require the user to use `customize-set-variable` instead of `setq` or `setq-default` ?
Indicating that you want your function to be called even when a variable is set by the likes of `setq`, which means you're looking for the variable-watcher functionality.
Refer to `C-h``i``g` `(elisp)Watching Variables` for details.
Note that this feature has been available only since Emacs 26.1. Prior to that you cannot do what you're asking for.
> 2 votes
# Answer
It's not true that `:set` is used only for interactive use of Customize.
Functions `customize-set-variable` and `customize-save-variable` respect the `:set` function of the `defcustom`.
> **`customize-set-variable`** is an interactive autoloaded compiled Lisp function in `cus-edit.el`.
>
> `(customize-set-variable VARIABLE VALUE &optional COMMENT)`
>
> Set the default for `VARIABLE` to `VALUE`, and return `VALUE`.
>
> `VALUE` is a Lisp object.
>
> **If `VARIABLE` has a `custom-set` property, that is used for setting `VARIABLE`, otherwise `set-default` is used.**
>
> If `VARIABLE` has a `variable-interactive` property, that is used as if it were the arg to `interactive` (which see) to interactively read the value.
>
> If `VARIABLE` has a `custom-type` property, it must be a widget and the `:prompt-value` property of that widget will be used for reading the value.
>
> If given a prefix (or a `COMMENT` argument), also prompt for a comment.
> 1 votes
---
Tags: customize, customization, defcustom
---
|
thread-55014
|
https://emacs.stackexchange.com/questions/55014
|
How do I move a subtree to another file
|
2020-01-19T16:21:11.967
|
# Question
Title: How do I move a subtree to another file
In org-mode I frequently want to move one (top-level) tree to another file. I can do this by first calling `org-cut-special` (C-c C-x C-w) in the source file, then switching to the target file and calling `org-yank` (C-y) there. But this is rather tedious.
Is there a simpler way to do it?
# Answer
Answering my own question here. I suspected that `org-refile` was the way to go (thanks @lawlist), but I couldn't get it to refile a tree at the topmost (i.e., headline) level.
I turns out that I need to do this:
```
(setq org-refile-use-outline-path 'file)
```
That allows me to refile at the top level.
> 1 votes
---
Tags: org-mode
---
|
thread-55028
|
https://emacs.stackexchange.com/questions/55028
|
How can I disable company-mode in a shell when it is remote?
|
2020-01-20T18:50:28.090
|
# Question
Title: How can I disable company-mode in a shell when it is remote?
I am using `(global-company-mode 1)` but using remote shell it is annoyingly slow.
How can I disable company mode when I open a shell buffer, but only if it's a remote shell?
The problem manifests when I SSH to a remote server using `C-x f /ssh:root@server.com:/` and then `M-x shell`.
# Answer
> 1 votes
In order to know that a buffer represents a remote connection, you can use `file-remote-p`.
You can read about this function Here
For example, in a shell buffer, `(file-remote-p default-directory)` will allow you to differentiate between a local shell and a remote shell.
In order to toggle company-mode, you can call the `company-mode` function with a parameter of `-1` (negative one).
To perform actions only in a shell buffer, you can add a function hook to the `shell-mode-hook` list. You can read about what hooks are and how to use them Here
Putting it all together:
1. Write a function that disables company mode in the current buffer only when it is remote:
```
(defun my-shell-mode-setup-function ()
(when (and (fboundp 'company-mode)
(file-remote-p default-directory))
(company-mode -1)))
```
2. Add this function to your `shell-mode-hook`s
```
(add-hook 'shell-mode-hook 'my-shell-mode-setup-function)
```
---
Tags: shell, company-mode
---
|
thread-55024
|
https://emacs.stackexchange.com/questions/55024
|
How to make a temporary directory that gets deleted once the body is finished?
|
2020-01-20T11:57:42.200
|
# Question
Title: How to make a temporary directory that gets deleted once the body is finished?
Is there a way to temporarily create a new directory, then remove it when the body of the code has finished?
```
(with-temp-directory path
(write-test-files-into path)
(other-test-functions path))
;; path is now deleted!
```
Similar to the Python function `tempfile.TemporaryDirectory` by a similar name:
```
# create a temporary directory using the context manager
with tempfile.TemporaryDirectory() as tmpdirname:
print('created temporary directory', tmpdirname)
```
# Answer
`make-temp-file` can be used to make a directory instead of a file, this example simply calls `make-temp-file`, then removes the directory afterwards.
```
(let ((temp-dir (make-temp-file "foo" t)))
(unwind-protect
(progn
;; do stuff
)
(delete-directory temp-dir t)))
```
This same functionality as a macro:
```
(defmacro with-temp-dir (temp-dir &rest body)
`(let ((,temp-dir (make-temp-file "" t)))
(unwind-protect
(progn
,@body)
(delete-directory ,temp-dir t))))
```
> 6 votes
# Answer
```
;; Inspired from `dired-create-directory` code.
(defun with-temp-dir (dir)
"..."
(let* ((expanded (directory-file-name (expand-file-name dir)))
(try expanded)
new)
(unwind-protect
(progn
(when (file-exists-p expanded)
(error "Cannot create directory %s: file exists" expanded))
;; Find the topmost nonexistent parent dir (variable `new')
(while (and try (not (file-exists-p try)) (not (equal new try)))
(setq new try
try (directory-file-name (file-name-directory try))))
(make-directory expanded t)
(write-test-files expanded)
(other-test-functions expanded))
(delete-directory new t))))
```
Or if you want to do arbitrary things in the directory, not just `write-test-files` and `other-test-functions`, use a macro:
```
(defmacro with-temp-dir (dir &rest body)
"..."
`(let* ((expanded (directory-file-name (expand-file-name ',dir)))
(try expanded)
new)
(unwind-protect
(progn
(when (file-exists-p expanded)
(error "Cannot create directory %s: file exists" expanded))
;; Find the topmost nonexistent parent dir (variable `new')
(while (and try (not (file-exists-p try)) (not (equal new try)))
(setq new try
try (directory-file-name (file-name-directory try))))
(make-directory expanded t)
,@body)
(delete-directory new t))))
```
Then you would do, e.g.:
```
(with-temp-dir "/your/temp/dir" (write-test-files ...) (other-test-functions ...))
```
> 3 votes
---
Tags: directories, directory
---
|
thread-54993
|
https://emacs.stackexchange.com/questions/54993
|
Keep ivy-initial-inputs-alist nil after counsel loaded
|
2020-01-18T16:52:54.757
|
# Question
Title: Keep ivy-initial-inputs-alist nil after counsel loaded
I want to keep the alist `ivy-initial-inputs-alist` `nil` after `ivy` and `counsel` are loaded. Therefore, I have the following configuration:
```
(use-package ivy
:ensure t
:config
;; some keybindings
(setq ivy-initial-inputs-alist nil))
```
However, this doesn't work after `counsel` is loaded. When I check the alist value, I get this:
```
Value:
((counsel-minor . "^+")
(counsel-package . "^+")
(counsel-org-capture . "^")
(counsel-M-x . "^")
(counsel-describe-function . "^")
(counsel-describe-variable . "^"))
Original value was
((org-refile . "^")
(org-agenda-refile . "^")
(org-capture-refile . "^")
(Man-completion-table . "^")
(woman . "^"))
```
meaning that the alist was set to `nil`, but `counsel` set it again later.
The only line that has something to do with `ivy-initial-inputs-alist` in `counsel.el` is:
```
(cl-pushnew '(counsel-package . "^+") ivy-initial-inputs-alist :key #'car)
```
How can I make the `setq` persistent?
# Answer
You can set it after `counsel` is loaded with:
```
(with-eval-after-load 'counsel
(setq ivy-initial-inputs-alist nil))
```
See `(elisp) Hooks for Loading`.
You can achieve the same thing with `use-package` as follows:
```
(use-package counsel
:defer t
:config
(setq ivy-initial-inputs-alist nil))
```
> 2 votes
---
Tags: variables, ivy
---
|
thread-55009
|
https://emacs.stackexchange.com/questions/55009
|
Completing underscored words without making _ a word character
|
2020-01-19T14:40:37.777
|
# Question
Title: Completing underscored words without making _ a word character
I would like to use `evil-complete-previous` (or whatever) to complete `strings_such_as_this`, which is by default not possible. It is possible after `(modify-syntax-entry ?_ "w")`, but this has the undesired side-effect of rendering it impossible to jump from the beginning of the string to the third `s` with `(evil-forward-word-begin)` (`w`). Can I get the effect without the side-effect?
# Answer
I don't know if this is the best solution, but it works.
```
(defun evil*-complete-previous () (interactive)
(let ((old (string (char-syntax ?_))))
(modify-syntax-entry ?_ "w")
(evil-complete-previous)
(modify-syntax-entry ?_ old)))
(define-key evil-insert-state-map (kbd "M-p") 'evil*-complete-previous)
```
> 0 votes
---
Tags: evil, completion, syntax
---
|
thread-54956
|
https://emacs.stackexchange.com/questions/54956
|
How to show trees from archive files by default (a.k.a. (org-agenda-archives-mode 'files))?
|
2020-01-16T16:18:10.897
|
# Question
Title: How to show trees from archive files by default (a.k.a. (org-agenda-archives-mode 'files))?
I want my default agenda view to include archived trees from `.org_archive` files. From the manual we learn:
> `v a (org-agenda-archives-mode)`
> `v A (org-agenda-archives-mode 'files)`
> Toggle Archives mode. In Archives mode, trees that are marked ARCHIVED are also scanned when producing the agenda. When you use the capital A, even all archive files are included. To exit archives mode, press v a again.
However, when I `(org-agenda-archives-mode 'files)` I get the following error at startup:
```
Symbol's function definition is void: org-agenda-archives-mode
```
How can I get the default-agenda to include archived trees?
# Answer
> 1 votes
`org-agenda-archives-mode` is a *variable* defined in `org-agenda.el`. Its default value is `nil`
```
Documentation:
Non-nil means the agenda will include archived items.
If this is the symbol ‘trees’, trees in the selected agenda scope
that are marked with the ARCHIVE tag will be included anyway. When this is
t, also all archive files associated with the current selection of agenda
files will be included.
```
`org-agenda-archives-mode` is also a *function*; however, the O.P. seeks to set the default value and this is done via the *variable*.
In general, `org-mode` uses prefixes to let the user know which library contains variables/functions with said prefixes. In this case, the prefix is `org-agenda-...`. Thus, we want to load the library before setting the variable.
```
(require 'org-agenda)
(setq org-agenda-archives-mode t)
```
---
Tags: org-mode, org-agenda
---
|
thread-55042
|
https://emacs.stackexchange.com/questions/55042
|
How to make an alist without repeating key/values?
|
2020-01-21T16:40:15.213
|
# Question
Title: How to make an alist without repeating key/values?
When writing an alist where all the key/value pairs have keys that are variables, is there a convenient way to write this in Elisp without repetition?
eg:
```
`((foo . ,foo)
(long-variable-name . ,long-variable-name)
(yet-another-long-variable-name . ,yet-another-long-variable-name)
(you-get-the-idea . ,you-get-the-idea))
```
So the same structure could be written as:
```
(alist-from-vars
foo
long-variable-name
yet-another-long-variable-name
you-get-the-idea)
```
... with an arbitrary number of arguments.
# Answer
> 3 votes
If you don't want to quote the variable, you need to use a macro instead of a function, e.g.,
```
(defmacro alist-from-vars (&rest vars)
`(list ,@(mapcar (lambda (var) `(cons ',var ,var))
vars)))
(macroexpand '(alist-from-vars a b))
;; => (list (cons (quote a) a) (cons (quote b) b))
(let ((a 1)
(b 2))
(alist-from-vars a b))
;; => ((a . 1) (b . 2))
```
# Answer
> 2 votes
I don't get exactly what you're trying to get, but maybe this at least helps you find the way:
```
(defun alist-from-vars (&rest vars)
(mapcar (lambda (x) `(,x . ,(symbol-value x))) vars))
(let ((a 12)
(b 24)
(c 7))
(alist-from-vars 'a 'b 'c))
```
---
Tags: alists
---
|
thread-54979
|
https://emacs.stackexchange.com/questions/54979
|
Killing current buffer reliably
|
2020-01-17T18:17:25.330
|
# Question
Title: Killing current buffer reliably
I try to add a nicer key binding to kill the current buffer.
An obvious solution is to use `kill-this-buffer`, but often it does not work, or e.g. does not work the first time. The key binding for it is definitely not overridden by the buffers keymap, etc.
Indeed, the docs for `kill-this-buffer` say:
> This command can be reliably invoked only from the menu bar, otherwise it could decide to silently do nothing.
This is exactly the observed behavior.
What could be a nice alternative? Is something like `(kill-buffer (current-buffer))` going to work reliably instead? Am I missing any subtleties?
# Answer
Short answer: `(kill-buffer (current-buffer))` works fine.
Longer answer: My init.el has
```
;; kill the current buffer instead of choosing
;; http://pragmaticemacs.com/emacs/dont-kill-buffer-kill-this-buffer-instead/
;; except that kill-this-buffer may break if menus are not available:
;; https://www.reddit.com/r/emacs/comments/64xb3q/killthisbuffer_sometimes_just_stops_working/
(bind-key "k" (lambda () (interactive) (kill-buffer (current-buffer))) ctl-x-map)
```
Check the links therein for more discussion.
> 2 votes
# Answer
You can use the function `kill-current-buffer` from `simple.el`. The docstring says:
> kill-current-buffer is an interactive compiled Lisp function in ‘simple.el’.
>
> (kill-current-buffer)
>
> Kill the current buffer. When called in the minibuffer, get out of the minibuffer using ‘abort-recursive-edit’.
>
> This is like ‘kill-this-buffer’, but it doesn’t have to be invoked via the menu bar, and pays no attention to the menu-bar’s frame.
> 3 votes
# Answer
The fastest way is by a keyboard shortcut, which is `C-x k`.
> -2 votes
---
Tags: buffers, kill-buffer
---
|
thread-55040
|
https://emacs.stackexchange.com/questions/55040
|
Magit: Howto create a new commit ignoring white-space differences
|
2020-01-21T15:44:20.293
|
# Question
Title: Magit: Howto create a new commit ignoring white-space differences
I'm using magit 20191128.39 on Emacs 26.3 When changing a python script resulting in a new unstaged change, git/magit should ignore whitespace-differences. A `git diff -w` will do the trick, but I'd like to get the same result inside magit. Any hint here?
# Answer
In the status buffer, open the diff menu using `d`.
From here you can set the `-w` flag by pressing `w`.
Many magit commands will pop these menus, when you are changing options you can save the current options as your default settings.
After enabling the `-w` flag, press `C-x``C-s` to save them as your default.
After closing the menu you should see that the status buffer diffs now reflect your preference for `-w`, as well as future diff buffers that you can open via other means.
> 3 votes
---
Tags: magit, git
---
|
thread-55063
|
https://emacs.stackexchange.com/questions/55063
|
bookmark-jump to org-mode file with collapsed headings not working as expected
|
2020-01-22T19:43:20.490
|
# Question
Title: bookmark-jump to org-mode file with collapsed headings not working as expected
I have a bookmark in one of my org files (set using the usual emacs bookmarks), but I'm finding that when I try to jump to the bookmark (with the usual `C-x r b`, which invokes `bookmark-jump`), it doesn't jump to the right place if the heading containing the location for my bookmark is collapsed.
Is there a way to get org and `bookmark-jump` to cooperate? I think what I want is something analogous to `S-tab` and `C-c C-r` (`org-reveal`): after `S-tab`, point is not moved, but the headlines collapse; if I then do `C-c C-r`, org shows exactly those heading necessary to display the exact line point is on. I want `bookmark-jump` to do the same thing -- put point on the right line -- so that even if org has the heading collapsed, things like `org-reveal` do what I expect.
Is there a way to do this? Or an org-specific feature for this kind of bookmark?
I have emacs 26.1 and org-mode 9.3.1.
# Answer
> 1 votes
If your Org mode contains the function `org-bookmark-jump-unhide`, then all you have to do is add it to `bookmark-after-jump-hook`:
```
(add-hook 'bookmark-after-jump-hook '#org-bookmark-jump-unhide)
```
If your emacs version's `bookmark.el` does not define/use `bookmark-after-jump-hook`, then you can advise `bookmark-jump`:
```
(defadvice bookmark-jump (after org-make-visible activate)
"Make the position visible."
(org-bookmark-jump-unhide))))
```
All of this comes courtesy of the current `org-compat.el` file.
---
Tags: org-mode, bookmarks
---
|
thread-55044
|
https://emacs.stackexchange.com/questions/55044
|
org-agenda not showing any todos
|
2020-01-21T17:10:00.170
|
# Question
Title: org-agenda not showing any todos
No items are showing when I load the agenda view. When I press `C-c a`, the agenda view menu comes up fine. But hitting `a` brings up an empty list, and so does `t`.
`M-x describe-variable RET org-agenda-files` shows
There are tonnes of TODO items in `~/org/todo.org`, eg:
My init is defined in `~/.emacs.d/init.el` and I do not have an `~/.emacs`. My `init.el` has only one definition of `org-agenda-files`.
I really am at a loss as to why this is not working.
Emacs version 26.3 Org version 9.3.1
Not sure what other information might be useful?
I have been using Emacs for a while, but would consider myself a noob with custom configuration and org mode.
**UPDATE**:
The Messages buffer is showing errors like this:
```
Press key for agenda command (unrestricted):
org-agenda-get-todos: Wrong type argument: number-or-marker-p, "E"
user-error: Command not allowed in this line [3 times]
```
I set `debug-on-entry` for `org-agenda-get-todos`, and it shows this in the debug buffer:
```
Debugger entered--entering a function:
* org-agenda-get-todos()
org-agenda-get-day-entries("~/org/todo.org" (1 21 2020) :todo)
org-todo-list(nil)
funcall-interactively(org-todo-list nil)
call-interactively(org-todo-list)
org-agenda(nil)
funcall-interactively(org-agenda nil)
call-interactively(org-agenda nil nil)
command-execute(org-agenda)
```
# Answer
> 1 votes
The solution here was that I had the following lines in my `~/.emacs.d/init.el`:
```
(setq org-highest-priority "A")
(setq org-lowest-priority "E")
(setq org-default-priority "B")
```
But they should have been
```
(setq org-highest-priority ?A)
(setq org-lowest-priority ?E)
(setq org-default-priority ?B)
```
---
Tags: org-mode, org-agenda
---
|
thread-55060
|
https://emacs.stackexchange.com/questions/55060
|
"Run all code blocks above this point" in org-babel?
|
2020-01-22T14:55:52.653
|
# Question
Title: "Run all code blocks above this point" in org-babel?
I know you can use `org-babel-execute-src-block` (`C-c C-c`) to execute individual code blocks, but is there something akin to "Run all chunks above" that RStudio has for Rmarkdown files?
# Answer
You can easily run **all** code blocks via `C-c C-v C-b`, or all blocks in a subtree. I don't think **above this point** is implemented.
It would be fairly easy write a custom function that takes all text below the point, hides it, executes all code blocks, and then restores the text. I would do that rather than taking all text above the point and executing it in a temporary buffer, because some code blocks may use the buffer-name or file-name so it should not be changed.
> 5 votes
---
Tags: org-mode, org-babel
---
|
thread-3627
|
https://emacs.stackexchange.com/questions/3627
|
Detecting variable changed outside customize
|
2014-11-16T23:45:37.860
|
# Question
Title: Detecting variable changed outside customize
I have used "Customize" to set a value for `semantic-lex-c-preprocessor-symbol-file`. However, after loading up .emacs, this isn't the value I see. On opening up the "Customize" menu for this variable, I see that its state is "Changed outside customize". How do I find it where this was changed? Also, what is the right way of customizing variables to avoid such issues?
# Answer
It is not easy to find *where* such a change was made. The easiest way to find it is to *recursively bisect your init file*, to find out which part of it causes this.
To do that you can use command `comment-region`. With `C-u` it uncomments the region. Comment out 1/2, then 3/4, then 7/8, then 15/16,... of your init file.
Beyond that, code such as this will detect *which* variables have been changed outside Customize (but I think you already know which variables are concerned):
```
(let ((vars ()))
(mapatoms
(lambda (symbol)
(let ((cval (or (get symbol 'customized-value)
(get symbol 'saved-value)
(get symbol 'standard-value))))
(when (and cval ; It is declared with defcustom.
(default-boundp symbol) ; It has a value.
(not (equal (eval (car cval)) ; Value does not match customize's.
(default-value symbol))))
(push symbol vars)))))
(message "Variables changed outside: %s" vars))
```
If you want to let something change a value outside Customize, but you want Customize to consider that it was changed inside Customize, you can do it using library **`cus-edit+.el`**. See also Customizing and Saving on Emacs Wiki.
As for the right way to avoid such issues: use Customize to change and save the value. But you already did that. As you say, some other code seems to be changing the value after your saved value is loaded.
(Wrt where to let Customize save changes, I recommend that you use a separate `custom-file`, instead of letting Customize write stuff to your init file.)
> 4 votes
# Answer
Emacs version 26.1 and higher allows you to trigger the debugger when a variable changes. Place the following code near the beginning of your `init.el`:
```
(debug-on-variable-change 'semantic-lex-c-preprocessor-symbol-file)
```
Restart your emacs. Each time the variable is changed, you'll enter the debugger with the corresponding backtrace. After each occurence you can press `c` to continue the execution.
For more information see the elisp manual.
The second part of your question was answered accurately by Drew. Personally, I would recommend keeping the `custom-set-variables` block at the end of your init file.
> 6 votes
---
Tags: customize, semantic-mode
---
|
thread-55070
|
https://emacs.stackexchange.com/questions/55070
|
How to "call" a keymap
|
2020-01-23T04:28:19.957
|
# Question
Title: How to "call" a keymap
I would like to have a function `call-keymap` which takes one argument `km` (a keymap) and such that the result of `(call-keymap km)` is the same as binding `km` to a key and then pressing that key.
It should look something like this
```
(defun call-keymap (km)
(while (keymapp km)
(setq km (lookup-key km (read-key-sequence ""))))
(call-interactively km))
```
except that this doesn't work (specifically the last line is wrong, since a non-keymap entry of a keymap needn't be a function).
Intuitively, it would seem that the main command loop in emacs should be something like
```
(while t
(call-keymap (current-global-map))
```
(or rather, it should do something with `current-active-maps` instead of `current-global-map`).
I was surprised to not be able to find a built-in function with the desired functionality of `call-keymap`, since this seems to me to be such a basic function.
Could someone please point me to such a built-in, or indicate how to fix the above definition?
---
**Edit 2019-01-23**
Stefan very rightly asked that I explain what my use-case is for such a function.
I use `evil-mode` and have `SPC` as a prefix-key for various useful commands when in `normal-state`. In `insert-state`, I would like some other binding (say, `M-SPC`) to produce the same behaviour as `SPC` in normal mode (I think emacs-DOOM has such a feature). My idea was then to bind `M-SPC` to a function which fetches the current `normal-state` binding of `SPC` (which is a keymap) and calls it.
Presumably, there are other good solutions to this, so that my original question may be moot, though I would be still be interested to know the answer. For example, here is one quite-hacky-but-maybe-not-entirely-unsatisfactory solution to my problem:
```
(defun set-alt-space ()
(evil-local-set-key 'insert (kbd "M-SPC") (key-binding (kbd "SPC"))))
(add-hook 'evil-normal-state-exit-hook 'set-alt-space)
```
# Answer
> 3 votes
Assuming your keymap is a menu, you can use `popup-menu`.
If it's not a menu but is just a normal keymap for normal keys (e.g. typically bound to a prefix key), then I don't think there's a predefined function for that. But in your example `call-keymap` function, if you replace `call-interactively` with `execute-command`, should cover the majority of cases. Of course, it still won't reproduce the normal way commands are executed because it fails to set `this-command`, `last-command`, run `pre/post-command-hook`, handle the `prefix-arg`, move cursor out of invisible text, etc...
To faithfully reproduce the way the command loop runs commands, the only good way is to ... use the command loop. One way is with `recursive-edit`, but that covers a *sequence* of commands rather than just one (and it needs to be exited "manually").
In your case, I think the better answer is `set-transient-map`. E.g. your `M-SPC` command could look something like:
```
(defun my-one-time-normal-SPC ()
(interactive)
(let ((map (lookup-key evil-normal-state-map "\s")))
(set-transient-map map)))
```
---
Tags: keymap
---
|
thread-55074
|
https://emacs.stackexchange.com/questions/55074
|
Restore after `maximize-window`
|
2020-01-23T12:30:10.000
|
# Question
Title: Restore after `maximize-window`
If I have multiple windows open, I can maximize one using `M-x maximize-window`.
How should I restore the windows to their original size?
# Answer
> 2 votes
One possible way: save the current window configuration to a register, maximize and then when you are done, restore the saved window configuration. E.g. to save it in register `R`: `C-x r w R`; then to restore: `C-x r j R`. These run the commands `window-configuration-to-register` and `jump-to-register` resp. You can look at the doc strings of these functions with `C-h f RET window-configuration-to-register RET` e.g.
Here's a link to the relevant section of the Emacs manual.
---
Tags: window
---
|
thread-55081
|
https://emacs.stackexchange.com/questions/55081
|
Automatically highlight elements in an XML buffer
|
2020-01-23T18:46:37.913
|
# Question
Title: Automatically highlight elements in an XML buffer
I spend a lot of time in XML buffers using nxml-mode (Emacs 26). Out of hundreds of XML elements, I am only interested in one or two. How can I have Emacs always show the XML elements I'm interested in with a different colour? This will help me keep track of the important elements while working without having to keep searching with `C-s` and `C-r`.
For example, in the following XML file, I want the tags for element `THING_NAME` to show up in a different coloured font instead of the default blue, and leave the tags for elemenst `XML_FILE`, `THING_VERSION`, and `THING_TYPE` in the default colour.
```
<?xml version='1.0' encoding='ISO-8859-'?>
<XML_FILE>
<THING_VERSION>2.2</THING_VERSION>
<THING_NAME>BOB</THING_NAME>
<THING_TYPE>ITEM</THING_TYPE>
</XML_FILE>
```
Here's a screenshot. It would be great if the highlighted tags for `THING_NAME` were in a different colour, like pink or red, to make it easier to see in large files.
\[
I've tried adding `font-lock-add-keywords` to init.el but it had no effect. For example:
```
(font-lock-add-keywords 'nxml-mode
'(("THING_NAME" . font-lock-keyword-face)))
```
I also tried adding a hook to the mode using `add-hook` from the Emacs manual:
```
(add-hook 'nxml-mode-hook
(lambda ()
(font-lock-add-keywords nil
'(("\\(THING_NAME\\)" 1
font-lock-warning-face t)))))
```
After reading the nxml-mode Emacs documentation and Emacs wiki entries, and installing themes from MELPA and looking at the code, I'm still unsure of how to proceed.
This has been driving me crazy! Any help would be very appreciated, and I'm sure many others would find this useful. Maybe I am approaching this the wrong way. Would it be better to have an always-on search that permanently highlighted specific matches?
---
**Solution after the response from `glucas`, shown below**
Thanks to `glucas` I created a regexp interactive highlight for "THING\_NAME". The keys I typed were:
```
M-s h r THING_NAME RET RET
```
I extended this to good final solution by creating a keyboard macro to automatically bind `C-c t` to the interactive highlight in ~/.emacs.d/init.el. The macro is named `thingname`, so I can also type `M-x thingname`. Notice how the regexp search term "THING\_NAME" is escaped as "?T ?H ?I ?N ?G ?\_ ?N ?A ?M ?E":
```
(fset 'thingname
[?\M-s ?h ?r ?T ?H ?I ?N ?G ?_ ?N ?A ?M ?E return return])
(global-set-key (kbd "C-c t") 'thingname)
```
Applied to the example XML above, it looks like this:
You can add multiple highlights, each with a different colour, by repeating the call to M-s h r as many times as needed. Here, I add another highlight for "THING\_WEIGHT" to the same binding:
```
(fset 'thingname
[?\M-s ?h ?r ?T ?H ?I ?N ?G ?_ ?N ?A ?M ?E return return
?\M-s ?h ?r ?T ?H ?I ?N ?G ?_ ?W ?E ?I ?G ?H ?T return return])
(global-set-key (kbd "C-c t") 'thingname)
```
# Answer
Emacs provides a general-purpose highlight mechanism which might work here. See Interactive Highlighting in the Emacs manual.
The relevant commands are `highlight-phrase` or `highlight-regexp` to define what you want to highlight (and in what color). You can ask Hi Lock mode to save the highlight instructions in the file itself using `hi-lock-write-interactive-patterns`. That gives you a flexible way to define and persist highlight instructions without writing any Elisp.
Alternatively you can define you own functions to set up highlighting with the same commands, and hook them to nxml mode. That would be a better approach if you want the same highlight rules across many files and/or cannot add comments to the files.
For example:
```
(defun my-xml-highlights ()
(interactive)
(highlight-phrase "THING_NAME" 'hi-yellow)
(highlight-phrase "THING_WEIGHT" 'hi-pink))
(global-set-key (kbd "C-c t") 'my-xml-highlights)
```
> 1 votes
---
Tags: font-lock, syntax-highlighting, highlighting, nxml
---
|
thread-55079
|
https://emacs.stackexchange.com/questions/55079
|
Help; how use Persistent Sets of Completion Candidates for search?
|
2020-01-23T18:09:09.413
|
# Question
Title: Help; how use Persistent Sets of Completion Candidates for search?
I want to use a set of files inside my directory `~/Dokumente` to search for changes in title, content. So I saved such a set of file names persistently, using `C-}` during file-name completion with Icicles.
Later, I can use `C-{` to restore that set of file names as completion candidates for a command that prompts for a file name.
But how can I combine this with command `icicle-locate` (or another command that prompts for a file name)?
Command `icicle-locate` can used with `C-M-j` to filter by both file name AND file content. How can I do that and also take advantage of my saved persistent set of file names?
# Answer
This answer is for using command `icicle-find-file-absolute`, which is similar in most regards to `icicle-locate`.
But `icicle-locate` uses a prefix arg differently, passing it to system-command `locate`. So `icicle-locate` doesn't handle the use of a prefix arg to make multi-completion candidates include also a last modification-date middle component. (Command `icicle-locate-file` is more similar to `icicle-find-file-absolute` than is `icicle-locate`, which uses system command `locate`.)
The short, tl;dr, answer to your question is that even when completing to match both file name and file content, the completion candidates shown in `*Completions*` are just the file names, and it is perfectly OK to use `C-{` to retrieve a set of these.
---
1. (You already did this.) Use **`C-}`** during file-name completion, to save the file names that match your minibuffer pattern persistently. Let's say you saved this in file `foo.el`, using name set-name `foo`.
2. `M-x icicle-find-file-absolute` (or just `C-u C-x C-f`).
3. At the prompt for a file name, use **`C-{`**, to restore your saved set of file names. At the prompt, enter the name of the saved set, `foo`. The saved names are shown as the completion candidates in buffer `*Completions*`.
4. Type **`C-M-j`**, to say that you are done matching file names and you now want to give a pattern to match file content.
5. Type a pattern to match file content, e.g., `toto.*titi`. Use `S-TAB` to update `*Completions*`, to show only the names of files whose content matches regexp `toto.*titi`.
---
If you want to match also the file last-modification dates, then use a negative prefix arg. In that case, after step 3, use **`C-M-j`** and type a pattern that matches the dates you want, then continue with step 4 (a second `C-M-j` followed by a file-content pattern).
---
As mentioned, `icicle-locate` is a bit different, because for it the prefix arg is passed to `locate`, so you can't use it to include last modification-date matching. But the general approach is the same.
---
See also:
> 1 votes
---
Tags: completion, find-file, icicles, filenames
---
|
thread-55089
|
https://emacs.stackexchange.com/questions/55089
|
Emacs leaving behind files preceded with # despite lock files being disabled
|
2020-01-23T22:25:53.100
|
# Question
Title: Emacs leaving behind files preceded with # despite lock files being disabled
I've noticed that emacs is leaving behind files in the directories of files I've edited with it. The files are named the same as the original, except the filename is preceeded and succeeded with a # character. For example, something like `#file.c#`, for example (if the original file was named `file.c` ).
I've already disabled lockfiles and changed the default directory backup files are saved to in my init.el script, like so:
```
(setq create-lockfiles nil)
(setq backup-directory-alist `(("." . "~/.saves")))
```
So I'm wondering why these files are generated, what their purpose is, and if there's a way I can supress them/change where they are saved to.
# Answer
> 2 votes
As mentioned by Drew, the files in question are auto-save files, which are distinct from backup files. Unfortunately for some reason, there is no index entry for `#` pointing to `Auto Save Files` in the emacs manual, hence my confusion.
My solution was simply to also change the location auto-save files are saved to, namely a hidden directory in my home directory named `.saves`, by adding the following line to my configuration file:
```
(setq auto-save-file-name-transforms `((".*" "~/.saves" t)))
```
# Answer
> 2 votes
The Emacs manual (`C-h r`) is your friend for such a question. Use `i` in the manual to look something up in the index. For example, `i auto save` lets you get to node **Auto Save**, and the first item in the menu there takes you to node **Auto-Save Files**.
There you get a complete description of what these files are, what they are for, how to recognize them, how to manage them, etc.
Similarly, for backup files. `i backup file` (or `i backup-directory-alist`) takes you to node **Backup Files**, which tells you all you'll want to know about backup files. In particular, there, you can see that backup files are different, in name and purpose, from auto-save files.
Same thing for lock files: `i lock file` (or `i create-lockfiles`) takes you to node **Interlocking**. There, you can see that lock files are different, in name and purpose, from auto-save files.
If, after taking a look at these doc pages, you have a more specific question about these files, please pose that (separately).
---
Tags: auto-save
---
|
thread-55095
|
https://emacs.stackexchange.com/questions/55095
|
why defcustom variable is not seeable from describe symbol?
|
2020-01-24T06:19:39.600
|
# Question
Title: why defcustom variable is not seeable from describe symbol?
take org-brain-path for example:
```
(defcustom org-brain-path (expand-file-name "brain" org-directory)
"The root directory of your org-brain.
`org-mode' files placed in this directory, or its subdirectories,
will be considered org-brain entries."
:group 'org-brain
:type '(directory))
```
I want to check its current value with `describe-symbol org-brain-path`, but I cannot find `org-brain-path` in `describe-symbol` list.
Why and how to check the current value?
# Answer
```
(require 'org-brain)
```
is needed in order to make the `defcustom` variables it defines become available.
> 1 votes
---
Tags: defcustom
---
|
thread-55098
|
https://emacs.stackexchange.com/questions/55098
|
Unescape elisp string
|
2020-01-24T07:33:00.107
|
# Question
Title: Unescape elisp string
I have a function which returns a file path, but the returned value has backslash excaped 'special' characters e.g.
"/home/fred/Documents/This\ file\ \\(20200120\\).txt"
but the function where I want to use this value does not handle the string escaping and just wants the plain filename string i.e.
"/home/fred/Documents/This file (20200120).txt"
What would be the canonical way to do this in elisp?
My quick and dirty solution (which seems to work) is a simple function
```
(defun tx-parse-path (p)
(concat (reduce #'(lambda (acc l)
(if (not (= ?\\ l))
(cons l acc)
acc))
(reverse p)
:initial-value '())))
```
I suspect there is some built-in function, but have not found it. I don't need to worry about win32 compatibility (only use GNU Linux and macOS) and of course, the flaw with the brute force solution above is that it will strip legitimate '\\' from a filename.
# Answer
> 1 votes
You could simply say:
```
(replace-regexp-in-string "\\\\\\(.\\|\n\\)" "\\1" STRING)
```
Or equivalently:
```
(replace-regexp-in-string (rx "\\" (group anything)) "\\1" STRING)
```
---
Tags: string, escape
---
|
thread-55050
|
https://emacs.stackexchange.com/questions/55050
|
What are the main differences between latexmk and C-c C-a from Auctex?
|
2020-01-21T20:23:00.537
|
# Question
Title: What are the main differences between latexmk and C-c C-a from Auctex?
I was wondering if anyone knows if `C-c C-a` in AucTeX is using behind the scenes latexmk or not? I've tried looking into the source files for both `C-c C-c` and `C-c C-a` but I couldn't find in any those traces of latexmk.
On a side note what best way to integrate latexmk in AucTeX workflow?
# Answer
> 5 votes
`C-c C-a` uses AuCTeX's heuristics for deciding which list of commands to run. The usual case is to use the function `TeX-command-default` which is defined in `tex-buf.el`. So no, `latexmk` is not used.
You can make `latexmk` accessible from `C-c C-c` by customizing `TeX-command-list`. One possibility is to a add an element of the form
```
INS DEL :
Name: LaTeXmk
Command: latexmk %s
How: Value Menu TeX-run-TeX
Create a process for NAME using COMMAND to format FILE with TeX.
Prompt: Toggle off (nil)
Modes: Value Menu All
Menu elements:
INS DEL Lisp expression: :help
INS DEL Lisp expression: "Run latexmk."
INS
```
which adds
```
("LaTeXmk" "latexmk %s" TeX-run-TeX nil t :help "Run latexmk.")
```
to `TeX-command-list`. Once this is done, on typing `C-c C-c` you can choose `LaTeXmk` as the command to run. Next time you type `C-c C-c` this will be offered as the default, so can be accepted with just `RET`.
Look at the other elements in `TeX-command-list` to get an idea of ways to pass further options to `latexmk` should you need them.
# Answer
> 3 votes
Why not just add it directly to ~/.emacs?
```
(with-eval-after-load 'tex
(add-to-list
'TeX-command-list
'("LaTeXmk" "latexmk %s" TeX-run-TeX nil t :help "Run latexmk.")))
```
---
Tags: latex, auctex, automation
---
|
thread-55057
|
https://emacs.stackexchange.com/questions/55057
|
Goto line by number in folded org buffer
|
2020-01-22T12:35:01.697
|
# Question
Title: Goto line by number in folded org buffer
I looking for a way to go to the specific line by number in an org file, when the structure is folded. An ideal solution would be to unfold only necessary headings to put the cursor in the line. I was looking for a while for some solution for this, but I didn't find any silver bullet so far.
# Answer
You might like to try `M-x reveal-mode` which will automatically un-hide things so as to make the text around cursor visible.
> 3 votes
# Answer
Here the function I use
```
(defadvice goto-line (after unfold-tree activate)
(when (outline-invisible-p)
(save-excursion
(outline-previous-visible-heading 1)
(org-show-subtree))))
```
> 1 votes
---
Tags: org-mode
---
|
thread-18831
|
https://emacs.stackexchange.com/questions/18831
|
How to apply mapcar to a function with multiple arguments
|
2015-12-13T13:19:22.470
|
# Question
Title: How to apply mapcar to a function with multiple arguments
I have `packages` variables that have list of github users and package names.
```
(defvar packages '('("auto-complete" . "auto-complete")
("defunkt" . "markdown-mode")))
```
I want to `git clone` if the file is not exist yet.
```
(defun git-clone (author name)
(let* ((repo-url (concat "git@github.com:" author "/" name ".git")))
(print repo-url)
(unless (file-exists-p (concat "~/.emacs.d/git/" name))
(shell-command (concat "git clone " repo-url " ~/.emacs.d/git/" name)))))
```
And I want to apply `git-clone` to all packages variable to `packages` list. But I could not figure out how to apply with arguments.
```
; This obviously doesn't work
(mapcar `git-clone `packages)
```
# Answer
You can create an anonymous lambda function to take each element of your list and apply your function to it.
Example:
```
(defvar packages '(("auto-complete" . "auto-complete")
("defunkt" . "markdown-mode")))
(defun toy-fnx (author name)
"Just testing."
(message "Package %s by author %s" name author)
(sit-for 1))
(mapcar (lambda (package)
(funcall #'toy-fnx (car package) (cdr package)))
packages)
```
Note that, if you don't care about the return values (ie, your function is only for side effects, which appears to be the case here), you can use `mapc` in place of `mapcar`:
```
(mapc (lambda (package)
(funcall #'toy-fnx (car package) (cdr package)))
packages)
```
For your specific purposes, a loop may be simplest:
```
(cl-dolist (package packages) ; or dolist if you don't want to use cl-lib
(funcall #'toy-fnx (car package) (cdr package)))
```
> 9 votes
# Answer
If you're happy using dash.el you can use `-each` and destructuring `-let`:
```
(require 'dash)
(--each packages
(-let [(author . name) it]
(git-clone author name)))
```
Alternatively, you can use `-lambda` from dash.el to create an anonymous function with destructuring:
```
(mapcar
(-lambda ((author . name)) (git-clone author name))
packages)
```
> 9 votes
# Answer
Building on the answer by Dan, if you do this kind of thing often it may be useful to define a 'starred' variant of `mapcar`, as one does in e.g. Python:
```
(defun my-mapcar* (func arglist)
(mapcar
(lambda (args)
(apply func args))
arglist))
```
so that e.g.
```
(my-mapcar* #'+ '((1) (1 1) (1 1 1) (1 1 1 1))
⇒ (1 2 3 4)
```
> 1 votes
---
Tags: mapping
---
|
thread-55104
|
https://emacs.stackexchange.com/questions/55104
|
How to navigate in a Dired buffer?
|
2020-01-24T12:20:48.647
|
# Question
Title: How to navigate in a Dired buffer?
window 10, Emacs 26.1, Dired+
Suppose I open in Dired+ mode some folder:
```
d:/TEMP/test_folder/folder2/
```
I need next:
1. When press button "**End**" then go to the last file in the folder. Like this:
2. When press button "**Home**" then go to the first file in the folder. Like this:
3. When press button "**Backspace**" then go to the up folder. Like this:
# Answer
> 1 votes
1.
```
(defun my/dired-last-file ()
(interactive)
(end-of-buffer)
(dired-next-line -1))
```
2.
```
(defun my/dired-first-file ()
(interactive)
(beginning-of-buffer)
(while (and (not (eobp))
(or (bolp)
(member (dired-get-filename 'no-dir t)
'("." ".."))))
(dired-next-line 1)))
```
3. Bind `<backspace>` to `dired-up-directory`.
# Answer
> 1 votes
Since you mention Dired+, Menu-bar menu **Dir**, submenu **Navigation** has these items, with associated keyboard keys:
* **Next Dirline** (**`>`**)
* **Prev Dirline** (**`<`**)
* **Next Subdir** (**`C-M-n`**)
* **Prev Subdir** (**`C-M-p`**)
* **Up Directory** (**`^`**)
* **Tree Up** (**`C-M-u`**)
* **Tree Down** (**`C-M-d`**)
* **Move To This Subdir** (**`i`**)
`C-M-u` and `C-M-d` are the same in vanilla Dired. Vanilla Dired also offers (less useful) versions of `^`, `i` and `C-M-p`.
* For your #1, just use `M-> p`. Or, if by "the folder" you mean the current subdir, use `C-M-n p p`.
* For your #2, you can use `M-< n`, repeating `n` as needed. Or, if by "the folder" you mean the current subdir, use `C-M-p n`, repeating `n` as needed.
* For your #3, use `C-M-p`, possibly repeated.
---
Tags: dired, motion
---
|
thread-55114
|
https://emacs.stackexchange.com/questions/55114
|
Capture at an arbitrary date
|
2020-01-24T18:47:38.237
|
# Question
Title: Capture at an arbitrary date
In this example I changed the date for `Entered` to 12/07/2019 at the capture editing stage. Yet it gets filed under today's date. How can file it under the right date, that is 12/07/2019? Ideally in one step. But if not, the obvious additional steps would be 1/ create a headline for 12/07/2019, and its parents. 2/ `org-refile` under the hl created in 1/. How to do 1/?
PS: I'm using a variant of the capture proposed here:
```
(defun my-org-capture ()
"Read file name to capture to."
(interactive)
(setq my-org-capture-filename
(read-file-name "Capture to: " "~/Documents/write/notes/journal"
"inbox.org" t))
(call-interactively #'org-capture))
```
# Answer
> 1 votes
The capture template you linked to is the key here:
```
("j" "Journal" entry
(file+olp+datetree "~/Documents/write/notes/journal/inbox.org")
"* %?
Entered on %U
%i
%a")
```
The date you are modifying is in the content of the entry: the `%U` gets replaced with the current timestamp which you are then modifying.
However the 'file+olp+datetree' target defines where the entry will actually go, and in this case the default for a datetree is to add a heading for today's date. That heading is not related to the content of the entry that you are editing.
What you want here is to override the default behavior of datetree. If you always want to be prompted, add the optional `:time-prompt` property to your capture template. If most of the time the default behavior is what you want, you can leave the template as-is and instead use a `C-1` prefix to trigger the prompt.
From the Org Template elements documentation:
> ```
> ‘:time-prompt’
> Prompt for a date/time to be used for date/week trees and when
> filling the template. Without this property, capture uses the
> current date and time. Even if this property has not been
> set, you can force the same behavior by calling ‘org-capture’
> with a ‘C-1’ prefix argument.
>
> ```
---
Tags: org-capture, org-refile
---
|
thread-36024
|
https://emacs.stackexchange.com/questions/36024
|
Mouse wheel not working with new mouse
|
2017-10-09T16:02:42.493
|
# Question
Title: Mouse wheel not working with new mouse
I'm running Emacs 25.1.1 on Debian. No particularly elaborate setup.
I recently bought a new mouse, a Logitech MX Anywhere 2S, though I am not using any of the "programmable" features. I simply use the mouse via Bluetooth. I haven't changed anything anywhere.
It works fine in every other application, but in Emacs, when I try to scroll, I get beeps and `C-M-( [or C-M-)] is undefined`. `mouse-wheel-mode` *is* enabled.
The other aspects of the mouse work as expected; I can paste using the middle button, for example.
Any thoughts on how to fix this?
# Answer
If your mouse wheel rotation is seen by Emacs as keys `C-M-(` and `C-M-)` then you presumably need to bind those two keys, to make the wheel work with Emacs.
For example:
```
(global-set-key (kbd "C-M-(") 'mwheel-scroll)
(global-set-key (kbd "C-M-)") 'mwheel-scroll)
```
Or whatever command is appropriate for your use (and platform).
But what are your values of these user options (use `C-h v`)?
* `mouse-wheel-down-event`
* `mouse-wheel-up-event`
`mouse-wheel-mode` uses the values of those two options to construct the keys that it binds to `mwheel-scroll`.
You might also do this, to find out what keys `mouse-wheel-mode` has bound to `mwheel-scroll`: `C-h w mwheel-scroll`.
> 1 votes
# Answer
```
;; Fix mouse wheel
(global-set-key (kbd "C-M-(") (kbd "<mouse-4>"))
(global-set-key (kbd "C-M-)") (kbd "<mouse-5>"))
```
This is a combination of answer: https://emacs.stackexchange.com/a/36036/17985 and some comments, and this: https://emacs.stackexchange.com/a/49083/17985
> 1 votes
# Answer
It may be possible to adjust the mouse's configuration in Emacs, using some available X Window System utilities, such as xmodmap(1). There's also the imwheel utility, and the evdev input driver for the X Window System.
Although I'm not familiar with the specific configuration, I've found some documentation, such that provides some introductory information about these features of the X Window System. Along with the system manual pages, maybe it could be helpful towards determining a configuration that "Just works"
> 0 votes
# Answer
Your mouse wheel scroll mappings match my initial Emacs settings as well.
Add the following to your `$HOME/.emacs` file.
I find scrolling by four lines optimal.
```
;; Mouse wheel scroll
;; My scroll wheel is mapped to C-M-( C-M-)
(defun scroll-up-4-lines ()
"Scroll up 4 lines."
(interactive)
(scroll-up 4))
(defun scroll-down-4-lines ()
"Scroll down 4 lines."
(interactive)
(scroll-down 4))
(global-set-key (kbd "C-M-(") 'scroll-down-4-lines)
(global-set-key (kbd "C-M-)") 'scroll-up-4-lines)
```
> 0 votes
---
Tags: mouse
---
|
thread-32405
|
https://emacs.stackexchange.com/questions/32405
|
how to include remote images in org-mode export to LaTeX?
|
2017-04-27T00:00:51.803
|
# Question
Title: how to include remote images in org-mode export to LaTeX?
When I paste the URL of an image into an org-mode file and then export it to HTML, the remote image URL gets turned into an `img` tag and displayed in my HTML file without the need for me to save the image locally.
For instance, if I have a file `foo.org` consisting solely of the text `https://vetstreet-brightspot.s3.amazonaws.com/fa/19/73e1a8864e8a868b30d728f81431/most-popular-puppy-names-2016-thinkstockphotos-527135315.jpg`, it will export to an HTML file with a viewable image.
I'd like to do the same thing with PDFs. How can I include remote images when exporting to PDF via LaTeX?
# Answer
Try the latest org-mode. The Newsgroups, "gmane.emacs.orgmode" has an entry dated Sun, 19 Jan 2020, with news of a text/x-patch 0001-org.el-Add-inline-remote-image-display.patch.
> 1 votes
---
Tags: org-mode, org-export, latex
---
|
thread-55122
|
https://emacs.stackexchange.com/questions/55122
|
How to run a command with 'modify-syntax-entry' reset?
|
2020-01-25T13:39:00.690
|
# Question
Title: How to run a command with 'modify-syntax-entry' reset?
I have used `modify-syntax-entry` to remove underscores from being delimiting characters. e.g:
`(modify-syntax-entry ?_ "w")`
However I would like to temporary allow underscores to be used as a delimiter.
Normally I would temporarily override a variable with `let` in a function.
How can the syntax table be temporarily overridden?
# Answer
> 1 votes
You can create a new syntax table, then run the command in a `with-syntax-table` block:
This is an example of delete forward/backward word, with a modified syntax table.
```
(defun kill-word-sans-delimiter-impl (arg)
(let ((table (make-syntax-table)))
(dolist (ch (list ?- ?_))
(modify-syntax-entry ch "_" table))
(with-syntax-table table (kill-word arg))))
(defun kill-word-backward-sans-delimiter (arg)
(interactive "p")
(kill-word-sans-delimiter-impl (- arg)))
(defun kill-word-forward-sans-delimiter (arg)
(interactive "p")
(kill-word-sans-delimiter-impl arg))
```
---
Tags: syntax-table
---
|
thread-55125
|
https://emacs.stackexchange.com/questions/55125
|
Newsticker failure: (wrong-type-argument listp \.\.\.)
|
2020-01-25T15:58:07.547
|
# Question
Title: Newsticker failure: (wrong-type-argument listp \.\.\.)
Suddenly newsticker is failing to load. I get the following stack trace on error. I have made no recent upgrades.
```
Debugger entered: Lisp error: (wrong-type-argument listp \.\.\.)
newsticker--stat-num-items(Bus\\ Driver\\ Diaries new immortal)
apply(newsticker--stat-num-items Bus\\ Driver\\ Diaries (new immortal))
newsticker--stat-num-items-for-group(Bus\\ Driver\\ Diaries new immortal)
newsticker--treeview-tree-get-tag("Bus Driver Diaries" nil "feeds-4")
#f(compiled-function (g) #<bytecode 0x2370c3d>)("Bus Driver Diaries")
mapcar(#f(compiled-function (g) #<bytecode 0x2370c3d>) ("Sacha Chua" "Good Questions" "Quote of the day" "Tory C Anderson" "Bus Driver Diaries" "Dadacity" "Austen Knows Best" "Every Day Miracles" "Vi Hart" "Brain Pickings" "Inside Clojure" "Reddit Clojure" "Reddit Emacs" "Reddit Postgres" "Reddit Programming Languages"))
newsticker--treeview-tree-expand((tree-widget :args nil :expander newsticker–treeview-tree-expand :tag #("Feeds" 0 5 (mouse-face highlight help-echo "Feeds" :nt-vfeed nil :nt-feed nil :nt-id "feeds" keymap (keymap (13 . newsticker-treeview-tree-do-click) (10 . newsticker-treeview-tree-do-click) (mouse-3 . newsticker-treeview-tree-click) (mouse-1 . newsticker-treeview-tree-click)) face newsticker-treeview-face)) :expander-p #f(compiled-function (&rest \_) #<bytecode 0x204a4dd>) :leaf-icon newsticker–tree-widget-leaf-icon :nt-group ("Sacha Chua" "Good Questions" "Quote of the day" "Tory C Anderson" "Bus Driver Diaries" "Dadacity" "Austen Knows Best" "Every Day Miracles" "Vi Hart" "Brain Pickings" "Inside Clojure" "Reddit Clojure" "Reddit Emacs" "Reddit Postgres" "Reddit Programming Languages") :nt-id "feeds" :keep (:nt-id) :open t :node (item :tag #("Feeds" 0 5 (mouse-face highlight help-echo "Feeds" :nt-vfeed nil :nt-feed nil :nt-id "feeds" keymap (keymap (13 . newsticker-treeview-tree-do-click) (10 . newsticker-treeview-tree-do-click) (mouse-3 . newsticker-treeview-tree-click) (mouse-1 . newsticker-treeview-tree-click)) face newsticker-treeview-face)))))
widget-apply((tree-widget :args nil :expander newsticker–treeview-tree-expand :tag #("Feeds" 0 5 (mouse-face highlight help-echo "Feeds" :nt-vfeed nil :nt-feed nil :nt-id "feeds" keymap (keymap (13 . newsticker-treeview-tree-do-click) (10 . newsticker-treeview-tree-do-click) (mouse-3 . newsticker-treeview-tree-click) (mouse-1 . newsticker-treeview-tree-click)) face newsticker-treeview-face)) :expander-p #f(compiled-function (&rest \_) #<bytecode 0x204a4dd>) :leaf-icon newsticker–tree-widget-leaf-icon :nt-group ("Sacha Chua" "Good Questions" "Quote of the day" "Tory C Anderson" "Bus Driver Diaries" "Dadacity" "Austen Knows Best" "Every Day Miracles" "Vi Hart" "Brain Pickings" "Inside Clojure" "Reddit Clojure" "Reddit Emacs" "Reddit Postgres" "Reddit Programming Languages") :nt-id "feeds" :keep (:nt-id) :open t :node (item :tag #("Feeds" 0 5 (mouse-face highlight help-echo "Feeds" :nt-vfeed nil :nt-feed nil :nt-id "feeds" keymap (keymap (13 . newsticker-treeview-tree-do-click) (10 . newsticker-treeview-tree-do-click) (mouse-3 . newsticker-treeview-tree-click) (mouse-1 . newsticker-treeview-tree-click)) face newsticker-treeview-face)))) :expander)
tree-widget-value-create((tree-widget :args nil :expander newsticker–treeview-tree-expand :tag #("Feeds" 0 5 (mouse-face highlight help-echo "Feeds" :nt-vfeed nil :nt-feed nil :nt-id "feeds" keymap (keymap (13 . newsticker-treeview-tree-do-click) (10 . newsticker-treeview-tree-do-click) (mouse-3 . newsticker-treeview-tree-click) (mouse-1 . newsticker-treeview-tree-click)) face newsticker-treeview-face)) :expander-p #f(compiled-function (&rest \_) #<bytecode 0x204a4dd>) :leaf-icon newsticker–tree-widget-leaf-icon :nt-group ("Sacha Chua" "Good Questions" "Quote of the day" "Tory C Anderson" "Bus Driver Diaries" "Dadacity" "Austen Knows Best" "Every Day Miracles" "Vi Hart" "Brain Pickings" "Inside Clojure" "Reddit Clojure" "Reddit Emacs" "Reddit Postgres" "Reddit Programming Languages") :nt-id "feeds" :keep (:nt-id) :open t :node (item :tag #("Feeds" 0 5 (mouse-face highlight help-echo "Feeds" :nt-vfeed nil :nt-feed nil :nt-id "feeds" keymap (keymap (13 . newsticker-treeview-tree-do-click) (10 . newsticker-treeview-tree-do-click) (mouse-3 . newsticker-treeview-tree-click) (mouse-1 . newsticker-treeview-tree-click)) face newsticker-treeview-face)))))
widget-apply((tree-widget :args nil :expander newsticker–treeview-tree-expand :tag #("Feeds" 0 5 (mouse-face highlight help-echo "Feeds" :nt-vfeed nil :nt-feed nil :nt-id "feeds" keymap (keymap (13 . newsticker-treeview-tree-do-click) (10 . newsticker-treeview-tree-do-click) (mouse-3 . newsticker-treeview-tree-click) (mouse-1 . newsticker-treeview-tree-click)) face newsticker-treeview-face)) :expander-p #f(compiled-function (&rest \_) #<bytecode 0x204a4dd>) :leaf-icon newsticker–tree-widget-leaf-icon :nt-group ("Sacha Chua" "Good Questions" "Quote of the day" "Tory C Anderson" "Bus Driver Diaries" "Dadacity" "Austen Knows Best" "Every Day Miracles" "Vi Hart" "Brain Pickings" "Inside Clojure" "Reddit Clojure" "Reddit Emacs" "Reddit Postgres" "Reddit Programming Languages") :nt-id "feeds" :keep (:nt-id) :open t :node (item :tag #("Feeds" 0 5 (mouse-face highlight help-echo "Feeds" :nt-vfeed nil :nt-feed nil :nt-id "feeds" keymap (keymap (13 . newsticker-treeview-tree-do-click) (10 . newsticker-treeview-tree-do-click) (mouse-3 . newsticker-treeview-tree-click) (mouse-1 . newsticker-treeview-tree-click)) face newsticker-treeview-face)))) :value-create)
widget-default-create((tree-widget :args nil :expander newsticker–treeview-tree-expand :tag #("Feeds" 0 5 (mouse-face highlight help-echo "Feeds" :nt-vfeed nil :nt-feed nil :nt-id "feeds" keymap (keymap (13 . newsticker-treeview-tree-do-click) (10 . newsticker-treeview-tree-do-click) (mouse-3 . newsticker-treeview-tree-click) (mouse-1 . newsticker-treeview-tree-click)) face newsticker-treeview-face)) :expander-p #f(compiled-function (&rest \_) #<bytecode 0x204a4dd>) :leaf-icon newsticker–tree-widget-leaf-icon :nt-group ("Sacha Chua" "Good Questions" "Quote of the day" "Tory C Anderson" "Bus Driver Diaries" "Dadacity" "Austen Knows Best" "Every Day Miracles" "Vi Hart" "Brain Pickings" "Inside Clojure" "Reddit Clojure" "Reddit Emacs" "Reddit Postgres" "Reddit Programming Languages") :nt-id "feeds" :keep (:nt-id) :open t :node (item :tag #("Feeds" 0 5 (mouse-face highlight help-echo "Feeds" :nt-vfeed nil :nt-feed nil :nt-id "feeds" keymap (keymap (13 . newsticker-treeview-tree-do-click) (10 . newsticker-treeview-tree-do-click) (mouse-3 . newsticker-treeview-tree-click) (mouse-1 . newsticker-treeview-tree-click)) face newsticker-treeview-face)))))
widget-apply((tree-widget :args nil :expander newsticker–treeview-tree-expand :tag #("Feeds" 0 5 (mouse-face highlight help-echo "Feeds" :nt-vfeed nil :nt-feed nil :nt-id "feeds" keymap (keymap (13 . newsticker-treeview-tree-do-click) (10 . newsticker-treeview-tree-do-click) (mouse-3 . newsticker-treeview-tree-click) (mouse-1 . newsticker-treeview-tree-click)) face newsticker-treeview-face)) :expander-p #f(compiled-function (&rest \_) #<bytecode 0x204a4dd>) :leaf-icon newsticker–tree-widget-leaf-icon :nt-group ("Sacha Chua" "Good Questions" "Quote of the day" "Tory C Anderson" "Bus Driver Diaries" "Dadacity" "Austen Knows Best" "Every Day Miracles" "Vi Hart" "Brain Pickings" "Inside Clojure" "Reddit Clojure" "Reddit Emacs" "Reddit Postgres" "Reddit Programming Languages") :nt-id "feeds" :keep (:nt-id) :open t :node (item :tag #("Feeds" 0 5 (mouse-face highlight help-echo "Feeds" :nt-vfeed nil :nt-feed nil :nt-id "feeds" keymap (keymap (13 . newsticker-treeview-tree-do-click) (10 . newsticker-treeview-tree-do-click) (mouse-3 . newsticker-treeview-tree-click) (mouse-1 . newsticker-treeview-tree-click)) face newsticker-treeview-face)))) :create)
widget-create(tree-widget :tag #("Feeds" 0 5 (mouse-face highlight help-echo "Feeds" :nt-vfeed nil :nt-feed nil :nt-id "feeds" keymap (keymap (13 . newsticker-treeview-tree-do-click) (10 . newsticker-treeview-tree-do-click) (mouse-3 . newsticker-treeview-tree-click) (mouse-1 . newsticker-treeview-tree-click)) face newsticker-treeview-face)) :expander newsticker–treeview-tree-expand :expander-p #f(compiled-function (&rest \_) #<bytecode 0x204a4dd>) :leaf-icon newsticker–tree-widget-leaf-icon :nt-group ("Sacha Chua" "Good Questions" "Quote of the day" "Tory C Anderson" "Bus Driver Diaries" "Dadacity" "Austen Knows Best" "Every Day Miracles" "Vi Hart" "Brain Pickings" "Inside Clojure" "Reddit Clojure" "Reddit Emacs" "Reddit Postgres" "Reddit Programming Languages") :nt-id "feeds" :keep (:nt-id) :open t)
newsticker–treeview-tree-update()
newsticker–treeview-buffer-init()
newsticker-treeview()
newsticker-show-news()
funcall-interactively(newsticker-show-news)
call-interactively(newsticker-show-news nil nil)
command-execute(newsticker-show-news)
```
# Answer
> 1 votes
It turns out that one of the blogspot blogs on my list, which I'd followed for a while previously, had started to require password authentication (and I didn't know the password). Some result of caching was that it was breaking the whole system. Here was the solution:
1. Remove the offending blog from `newsticker-url-list` (which I defined via customize, in my custom file).
2. Remove the Newsticker cache folder for me located `~/emacs/emacs.d/newsticker/`. I renamed the directory to `newsticker_bak` so I could recover if necessary.
Now I restarted emacs and everything was happy again.
---
Tags: debugging
---
|
thread-55096
|
https://emacs.stackexchange.com/questions/55096
|
How to make fonts show anti-aliased on Linux/X11?
|
2020-01-24T06:33:19.193
|
# Question
Title: How to make fonts show anti-aliased on Linux/X11?
With Linux/X11, certain font's show without anti-aliasing.
* `JetBrains Mono`
* `Cascadia Code`
* These two fonts show with anti-aliasing in other programs (st terminal for example).
* All other fonts show with anti-aliasing (Source Code Pro, Fira Code Medium, Courier Code, Monoid).
* This is the feature-set of emacs `XPM JPEG TIFF GIF PNG RSVG IMAGEMAGICK SOUND GPM DBUS GSETTINGS GLIB NOTIFY ACL GNUTLS LIBXML2 FREETYPE M17N_FLT LIBOTF XFT ZLIB TOOLKIT_SCROLL_BARS GTK3 X11 XDBE XIM MODULES THREADS LIBSYSTEMD LCMS2`
---
Any hints on how to resolve this?
This is X11 with `JetBrains Mono-13` font, I think this is related to Emacs, not `fontconfig`, since the `st` terminal displays the font properly.
This is `emacs -nw` running in `st` terminal.
# Answer
Found a solution, neither of these fonts define themselves as mono-spaced, the solution is to force this.
This can be done in `fonts.conf` or through the font specifier.
* `Cascadia Code-13:spacing=90` (dual spacing)
* `JetBrains Mono-13:spacing=100` (mono spacing)
---
Modifying the `fonts.conf` is meant to work too, although I couldn't get it working. See link.
> 3 votes
---
Tags: fonts, x11
---
|
thread-10475
|
https://emacs.stackexchange.com/questions/10475
|
Wrong letter spacing when using certain fonts
|
2015-04-02T19:45:20.543
|
# Question
Title: Wrong letter spacing when using certain fonts
I'm using Classic Console font in buffers. Unfortunately for some reason letter spacing is terrible in Emacs while being correct in Konsole and other programs.
Text in Emacs:
Text in Konsole (using the same font and size):
Any idea how to fix this?
**Another case with Courier Prime:**
```
'(default ((t (:family "Courier Prime" :foundry "QUQA"
:slant normal :weight normal :height 83
:width normal :spacing 10))))
```
`:spacing 10` did not work.
# Answer
> 1 votes
10 is not a valid spacing, try: `90` dual or `100` mono.
Eg:
```
'(default ((t (:family "Courier Prime" :foundry "QUQA"
:slant normal :weight normal :height 83
:width normal :spacing 90))))
```
---
Tags: fonts, linux
---
|
thread-54914
|
https://emacs.stackexchange.com/questions/54914
|
rewrite relative or absolute path from inherited tramp ssh property with org-babel
|
2020-01-14T14:45:25.800
|
# Question
Title: rewrite relative or absolute path from inherited tramp ssh property with org-babel
I define a global remote session for all my sh block code with properties
```
:PROPERTIES
:HEADER-ARGS:bash: :dir /ssh:xxx@myvm:/home/xxx/
:END:
```
In my other bash blocks, I inherit this property, but after working folder was created, my code are executed in sub folder of `/home/xxx`
Here an example with creation of two folders in `/home/xxx` : `todolist1` and `todolist2`
I finally found that `noweb` is a good path to follow :
```
* Example
:PROPERTIES:
:HEADER-ARGS:bash: :dir /ssh:xxx@myvm:/home/xxx/
:END:
#+NAME: createdir
#+BEGIN_SRC bash :var folder="" :exports none
if [ -n "${folder}" ] ; then
if [ -d "${folder}" ]; then
rm -Rf "${folder}"
fi
mkdir "${folder}"
fi
#+END_SRC
#+NAME: gotodir
#+BEGIN_SRC bash :var folder="" :exports none
if [ -n "${folder}" ] ; then
cd "${folder}"
fi
#+END_SRC
#+BEGIN_SRC bash :var folder="todolist1" :noweb yes :exports both
<<createdir>>
#+END_SRC
#+BEGIN_SRC bash :var folder="todolist2" :noweb yes :exports both
<<createdir>>
#+END_SRC
// First action on todolist 1
#+NAME: addmytodolist1
#+BEGIN_SRC bash :var folder="todolist1" :noweb yes :exports both :results verbatim
<<gotodir>>
cat > todolist1.org <<EOF
#mytodolist
- [ ] item 1
- [X] item 2
EOF
#+END_SRC
// Second action on todolist 1
#+NAME: addmytodolist12
#+BEGIN_SRC bash :var folder="todolist1" :noweb yes :exports both :results verbatim
<<gotodir>>
cat >> todolist1.org <<EOF
- [ ] item 3
EOF
#+END_SRC
// First action on todolist 2
#+NAME: addmytodolist2
#+BEGIN_SRC bash :var folder="todolist2" :noweb yes :exports both :results verbatim
<<gotodir>>
cat > todolist2.org <<EOF
- [X] item 1
- [X] item 2
- [ ] item 3
- [X] item 4
EOF
#+END_SRC
```
To write less verbose and better maintainable code, i try without success :
* to hide the `<<gotodir>>` instruction from export using `:prologue <<gotodir>>` =\> failed
* I also try to directly expand `dir:` into header args, but that doesn't take in account the remote TRAMP ssh connexion : `#BEGIN_SRC sh :var folder="todolist1" :dir (expand-file-name (org-sbe "gotodir"))`
* I suppose it exist some elisp code to get TRAMP ssh folder, and rewrite it/overwrite it by using new url `{trampfolder}/todolist1` or `{trampfolder}/todolist2` ?
There are probably better and more robust way to do that, I'm interested to know what org-mode/org-babel guru :) !
# Answer
> 1 votes
Use elisp in the `:dir` header to fetch the value the `:HEADER-ARGS:bash` from the `PROPERTIES` drawer, remove original `:dir` string and return new value with a subdirectory appended.
* For example, to append the `todolist1`, subdirectory, set the header below on the bash code block.
```
:dir (format "%s/todolist1" (replace-regexp-in-string ":dir +" "" (org-entry-get nil "HEADER-ARGS:bash" t)))
```
Below is an full example, which executes 3 bash code blocks via `tramp` in the default, `todolist1`, and `todolist2` directories.
```
* Example
:PROPERTIES:
:HEADER-ARGS:bash: :dir /ssh:xxx@myvm:/home/xxx
:END:
- The block below will execute in =/ssh:xxx@myvm:/home/xxx=, i.e. the default =:dir=
#+BEGIN_SRC bash
echo "$USER@$HOSTNAME executed this block in the $PWD directory"
#+END_SRC
#+RESULTS:
: xxx@myvm executed this block in the /home/xxx directory
- The block below will execute in =/ssh:xxx@myvm:/home/xxx/todolist1=
#+BEGIN_SRC bash :dir (format "%s/todolist1" (replace-regexp-in-string ":dir +" "" (org-entry-get nil "HEADER-ARGS:bash" t)))
echo "$USER@$HOSTNAME executed this block in the $PWD directory"
#+END_SRC
#+RESULTS:
: xxx@myvm executed this block in the /home/xxx/todolist1 directory
- The block below will execute in =/ssh:xxx@myvm:/home/xxx/todolist2=
#+BEGIN_SRC bash :dir (format "%s/todolist2" (replace-regexp-in-string ":dir +" "" (org-entry-get nil "HEADER-ARGS:bash" t)))
echo "$USER@$HOSTNAME executed this block in the $PWD directory"
#+END_SRC
#+RESULTS:
: xxx@myvm executed this block in the /home/xxx/todolist2 directory
```
---
The `noweb` functionality built into org-mode is amazingly useful!
* Assign names to `SRC` blocks using `#+NAME:` or `:new-ref` headers.
> e.g. `#+NAME: my-code` or `:noweb-ref my-code`
* `SRC` blocks with the same name become a single block when read in order from the top to bottom of the org file.
* Names provide 2 new features inside other `SRC` blocks with the `:noweb yes` header.
+ Use `<<my-code>>` syntax to automatically embed code from blocks named `my-code`.
+ Use `<<my-code()>>` syntax to execute blocks named `my-code` and automatically embed the `#+RESULTS:` generated by the named block. As extra bonus, you can pass variables in the the `()` to the named blocks before execution.
* Use the `:tangle` and `:file` headers to generate multiple files out and org file. As an added bonus, use `:mkdir yes` to automatically create missing subdirectories.
* Mix and match these features to generate source code, config files, images and other forms human documentation from an org-mode file. In the past, I have generated 100+ customized files to build a project from a single org file.
Thanks for asking your question!
---
> **The code in this answer was tested using:**
> emacs version: GNU Emacs 25.2.1 (x86\_64-unknown-cygwin, GTK+ Version 3.22.10)
> org-mode version: 9.1.2
---
Tags: org-mode, org-babel, tramp
---
|
thread-55131
|
https://emacs.stackexchange.com/questions/55131
|
Spaces don't work as expected in isearch
|
2020-01-25T19:43:51.277
|
# Question
Title: Spaces don't work as expected in isearch
I recently installed a new major mode for something I'm working on, and suddenly spaces in expressions I'm searching for don't work as expected. Help!
# Answer
> 1 votes
Anything that makes changes to your `~/.emacs`/`~/.emacs.d/init.el` initialisation file may, for various reasons, tinker with the emacs variables `isearch-regexp-lax-whitespace` and `search-whitespace-regexp`. This may lead to behaviour other than what most emacs users are used to, that is, a single space character standing for an arbitrary number of whitespace characters. Thus, the fix would involve restoring these variables to their defaults, by adding the following lines at the end of the initialisation file.
`(setq isearch-regexp-lax-whitespace t)` `(setq search-whitespace-regexp "\\s-+")`
---
Tags: isearch
---
|
thread-10659
|
https://emacs.stackexchange.com/questions/10659
|
ede-cpp-root-project is missing
|
2015-04-13T11:37:56.637
|
# Question
Title: ede-cpp-root-project is missing
The cedet info I am using with emacs 23.4.1
```
ECB 2.40 uses CEDET 1.0 (contains semantic 2.0, eieio 1.3, speedbar <unknown version>).
```
I am trying to create a cpp-root-project for out-of-source-tree building, however, when I try to create a project definition using
```
(ede-cpp-root-project "project-root"
:file "~/dev/gorgon/build/dummy-makefile"
:include-path '("/Source")
;:system-include-path '("~/linux")
)
```
by requiring the file containing above code to load with
```
(require 'projects)
```
it gives following error
```
Symbol's function definition is void : ede-cpp-root-project
```
at first I thought maybe this "feature" is lacking so I tried to list available projects from ede projects and it listed
```
Automake
make
```
My question is does this functionality supported in CEDET 1.0 or am I doing something wrong?
the codes related to ede in my init.el file
```
(global-ede-mode 1)
(semantic-mode 1)
(ede-enable-generic-projects)
(global-semantic-idle-scheduler-mode)
(global-semantic-idle-completions-mode)
(global-semantic-decoration-mode)
(global-semantic-highlight-func-mode)
(global-semantic-show-unmatched-syntax-mode)
```
# Answer
According to the `Commentary: for`../ede/ede-cpp-root.el\`, the file should only be the FILENAME and not a path. Try changing to
```
(ede-cpp-root-project "project-root"
:file "dummy-makefile"
:include-path '("/Source" "~/dev/gorgon/build")
;:system-include-path '("~/linux")
)
```
cedet-1.1 is very old. Try updating to cedet-2.0.
> 0 votes
---
Tags: cedet
---
|
thread-315
|
https://emacs.stackexchange.com/questions/315
|
Using DeskTop for basic project management
|
2014-09-26T13:02:52.007
|
# Question
Title: Using DeskTop for basic project management
I would like to use DeskTop for basic project management, i.e. opening a set of buffers and restore histories depending on the project I am working on. Is this possible, i.e. having one desktop file in a project directory and how can I achieve this?
# Answer
I needed to manage the desktop files just like you; have a separate desktop file for each project and save buffers, Emacs variables, etc independently for each.
I was able to achieve that using a package called `bookmark+`.
# bookmark+
Library **Bookmark+** manages different types of bookmarks, one of those is **Desktop Bookmarks**.
After installing the package,
* You need to have `(require 'bookmark+)` in your `init.el`
* To create a bookmark for each project, set up the buffers you'd like for each project and do `M-x bmkp-set-desktop-bookmark` or `C-x p K`. That will ask you where you want to save the desktop file and you can choose to save it in that project's folder.
* Once you have set the desktop bookmarks for all projects, you can jump to different bookmarks using `M-x bmkp-desktop-jump` or `C-x j K`.
The Bookmark+ doc on Emacs Wiki is very informative if you want to learn more about this package.
# desktop.el
In addition to that, I have the following to set up the `desktop` package where I can choose what all I want to save per desktop
```
(desktop-save-mode 1)
;; Source: https://github.com/purcell/emacs.d/blob/master/lisp/init-sessions.el
; save a bunch of variables to the desktop file
;; for lists specify the len of the maximal saved data also
(setq desktop-globals-to-save
(append '((comint-input-ring . 50)
(compile-history . 30)
desktop-missing-file-warning
(dired-regexp-history . 20)
(extended-command-history . 30)
(face-name-history . 20)
(file-name-history . 100)
(grep-find-history . 30)
(grep-history . 30)
(ido-buffer-history . 100)
(ido-last-directory-list . 100)
(ido-work-directory-list . 100)
(ido-work-file-list . 100)
(magit-read-rev-history . 50)
(minibuffer-history . 50)
(org-clock-history . 50)
(org-refile-history . 50)
(org-tags-history . 50)
(query-replace-history . 60)
(read-expression-history . 60)
(regexp-history . 60)
(regexp-search-ring . 20)
register-alist
(search-ring . 20)
(shell-command-history . 50)
tags-file-name
tags-table-list)))
```
# Saving project-specific desktops when quitting emacs
I find it useful to bind the below function to `C-x C-c` so that the desktops get saved automatically when I quit emacs.
```
(defun save-desktop-save-buffers-kill-emacs ()
"Save buffers and current desktop every time when quitting emacs."
(interactive)
(desktop-save-in-desktop-dir)
(save-buffers-kill-emacs))
```
At times, I wouldn't want to save the desktop when quitting emacs. For those occasions, I use this other function and have bound that to `C-x M-c`.
```
;; Kill emacs when running in daemon mode or not
;; Source: http://lists.gnu.org/archive/html/emacs-devel/2011-11/msg00348.html
(defun tv-stop-emacs ()
(interactive)
(if (daemonp)
(save-buffers-kill-emacs)
(save-buffers-kill-terminal)))
```
> 14 votes
# Answer
I tend to use the following setup to save and load/read the desktop file from the local directory of the respective projects:
```
(require 'desktop)
(setq desktop-path (list "./"))
(desktop-save-mode 1)
(desktop-read)
```
This is not without issues as switching projects via e.g., projectile or other project management utilities does not load any desktop files but one can utilize the `projectile-after-switch-project-hook` function to call a private function to do the needful
> 0 votes
---
Tags: session, desktop, project
---
|
thread-55134
|
https://emacs.stackexchange.com/questions/55134
|
org-priority and org-insert-structure-template key binding clash
|
2020-01-26T07:45:54.807
|
# Question
Title: org-priority and org-insert-structure-template key binding clash
I'm using or-mode 9.2 and when I hit `C-c C-,` and I got the following message:
```
Before first headline at position 480 in buffer index.org
```
The message indicates that the key actually get translated as `C-c ,`, which maps to `org-priority`. I turn on `M-x toggle-debug-on-error` and see the following when I press `C-c C-,`
```
Debugger entered--Lisp error: (error "Before first headline at position 470 in buffer index.org")
signal(error ("Before first headline at position 470 in buffer index.org"))
error("Before first headline at position %d in buffer %s" 470 #<buffer index.org>)
org-back-to-heading(t)
org-priority(nil)
funcall-interactively(org-priority nil)
call-interactively(org-priority nil nil)
command-execute(org-priority)
```
Does anyone run into issue like this?
# Answer
> 2 votes
I don't know anything about Macs or iTerm2, but running emacs in a terminal will sometimes cause problems like this. E.g. I work on Linux under X with a GUI emacs, but if I start an `xterm` or `gnome-terminal` and run `emacs -nw` in it, the key `C-,` does not exist: if I hold down the `Control` key and press `,` what I get is just `,`. This is probably what you are running into.
In GUI Emacs under X, the window system allows emacs to synthesize keys: it knows that you pressed down the `Control` key and then you pressed down `,` so emacs can pretend that it saw a `C-,`.
Try it: say `C-h c C-,` \- if you try this in GUI emacs, it will most probably say `C-, is undefined` because most modes don't define it. But note that it actually saw a `C-,`. If you try the same thing in your terminal emacs, it'll say `, runs the command self-insert-command`: it does not know that you pressed the `Control` key; it only sees the comma.
What to do? You can run GUI emacs instead; or you can bind `org-insert-structure-template` to some key that you *can* press - function keys might be useful here, because terminal emacs (at least xterm and gnome-terminal on linux - YMMV) recognizes not just the bare key (e.g. F1), but also modified versions: `S-F1` is known as `<f13>` (there are usually twelve function keys on standard US keyboards) and `C-F1` is known as `<f25>`. You can check these things out with the `C-h c` trick above.
So you can try something like this:
```
(define-key org-mode-map (kbd "<f25>") 'org-insert-structure-template)
```
Then pressing `C-F1` would invoke the `org-insert-structure-template` command.
---
Tags: org-mode
---
|
thread-55140
|
https://emacs.stackexchange.com/questions/55140
|
define-key doesn't seem to work on certain keymap
|
2020-01-27T00:13:31.550
|
# Question
Title: define-key doesn't seem to work on certain keymap
I'm trying to add some bindings to `undo-tree-visualizer-mode-map`. To do so I use:
```
(define-key undo-tree-visualizer-mode-map (kbd "S-l") 'undo-tree-visualizer-quit)
```
But it doesn't work, and if I do `describe-keymap` afterwards I see that the binding wasn't added.
There seems to be a few keymap where this behavior happens, such as `ivy-occur-mode-map` and `Info-mode-map` as well.
Any idea why is that? And how can I add bindings to those keymaps?
# Answer
> 4 votes
> ```
> S-l
>
> ```
You need to use `L` rather than `S-l`.
This is a quirk of key sequences in Emacs -- for letters (a-z), the shift modifier syntax `S-` won't do what you want, *unless* `C-` is also used in the sequence.
You should therefore write upper-case letters explicitly in key sequences.
See also https://stackoverflow.com/q/38180797/324105
For clarity:
```
(kbd "L")
"L"
(kbd "S-l")
[33554540]
(kbd "C-l")
"^L"
(kbd "C-L")
"^L"
(kbd "C-S-l")
[33554444]
```
Arguably Emacs ought to translate `[33554540]` to `"L"`, or otherwise recognise it as intended, but in practice (at least at present) that doesn't happen.
---
Tags: key-bindings
---
|
thread-55143
|
https://emacs.stackexchange.com/questions/55143
|
Change the color of ivy-current-match depending on the caller
|
2020-01-27T02:08:19.017
|
# Question
Title: Change the color of ivy-current-match depending on the caller
When using `ivy`, say I want the current match to be red when calling `counsel-M-x`, but blue when calling `counsel-find-file`.
Is there a simple way of changing `ivy-current-match` depending on the function calling it?
# Answer
> 1 votes
AFAIK, there is no built-in support for this, but Ivy provides various hooks that you can plug your own logic into. Here is one way to achieve what you want, using the `ivy-hooks-alist` user option:
```
(defvar my-ivy-match-faces
'((counsel-M-x (:background "red")))
"Alist mapping Ivy callers to a list of face specs.
Used by `my-ivy-remap-match-face', which see.")
(defun my-ivy-remap-match-face ()
"Locally remap `ivy-current-match' to caller-specific face specs.
Which face specs to apply for each caller is determined by
`my-ivy-match-faces'. If the current caller is unknown, or if
there is no entry for it, no remapping is applied."
(when-let* ((caller (ivy-state-caller ivy-last))
(specs (alist-get caller my-ivy-match-faces)))
(apply #'face-remap-add-relative 'ivy-current-match specs)))
(with-eval-after-load 'ivy
;; Remap the current match face as the default Ivy hook. Note that specifying
;; a different hook for a particular caller will override this setting.
(setf (alist-get t ivy-hooks-alist) #'my-ivy-remap-match-face))
```
The idea here is to look up the current Ivy caller (e.g. `counsel-M-x`) right after Ivy has set up the minibuffer, and then locally remap\[1\] the `ivy-current-match` face to a list of face specs of your choosing. In the sample code above, I have remapped the background to be red for `counsel-M-x` (see the variable `my-ivy-match-faces`).
Note that the way I modify `ivy-hooks-alist`, namely by setting `my-ivy-remap-match-face` as the default fallback hook, is kind of brittle. This is because any subsequent addition to this alist may override `my-ivy-remap-match-face`. Vanilla Ivy does not modify `ivy-hooks-alist`, so this is not an issue at the moment, but it may become one in the future or if you use other packages which modify this user option.
A more robust solution would then be to submit a feature request or PR\[2\] to make `ivy-hooks-alist` more flexible, e.g. by supporting multiple hooks per caller, and always running the default fallback hooks.
If that is not an option, you can advise\[3\] specific entries in `ivy-hooks-alist` to do your bidding. I will be happy to provide a sample implementation of this if asked.
---
Tags: faces, ivy
---
|
thread-55148
|
https://emacs.stackexchange.com/questions/55148
|
Configure the delay before window showing command completions is shown
|
2020-01-27T15:12:35.897
|
# Question
Title: Configure the delay before window showing command completions is shown
When I start entering a command and pause, this helpful window pops up at the bottom:
When I don't pause, it doesn't show up.
But sometimes, it takes more time to complete a command that I know, e.g. if it requires me to access modifier keys like shift or control.
In those cases, this window briefly flashes and disappears, often also freezing up the editor for about half a second or so.
How can I increase this pause time so I'm only shown the command completions if the pause is longer than, say 2 seconds?
# Answer
> 0 votes
What are you using for showing command completions? That looks a like `which-key`. If that's the case, I think you should modify `which-key-idle-delay`:
```
Delay (in seconds) for which-key buffer to popup. This
variable should be set before activating which-key-mode.
A value of zero might lead to issues, so a non-zero value is
recommended
(see https://github.com/justbur/emacs-which-key/issues/134).
```
You may need to disable and re-enable `which-key-mode` to see the change take effect.
---
Tags: spacemacs, completion
---
|
thread-55113
|
https://emacs.stackexchange.com/questions/55113
|
Preload problem: Emacs as daemon in X
|
2020-01-24T17:14:53.010
|
# Question
Title: Preload problem: Emacs as daemon in X
Background:
I want to use emacs like tmux which can run as persistent session as well as shorten the time for me to start bringing up emacs when I want to (as inspired by these: Emacs and a Tmux replacement and Detaching and re-attaching to emacs server )
In my .profile, I tried to start emacs in daemon mode in the background, and it didn't start, and there was this message:
```
http://bugzilla.gnome.org/show_bug.cgi?id=85715
Emacs might crash when run in daemon mode and the X11 connection is unexpecedly lost.
Using an Emacs configured with --with-x-toolkit=lucid does not have this problem.
```
Then I start `emacs with -Q --debug-init --daemon --with-x-toolkit=lucid`.
But the process hangs there as well as my logging in.
When I check with tty1, I see always 2 pairs of processes:
```
14183 ? Sl 0:00 /usr/bin/gnome-keyring-daemon --daemonize --login
14187 ? Sl 0:00 /usr/bin/gnome-keyring-daemon --daemonize --login
14132 ? S 0:00 /usr/bin/emacs -Q --debug-init --daemon --with-x-toolkit=lucid
14138 ? Ssl 0:00 /usr/bin/emacs -Q --debug-init --daemon --with-x-toolkit=lucid
```
And if I kill one of the emacs process (usually with the single S), then the other keyring-daemon process will disappear and I will be automatically brought back to the logon screen and the logon will be successful too. One examination with `ps x` in the Xsession, there is only 1 emacs process and only 1 keyring process.
Questions:
1. What is happening so that the emacs startup hangs?
2. What can I do in my settings to make the emacs daemon startup nicely?
\[I am using Emacs 25.1.1 on all most updated Devuan ASCII 2.1 distro (I know, my distro "Devuan" is so slow to update packages)\]
Edit 1: After I have fully started X and in XWindows environment, and if I do a `$> killall emacs` first and make sure no emacs process is running, and then try starting the daemon with the same line. Here is the result:
```
My_User_Name@devux:~$ emacs --daemon
Warning: due to a long standing Gtk+ bug
bugzilla.gnome.org/show_bug.cgi?id=85715
Emacs might crash when run in daemon mode and the X11 connection is unexpectedly lost.
Using an Emacs configured with --with-x-toolkit=lucid does not have this problem.
```
(and then starting my site-list and then .emacs etc.)
```
Starting Emacs daemon.
My_User_Name@devux:~$ ps x | grep emacs
17553 ? Ssl 0:06 emacs --debug-init --daemon
18843 pts/0 S+ 0:00 grep --color=auto emacs
```
Edit 2: On further trial-and-error, I move the `emacs --daemon` from `.profile` to `.xsessionrc`, and then to the startup tab of `xfce4-session-settings`. And there is no hiccup for starting the daemon or for the login. I will investigate further for the actual reasons. \[By the way, having the emacs daemon started does some convenience for me: my emacs startup time is beyond 12-15 seconds, and now with emacsclient -c -q, I can bring up a frame in less than a second and emacs serves also some functions like tmux in the background.\]
# Answer
Don't use all those options at once; some of them are doing incompatible things:
* `--debug-init` loads emacs, and stops with a stack trace if it encounters a problem. If it's in daemon mode, you won't see this, so won't know anything unexpected has happened. Thus, it will seem as if Emacs has crashed or become unresponsive. Also, if you are debugging your init, you need to actually load your init. That means you can't use the `--Q` option (see next)
* `-Q` means don't load any of your configuration files. Which are the things that `debug-init` is trying to debug. You only use `-Q` when you think you have an emacs bug to sort out, not when you want to load a normal Emacs session
* `--daemon` loads Emacs to run as a server in the background. This will be a problem if emacs encounters any problems during start up. When it does, it will often ask the user for some input.
* `--with-x-toolkit=lucid` is a compile option. It doesn't do anything useful when you try to start emacs. It might cause problems, if Emacs interprets it as the name of a file it should open. This could generate a problem, and if Emacs is trying to start in daemon mode you won't see any visible sign of the problem.
What should you actually be doing? First, make sure Emacs starts normally when you call it from the command line with regular `emacs` (i.e., no options).
If there are any errors, you'll need to fix these before trying to use `daemon` mode. You can ignore the warning about the lucid toolkit, if that's the only problem you see. (you can fix that by recompiling emacs yourself, but it's probably not necessary).
Once you confirm that `emacs` loads a properly configured emacs session, you can close that session and try starting the daemon: `emacs --daemon`. Then check that you can open a new client via `emacsclient`. If that works, you can add `emacs --daemon` to the appropriate spot to have it start when you login (which could be .profile, or wherever your desktop manager looks for files to start at login.
> 1 votes
# Answer
I’m not super sure this is an emacs issue. Here are some things to try:
1. I think your `.profile` file can be run a bunch of times. Maybe try moving that command into your `.xprofile`
2. Maybe just set your `EDITOR` to `"emacsclient -ca="`. Then the emacs will start whenever you actually want to use it. But maybe you want to have emacs do things in the background.
> 0 votes
---
Tags: start-up, bash, emacs-daemon, daemon, gtk3
---
|
thread-12556
|
https://emacs.stackexchange.com/questions/12556
|
Disabling the "Auto-saving...done" message
|
2015-05-20T18:14:38.023
|
# Question
Title: Disabling the "Auto-saving...done" message
I want my documents to be auto-saved, but I don't want to be interrupted with the message "Auto-saving...done" every few minutes.
Is there a way to just disable this message, but not the auto-saving functionality?
I have tried the following without success: https://stackoverflow.com/questions/22511847/how-to-disable-auto-save-message
# Answer
> 6 votes
> Is there a way to just disable this message, but not the auto-saving functionality?
Yes, Emacs 27 will introduce the user option `auto-save-no-message`:
```
auto-save-no-message is a variable defined in ‘keyboard.c’.
Its value is nil
You can customize this variable.
This variable was introduced, or its default value was changed, in
version 27.1 of Emacs.
Documentation:
Non-nil means do not print any message when auto-saving.
```
Quoth `(emacs) Auto Save`:
```
18.6 Auto-Saving: Protection Against Disasters
==============================================
From time to time, Emacs automatically saves each visited file in a
separate file, without altering the file you actually use. This is
called “auto-saving”. It prevents you from losing more than a limited
amount of work if the system crashes.
When Emacs determines that it is time for auto-saving, it considers
each buffer, and each is auto-saved if auto-saving is enabled for it and
it has been changed since the last time it was auto-saved. When the
‘auto-save-no-message’ variable is set to ‘nil’ (the default), the
message ‘Auto-saving...’ is displayed in the echo area during
auto-saving, if any files are actually auto-saved; to disable these
messages, customize the variable to a non-‘nil’ value. Errors occurring
during auto-saving are caught so that they do not interfere with the
execution of commands you have been typing.
```
To customise the variable, you can either `M-x``customize-variable``RET``auto-save-no-message``RET` or simply:
```
(setq-default auto-save-no-message t)
```
# Answer
> 2 votes
You can ensure `do-auto-save` is called with the correct argument to suppress the message by *advising* the function:
```
(defun my-auto-save-wrapper (save-fn &rest args)
(apply save-fn '(t)))
(advice-add 'do-auto-save :around #'my-auto-save-wrapper)
```
# Answer
> 0 votes
because `do-auto-save` is called by `c` code here, so `advice` is not possible here.
we can use an idle timer. following code is tested.
```
(setq auto-save-list-file-prefix nil)
(setq auto-save-visited-file-name t)
(setq auto-save-timeout 0)
(setq auto-save-interval 0)
(defun my-auto-save-silent ()
(do-auto-save t))
(run-with-idle-timer 1 t #'my-auto-save-silent)
```
also, cf. http://tinyurl.com/ydeyn4ks
# Answer
> 0 votes
Auto save runs `auto-save-hook` before saving so you can use this to temporary disable messages (they are still logged to the `*Messages*` buffer):
```
(add-hook 'auto-save-hook 'auto-save-silence+)
(defun auto-save-silence+ ()
(setq inhibit-message t)
(run-at-time 0 nil
(lambda ()
(setq inhibit-message nil))))
```
---
Tags: auto-save, message
---
|
thread-55156
|
https://emacs.stackexchange.com/questions/55156
|
How to match the nondirectory part of a filename with a regular expression?
|
2020-01-28T01:26:18.450
|
# Question
Title: How to match the nondirectory part of a filename with a regular expression?
Whats the correct way to match a filename from a full path using `string-match-p`.
Say I want to check if the file is a git commit message `COMMIT_EDITMSG` or `svn-commit.tmp` or `svn-commit.3.tmp` to pass to 3rd party code that only takes regular expressions (something like `auto-mode-alist`).
eg: `(string-match my-clever-regex "/path/to/svn-commit.3.tmp")`
Using the `COMMIT_EDITMSG` as an example:
* `"COMMIT_EDITMSG\\'"` also matches `PREFIX_COMMIT_EDITMSG`.
* `"/COMMIT_EDITMSG\\'"` fails to match `COMMIT_EDITMSG` or `\COMMIT_EDITMSG`.
How can I match a filename which may or may not contain a path?
# Answer
This regular expression matches both `COMMIT_EDITMSG` and `/path/to/COMMIT_EDITMSG`.
```
(string-match-p "\\`\\(?:.*[\\/]\\)?COMMIT_EDITMSG\\'" "/path/to/COMMIT_EDITMSG")
```
---
If the filename is from `buffer-file-name` there is no need to check for `\` separators as Emacs converts them to `/`, there is also no need to account for no need to account for only the filename case as the filename will either be the full path or `./`.
Since this isn't part of the original question, adding this as a second example.
```
(string-match-p "/COMMIT_EDITMSG\\'" "/path/to/COMMIT_EDITMSG")
```
---
Thanks to suggestions from @phils which helped improve this answer.
> 0 votes
# Answer
I'd do
```
(equal "COMMIT_EDITMSG"
(file-name-nondirectory <file>))
```
> 4 votes
---
Tags: regular-expressions, git, filenames
---
|
thread-50212
|
https://emacs.stackexchange.com/questions/50212
|
Is there a better way in Emacs Lisp to print the list of monospace fonts in a separate buffer?
|
2019-04-29T14:38:41.793
|
# Question
Title: Is there a better way in Emacs Lisp to print the list of monospace fonts in a separate buffer?
Is there a better way in Emacs Lisp to print the list of monospace fonts in a separate buffer?
I found out the following Emacs Lips code in a gist on Github:
```
(defun font-is-mono-p (font-family)
;; with-selected-window
(let ((wind (selected-window))
m-width l-width)
(with-current-buffer "*Monospace Fonts*"
(set-window-buffer (selected-window) (current-buffer))
(text-scale-set 4)
(insert (propertize "l l l l l" 'face `((:family ,font-family))))
(goto-char (line-end-position))
(setq l-width (car (posn-x-y (posn-at-point))))
(newline)
(forward-line)
(insert (propertize "m m m m m" 'face `((:family ,font-family) italic)))
(goto-char (line-end-position))
(setq m-width (car (posn-x-y (posn-at-point))))
(eq l-width m-width))))
(defun compare-monospace-fonts ()
"Display a list of all monospace font faces."
(interactive)
(pop-to-buffer "*Monospace Fonts*")
(erase-buffer)
(dolist (font-family (font-family-list))
(when (font-is-mono-p font-family)
(let ((str font-family))
(newline)
(insert
(propertize (concat "The quick brown fox jumps over the lazy dog 1 l; 0 O o ("
font-family ")\n") 'face `((:family ,font-family)))
(propertize (concat "The quick brown fox jumps over the lazy dog 1 l; 0 O o ("
font-family ")\n") 'face `((:family ,font-family) italic)))))))
```
The way it tries to find out if a font is mono-spaced is to print some lines and check for their length as far as I can see:
But is there a better way, e.g. to **filter out** only the mono spaced fonts to begin with, I mean without relying on actually printing strings in that font and comparing the width of the display. I mean by using some font specification, etc. I read https://www.gnu.org/software/emacs/manual/html\_node/elisp/Low\_002dLevel-Font.html, but it doesn't mention anything about "monospace" (unlike https://www.gnu.org/software/emacs/manual/html\_node/emacs/Fonts.html).
# Answer
The following seems working:
```
(seq-filter (lambda (font)
(when-let ((info (font-info font)))
(string-match-p "spacing=100" (aref info 1))))
(font-family-list))
;; =>
("Andale Mono"
"Courier"
"Courier New"
"GB18030 Bitmap"
"Input"
"Menlo"
"Monaco"
"PT Mono"
"Source Code Pro"
"Apple Braille"
"Apple Color Emoji")
```
the above produces the same result as macOS's Font Book.app:
I am not a font expert and `spacing=100` is from by https://unix.stackexchange.com/questions/363365/command-to-list-all-monospace-fonts-known-to-fontconfig/363368.
> 3 votes
# Answer
Small modification of @xuchunyang's answer for Windows, Emacs 26:
```
(require 'subr-x)
(seq-filter (lambda (font)
(when-let ((info (font-info font)))
(string-match-p "-mono-" (aref info 0))))
(font-family-list))
```
> 2 votes
---
Tags: fonts
---
|
thread-55161
|
https://emacs.stackexchange.com/questions/55161
|
fill-paragraph does not honor fill-column
|
2020-01-28T08:54:37.977
|
# Question
Title: fill-paragraph does not honor fill-column
`C-h v` `fill-column` gives me 80.
Pasting the lorem ipsum text in `*scratch*` (lines longer than 80) then going `M-x` `fill-paragraph` fills around column 66.
The same in `c-mode`. In this mode, comment wraps seem to work, but not raw text outside code.
If I switch to `text-mode`, filling paragraphs work as I expect (column 80).
What makes it fail in `*scratch*` and in `c-mode`?
# Answer
Filling is a general facility which can depend on more than just the `fill-column` variable, however the first thing to test is simply that you're checking the `fill-column` value for the correct buffer -- it can have a different value in each buffer; so if you typed `C-h``v` from some other buffer, you might see the wrong value.
`C-h``f` `fill-paragraph` tells us that its behaviour depends on the value of the `fill-paragraph-function` variable, which in turn is described thus:
> ```
> Mode-specific function to fill a paragraph, or nil if there is none.
> If the function returns nil, then `fill-paragraph' does its normal work.
> A value of t means explicitly "do nothing special".
> Note: This only affects `fill-paragraph' and not `fill-region'
> nor `auto-fill-mode', so it is often better to use some other hook,
> such as `fill-forward-paragraph-function'.
>
> ```
In `*scratch*` `C-h``v` `fill-paragraph-function` leads us to:
> ```
> lisp-fill-paragraph is an interactive compiled Lisp function in
> `lisp-mode.el'.
>
> (lisp-fill-paragraph &optional JUSTIFY)
>
> Like M-q, but handle Emacs Lisp comments and docstrings.
> If any of the current line is a comment, fill the comment or the
> paragraph of it that point is in, preserving the comment's indentation
> and initial semicolons.
>
> ```
Similarly, in `c-mode` buffers we're using the function `c-fill-paragraph` (which see).
As you might imagine, many of the mode-specific functions use alternative variables with `fill-column` in their name, so this ought to show you some illuminating things as well:
`M-x` `apropos-variable` `RET` `fill-column` `RET`
> 2 votes
---
Tags: fill-paragraph, auto-fill-mode, fill-column
---
|
thread-55165
|
https://emacs.stackexchange.com/questions/55165
|
Uneven line numbers with display-line-numbers
|
2020-01-28T11:11:54.903
|
# Question
Title: Uneven line numbers with display-line-numbers
Emacs for some reason did not vacate equal spaces for each line number, So the lines were starting at different places which made it harder to keep track of alignment. It wasn't just the relative mode which had this problem, even the absolute mode does. Linum mode is quite heavy when compared to display-line-numbers.el.
# Answer
> 4 votes
This is what fixed my issue. All this is doing is, when the buffer is being setup for reading it would read the last line number and add the width of the number as the display-line-numbers-width.
```
(defun display-line-numbers-equalize ()
"Equalize The width"
(setq display-line-numbers-width (length (number-to-string (line-number-at-pos (point-max))))))
(add-hook 'find-file-hook 'display-line-numbers-equalize)
```
---
Tags: display, line-numbers
---
|
thread-55176
|
https://emacs.stackexchange.com/questions/55176
|
Can Dired query replace use regular expression to rename a group of files?
|
2020-01-28T23:48:08.013
|
# Question
Title: Can Dired query replace use regular expression to rename a group of files?
So I have long list of files that I'm trying to use regex to rename but, it looks like it does not take standard regular expressions. I’m sure I’m just doing this incorrectly.
After entering dired and `C-x C-q` to make the files writable. I do `M-%` or `query-replace-regexp` to start the regex file rename but it does not work.
I tried doing a query replace for `.eps\d.*` to match everything then a replace with `.mkv` with no luck. What is the proper way to complete this task?
Starting File list example:
```
Show.S03E01.eps3.0.modifer322344.mkv
Show.S03E02.eps3.1.someihtng.else.mkv
Show.S03E03.eps3.2.lega.matters.mkv
Show.S03E04.eps3.3.data.par2.mkv
```
Finished File list example:
```
Show.S03E01.mkv
Show.S03E02.mkv
Show.S03E03.mkv
Show.S03E04.mkv
```
# Answer
> 3 votes
> I do `M-%` to start the regex file rename but it does not work.
`M-%` runs the command `query-replace`
`C-M-%` runs the command `query-replace-regexp`
---
> I see that it does not like backslash as an escape like `\d` for digits.
Indeed; a digit is matched with `[0-9]` or `[[:digit:]]`
You can read about the regular expression syntax supported by Emacs with:
* `C-h``i``g` `(emacs)Search`
* `C-h``i``g` `(elisp)Regular Expressions`
---
> I tried doing a query replace for `.eps\d.*` to match everything then a replace with `.mkv`
Search for `\.eps[0-9].*`
or perhaps `\.eps[0-9].*\.mkv`
---
Tags: dired, regular-expressions, query-replace
---
|
thread-55175
|
https://emacs.stackexchange.com/questions/55175
|
Ispell suggested word window too small
|
2020-01-28T21:31:55.773
|
# Question
Title: Ispell suggested word window too small
When I use `ispell`, it suggests replacements for misspelled words in a window at the top of the screen. However, it is too small, and I can barely read the words it contains.
How do I increase the size of the "suggestions" window?
I'm using Emacs in GUI mode. Currently, I primarily use it on my work MacBook (Mac OS Mojave) but I believe I've observed similar results in Ubuntu 19.10.
# Answer
Customize the variable `ispell-choices-win-default-height`, which has a default value of `2`. The doc-string states:
```
"The default size of the `*Choices*' window, including the mode line.
Must be greater than 1."
```
> 3 votes
---
Tags: window, ispell
---
|
thread-55181
|
https://emacs.stackexchange.com/questions/55181
|
How to set the default of `truncate-lines` for dired buffers to `truncate`?
|
2020-01-29T07:42:49.953
|
# Question
Title: How to set the default of `truncate-lines` for dired buffers to `truncate`?
How can I set the default of `truncate-lines` for dired buffers to `truncate`?
I.e. when I open a new dired buffer it should show the directory truncated and not wrapped into the next line.
# Answer
> 3 votes
```
(defun my-dired-mode-hook ()
"Custom behaviours for `dired-mode'."
;; `truncate-lines' is automatically buffer-local.
(setq truncate-lines t))
(add-hook 'dired-mode-hook #'my-dired-mode-hook)
```
---
Tags: dired, major-mode, line-truncation
---
|
thread-55184
|
https://emacs.stackexchange.com/questions/55184
|
How to highlight in different colors for variables inside `fstring` on python-mode
|
2020-01-29T11:23:11.193
|
# Question
Title: How to highlight in different colors for variables inside `fstring` on python-mode
I am using `python-mode` which colors the parameters.
When I concatinate strings the variable color is represented as different:
On the other hand, if I use `fstring`, the variable is not represented as different color:
Please note that, if I enter non-existing variable, `python-mode` detects it:
**\[Q\]** Is there any way to give a color to variables inside a `fstring` under `python-mode`?
# Answer
I think this will do it for Emacs versions \< 27.1
```
(require 'python)
(setq python-font-lock-keywords
(append python-font-lock-keywords
'(;; this is the full string.
;; group 1 is the quote type and a closing quote is matched
;; group 2 is the string part
("f\\(['\"]\\{1,3\\}\\)\\(.+?\\)\\1"
;; these are the {keywords}
("{[^}]*?}"
;; Pre-match form
(progn (goto-char (match-beginning 0)) (match-end 0))
;; Post-match form
(goto-char (match-end 0))
;; face for this match
(0 font-lock-variable-name-face t))))))
```
For later versions replace `python-font-lock-keywords` with `python-font-lock-keywords-maximum-decoration`.
I think this works on all strings now, including multiline ones (that seems to be a tricky one in general though). I left the {} in the highlight, they get replaced and that made sense to me.
Here is what it looks like for me:
font lock is hard!
The two other posts I looked at related to this are:
1. Repeated regex capture for font-lock
2. Python mode - custom syntax highlighting.
> 11 votes
---
Tags: python, syntax-highlighting, coloring
---
|
thread-55180
|
https://emacs.stackexchange.com/questions/55180
|
How do I efficiently copy or move elements from one vector to another?
|
2020-01-29T06:17:28.337
|
# Question
Title: How do I efficiently copy or move elements from one vector to another?
I'm working on optimizing some Emacs Lisp code that I've written. Part of this code needs to move elements from one vector to another. Currently, I have this code:
```
(defun copy-elements (source source-begin source-end
destination destination-begin)
"Copy elements from SOURCE to DESTINATION.
We start at SOURCE[SOURCE-BEGIN], and the last element copied is
SOURCE[SOURCE-END - 1].
These elements are copied beginning at DESTINATION[DESTINATION-BEGIN].
This means DESTINATION must have enough space.
This method returns DESTINATION, and does not modify SOURCE.
If SOURCE and DESTINATION are the same, overlapping could cause issues."
(dotimes (i (- source-end source-begin))
(setf (seq-elt destination (+ i destination-begin))
(seq-elt source (+ source-begin i))))
destination)
```
This works fine:
```
ELISP> (let ((v1 [1 2 3]) (v2 [4 5 6])) (copy-elements v1 0 1 v2 2) (list v1 v2))
([1 2 3]
[4 5 1])
```
But it's not as efficient as it could be. Even though we know we're working on consecutive elements, we move each one separately.
Is there a way to move or copy these elements? I don't need to share structure, so copying them would be perfectly fine if that's more efficient.
In `fns.c`, the function `copy-sequence` uses the C function `memcpy` to move things around vectors, but I don't see a way to do that myself.
What can I do to speed up moving consecutive elements from one vector to another?
# Answer
I don't think there's such a thing and using `memcpy` on incompatible types is risky, so I went for the dumb solution in my last emulator project:
```
(defun chip8--memcpy (dest dest-offset src src-offset n)
(dotimes (i n)
(aset dest (+ dest-offset i) (aref src (+ src-offset i)))))
```
It works fine because copying memory isn't the bottleneck in my program, drawing pixels is.
> 2 votes
---
Tags: data-structures
---
|
thread-55178
|
https://emacs.stackexchange.com/questions/55178
|
How do I get ein to find conda packages?
|
2020-01-29T03:26:37.803
|
# Question
Title: How do I get ein to find conda packages?
I'm trying to use ein to edit a jupyter notebook. I used conda to install the 'turicreate' package in a virtual environment and activated it. When I run the regular browser based jupyter notebook command everything works. Only inside ein does it not work -- I can open the notebook, but when I try to import turicreate it complains it can't find the module.
First I tried:
```
(setq ein:jupyter-default-server-command (format "%s/anaconda3/bin/jupyter" (getenv "HOME")))
```
This got ein to open the notebook, but the import failed. I figured the conda env wasn't propagating so I opened a shell, activated the environment and did:
```
$ env | grep -i py
$ env | grep -i conda
```
To see if activating just set env vars. So then I tried:
```
(setenv "CONDA_DEFAULT_ENV" "virtual_environment_name")
(setenv "CONDA_PREFIX" (format "%s/anaconda3/envs/virtual_environment_name" (getenv "HOME")))
```
I shutdown all jupyter servers and tried `ein:run` again. Still no dice.
So then I wrote a shell script:
```
#!/bin/bash
conda activate virtual_environment_name
$HOME/anaconda3/bin/jupyter "$@"
```
And set:
```
(setq ein:jupyter-default-server-command (format "%s/jupyter-with-anaconda.sh" (getenv "HOME")))
```
And it STILL can't find the module. At this point I'm at a loss. I have no idea how the environment state gets to the browser based jupyter so I don't know how to duplicate it for ein.
Any ideas?
# Answer
My script didn't work for 2 reasons:
* `conda` wasn't in my path
* `conda activate` doesn't work in bash scripts out of the box because it relies on bash functions
Solution:
```
#!/bin/bash
set -e
set -o pipefail
# otherwise can't find conda
export PATH=$HOME/anaconda3/bin:$PATH
# either of these will make conda activate work inside a bash script
# https://stackoverflow.com/questions/34534513/calling-conda-source-activate-from-bash-script
# https://github.com/conda/conda/issues/7980
#source $(conda info --base)/etc/profile.d/conda.sh
eval "$(conda shell.bash hook)"
conda activate virtual_environment_name
jupyter "$@"
exit $?
```
> 2 votes
---
Tags: environment, ein
---
|
thread-18404
|
https://emacs.stackexchange.com/questions/18404
|
Can I display org-mode attachments as inline images in my document?
|
2015-11-26T00:29:01.190
|
# Question
Title: Can I display org-mode attachments as inline images in my document?
I have image files that I have included as org-mode attachments. I would like to display them inline in emacs (as I could a hyper-linked external image).
Is there some standard way to do this?
# Answer
I wish it would be little easier to found, but all you have to do is:
1. Define new Org-mode link abbreviation, lets' name it `att`
2. Use it like `[[att:somefile.extension]]`
## Define new link abbreviation
```
(require 'org-attach)
(setq org-link-abbrev-alist '(("att" . org-attach-expand-link)))
```
## Use it in link
Then you use it through `org-insert-link` as usually, just link type will be `att`. Here is simple example:
```
* TODO Some heading
:PROPERTIES:
:Attachments: someimage.png
:ID: 6b0817ee-27aa-4e7e-8a09-541ccbfee2c9
:END:
[[att:someimage.png]]
```
For image to actually display, I have to use `org-toggle-inline-images` after I add link even when I have `org-startup-with-inline-images` enabled. But it is same with every added image, not only those from *org-attach*.
*Edit: I found out that `org-attach` is not autoloaded on Org mode load. We need to require it or `org-attach-expand-link` function would be undefined.*
> 8 votes
# Answer
This is now built in to org. Use the `attachment:` link type. See: https://orgmode.org/manual/Attachment-links.html#Attachment-links
> 5 votes
# Answer
The best I have found so far is to do it using `org-insert-link`. After having attached a PNG for example, the properties drawer looks like this:
```
:PROPERTIES:
:Attachments: ipython-notebook-in-emacs-with-ein.png
:ID: 91ededb1-20cc-4b88-9e6d-a03f48e985e3
:END:
```
I then do `M-x org-insert-link` (`C-x C-l`). When prompted, I select `file:` and then select the file in the subdirectory `data/91/ededb.../ipython...` (the `data` is standard, the `91` and the rest you can deduce from the ID and the attachment name).
After completing this, I am left with a `file:` link to the relative position of the attachment. With `M-x org-toggle-inline-images` you can make the linked attachment show up inline.
> 3 votes
---
Tags: org-mode
---
|
thread-55182
|
https://emacs.stackexchange.com/questions/55182
|
Tramp, transfer configuration file
|
2020-01-29T07:52:39.413
|
# Question
Title: Tramp, transfer configuration file
To establish an ssh connection, I use the configuration file.`;ssh remoteHost -F /home/alamd/ПакетыДоступа/root_91_211_249_142/config`. Is it possible to transfer ssh connection settings from such a file to tramp? I found that it is possible to pass options through
> 'tramp-ssh-controlmaster-options'
, but it seems there is no option to transfer the configuration file. Thanks.
# Answer
If you mean to use this config file in Tramp instead of `~/.ssh/config`, you need to tell Tramp so in `tramp-methods`. Something like
```
(progn
(require 'tramp-sh)
(let ((args (assoc 'tramp-login-args (assoc "ssh" tramp-methods))))
(setcar
(cdr args)
(append
'(("-F" "/home/alamd/ПакетыДоступа/root_91_211_249_142/config"))
(cadr args)))))
```
> 1 votes
---
Tags: tramp, ssh
---
|
thread-55129
|
https://emacs.stackexchange.com/questions/55129
|
hs-minor-mode and sage-shell-mode (derived from python-mode)
|
2020-01-25T16:23:15.513
|
# Question
Title: hs-minor-mode and sage-shell-mode (derived from python-mode)
I would like to use emacs' hide-show mode (to collapse class and function definitions) with Sho Takemori's `sage-shell-mode` (for the SageMath computer algebra system) which derives from `python-mode`.
Although emacs does not complain when I do `M-x hs-minor-mode`, it does not work, in particular, `M-x hs-hide-all` does not appear to be doing anything.
`sage-shell-mode` is available at https://github.com/sagemath/sage-shell-mode
# Answer
> 1 votes
I already filled a feature request for recognizing derived modes through `hideshow`.
Until this feature request is handled you can use the following workaround in your init file:
```
(defun my-sage-initialize-hs ()
"Initialize `hs-special-mode-alist' for `sage-shell:sage-mode'.
Note: Function `python-mode' must be run at least once to make this work."
(unless (assoc 'sage-shell:sage-mode hs-special-modes-alist)
(add-to-list 'hs-special-modes-alist
(cons 'sage-shell:sage-mode
(cdr (assoc 'python-mode hs-special-modes-alist)))))
(hs-minor-mode))
(add-hook 'sage-shell:sage-mode-hook #'my-sage-initialize-hs)
```
The workaround *links* the settings for `python-mode` in `hs-special-modes-alist` to a new entry for `sage-shell-mode`.
Tested with Emacs 26.3, and `sage-shell-mode-20191103.1040`.
When the feature request is accepted and built into `hideshow.el` you do not need that workaround anymore since `sage-shell-mode` is really derived from `python-mode`.
---
Tags: hideshow
---
|
thread-55056
|
https://emacs.stackexchange.com/questions/55056
|
How to improve eldoc + lsp-mode output with C/C++ comments?
|
2020-01-22T12:34:24.657
|
# Question
Title: How to improve eldoc + lsp-mode output with C/C++ comments?
When using eldoc with lsp-mode, there are some irritations with the default output.
* Various characters are backslash escaped, so:
`/* This: isn't so -> "good", you see. */`
Displays as:
`This\: isn\'t so -\> \"good\"\, you see.`
* Blank lines are included so:
```
/**
* This is a comment.
*/
```
Displays as:
```
This is a comment.
```
Has a blank lines above and below it.
---
Is there a convenient way to show eldoc as plain-text with blank lines stripped from the start & end, or does this require writing my own `eldoc-message-function` ?
Note while formatting for doxygen would be nice too, plain un-escaped text is fine.
# Answer
`lsp-mode` uses `markdown-mode` for rendering documentation which has issues regarding: see also https://github.com/jrblevin/markdown-mode/issues/409 . If you want to render it in a different way you may modify `lsp-language-id-configuration`.
> 0 votes
---
Tags: lsp-mode, eldoc
---
|
thread-55189
|
https://emacs.stackexchange.com/questions/55189
|
Create custom "mode-hook" for other programming languages
|
2020-01-30T04:40:50.603
|
# Question
Title: Create custom "mode-hook" for other programming languages
For C/C++, I have the following to be run when I do `M-x compile` on a .c/.cpp file
```
(add-hook 'c++-mode-hook
(lambda ()
(set (make-local-variable 'compile-command)
(concat "g++ " buffer-file-name " && ./a.out" ) )))
```
Now, say I work on some other languages that do not have mode-hook, say R. I want to do something like this:
```
(add-hook 'r-mode-hook
(lambda ()
(set (make-local-variable 'compile-command)
(concat "Rscript " buffer-file-name ) )))
```
After putting above code in my init.el and reloading emacs, there are no errors on startup. I went ahead and open and .r file, but `M-x compile` does not result in: Rscript . Instead, I got the default prompt from `M-x compile`: make -k.
Is there a way to do this?
# Answer
> 5 votes
As far as I know, there's no `r-mode` in Emacs. Instead, you're probably using ESS's support for R, whose major mode is called `ess-r-mode` IIRC, so you'd want to use `ess-r-mode-hook`. But as @phils said: check the value of `major-mode` to be sure.
---
Tags: major-mode, compile
---
|
thread-31999
|
https://emacs.stackexchange.com/questions/31999
|
Config, examples and use cases of Library Of Babel
|
2017-04-07T11:42:41.690
|
# Question
Title: Config, examples and use cases of Library Of Babel
I want to understand how org-babel's Library Of Babel works. Seems like a powerful yet underused tool.
The documentation says that I can
> add code to the library, by first saving the code in regular ‘src’ code blocks of an Org file, and then load the Org file with org-babel-lob-ingest, which is bound to C-c C-v i.
What is that `org-babel-lob-ingest` truly doing? It is just appending all source blocks within an Org File to another file?
And what are the use cases of this? Can I see what I have in my Library interactively? Can I use noweb syntax with source blocks within the Library? What do I need to do to start using it?
Any examples and links to tutorials are very welcome.
# Answer
There is a nice introduction to the library of babel in `library-of-babel.org` which is located in Org’s source directory. To use those examples of named source-code blocks in other files, populate the `org-babel-library-of-babel` variable with
```
#+begin_src elisp :results scalar
(org-babel-lob-ingest "/path/to/org-mode/doc/library-of-babel.org")
#+end_src
#+results:
: 21
```
One of the 21 blocks is named “transpose” and probably does what it’s supposed to do:
```
#+name: tbl
| a | 1 |
| d | 2 |
| a | 3 |
| d | 4 |
| d | 5 |
| c | 6 |
#+begin_src elisp :results table :post transpose(table=*this*) :var var=tbl
var
#+end_src
#+results:
| a | d | a | d | d | c |
| 1 | 2 | 3 | 4 | 5 | 6 |
```
You may as well add your own code blocks, especially something you may find yourself using a lot in the future. As an example, the following allows me to aggregate values in the named table by the first column:
```
#+name: aggregatebycol1
#+begin_src elisp :results table :var table='() fun='()
(let (res)
(mapc
(lambda (x)
(push `(,(car x) ,(apply fun (mapcar 'cadr (cdr x)))) res))
(seq-group-by 'car table))
(nreverse res))
#+end_src
```
Save the block in any file and add it to `org-babel-library-of-babel`:
```
#+begin_src elisp :results scalar
(org-babel-lob-ingest (buffer-file-name))
#+end_src
#+results:
: 1
#+header: :post aggregatebycol1(table=*this*, fun='+)
#+begin_src elisp :results table :var var=tbl
var
#+end_src
#+results:
| a | 4 |
| d | 11 |
| c | 6 |
```
> 10 votes
# Answer
TL;DR: Using a persistent library of babel stored in one file can be a simple 3-step setup:
* Create an `org`-mode file `~/.emacs.d/library-of-babel.org`.
* Add a line `(org-babel-lob-ingest "~/.emacs.d/library-of-babel.org")` to your Emacs conf.
* Collect useful functions in that file, they will be read during emacs startup.
---
The Library-Of-Babel-file is where e.g. the `aggregatebycol1` block from @mutbuerger would be saved to.
Another simple example use-case would be having a code-block, that generates table data with a header row, but does not mark the headerrow with an `'hline`. This is not tragic for simple display, but may make further automated processing more involved. The solution here could be using a small code-block for post-processing from somewhere on the internet:
```
#+name: addhdr
#+begin_src emacs-lisp :var tbl=""
(cons (car tbl) (cons 'hline (cdr tbl)))
#+end_src
```
This will simply pipe through the data while splicing in an `'hline` as a second row.
To use this block later in other org files, simply add a `:post`-processing stanza to your data-generating org source block:
```
#+NAME: Example
#+BEGIN_SRC elisp :post addhdr(*this*)
'(("Header1" "Column2" "Three")("R1C1V" "2" "C3R1")("4" "5" "6"))
#+END_SRC
#+RESULTS: Example
| Header1 | Column2 | Three |
|---------+---------+-------|
| R1C1V | 2 | C3R1 |
| 4 | 5 | 6 |
```
You can also easily give pre-existing tables to functions in your LOB:
```
#+NAME: ExData
| h1 | h2 |
| dh1r1 | dh2r1 |
| dh1r2 | dh2r2 |
#+CALL: addhdr(ExData)
```
In my library I have chapters to organize different types of functionality: Data-Generation, Filtering, PrettyPrinting, ... Just remember to `ingest` again after adding new blocks.
> 6 votes
---
Tags: org-mode, org-babel
---
|
thread-20129
|
https://emacs.stackexchange.com/questions/20129
|
How can I filter table in org mode
|
2016-02-06T22:53:26.123
|
# Question
Title: How can I filter table in org mode
For example, I want to filter table that make it shows the row which only contains "USA" string in the column 3 and 4.
# Answer
You can use a multitude of solutions. I assume you want to produce a new table based on an existing one. This involves babel functionality where you define code blocks that produce the new table. The code blocks can be in many languages, and you even can define such a code block to be used afterwards normally in table formulas.
I am showing here just an example using emacs lisp. You can find many more examples in my example collection on github: https://github.com/dfeich/org-babel-examples
```
*table filter
#+NAME: table1
| col1 | col2 | col3 | col4 | col5 |
|-------+------+------+------+------|
| row0 | 0 | CH | CH | 0 |
| row1 | 2 | D | CN | 5 |
| row2 | 4 | USA | PL | 10 |
| row3 | 6 | CN | D | 15 |
| row4 | 8 | JP | USA | 20 |
| row5 | 10 | PL | PL | 25 |
| row6 | 12 | USA | JP | 30 |
| row7 | 14 | D | CN | 35 |
| row8 | 16 | PL | USA | 40 |
| row9 | 18 | CN | D | 45 |
| row10 | 20 | CH | CH | 50 |
```
Now we define a filter function which produces a new table with the required values.
* I am reading in the previous table by using the **:var tbl=table1** argument in the BEGIN line.
* I define the value to be filtered in the same **:var** assignment by setting **val="USA"**
* Notice that I am using the **:colnames** argument in the BEGIN line in order to preserve the column headings.
* I only filter column 4 in these examples, for simplicity. But it is trivial to extend. If you want the explicit solution, just ask.
```
#+NAME: my-filter
#+BEGIN_SRC elisp :var tbl=table1 val="USA" :colnames y
(cl-loop for row in tbl
if (equal (nth 3 row) val)
collect row into newtbl
finally return newtbl)
#+END_SRC
#+RESULTS: my-filter
| col1 | col2 | col3 | col4 | col5 |
|------+------+------+------+------|
| row4 | 8 | JP | USA | 20 |
| row8 | 16 | PL | USA | 40 |
```
I can also use this function with the org-mode CALL syntax
```
#+CALL: my-filter(tbl=table1, val="CN") :colnames y
#+RESULTS:
| col1 | col2 | col3 | col4 | col5 |
|------+------+------+------+------|
| row1 | 2 | D | CN | 5 |
| row7 | 14 | D | CN | 35 |
```
I also demonstrate here the SQLite approach where I use your original requirement of filtering all the rows which contain the string either in columns 3 or 4. A minor drawback of the sqlite approach is that we have some boilerplate code to read in the table and create a SQLite DB.
```
#+NAME: my-filter2
#+BEGIN_SRC sqlite :db table1.sqlite :var tbl=table1 val="USA" :colnames yes
drop table if exists table1;
create table table1 (col1 VARCHAR, col2 INTEGER, col3 VARCHAR,
col4 VARCHAR, col5 INTEGER);
.import "$tbl" table1
select * from table1 where col3='$val' or col4='$val';
#+END_SRC
#+RESULTS:
| col1 | col2 | col3 | col4 | col5 |
|------+------+------+------+------|
| row2 | 4 | USA | PL | 10 |
| row4 | 8 | JP | USA | 20 |
| row6 | 12 | USA | JP | 30 |
| row8 | 16 | PL | USA | 40 |
#+CALL: my-filter2(tbl=table1, val="CN") :colnames y
#+RESULTS:
| col1 | col2 | col3 | col4 | col5 |
|------+------+------+------+------|
| row1 | 2 | D | CN | 5 |
| row3 | 6 | CN | D | 15 |
| row7 | 14 | D | CN | 35 |
| row9 | 18 | CN | D | 45 |
```
Hope that I understood your question correctly and that the links help you to find other variations of a solution.
> 26 votes
# Answer
I use q - Text as Data, and 2 functions in my `library-of-babel`(Conf-Example) to provide an easy interface to query/join org-inline tables and external `.*sv` files.
Under the hood, `q` (via ) also uses , like the second approach from @dfeich, but **removes** the need for noisy boilerplate-code specific to each individual source table. It just needs to be installed once via the system package manager, usually in `python-q-text-as-data`.
Once your library of babel is loaded with the 2 functions below, you only need a `#+Call:` like below in your org-file to use SQL queries.
```
#+CALL: Q[:stdin table1](where="col4=='USA'")
#+RESULTS:
| col1 | col2 | col3 | col4 | col5 |
|------+------+------+------+------|
| row4 | 8 | JP | USA | 20 |
| row8 | 16 | PL | USA | 40 |
```
This constructs a command-line like `SELECT $select FROM $from WHERE $where`, with defaults for the parameters to select all columns from `stdin` for output.
The code blocks to add to your library are:
```
** Add a header Row to tables
#+name: addhdr
#+begin_src emacs-lisp :var tbl=""
(cons (car tbl) (cons 'hline (cdr tbl)))
#+end_src
** Filtering with SQL
#+NAME: Q
#+HEADER: :results value table
#+HEADER: :var callOptsStd="-H -O -t" callOpts=""
#+HEADER: :post addhdr(*this*)
#+BEGIN_SRC shell :stdin Ethers :var select="*" from="-" where="1"
q $callOptsStd $callOpts "Select $select from $from where $where"
#+END_SRC
```
> 3 votes
---
Tags: org-mode, org-table
---
|
thread-55174
|
https://emacs.stackexchange.com/questions/55174
|
How to define a singe weak reference in elisp?
|
2020-01-28T21:31:36.820
|
# Question
Title: How to define a singe weak reference in elisp?
Hash tables in elisp supports weak references, however weak references may be useful without the need to use a hash.
How can a weak reference to an object be defined without having to use a hash-table containing one item?
# Answer
> 1 votes
General-purpose weak references would indeed be a useful general-purpose feature for elisp.
It's worth mentioning that in lieu of that functionality, there's a mini convenience library for exactly the strategy you mention (using a hash table with weak values and a single constant as a key) to obtain an effective weak reference: elisp-weak-ref.
---
Tags: hash-tables, garbage-collect
---
|
thread-55208
|
https://emacs.stackexchange.com/questions/55208
|
don't allow modification if there is autosave
|
2020-01-31T03:17:38.110
|
# Question
Title: don't allow modification if there is autosave
is it possible to disallow modification if there is an autosave version? I sometimes save a file only to find out that it has an autosave version but I am unable to recover because I saved.
# Answer
One can derive how to detect existing autosave data from the part of `after-find-file` that emits the message `"%s has auto save data; consider M-x recover-this-file"`.
Just enter `read-only-mode` in `find-file-hook` if a buffer has autosave data.
```
(defun my-make-auto-saved-file-read-only ()
"Set the buffer read-only if it has a recent auto-save file."
;; Stolen from `after-find-file':
(when (and
;; No need to warn if buffer is auto-saved
;; under the name of the visited file.
(not (and buffer-file-name
auto-save-visited-file-name))
(file-newer-than-file-p (or buffer-auto-save-file-name
(make-auto-save-file-name))
buffer-file-name))
(read-only-mode)))
(add-hook 'find-file-hook #'my-make-auto-saved-file-read-only)
```
Note, with this approach you must reset `read-only-mode` yourself after reverting the file. But that is very simple in Emacs with GUI. Just click on the remaining `%` in the mode line.
> 1 votes
---
Tags: auto-save
---
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.