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-60508
|
https://emacs.stackexchange.com/questions/60508
|
tramp mode on Ubuntu hangs while attempting ssh to 0.0.0.1
|
2020-09-05T20:18:43.343
|
# Question
Title: tramp mode on Ubuntu hangs while attempting ssh to 0.0.0.1
With emacs 25.2.2 on Ubuntu 18.04, if I try opening a file over ssh using a path such as `/ssh:somehost.example.com:/tmp/testfile`, it launches a sub-process that does:
```
/usr/bin/ssh -o ControlPath=%C 0.0.0.1
```
This IP address does not accept ssh connections, so the `ssh` subprocess hangs, and the file opening in emacs also hangs until the ssh eventually times out. Using `lsof`, it can be seen that the TCP connection to `0.0.0.1:ssh` is stuck in `SYN_SENT` state, consistent with it not receiving any response.
I found that it is possible to work around this by adding an iptables rule to reject the outgoing ssh connection to this address:
```
sudo iptables -A OUTPUT -d 0.0.0.1 -p tcp --dport 22 -j REJECT
```
so that this attempted ssh connection quickly receives a "connection refused", instead of the packet effectively being dropped and it just hanging. After this, emacs then connects to the actual target machine correctly, and the remote file can be edited.
Why is this connection to 0.0.0.1 being attempted, and how can this be prevented (in a way that does not require sudo access)?
# Answer
> 2 votes
The command `/usr/bin/ssh -o ControlPath=%C 0.0.0.1` is used to check, whether your local `ssh` command accepts the `ControlPath` option. `0.0.0.1` is a non-existing address; `ssh` shall return immediately with an error.
In more recent Tramp versions, the blocking is avoided by using the command `ssh -o ConnectTimeout=1 -o ControlPath=%C 0.0.0.1`. I recommend to upgrade to the Tramp version provided by GNU ELPA.
---
Tags: tramp, ssh, ubuntu
---
|
thread-60519
|
https://emacs.stackexchange.com/questions/60519
|
unescaped character literals detection error
|
2020-09-06T09:09:00.640
|
# Question
Title: unescaped character literals detection error
When I reload my init file I get an error (or warning) saying
```
unescaped character literals `?(', `?)', `?[', `?]' detected!
```
What does this error (warning) mean and how can one fix it?
# Answer
> 4 votes
Section 2.3.3.1 Basic Char Syntax of the Elisp manual says:
```
The usual read syntax for alphanumeric characters is a question mark
followed by the character; thus, ‘?A’ for the character ‘A’, ‘?B’ for
the character ‘B’, and ‘?a’ for the character ‘a’.
For example:
?Q ⇒ 81 ?q ⇒ 113
You can use the same syntax for punctuation characters. However, if
the punctuation character has a special syntactic meaning in Lisp, you
must quote it with a ‘\’. For example, ‘?\(’ is the way to write the
open-paren character. Likewise, if the character is ‘\’, you must use a
second ‘\’ to quote it: ‘?\\’.
```
Your init file contains `?(` but Emacs prefers to see `?\(`. The same goes for the other three characters mentioned in the warning.
You can load the Elisp manual inside Emacs with `C-h i`.
---
Tags: init-file, error-handling, characters
---
|
thread-60510
|
https://emacs.stackexchange.com/questions/60510
|
Nested noweb in org src blocks
|
2020-09-06T01:54:00.453
|
# Question
Title: Nested noweb in org src blocks
I have the following code blocks:
Block 1 is just one line. This is a MWE. In reality, I have several lines in block 1.
```
#+name: block1
#+begin_src python :noweb no :exports none
print("Block 1")
#+end_src
```
Block 2 has also been reduced for the sake of MWE.
```
#+name: block2
#+begin_src python :noweb no :exports none
<<block1>>
print("Block 2")
#+end_src
```
This shows a skeleton of myfunc. I want to include this skeleton to give an overview of myfunc.
```
#+name: block3
#+begin_src python :noweb no :exports code
def myfunc(x):
<<block2>>
#+end_src
```
Finally, this shows the full specification of myfunc.
```
#+begin_src python :noweb yes :exports code
<<block3>>
#+end_src
```
**What I expect it to look like when exported**
```
def myfunc(x):
print("Block 1")
print("Block 2")
```
**What it actually looks like**
```
def myfunc(x):
<<block1>>
print("Block 2")
```
How can I get the nested blocks to expand completely when I use :noweb yes?
# Answer
> 2 votes
Your example works if I set all headers with `:noweb yes` and then only the last block has `:tangle yes`.
A simpler example:
1. Add this at the top of the file: `#+PROPERTY: header-args :noweb yes :tangle no :exports code`
2. Remove all header args from the code blocks.
3. Add `:tangle yes` header to the "full specification".
---
Tags: org-mode, org-babel, noweb
---
|
thread-60527
|
https://emacs.stackexchange.com/questions/60527
|
Bash Environmental Variable Not Recognized
|
2020-09-06T15:37:06.753
|
# Question
Title: Bash Environmental Variable Not Recognized
I use Bash for my terminal on Debian. In my `.bashrc`, I've defined an environmental variable like so:
```
SSH_VAULT_VM="ssh-vault"
if [ "$SSH_VAULT_VM" != "" ]; then
export SSH_AUTH_SOCK=~user/.SSH_AGENT_$SSH_VAULT_VM
fi
```
This is to facilitate separating my SSH private/public keys on my bare metal host OS (Qubes OS) as described in this repo. The way split SSH works in Qubes OS is by hosting the private key in a VM, and the public key in another VM (from which I'm running Emacs). Whenever I use SSH then, a dialog box pop-up appears to confirm accessing the private key.
When I open Emacs from a Bash terminal, the `SSH_AUTH_SOCK` variable is properly defined (as observed in the `initial-environment` variable), and attempts to use the SSH key (e.g., in the `magit` package) succeed with the pop-up confirmation box. However, when I open the Emacs GUI (using X?), the `SSH_AUTH_SOCK` variable is incorrect (instead set to something like: `/tmp/ssh-[some random name]/agent.[3 digit number]`) and attempts to use the SSH key fail.
How can I make Emacs use my `.bashrc` settings such that this split SSH feature will work? I'd be happy to either correct some config to make Emacs load this variable correctly, or overwrite it with the correct value in my `.emacs.d` file. I've tried including something like: `(setenv "SSH_AUTH_SOCK" "/home/user/.SSH_AGENT_ssh-vault")` in my Emacs config, but that doesn't seem to work.
# Answer
I'd say you want it in the `.profile` instead `.bashrc`. It works from emacs terminal because it's associated with a terminal, thus reads the file first.
Read Bash startup files.
**edit:** I was assuming that we were talking about user configuration files, something that later I've realized it wasn't that clear. Also, you can use `.xsessionrc` to make those variables available on X sessions.
> 1 votes
---
Tags: bash, environment
---
|
thread-60420
|
https://emacs.stackexchange.com/questions/60420
|
Emacs outline-mode custom heading and space between headers
|
2020-09-01T07:22:21.503
|
# Question
Title: Emacs outline-mode custom heading and space between headers
I'm trying to define a structure for outline-minor-mode so I can organize my init.el conf without relying in org.
So far I could not get to work with two levels of heading, I would like to have ;;; and ;;;; as possible levels, so I could organize a little further.
My code so far:
```
;;; Outline-mode
;; Local Variables:
;; outline-regexp: ";\\{3,4\\} "
;; outline-heading-alist: ((";;; " . 1) (";;;; " . 2))
;; eval: (outline-minor-mode 1)
;; eval: (while (re-search-forward outline-regexp nil t) (outline-hide-subtree))
;; End:
```
I'm not very good at regex yet, so I'm not sure how to make it to work.
The problem is that without two levels of heading when I "hide all" the levels they got without any space or further organization like in the left image. I can try to break some lines like in the right image, but when I show/hide again the folding ignore the lines again.
I'm trying to avoid outshine and org, but I might migrate if I can't manage to accomplish the following:
# Answer
> 3 votes
Not 100% sure if I understand your question, but you may want to try setting `(setq outline-blank-line t)`.
Non-nil means to leave unhidden blank line before heading.
---
Tags: regular-expressions, outline-mode
---
|
thread-60515
|
https://emacs.stackexchange.com/questions/60515
|
How to replace an element of a list?
|
2020-09-06T07:47:12.670
|
# Question
Title: How to replace an element of a list?
Is there a way to replace an item in a list?
```
(replace-element-in-list (elem-src elem-dst ls &optional times comparison-fn))
;; ...
)
```
Example use: `(replace-element-in-list 1 100 '(3 2 1)) => '(3 2 100)`
# Answer
Here is a non destructive version.
```
(defun replace-element-in-list (elem-src elem-dst ls &optional times comparison-fn)
(setq times (or times (length ls)))
(mapcar
(lambda (item)
(cond
((and (> times 0)
(funcall (or comparison-fn #'eq) item elem-src))
(cl-decf times)
elem-dst)
(t
item)))
ls))
(replace-element-in-list 2 "2" '(1 2 3 2 4))
;; => (1 "2" 3 "2" 4)
(replace-element-in-list 2 "2" '(1 2 3 2 4) 1)
;; => (1 "2" 3 2 4)
(replace-element-in-list "2" 2 '("1" "2" "3" "2" "4") nil #'string=)
;; => ("1" 2 "3" 2 "4")
```
> 1 votes
# Answer
```
(require 'cl-lib)
(cl-substitute 100 1 '(3 2 1))
```
gives `(3 2 100)`.
```
(cl-substitute 100 1 '(3 2 1 2 1 2 1) :count 2)
```
gives `(3 2 100 2 100 2 1)`.
```
(cl-substitute 100 "one" '("three" "two" "one") :test #'string-equal)
```
gives `("three" "two" 100)`.
Furthermore, there are the keyword arguments `:start`, `:end`, and `:from-end`. See the doc.
> 5 votes
# Answer
The question doesn't specify what "replacement" means. Does it mean create and return a new list that is like the original one except for the indicated parts? Or does it mean replace in place, that is, modify the original list?
Here is an example that modifies the original list, i.e., a "destructive" operation.
```
(defun replace-element-in-list (old new xs)
(let ((tail (member old xs)))
(while tail
(setcar tail new)
(setq tail (member old tail))))
xs)
(replace-element-in-list 1 100 (list 3 1 2 1)) ; => (3 100 2 100)
```
If you want an optional `comparison-function` parameter, then use `(funcall comparison-function ...)` instead of `(member...)`, and default it to `member`.
If you want an optional `times` parameter then initialize a local counter to `0` and compare it to `times` in the `while` test etc.
```
(defun replace-element-in-list (old new xs &optional times compare-fn)
(let ((count 0)
tail)
(setq compare-fn (or compare-fn #'member)
tail (funcall compare-fn old xs))
(while (and tail (or (not times)
(<= (setq count (1+ count)) times)))
(setcar tail new)
(setq tail (funcall compare-fn old tail))))
xs)
(replace-element-in-list 1 100 (list 3 1 2 1 5 1 1 6))
; => (3 100 2 100 5 100 100 6)
(replace-element-in-list 1 100 (list 3 1 2 1 5 1 1 6) 3)
; => (3 100 2 100 5 100 1 6)
(setq x (list 1))
(replace-element-in-list x 100 (list 3 '(1) 2 x 5 (copy-sequence x) x 6) nil #'memq)
; => (3 (1) 2 100 5 (1) 100 6)
(replace-element-in-list x 100 (list 3 '(1) 2 x 5 (copy-sequence x) x 6) 1 #'memq)
; => (3 (1) 2 100 5 (1) (1) 6)
```
> 1 votes
---
Tags: list
---
|
thread-60526
|
https://emacs.stackexchange.com/questions/60526
|
mark-sexp (Wrong number of arguments)
|
2020-09-06T15:18:47.703
|
# Question
Title: mark-sexp (Wrong number of arguments)
```
((foo(bar))
(baz))
```
If point is on `bar` and I do `M-x mark-sexp`, I get this error:
```
Wrong number of arguments: (lambda nil "Activate the mark." (if (mark t) (progn (setq mark-active t) (if transient-mark-mode nil (setq transient-mark-mode (quote lambda))) (if (and select-active-regions (display-selections-p)) (progn (x-\
set-selection (quote PRIMARY) (current-buffer))))))), 1
```
```
Enabled minor modes: Async-Bytecomp-Package Auto-Composition
Auto-Compression Auto-Encryption Auto-Revert Column-Number Dap
Dap-Auto-Configure Dap-Tooltip Dap-Ui Dap-Ui-Controls
Dap-Ui-Many-Windows Diff-Auto-Refine Display-Time Electric-Indent
Electric-Pair File-Name-Shadow Font-Lock Global-Edit-Server-Edit
Global-Eldoc Global-Font-Lock Global-Git-Commit Global-Magit-File
Google-This Ido-Everywhere Iswitchb Jabber-Activity Line-Number
Magit-Auto-Revert Magit-File Mouse-Wheel Override-Global
Shell-Dirtrack Show-Paren Tool-Bar Tooltip Transient-Mark
Treemacs-Filewatch Treemacs-Follow Treemacs-Fringe-Indicator
Treemacs-Git Which-Key Xclip
```
# Answer
I don't see that with other any version of Emacs, from 20 through 26.3.
Are you actually in `emacs-lisp-mode` or `lisp-mode`? (You probably should be.)
Do you see the same thing if you start Emacs using `emacs -Q` (no init file)? If not, bisect your init file to find the culprit.
If you see the same thing without your init file, please provide a complete, step-by-step recipe to reproduce it, starting from `emacs -Q`.
> 1 votes
---
Tags: debugging, mark, sexp
---
|
thread-60525
|
https://emacs.stackexchange.com/questions/60525
|
org-mode table "width cookie" no longer working in 27.1?
|
2020-09-06T13:58:26.397
|
# Question
Title: org-mode table "width cookie" no longer working in 27.1?
The Linux distribution I use (Fedora 32) recently upgraded the included Emacs version from `26.3` to `27.1`. With this new version, it appears that the "width cookie" for the org-mode tables are no longer working.
For example, if I have the following:
```
| Test Column A | Test Column B |
|---------------+---------------|
| <30> | <5> |
|---------------+---------------|
| Data | Data |
| Data | Data |
| ... | ... |
```
While the tags are highlighted (a.k.a. recognized), they will neither expand column "A" nor shrink column "B". In Emacs 26.3 it was working as expected.
The additional tags `<l>` and `<r>` (either with or without a number) keep on aligning the text as before.
As a side-note: Numbers are not right-aligned unless `<r>` is specified for the entire column. That was also auto-detected before.
Is this a change in behavior for which I missed to change an option or is this a bug?
The answer to this question seems to be a crude workaround rather than a solution and would not be what I was looking for. It used to be automatic on cell change after using `TAB`.
# Answer
See \*** =align= STARTUP value no longer narrow table columns and \*** Dynamically narrow table columns. Alignment and shrinking are now independent of each other.
If you will allow me an editorial comment, I was as upset as you were when I encountered the change, but I no longer miss the old behavior at all. So give it a try, use `#+STARTUP: align shrink` (or the "permanent" equivalents, using `org-startup-align-all-tables` and `org-startup-shrink-all-tables`) and see if it grows on you.
I have not noticed any number alignment problems, but maybe you can provide a MWE (= Minimal Working Example)? Or maybe better, ask it as a separate question.
> 3 votes
---
Tags: org-mode, emacs27
---
|
thread-60499
|
https://emacs.stackexchange.com/questions/60499
|
Pass a subset of the columns of a table to a script
|
2020-09-05T08:19:03.250
|
# Question
Title: Pass a subset of the columns of a table to a script
I would like to pass only some columns of a table to a script:
```
#+name: table
#+RESULTS:
| Col0 | Col1 | Col2 | Col3 |
|-------+------+------+------|
| Line1 | 1 | 2 | 3 |
| Line2 | 4 | 5 | 6 |
#+name: log
#+begin_src emacs-lisp :var data="" :results value
data
#+end_src
#+call: log(data=table[,0;3])
```
Expected:
```
#+RESULTS:
| Col0 | Col3 |
|-------+------|
| Line1 | 3 |
| Line2 | 6 |
```
Actual:
```
#+RESULTS:
| Line1 | Line2 |
```
The `;` syntax is not in any manual, I made that up :-). How can I get a subset of the columns of a table?
## Workaround
It is possible to use Lisp to filter the list ourselves:
```
#+name: filter-columns
#+begin_src emacs-lisp :var data='() :columns='()
(let ((result (mapcar (lambda (line)
(mapcar (lambda (column) (seq-elt line column)) columns))
data)))
`(,(car result)
\hline
,@(cdr result)))
#+end_src
#+call: log[:colnames no](data=filter-columns[:colnames no](data=table,columns='(0 3)))
#+RESULTS:
| Col0 | Col3 |
| Line1 | 3 |
| Line2 | 6 |
```
# Answer
> **Note:** For everyday coding, I use code blocks to filter table data instead of Indexable Variable Values (IVV) because it is usually faster to write and explain the code block than it is to teach others or remember IVV syntax.
### Use `:` to select range of org-table columns when using Indexable Variable Values
> "Ranges of variable values can be referenced using two integers separated by a :, in which case the entire inclusive range is referenced."
```
#+BEGIN_SRC elisp :var data=table[2:3,1:3] :rownames no :hlines no :colnames no
data
#+END_SRC
#+RESULTS:
| 1 | 2 | 3 |
| 4 | 5 | 6 |
```
### Use code blocks to combine non contiguous columns and more advanced filtering
```
#+BEGIN_SRC elisp :var c0=table[,0] :var c3=table[,3] :rownames no :hlines no :colnames no
(cl-mapcar 'list c0 c3)
#+END_SRC
#+RESULTS:
| Col0 | Col3 |
| Line1 | 3 |
| Line2 | 6 |
```
Thank you for asking your question!
---
**This answer was validated using:**
> emacs version: GNU Emacs 27.1
> org-mode version: 9.3.7
> 1 votes
---
Tags: org-babel, org-table
---
|
thread-47789
|
https://emacs.stackexchange.com/questions/47789
|
How to remove email address from local database in mu4e?
|
2019-02-13T09:37:59.237
|
# Question
Title: How to remove email address from local database in mu4e?
I use `mu4e` to read and write email. One email address that was in the LDAP server before no longer exists, but it still shows and auto-completes in `mu4e`.
How can I remove that address from the local database? And where is that database stored?
# Answer
> 3 votes
For mu version \> 1.3.2. you need to define a filtering function and store its name in `mu4e-contact-process-function`, e.g. like in this example
```
(defun my-mu4e-contact-filter-function (addr)
(if (string-match-p
(concat "\\(?:no-?reply\\|.*\\.unwanted\\.domain\\.com\\|"
"unwanted\\.user@somedomain\\.com\\)")
addr)
nil
addr))
(setq mu4e-contact-process-function 'my-mu4e-contact-filter-function)
```
Note that the contact list only seems to get renewed when mu4e is started. So you will need to stop/restart mu4e upon changes.
# Answer
> 1 votes
Following the GitHub issue, one solution is to ignore that address in address completion. Add this code in `~/.emacs`:
```
(setq mu4e-compose-complete-ignore-address-regexp
(concat "\\(?:no-?reply\\|.*\\.unwanted\\.domain\\.com\\|"
"unwanted.email@domain\\.com\\)"))
```
and notice the escaping of periods with (`\\.`). Then restart `mu4e`.
The database of contacts will be stored in the Xapian database starting with `mu4e` 1.4.
---
Tags: mu4e
---
|
thread-60533
|
https://emacs.stackexchange.com/questions/60533
|
Org-mode overline emphasis not able to be followed by other characters
|
2020-09-06T19:35:39.230
|
# Question
Title: Org-mode overline emphasis not able to be followed by other characters
I use a lot of overline (in statistical formulae) and so I have the following in my `.emacs`:
```
(custom-set-variables
'(org-emphasis-alist
(quote (("*" bold)
("/" italic)
("_" underline)
("=" org-verbatim verbatim)
("+" (:strike-through t))
("~" (:overline t) verbatim))))
'(org-hide-emphasis-markers t)
'(org-pretty-entities t))
```
In other words, I want `~` to define overline and I want it to render in-line in Emacs.
This works great, however I cannot follow that emphasis (or any emphasis for that matter) with more characters such as superscript or subscript numbers. For example, `~X~_1` renders as literally `~X~` followed by a subscript `1`. The `X` is overlined *until* I type the underscore, then the emphasis tildes reappear.
I assume the solution has something to do with modifying `org-emphasis-regexp-components` and maybe use of a zero-width space between the emphasis and the subscript, but there I get lost.
Also I would love my PDF exports to render the same (at the moment, since I am using the `~` for overline, my overlined segments get rendered as code) so for a part 2, if we can update the PDF export to render overlines properly too, that would be amazing.
# Answer
You are right about having to modify `org-emphasis-regexp-components`. In particular, you have to add `_` and `^` to the regexp for the `post` component (be careful where you add them: leave the dash at the very beginning and leave the opening square bracket at the very end - I added them after the initial dash below):
```
#+begin_src emacs-lisp
(setf (nth 1 org-emphasis-regexp-components) "-_^[:space:].,:!?;'\")}\\[")
(setf (nth 4 org-emphasis-alist) '("~" (:overline t) verbatim))
#+end_src
```
After setting the latter, you need to reload Org mode as its doc string states: `M-x org-reload RET`.
That should take care of subscripts and superscripts in the buffer.
For PDF rendering, a possible implementation is to replace the current rendering of the `code` markup with an overline rendering. The relevant data structure is `org-latex-text-markup-alist`: we replace the code element with one of our own devising:
```
#+begin_src emacs-lisp
(require 'ox-latex)
(delete (assoc 'code org-latex-text-markup-alist) org-latex-text-markup-alist)
(add-to-list 'org-latex-text-markup-alist '(code . "\\ensuremath{\\overline{%s}}"))
#+end_src
```
That uses the `\overline` macro (which is only defined in math environments, hence the `\ensuremath`). That seems to work in the simple cases in your question. No guarantees however: there may be more complicated cases that break this.
The `require` might be needed in order to pick up the definition of the variable `org-latex-text-markup-list`.
> 2 votes
---
Tags: org-mode
---
|
thread-60467
|
https://emacs.stackexchange.com/questions/60467
|
Harvard style citation in org-mode, output problems
|
2020-09-03T07:01:22.730
|
# Question
Title: Harvard style citation in org-mode, output problems
Trying to cite papers in Harvard style by using org-ref (scimax). I found two posts about it in this forum : post#1 and post#2.
The problem that I am facing is that the output of .org file contains 1 or 2 citations in Harvard format and all others are in other format.
Could someone explain me the reason and a proper solution for that ?
My org file contains the following :
```
#+creator: Emacs 27.1 (Org mode 9.3.7)
#+LATEX_HEADER: \usepackage[round]{natbib}
#+LATEX_COMPILER: xelatex
#+latex_header: \usepackage{harvard}
Some content here ..... and some references [citep:Artetxe2017]. Some other references [cite:mikolov2013exploiting].
bibliographystyle:apalike
bibliography:./ref/references.bib
```
About the output:
The first reference is outputted properly but the next one is numeric; the only difference between two citations is the first one starts with a capital letter and the other does not. Is this the only problem ?
# Answer
> 0 votes
I found a temporary solution. It is not automatic as C-c C-e but it works.
First of all, using biblatex as reference "engine" is better. The org file that I am using has the following lines for Harvard reference.
```
#+creator: Emacs 27.1 (Org mode 9.3.7)
#+LATEX_HEADER: \usepackage[utf8]{inputenc}
#+LATEX_HEADER: \usepackage[backend=biber, style=apa, sorting=nyt]{biblatex}
#+LATEX_HEADER: \addbibresource{./ref/references.bib}
* Introduction
... inspired by /the noisy channel model/ of IT[fn:1](cite:shannon2001mathematical).
\newpage
\printbibliography
* Footnotes
[fn:1] information theory
```
Then in order to export it use C-c C-e, the org engine then automatically shows me the .tex version of the org file. I think latex inside emacs is configured to run BibTex instead of Biber. And Biblatex needs to use Biber. So inside the .tex file use C-c C-c then select biber. Then again press C-c C-c choose latex. Then references are given as expected.
---
Tags: org-mode, org-ref
---
|
thread-60428
|
https://emacs.stackexchange.com/questions/60428
|
org-mode: specifying a hyperlink target as regex and jumping directly to match?
|
2020-09-01T13:56:02.673
|
# Question
Title: org-mode: specifying a hyperlink target as regex and jumping directly to match?
The documentation of a Fortran code, being done in org-mode, is intended to be done in such a way that changing the Fortran source code to be documented should be kept at a minimum.
There is the problem that text like "type t\_obs", which is a definition, does also occur in comments and is not unique. A naive hyperlink
\[\[./obs.f90::type t\_obs\]\[obs.f90::t\_obs definition\]\]
finds the first occurence in the file, which is not the desired one. Specifying a line number in the link is not acceptable, as the code is under development by a group other than those doing the documentation.
Specifying hyperlinks to match a unique target could be attempted using regular expressions, e.g. of the form \[\[file:~/xx.org::/regexp/\]\].
To be specific, I have tried the hyperlink:
\[\[./obs.f90::/^ \*type t\_obs/\]\[obs.f90::t\_obs definition\]\]
However, clicking on this link then opens an Occur buffer that shows exactly one match. It then requires to additionally click on the match in order to jump to the link target.
Is there a trick to avoid the need for clicking on the match in the occur buffer and immediately jump to this / the first match?
Furthermore, as my colleagures tell me, the above hyperlink with the regex will not work properly in a PDF generated from the org file when viewed with a PDF viewer.
Do I need to write a specific file-search-function, or is there an easier way?
# Answer
OK, here's what I am working with right now:
```
(defun org-execute-file-search-in-fortran (s)
"Find the link search string S as a key. May be a regex."
(when (eq major-mode 'f90-mode)
;; Yes, we want to do the search in this file.
(goto-char (point-min))
(if (string-match "^/\\(.*\\)/$" s)
(progn
;; A regular expression
(setq ss (match-string 1 s))
;(message "org-execute-file-search-in-fortran with regex: '%s'" ss)
(and (re-search-forward ss nil t)
(goto-char (match-beginning 0))))
(progn
;; An ordinary string. We construct a regexp that searches for the key
;(message "org-execute-file-search-in-fortran with string: '%s'" s)
(and (re-search-forward (regexp-quote s) nil t)
(goto-char (match-beginning 0)))))
;; return t to indicate that the search is done.
t))
```
That's already doing mostly what I need.
The only thing I can think of now is a possible syntax in a link for getting the n-th match of a regex.
Would sth. like `file.f90::/regex/,n` or `file.f90::/regex/:n` make sense, or is there already a similar solution?
> 0 votes
---
Tags: org-mode, regular-expressions, search, org-link
---
|
thread-51061
|
https://emacs.stackexchange.com/questions/51061
|
Directed Acyclic Graphs in Org mode, and Cloned Nodes
|
2019-06-15T23:39:32.903
|
# Question
Title: Directed Acyclic Graphs in Org mode, and Cloned Nodes
By default, Org-mode headers form trees. That is, every header can have an arbitrary number of sub-tasks, and this relationship is recursive to an arbitrary depth. However, a task in practice can be a dependency of two parents. Adding this property creates a directed acyclic graph (a DAG).
This relationship is not supported out of the box by Org mode, though it is available in Leo, as well as a number of enterprise issue managers. Leo, in particular, implements a DAG through cloned nodes. These are nodes that can appear in more than one place in an outline. Hence, they can have multiple parents, correctly reflecting the property that they may be required for multiple higher-level concerns.
Further justification for this feature is provided in the Leo documentation on personal information management:
> Clones can greatly accelerate your work flow. To start a project, clone nodes related to the project and drag them at or near the top level, where you can get at them easily. When the project is complete, just delete the clones. This work flow is surprisingly effective:
>
> * The original nodes never move, but they change whenever their clones do.
> * There is nothing to “put back in place” when you are done. Just delete the clones.
>
> Used this way, clones create views: when you gather cloned nodes together for a project, you are, in effect, creating a project-oriented view of the outline. This view focuses your attention on only those nodes that are relevant to the task at hand.
How can cloned nodes be implemented in Org mode?
# Answer
Emacs 26.1 has built-in support for cloned text (function `text-clone-create`). At least part of the aspects of cloned nodes can be achieved with text clones.
Test usage:
1. Run the code below
2. Open an Org mode file
3. Mark an Org heading in that file with `M-x` `text-clone-mark-region`
4. Place point where you want to clone the text within the same file and call `M-x` `text-clone-copy`
5. Check how the clones work by editing the text within the clone or the cloned region
6. Save and close the file
7. Re-open the file and verify that the clones are preserved by repeating 5.
You can mark only a part of the stars of the original heading to promote the clone and you can insert stars before the clone to demote the clone.
```
(defface text-clone-overlay-face '((t :background "yellow"))
"Face for marking regions to be cloned.")
(defvar-local text-clone-overlay nil
"Store for the region to be cloned.")
(defun text-clone-mark-region (b e)
"Mark region from B to E for cloning."
(interactive "r")
(if text-clone-overlay
(move-overlay text-clone-overlay b e)
(setq text-clone-overlay (make-overlay b e))
(overlay-put text-clone-overlay 'face 'text-clone-overlay-face)))
(defun text-clone-copy (point)
"Copy the clone overlay region and create text-clone at POINT."
(interactive "d")
(let ((b (overlay-start text-clone-overlay))
(e (overlay-end text-clone-overlay)))
(when (and (>= point b)
(< point e))
(user-error "Point within cloned region"))
(let ((str (buffer-substring b e)))
(insert str)
(save-excursion
(goto-char point)
(text-clone-create b e)))))
(defvar-local text-clone-list nil
"List of text clones in current buffer.")
(defun text-clone-list (&optional begin end)
"Get clones in region from begin to end."
(let* ((cnt -1)
(ols (cl-loop for ol being the overlays
if (overlay-get ol 'text-clones)
do (overlay-put ol 'text-clone-index (cl-incf cnt))
and collect ol))
ret)
(dolist (ol ols)
(setq ret (cons
(append
(list
(overlay-start ol)
(overlay-end ol))
(mapcar
(lambda (clone)
(overlay-get clone 'text-clone-index))
(overlay-get ol 'text-clones)))
ret)))
(nreverse ret)))
(defun text-clone-save ()
"Add `text-clone-list' as local variable."
(save-excursion
(add-file-local-variable 'text-clone-list (text-clone-list))))
(defun text-clone-read ()
"Create text clones according to `text-clone-list'."
(let (clones)
(dolist (clone text-clone-list)
(let ((ol (make-overlay (car clone) (cadr clone))))
(overlay-put ol 'text-clones (nthcdr 2 clone))
(setq clones (cons ol clones))))
(setq clones (nreverse clones))
(dolist (clone clones)
(overlay-put clone
'text-clones
(mapcar (lambda (idx)
(nth idx clones))
(overlay-get clone 'text-clones)))
(overlay-put clone 'modification-hooks '(text-clone--maintain))
(overlay-put clone 'evaporate t))))
(define-minor-mode text-clone-mode
"Make text clones permanent in their file."
nil
nil
nil
(if text-clone-mode
(progn
(add-hook 'after-change-major-mode-hook #'text-clone-read t t)
(add-hook 'before-save-hook #'text-clone-save t t))
(save-excursion (add-file-local-variable 'text-clone-list nil))
(remove-hook 'before-save-hook #'text-clone-save t)
(remove-hook 'after-change-major-mode-hook #'text-clone-read t)))
(add-hook 'org-mode-hook #'text-clone-mode)
```
> 2 votes
# Answer
A packaged called `org-clones` is now available. It supports cloned nodes in Org mode.
> 0 votes
---
Tags: org-mode
---
|
thread-60543
|
https://emacs.stackexchange.com/questions/60543
|
EXWM - How to close another emacs opened inside exwm?
|
2020-09-07T22:34:51.690
|
# Question
Title: EXWM - How to close another emacs opened inside exwm?
Inside EXWM (from "term") I opened another Emacs session (`git commit` opened it).
How do I close this Emacs session?
# Answer
> 3 votes
The problem is that any commands you execute such as `C-x C-c` will be captured by the Emacs instance running EXWM.
The first thing to try - which did not work for OP - is to execute `M-x exwm-input-grab-keyboard` **with the secondary Emacs window selected**. This will set the window to `char` mode, and send the keys you type directly to that window. So `C-x C-c` will then cause that secondary Emacs to exit. If this works for you, you can set `exwm-input-toggle-keyboard` to a global key (`S-i` is a common binding).
If that does not work, you can send keystrokes to the secondary Emacs using `M-x exwm-input-send-next-key`. With the secondary Emacs window selected, you run the above command twice, sending first `C-x` then `C-c`. This command is bound by default to `C-c C-q` \- in that case you would type `C-c C-q C-x C-c C-q C-c`.
As a last resort, you would open a shell and search for `emacs` processes, and kill the secondary Emacs process.
The more important thing is to never let this happen again. You can do that by starting the Emacs daemon from your EXWM startup code with `(server-start)` and setting the EDITOR environment variable with `(setenv "EDITOR" "emacsclient")`. Then `git commit` will open the file in your running Emacs.
# Answer
> 3 votes
The best solution is simply to hit `C-c C-k` (`exwm-input-release-keyboard`) which puts the X-window containing the inner emacs into char-mode. Then, when that window has focus, almost all keyboard input, including `C-x C-c` is passed to the inner emacs.
Hit `s-r` (`exwm-reset`) to get the window back to normal line-mode.
# Answer
> 0 votes
I assume you can just kill the buffer (`C-x k`).
---
Tags: quitting, exwm
---
|
thread-52825
|
https://emacs.stackexchange.com/questions/52825
|
electric-pair for parentheses does not work in latex-mode
|
2019-09-25T07:24:40.603
|
# Question
Title: electric-pair for parentheses does not work in latex-mode
electric pairing for () does not work in latex-mode.
I have included regular parentheses () in my electric-pair-pairs list in .emacs. The list also includes \[\], {}, and "". However, when editing LaTeX documents, pairing of () does not work, only the other electric pairs.
I already checked the variable electric-pair-pairs when in LaTeX mode, but it is unchanged compared to the .emacs definition.
Here is a snippet of my .emacs dealing with electric-pairing
(electric-pair-mode 1) (setq electric-pair-pairs '( (?\\" . ?\\") (?{ . ?}) (?( . ?)) (?\[ . ?\])))
I appreciate any help form you guys.
Ulrich
Emacs 25.1.1 on Debian Stretch
# Answer
I encountered the same problem and solved it by adding
```
(setq electric-pair-preserve-balance nil)
```
It ignores the pairing logic that balances out the number of opening and closing delimiters. I can only guess the reason it works is that there is something specific in the tex file that causes a miscalculation of parentheses balancing. Even without the workaround, the problem does not occur in other tex files, e.g. an empty one.
> 1 votes
---
Tags: electric-pair-mode
---
|
thread-60547
|
https://emacs.stackexchange.com/questions/60547
|
Can I format the arguments in a table and provide the rows to a shell block as arguments?
|
2020-09-08T01:55:36.337
|
# Question
Title: Can I format the arguments in a table and provide the rows to a shell block as arguments?
In `org-mode`, is possible to provide arguments formatted as a table to a shell block?
E.g.
## argument
```
|a|b|
|c|d|
```
## shell script
```
echo $a
```
## expected results
```
a b
c d
```
Basically, I want `org-mode` to read the values in the table row by row and provide them to the shell block as *space* separated strings.
# Answer
> 0 votes
```
#+NAME: foo
| a | b | one |
| c | d | two |
#+BEGIN_SRC bash :var tbl=foo
for key in "${!tbl[@]}"; do
row=${tbl[$key]}
echo $key $row
done
#+END_SRC
#+RESULTS:
| c | d | two |
| a | b | one |
```
Note that row order is not preserved.
If you want to break out the columns, you can do that with `read`:
```
#+BEGIN_SRC bash :var tbl=foo
for key in "${!tbl[@]}"; do
row=${tbl[$key]}
IFS=" " read c0 c1 <<< ${row[@]}
echo $key $c1
done
#+END_SRC
#+RESULTS:
| c | two |
| a | one |
```
---
Tags: org-mode, shell
---
|
thread-60558
|
https://emacs.stackexchange.com/questions/60558
|
Controlling Behaviour of (Compilation) Window Creation
|
2020-09-08T13:35:58.300
|
# Question
Title: Controlling Behaviour of (Compilation) Window Creation
How do I control whether the output buffer `*Compile*` of `M-x compile` will be shown
* in an existing window or
* in a new window by splitting an existing window
?
My problem is that the compilation buffer is opened in an existing window that I want to leave unchanged for other content.
AFAICT, this behaviour is controlled by `display-buffer`.
# Answer
The command I was looking for was `display-buffer-in-direction`. My desire use was
```
(setq display-buffer-alist
`((,(rx bos
(| (literal "*compilation")
(literal "*shell")
(literal "*eshell")
(literal "*Compile-Log")))
display-buffer-in-direction
(window . ;reference window
t) ;either `t' (selected window), `main', `root', or an arbitrary valid window
(direction .
below) ;`below' (window) or `bottom' (of frame)
(window-height . 0.33) ;absolute (10) or relative (0.3)
)))
```
> 0 votes
---
Tags: window, compilation
---
|
thread-60559
|
https://emacs.stackexchange.com/questions/60559
|
Close completing-read dialog before continuing
|
2020-09-08T14:28:12.267
|
# Question
Title: Close completing-read dialog before continuing
I've written an elisp script to automate the process of taking screenshots. The script uses maim and imgur.sh. Not really important however. Here is the code:
```
;;; ../../.local/share/git/dotArch/.config/doom/userconfig/screenshot.el -*- lexical-binding: t; -*-
(defun db/screenshot ()
"Interactive menu for screenshots. Requires main, xsel, xclip and curl to be installed."
(interactive)
(let* ((actions '("Section" "Whole Screen"))
(targets '("Imgur" "Clipboard" "Locally"))
;; The default extension used for images.
(ext "png")
;; The default temporary directory used to store images.
(tmp-dir "/tmp/")
;; The default temporary name used for images.
(tmp-name "screenshot")
;; The full file path to a temporary image.
(tmp-file (concat tmp-dir tmp-name "." ext)))
(setq action (completing-read "Take screenshot of ..." actions )
target (completing-read "Save screenshot ..." targets ))
(setq result (db/screenshot-return-cmd action target tmp-file ext))
(call-process-shell-command (nth 1 result) nil nil nil)
(cond ((equal target "Locally")
(message (concat "Image will be saved to: " (nth 0 result))))
((equal target "Imgur")
(message "Image will be uploaded to Imgur. URL will be saved to the clipboard."))
((equal target "Clipboard")
(message "Image will be saved to the clipboard.")))))
(defun db/screenshot-return-cmd (source target tmp-file ext)
"Build the command to be executed for taking screenshots."
(let ((cmd ""))
(cond ((equal source "Section")
(cond ((equal target "Locally")
(print "section local")
(setq tmp-file (concat (read-directory-name "Select directory: " "~/") (read-string "File name (Without extension): ") "." ext))
(setq cmd (concat "maim -s " tmp-file)))
((equal target "Imgur")
(setq cmd (concat "maim -s " tmp-file "; imgur " tmp-file " | xclip -selection clipboard")))
((equal target "Clipboard")
(setq cmd (concat "maim -s | xclip -selection clipboard -t image/png")))))
((equal source "Whole Screen")
(cond ((equal target "Locally")
(setq tmp-file (concat (read-directory-name "Select directory: " "~/") (read-string "File name (Without extension): ") "." ext))
(setq cmd (concat "maim " tmp-file)))
((equal target "Imgur")
(setq cmd (concat "maim " tmp-file "; imgur " tmp-file " | xclip -selection clipboard")))
((equal target "Clipboard")
(setq cmd (concat "maim | xclip -selection clipboard -t image/png"))))))
(list tmp-file cmd)))
```
I'm still a noob with elisp, so any suggestions regarding my code are welcome.
I use `completing-read` to ask the user what he wants to screenshot and where to save it (For example 1: Whole screen, 2: Upload to imgur):
```
;; ...
(setq action (completing-read "Take screenshot of ..." actions )
target (completing-read "Save screenshot ..." targets ))
;; ...
```
After that I execute the corresponding command using `maim`. However the problem is that the second `completing-read`-dialog, where the user selects the target is still visible when maim takes the screenshot, resulting in something like this:
I hope you get my problem. I want the `completing-read` to close before I take the screenshot. Does anyone know how to achieve that?
# Answer
One option you have is to use the `sit-for` function after you get the user's response, but before you take the actual screenshot.
> 1 votes
---
Tags: completing-read
---
|
thread-60563
|
https://emacs.stackexchange.com/questions/60563
|
Keyboard map in X version of Emacs not respecting system map
|
2020-09-08T17:34:04.827
|
# Question
Title: Keyboard map in X version of Emacs not respecting system map
When I use emacs -nw in the terminal, it respects my keyboard map, but when I use the X version, I get a completely different map. I would expect that my X keyboard mapping would be respected as it is in all my other Linux installations.
I'm at a loss as I've never encountered this problem before. It's probably a simple reason, but the usual searches are bringing up nothing. Is there a setting that I have overlooked that needs to be made?
TIA
# Answer
Odd solution. In Manjaro I'd inadvertently set the Japanese keyboard layout. X emacs was respecting that setting, whereas the console version, and all other X apps were perhaps following locale.
> 1 votes
---
Tags: keyboard-layout
---
|
thread-60457
|
https://emacs.stackexchange.com/questions/60457
|
Can't save safe variables for further
|
2020-09-02T14:02:04.300
|
# Question
Title: Can't save safe variables for further
When I start Emacs it asks me if I want to allow "unsafe" variables which I agree and press '!' to save them for the future. Despite that, it still keeps asking me about it on every launch.
Here is the code that I like to run a per-directory basis:
```
(defun jarfar/org-tasks-refile-targets-local ()
"Set local 'org-refile-targets for specific org files with tasks."
(setq-local org-refile-targets
`(
(,my/org-backlog-file-path :maxlevel . 1)
(,my/org-inbox-file-path :maxlevel . 1)
(,my/org-tasks-file-path :maxlevel . 1)
(,my/org-taxes-file-path :maxlevel . 1)
)))
(dir-locals-set-class-variables 'jarfar/org-agenda-dir-class
'((nil . (
(eval . (progn (jarfar/org-tasks-refile-targets-local)))
))))
(dir-locals-set-directory-class org-agenda-directory 'jarfar/org-agenda-dir-class)
```
I tried many ways of suppressing this confirmation window but it keeps popping up.
Any idea?
# Answer
I managed to solve this with:
```
(setq enable-local-eval t)
(setq safe-local-eval-forms (list))
(add-to-list 'safe-local-eval-forms '(progn (jarfar/org-tasks-refile-targets-local)))
```
This post was helpful https://emacs.stackexchange.com/a/58332/18445.
> 0 votes
---
Tags: variables
---
|
thread-60490
|
https://emacs.stackexchange.com/questions/60490
|
error while loading shared libraries: libpoppler.so.101: cannot open shared object file: No such file or directory
|
2020-09-04T13:16:47.400
|
# Question
Title: error while loading shared libraries: libpoppler.so.101: cannot open shared object file: No such file or directory
Running Doom Emacs 2.0.9 on Emacs 27.1 on Manjaro KDE.
When I compile a latex documents, it produces a PDF file and opens an emacs window to display it. But what is displayed is some text and not the PDF file.
The `*Messages*` buffer carries an error that says:
> File mode specification error: (error Error running ‘/home/user/.emacs.d/.local/straight/build/pdf-tools/epdfinfo’: /home/user/.emacs.d/.local/straight/build/pdf-tools/epdfinfo: error while loading shared libraries: libpoppler.so.101: cannot open shared object file: No such file or directory
If that is of any use, this is happening after a massive update to the OS. Earlier, the new window would show the PDF file.
How do I correct this error?
# Answer
TL;DR
Go to `path/to/.emacs.d/elpa/pdf-tools-xxx/build` and run `make clean` to clean previously compiled contents manually.
Restart emacs and let it build pdf-tools. Then, pdf-tools works again :)
---
I have also met this problem.
Follow the error message, we can tell the problem is `epdfinfo` cannot find the library it wants, which is `libpoppler.so.101`.
After check the directory `/usr/lib/` I found there is no `libpoppler.so.101`, instead, we get `libpoppler.so.102`. Then I checked the pamac history and found the `poppler` related packages were updated from `0.90.1-1` to `20.08.1-1`. I think this is why `libpoppler.so` updated from 101 to 102.
The problem here is, after the update, pdf-tools tries to rebuild itself. However, it does not really do the rebuild, which I don't know why. (maybe make does not find the change of source code so it just skips all the rebuild. sorry, I only know little about compile.)
So, what I did is go to pdf-tools' directory which is `path/to/.emacs.d/elpa/pdf-tools-xxx/build` and run `make clean` to remove these object files manually. I also did `make clean` in the `server` subdirectory under `build`, but I am not sure if it is necessary. Then reopen emacs and let it rebuild the pdf-tools (or run `pdf-tools-install`, to rebuild it manually).
Now, pdf-tools works again.
Hope this can help.
> 3 votes
---
Tags: latex, pdf, preview-latex, pdf-tools, doom
---
|
thread-24033
|
https://emacs.stackexchange.com/questions/24033
|
When returning from emacsclient to iterm2, terminal not getting focus
|
2016-06-18T16:03:53.977
|
# Question
Title: When returning from emacsclient to iterm2, terminal not getting focus
I'm using iterm2 v3.0.2 with fishs hell and tmux in osx. When I'm opening file via emacsclient and closing buffer - I'm successfully returning to terminal, BUT iterm2 window has no focus, so I have to click on window to gain it. I tested behaviour inside tmux session and outside - the same behaviour.
My command to run emacsclient:
```
emacsclient -c -a \"\" $argv
```
# Answer
Maybe you can try to switch to your terminal app explicitly when `C-x #` (`server-edit`, the command to tell emacsclient that you finish editing):
```
(add-hook 'server-done-hook
(defun open-terminal ()
(shell-command "open -a Terminal")))
```
You also need to replace `Terminal` with `iTerm` since you are using iTerm2, not the built-in Terminal. I don't have iTerm2 installed on my Mac, so I can't try it myself.
> 1 votes
# Answer
I had the same problem, and managed to get it working by adding
```
(defun switch-back-focus ()
(shell-command "open -a iTerm"))
(add-hook 'server-done-hook 'switch-back-focus)
```
to my `init.el` file.
This does come with a couple of caveats - it will bring any Emacs frames to the front before it move back to iTerm2.
Thanks to @xuchunyang!
> 0 votes
---
Tags: emacsclient
---
|
thread-60492
|
https://emacs.stackexchange.com/questions/60492
|
Custom agenda sorting by CREATED date
|
2020-09-04T14:13:27.623
|
# Question
Title: Custom agenda sorting by CREATED date
I put together the function below but it doesn't work. The problem is `get-text-property` returns nil for every task.
Any idea how to get the CREATED property and fix the entire thing?
```
(defun jarfar/org-agenda-cmp-user-defined-created-date (a b)
"Org Agenda user function to sort tasks based on CREATED property."
(let* (
(time-a (get-text-property 0 'CREATED a))
(time-b (get-text-property 0 'CREATED b))
(time-a (if time-a (org-time-string-to-time time-a) nil))
(time-b (if time-b (org-time-string-to-time time-b) nil)))
(if (and time-a time-b)
(if (org-time< time-a time-b)
-1
(if (org-time> time-a time-b)
1
nil))
(if time-a time-a time-b)
)))
```
---
EDIT: Here is an example data file:
```
* Tasks
** TODO Task 1
:PROPERTIES:
:CREATED: [2020-07-23 Thu]
:END:
** TODO Task 2
:PROPERTIES:
:CREATED: [2020-06-15 Tue]
:END:
** TODO Task 3
:PROPERTIES:
:CREATED: [2020-05-22 Sat]
:END:
** TODO Task 4
:PROPERTIES:
:CREATED: [2020-06-01 Tue]
:END:
```
---
EDIT: Update to the function:
```
(defun jarfar/org-agenda-cmp-user-defined-created-date (a b)
"Org Agenda user function to sort tasks based on CREATED property."
(let* (
(marker-a (get-text-property 0 'org-marker a))
(marker-b (get-text-property 0 'org-marker b))
(time-a (if marker-a (org-entry-get marker-a "CREATED") nil))
(time-b (if marker-b (org-entry-get marker-b "CREATED") nil))
(time-a (if time-a (org-time-string-to-time time-a) nil))
(time-b (if time-b (org-time-string-to-time time-b) nil)))
(if (and time-a time-b)
(if (org-time< time-a time-b)
-1
(if (org-time> time-a time-b)
1
nil))
(if time-a time-a time-b)
)))
```
# Answer
The compare function is run on the agenda buffer, not the original org buffer. Various data from the original is inserted as text properties, but this doesn't include general org properties (as in things in the `:PROPERTIES:` drawer).
To retrieve generic data from an org entry, first get the position of the original entry (stored as the `org-marker` text property). Then use `org-entry-get` on that position:
```
(let ((a-pos (get-text-property 0 'org-marker a))
(a-time (org-entry-get a-pos "CREATED"))
))
```
> 2 votes
---
Tags: org-agenda, sorting, org-journal
---
|
thread-60572
|
https://emacs.stackexchange.com/questions/60572
|
How to NOT Auto Indent when a specific Character is inputted?
|
2020-09-09T06:55:27.060
|
# Question
Title: How to NOT Auto Indent when a specific Character is inputted?
So I recently encountered a problem programming in C that whenever I enter the left parenthesis character, `(`, Emacs auto-idents the code.
```
[4 spaces here]DATA *SeqQueueOut(
```
I know that there is this thing called `electric-ident-mode`, which I do not want to disable it. All I want to do is to not ident the code specifically whenever I type `(`. How can I do that in `init.el`?
# Answer
`C-h``k``(` tells us:
```
( runs the command c-electric-paren (found in c-mode-map), which
is an interactive compiled Lisp function in ‘cc-cmds.el’.
It is bound to ), (.
```
I suggest:
```
(with-eval-after-load "cc-mode"
(define-key c-mode-map (kbd "(") #'self-insert-command)
(define-key c-mode-map (kbd ")") #'self-insert-command))
```
> 2 votes
# Answer
`electric-indent-mode` is enabled by default. You can turn it off via `(electric-indent-mode -1)` in your `~/.emacs`, but if you want to only disable it for a particular char (e.g. `(`) in a particular major mode, the normal way could look like:
```
(add-hook '<foo>-mode-hook
(lambda ()
(setq electric-indent-chars
(delq ?\( electric-indent-chars))))
```
If a major mode does not obey `electric-indent-chars` I suggest you report it as a bug in that major mode (e.g. with `M-x report-emacs-bug` if it's bundled with Emacs).
> 0 votes
---
Tags: indentation, c, tabs
---
|
thread-60585
|
https://emacs.stackexchange.com/questions/60585
|
How to enter/render d-hat in emacs and latex export
|
2020-09-10T00:02:54.353
|
# Question
Title: How to enter/render d-hat in emacs and latex export
I want to be able to use d-hat (d with a caret (^) above it) in emacs to indicate an estimate of Cohen's 'd' (an effect size statistic).
How can I enter this in org-mode in a way that it renders within emacs, and also how can I make sure it exports out to latex/PDF?
Thanks
EDIT: Below are a tex file that resulted from a LaTeX export of a one-line org file, with the latex output
```
% Created 2020-09-17 Thu 16:09
% Intended LaTeX compiler: pdflatex
\documentclass[11pt]{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{graphicx}
\usepackage{grffile}
\usepackage{longtable}
\usepackage{wrapfig}
\usepackage{rotating}
\usepackage[normalem]{ulem}
\usepackage{amsmath}
\usepackage{textcomp}
\usepackage{amssymb}
\usepackage{capt-of}
\usepackage[colorlinks=true]{hyperref}
\author{U-BRXPS\brett}
\date{\today}
\title{}
\hypersetup{
pdfauthor={U-BRXPS\brett},
pdftitle={},
pdfkeywords={},
pdfsubject={},
pdfcreator={Emacs 26.3 (Org mode 9.1.9)},
pdflang={English}}
\begin{document}
\tableofcontents
This is a d-hat: \(\hat{d}\)
\end{document}
```
```
$ latex test.tex
This is pdfTeX, Version 3.14159265-2.6-1.40.21 (MiKTeX 20.6.29)
entering extended mode
(test.tex
LaTeX2e <2020-02-02> patch level 5
L3 programming layer <2020-07-17>
("C:\Program Files\MiKTeX\tex/latex/base\article.cls"
Document Class: article 2019/12/20 v1.4l Standard LaTeX document class
("C:\Program Files\MiKTeX\tex/latex/base\size11.clo"))
("C:\Program Files\MiKTeX\tex/latex/base\inputenc.sty")
("C:\Program Files\MiKTeX\tex/latex/base\fontenc.sty")
("C:\Program Files\MiKTeX\tex/latex/graphics\graphicx.sty"
("C:\Program Files\MiKTeX\tex/latex/graphics\keyval.sty")
("C:\Program Files\MiKTeX\tex/latex/graphics\graphics.sty"
("C:\Program Files\MiKTeX\tex/latex/graphics\trig.sty")
("C:\Program Files\MiKTeX\tex/latex/graphics-cfg\graphics.cfg")
("C:\Program Files\MiKTeX\tex/latex/graphics-def\dvips.def")))
(C:\Users\brett\AppData\Roaming\MiKTeX\tex/latex/grffile\grffile.sty)
y) (C:\Users\brett\AppData\Roaming\MiKTeX\tex/generic/pdfescape\pdfescape.sty)
(C:\Users\brett\AppData\Roaming\MiKTeX\tex/latex/hycolor\hycolor.sty)
(C:\Users\brett\AppData\Roaming\MiKTeX\tex/latex/letltxmacro\letltxmacro.sty)
(C:\Users\brett\AppData\Roaming\MiKTeX\tex/latex/auxhook\auxhook.sty)
(C:\Users\brett\AppData\Roaming\MiKTeX\tex/latex/kvoptions\kvoptions.sty)
("C:\Program Files\MiKTeX\tex/latex/hyperref\pd1enc.def")
(C:\Users\brett\AppData\Roaming\MiKTeX\tex/generic/intcalc\intcalc.sty)
(C:\Users\brett\AppData\Roaming\MiKTeX\tex/generic/etexcmds\etexcmds.sty)
("C:\Program Files\MiKTeX\tex/latex/url\url.sty")
(C:\Users\brett\AppData\Roaming\MiKTeX\tex/generic/bitset\bitset.sty
(C:\Users\brett\AppData\Roaming\MiKTeX\tex/generic/bigintcalc\bigintcalc.sty))
(C:\Users\brett\AppData\Roaming\MiKTeX\tex/generic/atbegshi\atbegshi.sty))
("C:\Program Files\MiKTeX\tex/latex/hyperref\hdvips.def"
("C:\Program Files\MiKTeX\tex/latex/hyperref\pdfmark.def"
(C:\Users\brett\AppData\Roaming\MiKTeX\tex/latex/rerunfilecheck\rerunfilecheck.
sty (C:\Users\brett\AppData\Roaming\MiKTeX\tex/latex/atveryend\atveryend.sty)
(C:\Users\brett\AppData\Roaming\MiKTeX\tex/generic/uniquecounter\uniquecounter.
sty))))
! Undefined control sequence.
<argument> U-BRXPS\brett
l.26 pdflang={English}}
?
```
# Answer
> 0 votes
If there is a Unicode d-hat, then using that should take care of it both in the buffer and in the PDF produced through LaTeX (assuming your LaTeX tool chain can handle Unicode, which should be no problem nowadays).
Unfortunately, I can't find such a Unicode character. In the absence of that, I would suggest you use a LaTeX math expression:
```
\(\hat{d}\)
```
which will produce a d-hat in the output. But it's not going to look like a d-hat in the buffer, unless you preview the LaTeX fragment with `M-x org-latex-fragment` (usually bound to `C-c C-x C-l`) - this is a toggle, so repeating it will eliminate the overlay and show you the LaTeX fragment again. You can preview all the LaTeX fragments in your buffer with `C-u C-u C-c C-x C-l` and if you want that to happen whenever you open the file, you can add a Local File Variables section at the end of your file:
```
# Local Variables:
# eval: (org-latex-fragment '(16))
# End:
```
This last trick is a general Emacs customization trick, applicable generally, not just for Org mode stuff.
See Embedded LaTeX in the manual. In the long run, if you have to do a lot of math, then learning some LaTeX and using this embedding is likely to be a more productive way to produce your documents.
---
Tags: org-mode
---
|
thread-34342
|
https://emacs.stackexchange.com/questions/34342
|
Is there any downside to setting `gc-cons-threshold` very high and collecting garbage when idle?
|
2017-07-22T10:44:39.067
|
# Question
Title: Is there any downside to setting `gc-cons-threshold` very high and collecting garbage when idle?
I added the following two lines to the top of my `init.el`:
```
(setq gc-cons-threshold (eval-when-compile (* 1024 1024 1024)))
(run-with-idle-timer 2 t (lambda () (garbage-collect)))
```
That means that instead of collecting garbage every 800kb of allocated memory, Emacs does so when idle, i.e. when the pausing does not bother me. (It also collects after allocating 1GB of memory, but I don't think that will happen).
This improved my startup time by about two thirds. In theory, it should also improve performance in general. Are there any downsides to this approach?
# Answer
> 8 votes
As far as I know, if you have the RAM, it's okay, but if Emacs ever did hit really high usage before GC'ing, it might take a long time. I'm not sure exactly what Eli means; ISTM that if you have enough memory, it should be okay, but he's the expert here.
Having said that, I've used these lines in my init file for a while now, and it helps reduce startup time without making the changes permanent:
```
;;;;; Startup optimizations
;;;;;; Set garbage collection threshold
;; From https://www.reddit.com/r/emacs/comments/3kqt6e/2_easy_little_known_steps_to_speed_up_emacs_start/
(setq gc-cons-threshold-original gc-cons-threshold)
(setq gc-cons-threshold (* 1024 1024 100))
;;;;;; Set file-name-handler-alist
;; Also from https://www.reddit.com/r/emacs/comments/3kqt6e/2_easy_little_known_steps_to_speed_up_emacs_start/
(setq file-name-handler-alist-original file-name-handler-alist)
(setq file-name-handler-alist nil)
;;;;;; Set deferred timer to reset them
(run-with-idle-timer
5 nil
(lambda ()
(setq gc-cons-threshold gc-cons-threshold-original)
(setq file-name-handler-alist file-name-handler-alist-original)
(makunbound 'gc-cons-threshold-original)
(makunbound 'file-name-handler-alist-original)
(message "gc-cons-threshold and file-name-handler-alist restored")))
```
# Answer
> -1 votes
https://bling.github.io/blog/2016/01/18/why-are-you-changing-gc-cons-threshold/ suggests leaving the default value for `gc-cons-threshold` and then finding which packages perform badly and increasing the value only for those parts.
The example includes disabling gc while the minibuffer is open.
```
(defun my-minibuffer-setup-hook ()
(setq gc-cons-threshold most-positive-fixnum))
(defun my-minibuffer-exit-hook ()
(setq gc-cons-threshold 800000))
(add-hook 'minibuffer-setup-hook #'my-minibuffer-setup-hook)
(add-hook 'minibuffer-exit-hook #'my-minibuffer-exit-hook)
```
I originally had this in `init.el`
```
;; Don't be so stingy on the memory, we have lots now. It's the distant future.
(setq gc-cons-threshold 20000000)
```
and https://github.com/lastquestion/explain-pause-mode was showing me gc was taking time in operations I wasn't expecting, most probably because its got to gc 20MB.
I think I'll look into a more tailored approach to this variable rather than a one size fits alls.
---
Tags: start-up, performance, garbage-collect
---
|
thread-52652
|
https://emacs.stackexchange.com/questions/52652
|
Elpy doesn't recognize I have virtualenv installed
|
2019-09-14T06:42:58.810
|
# Question
Title: Elpy doesn't recognize I have virtualenv installed
I am trying to get started with elpy but any python file I open elpy will complain and say
> eldoc error: (error Elpy necessitates the ’virtualenv’ python package, please install it with ‘pip install virtualenv‘)
Even if I am editing files in a directory with a virtualenv and I have $WORKON\_HOME set to that directory.
# Answer
`(setq elpy-rpc-virtualenv-path 'current)` works for me.
> 5 votes
# Answer
I followed this tutorial, and got the same error. When I looked at the buffer `elpy-virtualenv`, it showed the error that I have no module named `virtualenv` installed. It also showed me this:
```
Elpy failed to install its dedicated virtualenv due to the above
error. If the error details does not help you fixing it, You can
report this problem on Elpy repository on github.
In the meantime, setting the `elpy-rpc-virtualenv-path' option to
either `global' or `current' should temporarily fix the issue.
```
So I added the line `(setq elpy-rpc-virtualenv-path 'current)` in my `~/.emacs.d/init.el` file. That solved the problem "temporarily" as it said. The permanent solution is to install `virtualenv` via package manager. For Ubuntu and other debian-based Linux distro, it is easy: `sudo apt install virtualenv`.
> 1 votes
# Answer
it's all in the `sudo apt install virtualenv`
> 1 votes
---
Tags: elpy
---
|
thread-13463
|
https://emacs.stackexchange.com/questions/13463
|
Specify timezone in Org date format
|
2015-06-26T08:36:01.683
|
# Question
Title: Specify timezone in Org date format
When I write something like this: `<2015-07-05 Sun 20:00 GMT+0>`, and then try to edit it by pressing `C-c .`, Org removes the `GMT+0` part. So, I think it's in a wrong format.
Note: I don't want to set my time to a different timezone. I want dates in a particular document to be in that timezone.
# Answer
Time zone informatian is not currently part of date formats in `org-mode` and thus not part of the output from `C-c .`. Like `C-c C-c` on a timestamp any extraneous material in the date specification is removed and the week day is corrected to fit a given date, so partial junk input like
```
13-6-3 Wed Xyz 13:00
```
is output as
```
<2013-06-03 Mon 13:00>
```
a correct date, with matching day name.
It might be appropriate to make a feature request to the `org-mode` developers.
> 6 votes
# Answer
**Note:** this **only stores the local timezone** and keep it in your timestamps. It'll replace any timezone information by your local one. But at least it'll store your current local one.
**Note2:** all timestamps will work to my knowledge, but time ranges are then ambiguously displayed. Thanks to @He Yifei 何一非 to bring that up.
This is what I did:
```
(setq org-time-stamp-formats '("<%Y-%m-%d %a>" . "<%Y-%m-%d %a %H:%M %Z>"))
```
The important part is the `%Z`.
default is (from orgmode source):
```
(defconst org-time-stamp-formats '("<%Y-%m-%d %a>" . "<%Y-%m-%d %a %H:%M>")
"Formats for `format-time-string' which are used for time stamps.")
```
With this setting, all instances of timestamps in `orgmode` that I use and can think of get the timezone information added (ie: `<2020-09-15 Tue 09:00 CEST>`):
* modifying dates by hand and using `C-c C-c` (timezone will get added if missing)
* Clockin and Clockout with `C-c C-x C-i` / `C-c C-x C-o`
* `CLOSED`, `SCHEDULED`, `DEADLINE`
* `org-time-stamp` when inserting time and not only date info
And I didn't notice any issue, except that time ranges are not really useable (I don't use them). I'm using quite extensively all the clock/timestamps. This setting is available in `orgmode` for a very long time, before 2008 for sure, according to `org` git repository.
Let me add the fact that you should probably NEVER store naive timestamps (without timezones) anywhere. It is a pity that orgmode does this by default. Thankfully, it is easy to fix.
> 3 votes
---
Tags: org-mode, time-date
---
|
thread-41175
|
https://emacs.stackexchange.com/questions/41175
|
How to warn before sending email if Subject: is empty
|
2018-04-23T17:46:22.343
|
# Question
Title: How to warn before sending email if Subject: is empty
If I hit `C-c C-c` in `message-mode` (I use `notmuch`) in order to send an email I've composed, I want to be warned if the Subject: header is empty. E.g. "Really send without Subject? (yes or no)"
When composing new email I fill in the Subject after I have written the body because only then I know exactly what Subject: matches this emails contents best. Sadly I often forget to actually set the Subject and with message-mode the email is sent without Subject:.
I searched online, but I'm astonished that this does not seem to be a recurring topic let alone an already answered FAQ.
# Answer
> 11 votes
One way is to hook into `message-send-hook`:
```
message-send-hook is a variable defined in ‘message.el’.
Its value is nil
This variable may be risky if used as a file-local variable.
Documentation:
Hook run before sending messages.
This hook is run quite early when sending.
```
For example:
```
(defun my-confirm-empty-subject ()
"Allow user to quit when current message subject is empty."
(or (message-field-value "Subject")
(yes-or-no-p "Really send without Subject? ")
(keyboard-quit)))
(add-hook 'message-send-hook #'my-confirm-empty-subject)
```
# Answer
> 0 votes
Instead of adding the function to `message-send-hook`, as suggested by Basil, I ended up adding the very same function to `message-send-mail-hook` instead. For some reason (or none?) `message-send-hook` was always invoked twice for me (and it would ask me twice to confirm). `message-send-mail-hook` is called once only.
---
Tags: email, message-mode, notmuch
---
|
thread-43845
|
https://emacs.stackexchange.com/questions/43845
|
org-mode + evil: insert heading, set cursor to line ending, and change to insert mode?
|
2018-07-29T22:30:30.430
|
# Question
Title: org-mode + evil: insert heading, set cursor to line ending, and change to insert mode?
I am using spacemacs which contains `org-mode` and `evil`. Whenever I insert a heading (either `org-insert-heading`, `org-insert-heading-after-current` or `org-insert-subheading`), I have to do two extra actions: move cursor to the end of line, change to insert mode to start typing. How do I get these two actions done automatically for all the insert heading functions?
What I am thinking now is to write wraper functions for these functions, and then redefine the shortcut keys. But wouldn't there be a better way?
# Answer
> 3 votes
You need to set `org-M-RET-may-split-line` to `nil` via:
`(setq org-M-RET-may-split-line nil)` in your `.spacemacs` or `.emacs` file.
look at the documentation for `org-insert-heading` with `SPC h d f` in spacemacs or `C-h f` in emacs. Setting that variable to nil will tell org to never split the line on an insert.
# Answer
> 2 votes
The following function should meet your goal:
```
(defun my-insert-new-sibling-after-current (&optional force-heading)
(interactive)
(end-of-line)
(if force-heading ; is set to t
(cond
((org-on-heading-p) (org-insert-heading-after-current))
(t (progn
(org-speed-move-safe (quote outline-previous-visible-heading))
(end-of-line)
(org-insert-heading-respect-content nil))))
(cond
((org-on-heading-p) (org-insert-heading-after-current))
((org-at-item-p) (org-meta-return))
(t (org-return))))
(evil-append nil))
```
# Answer
> 1 votes
As pointed to in this answer, setting `evil-move-beyond-eol` to non-nil, although not very vimesque, would allow you to move pass the last character, fixing the unwanted behavior you're having.
---
Tags: org-mode, evil
---
|
thread-60592
|
https://emacs.stackexchange.com/questions/60592
|
How to setup ediff to open a new frame with the two comparison buffers
|
2020-09-10T13:58:16.420
|
# Question
Title: How to setup ediff to open a new frame with the two comparison buffers
When I issue `M-x ediff-buffers`I'd like ediff to create a new frame with the two buffers (and close this frame when done with the comparison). How can I customise ediff to do so?
I tried
```
(defun leo-ediff-before-setup ()
(make-frame))
(add-hook 'ediff-before-setup-hook 'leo-ediff-before-setup)
```
but this sets the initial frame *and* a new frame up for the comparison.
# Answer
The problem with the code in the question is that the newly made frame is not selected - and ediff operates on the selected frame. So, correct is:
```
(defun leo-ediff-before-setup ()
(select-frame (make-frame)))
(add-hook 'ediff-before-setup-hook 'leo-ediff-before-setup)
```
Of course there's more customisation needed if the frame is to be closed at the end of the ediff session.
> 1 votes
---
Tags: frames, hooks, ediff
---
|
thread-60604
|
https://emacs.stackexchange.com/questions/60604
|
Emacs failing to access HTTPS URL behind a proxy
|
2020-09-11T09:05:59.850
|
# Question
Title: Emacs failing to access HTTPS URL behind a proxy
I hoped that this problem's solution would solve it for me, but it didn't. I've got my proxy set up as follows (slightly redacted):
```
(setq url-proxy-services
'(("no_proxy" . "^\\(localhost\\|10.*\\)")
("http" . "proxy.xxx.com:8080")
("https" . "proxy.xxx.com:8080")))
```
and when I use `eww` to make a request I get (again, slightly redacted):
```
Request Error: https://www.google.co.uk/
XXX Dynamic IT
Request Error (invalid_request)
Proxy: xxx-xx-20
Url: https://www.google.co.uk/
Time: [11/09/2020:08:46:35 GMT]
Client: xxx.xxx.8.32
Your request for https://www.google.co.uk/ could not be processed. Request
could not be handled
This could be caused by a misconfiguration, or possibly a malformed
request.
```
I was wondering if this could be because it's trying to talk HTTPS to the proxy. I tried following the example on EmacsWiki where the protocol is included in the proxy specification, so I'd instead have:
```
(setq url-proxy-services
'(("no_proxy" . "^\\(localhost\\|10.*\\)")
("http" . "http://proxy.xxx.com:8080")
("https" . "http://proxy.xxx.com:8080")))
```
but this doesn't work either. I get a couple of lines in the `*Messages*` buffer that suggest I shouldn't be doing it that way:
```
Contacting host: http:80
open-network-stream: http/80 Temporary failure in name resolution
```
Am I doing something wrong and/or daft?
Thanks in advance.
# Answer
> 2 votes
This is most likely related to the following bug which was fixed in Emacs 26.1: https://debbugs.gnu.org/cgi/bugreport.cgi?bug=11788.
---
Tags: eww, proxy
---
|
thread-60609
|
https://emacs.stackexchange.com/questions/60609
|
Completion with help
|
2020-09-11T15:15:29.877
|
# Question
Title: Completion with help
I'm using `completing-read` to get an argument for an interactive command. The argument is a non-intuitive word (required for my application), so the completion list looks like this:
```
Possible completions are:
faz foo bar baz
```
I'd like it to also show some help, something like this:
```
Possible completions are:
faz Pogo quote part 2
foo Regular fubar
bar All the soap
baz Pogo quote part 1
```
Is there a straight-forward way to accomplish this, or something similar?
# Answer
I don't know about "straight-forward", but you can do it as follows:
```
(let* ((comps '(("faz" "Pogo quote part 2")
("foo" "Regular fubar")
...))
(completion-extra-properties
`(:annotation-function
,(lambda (s) (format " %s" (cadr (assoc s comps)))))))
(completing-read "Prompt: " comps))
```
> 1 votes
---
Tags: completion, help
---
|
thread-60613
|
https://emacs.stackexchange.com/questions/60613
|
Agenda sort by custom org timestamp property not working
|
2020-09-11T16:08:39.050
|
# Question
Title: Agenda sort by custom org timestamp property not working
The comparison function below meant to compare headings using custom CREATED property which store org timestamp. The problem is, it doesn't work - the sorting fallback to next sorting strategy which is `alpha-up`.
```
(defun jarfar/org-agenda-cmp-user-defined-created-date (a b)
"Org Agenda user function to sort tasks based on CREATED property."
(let* (
(marker-a (get-text-property 0 'org-marker a))
(marker-b (get-text-property 0 'org-marker b))
(time-a (if marker-a (org-entry-get marker-a "CREATED") nil))
(time-b (if marker-b (org-entry-get marker-b "CREATED") nil))
(time-a (if (jarfar/is-org-timestamp time-a) (org-time-string-to-time time-a) nil))
(time-b (if (jarfar/is-org-timestamp time-b) (org-time-string-to-time time-b) nil)))
(if (and time-a time-b)
(if (org-time< time-a time-b)
-1
(if (org-time> time-a time-b) 1 nil))
(if time-a -1 1)
)))
(defun jarfar/is-org-timestamp (arg)
"Returns 't' if 'arg' is org timestamp string, otherwise returns nil."
(and arg (stringp arg) (string-match org-ts-regexp0 arg)))
```
Example data file:
```
* Tasks
** TODO Task 1
:PROPERTIES:
:CREATED: [2020-03-01 Sun]
:END:
** TODO Task 2
:PROPERTIES:
:CREATED: [2020-05-01 Fri]
:END:
** TODO Task 3
:PROPERTIES:
:CREATED: [2020-07-01 Wed]
:END:
** TODO Task 4
:PROPERTIES:
:CREATED: [2020-06-01 Mon]
:END:
```
Any idea what is wrong with the function?
# Answer
> 0 votes
I managed to figure out what was the problem, I simply over complicate it. `org-time` comparison functions work with output of `org-entry-get` not `org-time-string-to-time`.
```
(defun jarfar/org-agenda-cmp-user-defined-created-date (a b)
"Org Agenda user function to sort tasks based on CREATED property."
(let* (
(marker-a (get-text-property 0 'org-marker a))
(marker-b (get-text-property 0 'org-marker b))
(time-a (if marker-a (org-entry-get marker-a "CREATED") nil))
(time-b (if marker-b (org-entry-get marker-b "CREATED") nil)))
(if (and time-a time-b)
(if (org-time< time-a time-b)
-1
(if (org-time> time-a time-b) 1 nil))
(if time-a -1 1)
)))
```
---
Tags: org-agenda
---
|
thread-60615
|
https://emacs.stackexchange.com/questions/60615
|
Orgmode - Vertical header
|
2020-09-11T19:48:15.470
|
# Question
Title: Orgmode - Vertical header
is it possible to create a vertical header with org mode, too?
Something like this (cyan colored fields):
You can create a horizontal header like this:
```
| Header | Header | Header | Header | Header |
|---------+---------+---------+---------+---------|
| Content | Content | Content | Content | Content |
```
but I want also a vertical header, too:
```
| Header | Header | Header | Header | Header |
|--------+---------+---------+---------+---------|
| Header | Content | Content | Content | Content |
| Header | Content | Content | Content | Content |
```
The reason for this is I want to export it to HTML.
The HTML will look like this:
```
<table border="2" cellpadding="6" cellspacing="0" frame="hsides" rules="groups">
<colgroup>
<col class="org-right">
<col class="org-right">
<col class="org-right">
<col class="org-right">
<col class="org-right">
<col class="org-right">
<col class="org-right">
<col class="org-right">
<col class="org-right">
<col class="org-right">
<col class="org-right">
<col class="org-right">
<col class="org-right">
</colgroup>
<thead>
<tr>
<th class="org-right" scope="col">.</th>
<th class="org-right" scope="col">1</th>
<th class="org-right" scope="col">2</th>
<th class="org-right" scope="col">3</th>
<th class="org-right" scope="col">4</th>
<th class="org-right" scope="col">5</th>
<th class="org-right" scope="col">6</th>
<th class="org-right" scope="col">7</th>
<th class="org-right" scope="col">8</th>
<th class="org-right" scope="col">9</th>
<th class="org-right" scope="col">10</th>
<th class="org-right" scope="col">11</th>
<th class="org-right" scope="col">12</th>
</tr>
</thead>
<tbody>
<tr>
<td class="org-right">1</td>
<td class="org-right">1</td>
<td class="org-right">2</td>
<td class="org-right">3</td>
<td class="org-right">4</td>
<td class="org-right">5</td>
<td class="org-right">6</td>
<td class="org-right">7</td>
<td class="org-right">8</td>
<td class="org-right">9</td>
<td class="org-right">10</td>
<td class="org-right">11</td>
<td class="org-right">12</td>
</tr>
</tbody>
</table>
```
if it supports vertical header it should be something like this:
```
<table border="2" cellpadding="6" cellspacing="0" frame="hsides" rules="groups">
<colgroup>
<col class="org-right">
<col class="org-right">
<col class="org-right">
<col class="org-right">
<col class="org-right">
<col class="org-right">
<col class="org-right">
<col class="org-right">
<col class="org-right">
<col class="org-right">
<col class="org-right">
<col class="org-right">
<col class="org-right">
</colgroup>
<thead>
<tr>
<th class="org-right" scope="col">.</th>
<th class="org-right" scope="col">1</th>
<th class="org-right" scope="col">2</th>
<th class="org-right" scope="col">3</th>
<th class="org-right" scope="col">4</th>
<th class="org-right" scope="col">5</th>
<th class="org-right" scope="col">6</th>
<th class="org-right" scope="col">7</th>
<th class="org-right" scope="col">8</th>
<th class="org-right" scope="col">9</th>
<th class="org-right" scope="col">10</th>
<th class="org-right" scope="col">11</th>
<th class="org-right" scope="col">12</th>
</tr>
</thead>
<tbody>
<tr>
<th class="org-right">1</th>
<td class="org-right">1</td>
<td class="org-right">2</td>
<td class="org-right">3</td>
<td class="org-right">4</td>
<td class="org-right">5</td>
<td class="org-right">6</td>
<td class="org-right">7</td>
<td class="org-right">8</td>
<td class="org-right">9</td>
<td class="org-right">10</td>
<td class="org-right">11</td>
<td class="org-right">12</td>
</tr>
</tbody>
</table>
```
Note the `th` element on the second code block instead of an `td` element on the `tbody`. I know I can do this with JavaScript but I want to know if `org-mode` may already support it, which would make things a lot easier.
# Answer
> 2 votes
To make the first column a "header" column, all you have to do is
```
(setq org-html-table-use-header-tags-for-first-column t)
```
either globally, or as a local file variable:
```
# Local Variables:
# org-html-table-use-header-tags-for-first-column: t
# End:
```
AFAIK, you cannot specify it per table though.
For example:
```
* Multiplication table
#+ATTR_HTML: :border 3 :rules all :frame border
| . | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 |
|----+----+----+----+----+----+----+----+----+-----+-----|
| 1 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 |
| 2 | 2 | 4 | 6 | 8 | 10 | 12 | 14 | 16 | 18 | 20 |
| 3 | 3 | 6 | 9 | 12 | 15 | 18 | 21 | 24 | 27 | 30 |
| 4 | 4 | 8 | 12 | 16 | 20 | 24 | 28 | 32 | 36 | 40 |
| 5 | 5 | 10 | 15 | 20 | 25 | 30 | 35 | 40 | 45 | 50 |
| 6 | 6 | 12 | 18 | 24 | 30 | 36 | 42 | 48 | 54 | 60 |
| 7 | 7 | 14 | 21 | 28 | 35 | 42 | 49 | 56 | 63 | 70 |
| 8 | 8 | 16 | 24 | 32 | 40 | 48 | 56 | 64 | 72 | 80 |
| 9 | 9 | 18 | 27 | 36 | 45 | 54 | 63 | 72 | 81 | 90 |
| 10 | 10 | 20 | 30 | 40 | 50 | 60 | 70 | 80 | 90 | 100 |
#+TBLFM: @2$2..@>$> = @1$0 * @0$1
* Local variables :noexport:
# Local Variables:
# org-html-table-use-header-tags-for-first-column: t
# End:
```
will be exported to HTML exactly as you show (except for the colors).
See the Tables in HTML export section of the manual for other variables, but beware of the `#+ATTR_HTML` syntax: it's as I show above for recent versions of Org mode, but the manual shows the old syntax:
```
#+ATTR_HTML: border="2" rules="all" frame="border"
```
which you might still have to employ, depending on your version. I'll open a bug about the doc.
---
\[OLD ANSWER: the following does not answer the question but it might be sufficiently interesting to leave in here.\]
If you mean something like this:
```
* Multiplication table
| . | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 |
| 1 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 |
| 2 | 2 | 4 | 6 | 8 | 10 | 12 | 14 | 16 | 18 | 20 | 22 | 24 |
| 3 | 3 | 6 | 9 | 12 | 15 | 18 | 21 | 24 | 27 | 30 | 33 | 36 |
| 4 | 4 | 8 | 12 | 16 | 20 | 24 | 28 | 32 | 36 | 40 | 44 | 48 |
| 5 | 5 | 10 | 15 | 20 | 25 | 30 | 35 | 40 | 45 | 50 | 55 | 60 |
| 6 | 6 | 12 | 18 | 24 | 30 | 36 | 42 | 48 | 54 | 60 | 66 | 72 |
| 7 | 7 | 14 | 21 | 28 | 35 | 42 | 49 | 56 | 63 | 70 | 77 | 84 |
| 8 | 8 | 16 | 24 | 32 | 40 | 48 | 56 | 64 | 72 | 80 | 88 | 96 |
| 9 | 9 | 18 | 27 | 36 | 45 | 54 | 63 | 72 | 81 | 90 | 99 | 108 |
| 10 | 10 | 20 | 30 | 40 | 50 | 60 | 70 | 80 | 90 | 100 | 110 | 120 |
| 11 | 11 | 22 | 33 | 44 | 55 | 66 | 77 | 88 | 99 | 110 | 121 | 132 |
| 12 | 12 | 24 | 36 | 48 | 60 | 72 | 84 | 96 | 108 | 120 | 132 | 144 |
#+TBLFM: @2$2..@>$> = @1$0 * @0$1
```
the answer is an emphatic YES.
I created the table with the following set of instructions:
* `M-x org-create-table RET 1x13 RET`: that creates a single column table with 13 rows.
* Type `.` in the first row, `1` in the second row and then keep typing `S-<Enter>` to fill the rest of the rows.
* `M-x org-table-transpose-table-at-point RET` to make it into a single row table.
* Press `TAB` to create the second row and move to the first column of it.
* Type `1` in the first column of the second row and then keep typing `S-<Enter>` to fill out the rest of that column.
You now have the first column and the first row, populated with what you show in your table. Now add a table formula under the table as shown above and press `C-c C-c`: the rest of the table gets filled out (you must activate Calc beforehand: type `M-x calc RET q` to do that).
The table formula says: fill out every other cell in the table (rows 2 to last and columns 2 to last) with the product of the numbers that you find in (row 1, current column) and (current row, column 1).
---
Tags: org-mode, org-export, html
---
|
thread-60619
|
https://emacs.stackexchange.com/questions/60619
|
org-habit consistency graph in new line
|
2020-09-11T22:30:54.293
|
# Question
Title: org-habit consistency graph in new line
I would like to display the consistency graph in a new line below the task. This way I can use it for quite a long time without covering task letters or breaking the layout
```
Example
10:00 ...... TODO Workout in the gy||||*||*||**|||*|||||||
should be displayed as ;; ^
10:00 ...... TODO Workout in the gym group ;; |
||||*||*||**|||*||||||| ;; <-- consistency graph
```
Any ideas on how to make the concistency graph easyer on the eyes (like this)?
# Answer
> 3 votes
I don't think there is an option for doing that, so if you really want it, you'll have to modify the Org mode sources and carry the patch privately (I doubt very much that this change would be accepted upstream). That means that every time that you want to update, you will have to apply the patch again (and again, and again...)
The patch itself is simple:
```
diff --git a/lisp/org-habit.el b/lisp/org-habit.el
index f76f0f213..5f2e11518 100644
--- a/lisp/org-habit.el
+++ b/lisp/org-habit.el
@@ -430,6 +430,8 @@ current time."
(while (not (eobp))
(let ((habit (get-text-property (point) 'org-habit-p)))
(when habit
+ (end-of-line)
+ (insert-before-markers "\n")
(move-to-column org-habit-graph-column t)
(delete-char (min (+ 1 org-habit-preceding-days
org-habit-following-days)
```
It just adds two lines to the function `org-habit-insert-consistency-graphs` in `org-habit.el` and since this function is only called when the agenda is created, it is a fairly safe change.
But as I said, you will have to carry the patch in perpetuity or fork the Org mode sources to create your own. Whether that's worth the bother is up to you to decide.
There *are* options to reposition the graph on the line and make it shorter or longer: as @gregoryg points out in a comment, you can change the position of the graph by customizing `org-habit-graph-column`; you can change the length of the graph by customizing `org-habit-preceding-days` and `org-habit-following-days`.
---
Tags: org-agenda, org-habit
---
|
thread-48365
|
https://emacs.stackexchange.com/questions/48365
|
custom-theme-set-faces does not work in emacs 27
|
2019-03-15T12:43:30.743
|
# Question
Title: custom-theme-set-faces does not work in emacs 27
I have some custom theme settings like
```
(package-initialize)
(load-theme 'leuven t)
(custom-theme-set-faces
'leuven
'(Man-overstrike ((t (:foreground "red3" :bold t))) t)
'(Man-underline ((t (:foreground "green3" :underline t))))
;; ... ignored
'(yas-field-highlight-face ((t (:background "#D4DCD8" :foreground "black" :box (:line-width -1 :color "#838383"))))))
```
in my `init.el` of a `emacs -q` session. It works perfectly in emacs 26.1, but not in emacs 27, that's no matter how many times I evaluate the code, there's no custom face changes. I searched google but I can't find if there's some API changes in emacs 27.
Work Eamcs Version: `GNU Emacs 26.1.92 (build 2, x86_64-apple-darwin18.2.0, Carbon Version 158 AppKit 1671.2) of 2019-02-26`
Unwork Emacs version: `GNU Emacs 27.0.50 (build 1, x86_64-apple-darwin18.2.0, NS appkit-1671.20 Version 10.14.3 (Build 18D109)) of 2019-03-10`
Any help will be appreciated.
# Answer
> 13 votes
Put this line in your init. Theme changes will take effect immediately in Emacs 27.
```
(setq custom--inhibit-theme-enable nil)
```
Presumably the automatic theme changing was disabled for a good reason. I haven't looked into the reason, but to set the value temporarily for just 1 statement you could do this.
```
(let ((custom--inhibit-theme-enable nil))
(custom-theme-set-faces
'leuven
;; theme settings
))
```
The double dashes -- in the name mean it is a "private" variable. So it is subject to change at any time and may not work forever.
I haven't looked into it too deeply. And there are a few other ways to make the color take effect immediately. But setting this variable to nil is the most straight forward way to get the old behavior back.
# Answer
> 10 votes
Another solution would be to add `enable-theme` to the custom theme settings, such as:
```
(when (< emacs-major-version 27)
(package-initialize))
(load-theme 'leuven t)
(custom-theme-set-faces
'leuven
'(Man-overstrike ((t (:foreground "red3" :bold t))) t)
'(Man-underline ((t (:foreground "green3" :underline t))))
;; ... ignored
'(yas-field-highlight-face ((t (:background "#D4DCD8" :foreground "black" :box (:line-width -1 :color "#838383"))))))
(enable-theme 'leuven) ;; ADD THIS LINE
```
Apparently the NEWS file for Emacs 27.1 mentioned this change:
```
Just loading a theme's file no longer activates the theme's settings.
Loading a theme with 'M-x load-theme' still activates the theme, as it
did before. However, loading the theme's file with 'M-x load-file',
or using 'require' or 'load' in a Lisp program, doesn't actually apply
the theme's settings until you either invoke 'M-x enable-theme' or
type 'M-x load-theme'. (In a Lisp program, calling 'enable-theme' or
invoking 'load-theme' with NO-ENABLE argument omitted or nil has the
same effect of activating a theme whose file has been loaded.) The
special case of the 'user' theme is an exception: it is frequently
used for ad-hoc customizations, so the settings of that theme are by
default applied immediately.
The variable 'custom--inhibit-theme-enable' controls this behavior;
its default value changed in Emacs 27.1.
```
---
Tags: themes
---
|
thread-24946
|
https://emacs.stackexchange.com/questions/24946
|
eldoc error: (error Variable binding depth exceeds max-specpdl-size)
|
2016-07-30T07:58:04.297
|
# Question
Title: eldoc error: (error Variable binding depth exceeds max-specpdl-size)
I am editing `org-mode` files with a lot of source code blocks. These blocks contain my own pseudo code that looks like this:
```
(A) {B} (C)
(D) {F} (Z)
```
When moving within these blocks there is a pause or delay of several seconds between movements. After that the error message `eldoc error: (error Variable binding depth exceeds max-specpdl-size)`is displayed. First I thought the recent 25.1.1 update of railwaycat's Emacs for Mac was the culprit. But after a downgrade to the latest 24 version, the issue is still there. I then tried to rollback any package updates (with `Spacemacs`). Alas, to no avail. What can I do?
# Answer
Following the suggestion of @wasamasa:
```
Debugger entered--Lisp error: (error "Lisp nesting exceeds ‘max-lisp-eval-depth’")
apply(provided-mode-derived-p org-mode org-mode)
derived-mode-p(org-mode)
org-get-limited-outline-regexp()
org-element--current-element(358 element top-comment nil)
org-element--parse-to(100)
org-element-at-point()
org-eldoc-get-src-lang()
org-eldoc-documentation-function()
apply(org-eldoc-documentation-function nil)
#f(advice-wrapper :before-until #f(compiled-function (&rest args) #<bytecode 0x15735cd3e435>) org-eldoc-documentation-function)()
eldoc--invoke-strategy()
eldoc-print-current-symbol-info()
org-eldoc-documentation-function()
apply(org-eldoc-documentation-function nil)
#f(advice-wrapper :before-until #f(compiled-function (&rest args) #<bytecode 0x15735cd3e435>) org-eldoc-documentation-function)()
eldoc--invoke-strategy()
eldoc-print-current-symbol-info()
org-eldoc-documentation-function()
apply(org-eldoc-documentation-function nil)
#f(advice-wrapper :before-until #f(compiled-function (&rest args) #<bytecode 0x15735cd3e435>) org-eldoc-documentation-function)()
eldoc--invoke-strategy()
eldoc-print-current-symbol-info()
org-eldoc-documentation-function()
apply(org-eldoc-documentation-function nil)
#f(advice-wrapper :before-until #f(compiled-function (&rest args) #<bytecode 0x15735cd3e435>) org-eldoc-documentation-function)()
eldoc--invoke-strategy()
eldoc-print-current-symbol-info()
org-eldoc-documentation-function()
apply(org-eldoc-documentation-function nil)
#f(advice-wrapper :before-until #f(compiled-function (&rest args) #<bytecode 0x15735cd3e435>) org-eldoc-documentation-function)()
eldoc--invoke-strategy()
eldoc-print-current-symbol-info()
org-eldoc-documentation-function()
apply(org-eldoc-documentation-function nil)
#f(advice-wrapper :before-until #f(compiled-function (&rest args) #<bytecode 0x15735cd3e435>) org-eldoc-documentation-function)()
eldoc--invoke-strategy()
eldoc-print-current-symbol-info()
org-eldoc-documentation-function()
apply(org-eldoc-documentation-function nil)
#f(advice-wrapper :before-until #f(compiled-function (&rest args) #<bytecode 0x15735cd3e435>) org-eldoc-documentation-function)()
eldoc--invoke-strategy()
eldoc-print-current-symbol-info()
org-eldoc-documentation-function()
apply(org-eldoc-documentation-function nil)
#f(advice-wrapper :before-until #f(compiled-function (&rest args) #<bytecode 0x15735cd3e435>) org-eldoc-documentation-function)()
eldoc--invoke-strategy()
eldoc-print-current-symbol-info()
org-eldoc-documentation-function()
apply(org-eldoc-documentation-function nil)
#f(advice-wrapper :before-until #f(compiled-function (&rest args) #<bytecode 0x15735cd3e435>) org-eldoc-documentation-function)()
eldoc--invoke-strategy()
eldoc-print-current-symbol-info()
org-eldoc-documentation-function()
apply(org-eldoc-documentation-function nil)
#f(advice-wrapper :before-until #f(compiled-function (&rest args) #<bytecode 0x15735cd3e435>) org-eldoc-documentation-function)()
eldoc--invoke-strategy()
eldoc-print-current-symbol-info()
org-eldoc-documentation-function()
apply(org-eldoc-documentation-function nil)
#f(advice-wrapper :before-until #f(compiled-function (&rest args) #<bytecode 0x15735cd3e435>) org-eldoc-documentation-function)()
eldoc--invoke-strategy()
eldoc-print-current-symbol-info()
org-eldoc-documentation-function()
apply(org-eldoc-documentation-function nil)
#f(advice-wrapper :before-until #f(compiled-function (&rest args) #<bytecode 0x15735cd3e435>) org-eldoc-documentation-function)()
eldoc--invoke-strategy()
eldoc-print-current-symbol-info()
org-eldoc-documentation-function()
apply(org-eldoc-documentation-function nil)
#f(advice-wrapper :before-until #f(compiled-function (&rest args) #<bytecode 0x15735cd3e435>) org-eldoc-documentation-function)()
eldoc--invoke-strategy()
eldoc-print-current-symbol-info()
org-eldoc-documentation-function()
apply(org-eldoc-documentation-function nil)
#f(advice-wrapper :before-until #f(compiled-function (&rest args) #<bytecode 0x15735cd3e435>) org-eldoc-documentation-function)()
eldoc--invoke-strategy()
eldoc-print-current-symbol-info()
org-eldoc-documentation-function()
apply(org-eldoc-documentation-function nil)
#f(advice-wrapper :before-until #f(compiled-function (&rest args) #<bytecode 0x15735cd3e435>) org-eldoc-documentation-function)()
eldoc--invoke-strategy()
eldoc-print-current-symbol-info()
org-eldoc-documentation-function()
apply(org-eldoc-documentation-function nil)
#f(advice-wrapper :before-until #f(compiled-function (&rest args) #<bytecode 0x15735cd3e435>) org-eldoc-documentation-function)()
eldoc--invoke-strategy()
eldoc-print-current-symbol-info()
org-eldoc-documentation-function()
apply(org-eldoc-documentation-function nil)
#f(advice-wrapper :before-until #f(compiled-function (&rest args) #<bytecode 0x15735cd3e435>) org-eldoc-documentation-function)()
eldoc--invoke-strategy()
eldoc-print-current-symbol-info()
org-eldoc-documentation-function()
apply(org-eldoc-documentation-function nil)
#f(advice-wrapper :before-until #f(compiled-function (&rest args) #<bytecode 0x15735cd3e435>) org-eldoc-documentation-function)()
eldoc--invoke-strategy()
eldoc-print-current-symbol-info()
org-eldoc-documentation-function()
apply(org-eldoc-documentation-function nil)
#f(advice-wrapper :before-until #f(compiled-function (&rest args) #<bytecode 0x15735cd3e435>) org-eldoc-documentation-function)()
eldoc--invoke-strategy()
eldoc-print-current-symbol-info()
org-eldoc-documentation-function()
apply(org-eldoc-documentation-function nil)
#f(advice-wrapper :before-until #f(compiled-function (&rest args) #<bytecode 0x15735cd3e435>) org-eldoc-documentation-function)()
eldoc--invoke-strategy()
eldoc-print-current-symbol-info()
org-eldoc-documentation-function()
apply(org-eldoc-documentation-function nil)
#f(advice-wrapper :before-until #f(compiled-function (&rest args) #<bytecode 0x15735cd3e435>) org-eldoc-documentation-function)()
eldoc--invoke-strategy()
eldoc-print-current-symbol-info()
org-eldoc-documentation-function()
apply(org-eldoc-documentation-function nil)
#f(advice-wrapper :before-until #f(compiled-function (&rest args) #<bytecode 0x15735cd3e435>) org-eldoc-documentation-function)()
.... ;; This goes on and on until we get:
timer-event-handler([t 0 0 100000 t #f(compiled-function () #<bytecode 0x15735d26f421>) nil idle 0])
```
> 0 votes
---
Tags: org-mode, spacemacs, eldoc
---
|
thread-60632
|
https://emacs.stackexchange.com/questions/60632
|
Git Repo for Doom Config With Different Platforms
|
2020-09-13T02:33:10.893
|
# Question
Title: Git Repo for Doom Config With Different Platforms
I have emacs on two separate platforms, and I would like it to function in much the same way on both, but there is some platform-dependent configuration as well. I have created a git repository in my .doom.d directory (where the doom configuration files are stored). I could have two branches, one for each platform, but then I end up re-implementing much of my config. I found this: https://softwareengineering.stackexchange.com/questions/200068/applying-commits-into-another-branch-without-merging. I would like to know if there is a better way (I am pretty new to git), preferably simpler. Is there something like a C preprocessor directive I could use where certain portions of my config are ommitted before they are evaluated based on the platform I am on? Is there something else that I don't know about? Any help is appreciated.
# Answer
There are lots of ways to do this. One way is to put system dependent stuff in a file `machine.el` where "machine" is what `(system-name)` outputs. I then put
```
(require (intern (system-name)) nil 'noerror)
```
in my `init.el` and keep everything in the same GitHub repo.
> 0 votes
---
Tags: git, config, doom
---
|
thread-60636
|
https://emacs.stackexchange.com/questions/60636
|
Make "org-edit-special" not insert spaces at the beginning of the line
|
2020-09-13T09:38:55.767
|
# Question
Title: Make "org-edit-special" not insert spaces at the beginning of the line
# The problem
When editing code blocks, I usually opens a new buffer by pressing `C-c '` (i.e. executing `org-edit-special`). The problem is that when I finish editing the buffer, two spaces are inserted to the beginning of each line which is something I don't want so I would like to make `org-edit-special` not insert those spaces after finishing editing the buffer that it opens.
In the gif shown below, you can see how two spaces are inserted at the beginning of each line after exiting the buffer that `org-edit-special` opens.
# Some notes
* I started emacs with `emacs -Q` to avoid my configuration interfere with the default functionality of`org-mode`.
* The gif starts when the black box appears at the right top corner and finishes when the `C-c /` key is pressed (it is shown by `screenkey`).
# Answer
Pressing `C-c '` executes `org-edit-special`. This functions calls `org-edit-src-code` when the cursor is inside a source code block.
The following quote was retrieved from the documentation of the variable `org-edit-src-content-indentation`.
> This should be the number of spaces added to the indentation of the #+begin line in order to compute the indentation of the block content after editing it with ‘M-x org-edit-src-code’.
So if you want no spaces to be added to each line, you need to set that value to 0.
```
(setq org-edit-src-content-indentation 0)
```
> 1 votes
---
Tags: org-mode
---
|
thread-60639
|
https://emacs.stackexchange.com/questions/60639
|
How to see the next few occurences of a repeated task in emacs org mode?
|
2020-09-13T14:29:27.740
|
# Question
Title: How to see the next few occurences of a repeated task in emacs org mode?
I have recently started using the timestamp feature of the org-mode and I have few tasks that repeat. For example:
```
* Match
<2020-09-09 Wed 07:00 +2w>
```
I am looking for a way to see the next few occurrences of this task. E.g. Sep 23, Oct 7th etc. I know of the command `C-c C-o` (`org-open-at-point`) that shows entire agenda for the date but I only want to see this single task (and future occurrences).
# Answer
You can restrict the agenda to the current buffer. Assuming you are following the convention in the manual where `C-c a` is bound to `org-agenda`, then from the buffer where your entry is located, type `C-c a` to get the agenda dispatcher, then `<` to restrict the agenda to the current buffer, then `a` to display the dily/weekly agenda. You can change the length of the displayed agenda using the normal keybindings (e.g. `v m` to change to a monthly view).
In summary, while the current buffer, type
`C-c a < a v m`
You should see the occurrences of the task in the current month. You can move forward in time with `f` (`org-agenda-later`) or backward in time with `b` (`org-agenda-earlier`). And instead of `m`, you can do `d`, `w`, `t` or `y`. Just press `v` to see all the choices. And read the manual for more complete information.
BTW, if you have more than one task in the buffer, that will show you *all* of those tasks. But you can select a region, and then use `<<` to restrict to that region: so you can slim down the agenda to a single task.
EDIT: To show only the dates that have entries, you can set `org-agenda-show-all-dates` to `nil` (it is `t` by default). Its doc string says:
> Non-nil means ‘org-agenda’ shows every day in the selected range. When nil, only the days which actually have entries are shown.
> 0 votes
---
Tags: org-mode, org-agenda
---
|
thread-60645
|
https://emacs.stackexchange.com/questions/60645
|
Forward, backward etc sexp not working
|
2020-09-14T02:26:25.193
|
# Question
Title: Forward, backward etc sexp not working
I want to use the `forward-sexp` function in Emacs, which on my Spacemacs for Mac is bound to `C-M-f`.
Similarly for the `backward-sexp`. However, upon pressing `C-` for Control, and then the Meta key, which is the Escape key, I'm getting the following in the minibuffer:
```
<C-escape> is undefined.
```
How to fix this?
# Answer
> 2 votes
If you don't have a `Meta` key (it is often `Alt`) then you can use `Escape`, yes.
But in that case, what you want to use is `Escape` *followed by* `Control` \+ `f`, which we write as `ESC C-f`.
That is, Emacs writes the key sequence as `ESC C-f` when it talks to you about it.
A `Meta` key, which we write as `M-`, is a **modifier key**, which means you press and *hold it down* while you press the next key. Same thing for the `Control` key, which we write as `C-`: it's also a modifier key. And so is the `Shift` key.
The `Escape` key is *not* a modifier key. It's a **prefix key**. You press and *release* it, then carry on with the other keys of the key sequence. So you press and *release* `Escape`, then you press and *hold down* `Control` while you press `f`.
See the Emacs manual, node User Input, and the Elisp manual, nodes Functions for Key Lookup and Prefix Keys.
---
Tags: motion, keystrokes, prefix-keys, sexp, modifier-key
---
|
thread-60627
|
https://emacs.stackexchange.com/questions/60627
|
How to delete mu4e attachment on macOS
|
2020-09-12T15:08:51.627
|
# Question
Title: How to delete mu4e attachment on macOS
I want to delete a large attachment from a mu4e message. This thread is similar, except that the required `altermime` tool does not seem available on `macOS` (not on Homebrew and no results from an online search).
How can I delete an attachment from a `mu4e` message?
# Answer
If you don't want to compile `altermime` yourself, you could install it from macports then follow @mankoff recipe.
> 1 votes
# Answer
My solution (at your link) involved manually installing `altermime` back when I used OS X. I don't think it was hard. Perhaps only `make` was required when I tried?
> 1 votes
---
Tags: osx, mu4e, attachment
---
|
thread-15016
|
https://emacs.stackexchange.com/questions/15016
|
How can I set custom date formats in org mode?
|
2015-08-24T20:17:11.683
|
# Question
Title: How can I set custom date formats in org mode?
I would like all my dates in org-mode to be displayed like `<Mon 24-Aug 2015>`. I found a piece of code that addresses the problem
```
(setq-default org-display-custom-times t)
(setq org-time-stamp-custom-formats '("<%b %e, %Y>" . "<%b %e, %Y %H:%M>"))
```
but I'm not sure how to edit it to fit my needs. Any ideas?
# Answer
```
(setq-default org-display-custom-times t)
(setq org-time-stamp-custom-formats '("<%a %e-%b %Y>" . "<%a %e-%b %Y %H:%M>"))
```
Will produce:
```
<2020-09-14 Mon>
```
and
```
<2020-09-14 Mon 16:02>
```
> 1 votes
---
Tags: org-mode, org-agenda
---
|
thread-60652
|
https://emacs.stackexchange.com/questions/60652
|
Is the formula line tracking column insert properly in an org table?
|
2020-09-14T17:40:19.747
|
# Question
Title: Is the formula line tracking column insert properly in an org table?
I exhibit with a simple table. My org version is Org mode version 9.2.4 (9.2.4-10-g3b006f-elpa @ /Users/alanwehmann/.emacs.d/elpa/org-20190715/)
```
| 1 | 2 | 3 | 4 |
| 5 | 6 | 7 | 8 |
| 9 | 10 | 11 | 12 |
| 5 | 6 | 7 | 8 |
#+TBLFM: @4$1=@-2::@4$2=@-2::@4$3=@-2::@4$4=@-2
```
insert a column using 'org-table-insert-column (don't update)
```
| 1 | | 2 | 3 | 4 |
| 5 | | 6 | 7 | 8 |
| 9 | | 10 | 11 | 12 |
| 5 | | 6 | 7 | 8 |
#+TBLFM: @4$2=@-2::@4$3=@-2::@4$4=@-2::@4$5=@-2
```
There is now a formula for the blank column and no formula for the first column.
# Answer
The problem goes away with version 9.4 of Org.
> 1 votes
---
Tags: org-table
---
|
thread-20092
|
https://emacs.stackexchange.com/questions/20092
|
Using conda environments in emacs
|
2016-02-05T19:22:33.657
|
# Question
Title: Using conda environments in emacs
What is the best way to use conda environmets using emacs as a Python IDE?
I have got different conda environments while programming in Python:
```
$ conda info -e
# conda environments:
#
django /Users/Pablo/anaconda/envs/django
scipy * /Users/Pablo/anaconda/envs/scipy
visual /Users/Pablo/anaconda/envs/visual
ml /Users/Pablo/anaconda/envs/ml
root /Users/Pablo/anaconda
```
But when I use `crtl`+`c` `crtl`+`c` emacs only uses my the Mac OS X default Python PATH. How can I chage it between all the different conda environments?
# Answer
> 26 votes
I'd suggest using pyvenv library, it provides a neat interface to selecting a virtual env among several alternatives updating interpreter and library paths. You will need to alter WORKON\_HOME variable (it defaults to `$HOME/.virtualenvs` used by virtualenvwrapper).
```
(setenv "WORKON_HOME" "/Users/Pablo/anaconda/envs")
(pyvenv-mode 1)
```
After that choose the environment with `M-x pyvenv-workon`.
# Answer
> 8 votes
I have recently incorporated Anaconda into my python development and was having similar problems setting up Emacs + flycheck + linters. This answer got me up and running, but I've modified it, since the `conda.el` package is available. The following will integrate in the Anaconda path and setup Emacs to recognize the currently active Anaconda env. As a bonus, it updates the Mode line with the env name.
```
;;Anaconda support
(require 'conda)
(setq conda-env-home-directory "<path-to>/anaconda3")
;;get current environment--from environment variable CONDA_DEFAULT_ENV
(conda-env-activate 'getenv "CONDA_DEFAULT_ENV")
;;(conda-env-autoactivate-mode t)
(setq-default mode-line-format (cons mode-line-format '(:exec conda-env-current-name)))
```
---
Tags: python, osx, path, environment
---
|
thread-38689
|
https://emacs.stackexchange.com/questions/38689
|
org Images in LaTeX export set default width
|
2018-02-08T15:22:21.003
|
# Question
Title: org Images in LaTeX export set default width
By default these org lines:
```
my image:
[[./figure1.png]]
```
are exported into these ones in latex:
```
\includegraphics[width=.9\linewidth]{./figure1.png}
```
How can I change the default value of width `\width=.9\linewidth`?
I know that it is possible to change locally just before each picture, but it is possible to set another default value?
```
#+ATTR_LATEX: :width 0.98\linewidth
[[./figure1.png]]
```
# Answer
> 8 votes
You can customize this via the variable `org-latex-image-default-width`.
To set just for the current file, you could put the following at the top of the file:
```
#+BIND: org-latex-image-default-width "0.98\\linewidth"
```
# Answer
> 2 votes
To put in .emacs (emacs config file) :
```
(setq org-export-allow-bind-keywords t)
```
To put in org file header :
```
#+BIND: org-latex-image-default-width ".98\\linewidth"
```
---
Tags: org-mode, org-export, latex
---
|
thread-60667
|
https://emacs.stackexchange.com/questions/60667
|
How to send quoted argument to call-process
|
2020-09-15T13:00:15.597
|
# Question
Title: How to send quoted argument to call-process
I want to use the imagemagick `convert` command to draw on a image file. I have the image data as raw-text in a buffer and now I would like to run `convert - -draw 'rectangle 0,0,100,100' -` on it (the dashes tell convert to use stdin for input and print the data to stdout). If I leave out the `-draw 'rectangle 0,0,100,100'` then I can just use `(call-process-region (point-min) (point-max) "convert" t t nil "-" "-")` to pass the buffer contents as stdin to the convert program and insert the from `convert` returned image data in the buffer (this does not do anything but it works, e.g. I could replace the last `-` with a filename to write the resulting image data to a file). However now I want to add the `-draw 'rectangle 0,0,100,100'` as an extra argument to `call-process-region` but I really can not find (out) how to do this properly. For example I tried `(call-process-region (point-min) (point-max) "convert" t t nil "-" "-draw" "'rectangle 0,0,50,50'" "-")` but then I get message `convert: non-conforming drawing primitive definition` rectangle 0,0,50,50' @ error/draw.c/RenderMVGContent/4473.\`
I tried to run it as a shell-command (i.e. using `/bin/bash -c`)? But then I don't know how to pass the buffer contents as input.
So I would like to know how to properly pass the single-quotes string `'rectangle 0,0,100,100'` to the command.
(FYI I would like to extend djvu.el to show annotations)
# Answer
> I would like to run `convert - -draw 'rectangle 0,0,100,100' -`
Note that you're quoting for the shell there, so that it will not break that argument into two, on account of the space.
> For example I tried `(call-process-region (point-min) (point-max) "convert" t t nil "-" "-draw" "'rectangle 0,0,50,50'" "-")`
Note that you've included the quotes which are for the shell in a call which is not being processed by a shell, which means that the `convert` process is *receiving* an argument containing those `'` surrounding characters.
That is like running this shell command:
```
convert - -draw "'rectangle 0,0,100,100'" -
```
Try:
```
(call-process-region (point-min) (point-max) "convert" t t nil
"-" "-draw" "rectangle 0,0,50,50" "-")
```
> 2 votes
---
Tags: command-line-arguments, call-process
---
|
thread-60656
|
https://emacs.stackexchange.com/questions/60656
|
How to cycle over a pre-defined list of fonts?
|
2020-09-14T23:36:04.290
|
# Question
Title: How to cycle over a pre-defined list of fonts?
I would like to be able to switch fonts quickly between a predefined list of mono-spaced fonts I know work well in Emacs.
Instead of selecting the font from all system fonts which shows too many, most not working well for writing code.
What's a good way to do this in Emacs?
# Answer
> 2 votes
1. Library Do Re Mi, command `doremi-font+` – cycle among fonts, choosing by name.
2. Library Icicles, multi-command `icicle-font`: similar to `doremi-font+`, but also supports completion, including regexp matching.
# Answer
> 0 votes
Here is a small set of functions I came up with.
* `font-cycle-list` a list of font named to cycle.
* `font-cycle-forward`, `font-cycle-backward` are interactive functions to bind to keys.
* This is initialized on first use, including the current font in the list if it's not already included.
```
;; Must be initialized to a list of strings.
(defvar font-cycle-list nil)
;; The index of the font in `font-cycle-index',
;; initialized on first use.
(defvar font-cycle-index nil)
(defun font-cycle--index-update ()
(set-face-attribute 'default nil :font (nth font-cycle-index font-cycle-list)))
(defun font-cycle-list--index-ensure (font-name font-name-no-attrs)
"Add to the font list or return index if it's not already there."
(catch 'result
(let ((index 0))
(dolist (font-name-iter font-cycle-list)
(when (string-equal font-name-no-attrs (car (split-string font-name-iter ":")))
(throw 'result index))
(setq index (1+ index))))
(push font-name font-cycle-list)
;; First in the list (don't bother adding in ordered).
(throw 'result 0)))
;; Use custom font from environment when available.
(defun font-cycle--init ()
"Initialize `font-cycle-index', adding to `font-cycle-list'
or replacing one of it's values when the default font is already in the list.
Replacement is done so any fine tuning to the default font is kept (attributes for e.g)."
(unless font-cycle-list
(user-error "The variable 'font-cycle-list' is not a list of fonts!"))
(let ((font-index-test nil))
(let ((current-font (font-get (face-attribute 'default :font) :name)))
(unless (string-equal current-font "")
(let ((current-font-no-attrs (car (split-string current-font ":"))))
(setq font-index-test
(font-cycle-list--index-ensure
current-font
current-font-no-attrs)))))
(if font-index-test
(setq font-cycle-index font-index-test)
;; Fall-back to first font (unlikely we can't find our own font).
(unless font-cycle-index
(setq font-cycle-index 0))
(font-cycle--index-update))))
;; Run once, when placing the current font in the cycle list.
(defun font-cycle--ensure-once ()
(unless font-cycle-index
(font-cycle--init)))
;; Public Functions.
(defun font-cycle-step (arg)
"Cycle the font in `font-cycle-list' forward or backward ARG times (default to 1)."
(interactive "p")
(unless (display-graphic-p)
(user-error "Cannot cycle fonts on non-graphical frame window."))
(font-cycle--ensure-once)
(setq arg (or arg 1))
(setq font-cycle-index (mod (+ font-cycle-index arg) (length font-cycle-list)))
(font-cycle--index-update)
(message (nth font-cycle-index font-cycle-list)))
(defun font-cycle-forward (arg)
(interactive "p")
(font-cycle-step 1))
(defun font-cycle-backward (arg)
(interactive "p")
(font-cycle-step -1))
```
Font list and key bindings:
```
(setq font-cycle-list
(list
"Anonymous Pro Medium 14"
"Consolas 15"
"Fantasque Sans Mono Medium 14"
"Fira Code Medium 13"
"Hermit Medium 13"
"IBM 3270 Medium 17"
"IBM Plex Mono 13"
"Inconsolata-g 13"
"Input Mono Light 15"
"Iosevka Medium 17"
"Luculent Medium 16"
"Monoid Medium 13"
"Source Code Pro Medium 10"))
;; Key bindings Alt-PageUp/Down.
(when (display-graphic-p)
(define-key global-map (read-kbd-macro "<M-prior>") 'font-cycle-forward)
(define-key global-map (read-kbd-macro "<M-next>") 'font-cycle-backward))
```
---
Tags: fonts, cycling
---
|
thread-60617
|
https://emacs.stackexchange.com/questions/60617
|
Different fill-column for comments than code in programming modes
|
2020-09-11T20:55:19.720
|
# Question
Title: Different fill-column for comments than code in programming modes
I don't mind if the occasional code line runs long. For example, the Shopify ruby standard allows lines of 120. But I want comments to be restricted to the first 78 lines or so. Is there any way in a programming major mode to have a different fill column for comment lines than for code line?
# Answer
OK. With some prodding from @wvxvw, I looked at some source code, though the code for `fill-paragraph` rather than `ruby-mode`. There is a function for filling comments, but it does not take a `fill-column` parameter. So, I tried the following advice, which appears to do the trick:
```
(defvar ded:fill-column-for-progs 78)
(defun ded:prog-fill-paragraph (orig-fun &rest args)
(let ((fill-column ded:fill-column-for-progs))
(apply orig-fun args)))
(advice-add 'fill-comment-paragraph :around #'ded:prog-fill-paragraph)
```
The `ded:` is just my personal prefix. So far, so good. It even uses justification when used with the universal argument.
> 0 votes
---
Tags: fill-column
---
|
thread-60379
|
https://emacs.stackexchange.com/questions/60379
|
`C-c C-e l o` does not open the pdf anymore
|
2020-08-29T09:42:03.167
|
# Question
Title: `C-c C-e l o` does not open the pdf anymore
After upgrading to Emacs 27, I noticed that, for any org document, `C-c C-e l o` now behaves on my computer as `C-c C-e l p`: i.e., the pdf is correctly produced, but is not displayed anymore on side window.
Even when opening the document with `emacs -q`, I have the same behavior, so I guess that the problem is not related to my init file. (However, all my pdfs used to be displayed in Emacs with `pdf-tools` and not with the standard `doc-view`: don't know if this may be part of the problem.)
Anyway, when I run a `C-c C-e l o` on a file essai.org, I have the following output in the `*Messages*` buffer:
```
Processing LaTeX file essai.tex...
PDF file produced.
Running /usr/bin/xdg-open /home/fs/Documents/essai.pdf...done
```
but no buffer is created and displayed within Emacs for the pdf output. I have no clue for that problem...
Thanks!
# Answer
> 2 votes
A solution kindly given by a member of org-mode mailing list: simply add
```
(push '("\\.pdf\\'" . emacs) org-file-apps)
```
in the `.emacs` file.
This works for me.
---
Tags: org-mode, org-export, emacs27
---
|
thread-60674
|
https://emacs.stackexchange.com/questions/60674
|
Do m-x command on entering buffer with a specific file type
|
2020-09-15T18:53:08.710
|
# Question
Title: Do m-x command on entering buffer with a specific file type
Sorry if this is a really noob question. I have recently gotten into Emacs with the Spacemacs distribution and I installed a plugin called "focus." I want to be able to have the command "focus-mode" run when I open a specific buffer type, but I don't know to do this. I have to do M-x and type in "focus-mode" and it's kind of inconvenient. I really don't know Emacs Lisp that well. Is there anything I can put in the user config to achieve this? Thanks in advance.
# Answer
> 3 votes
The usual mechanism is called a hook: a hook is a variable containing a list of functions, and when the hook is run, every function in the list is executed. Every major mode has an associated hook which is run when that mode is enabled. Finally, there is a variable called `auto-mode-alist` which associates a major mode with a file (usually using the suffix of the filename).
E.g. the `auto-mode-alist` probably already contains an entry associating the suffix ".py" to the major mode `python-mode`. That mode has a hook `python-mode-hook` which is run when `python-mode` is enabled in any buffer, and that runs all the functions in the hook. So all you have to do is add a function that enables the minor mode of your plugin to the hook - something like this should be added to your initialization file:
```
(add-to-hook 'python-mode-hook #'focus-mode)
```
Then when you visit a file `foo.py`, Emacs knows to enable `python-mode` on the file because it finds an entry like this: `("\\.py\\'" . python-mode)` in `auto-mode-alist`. When `python-mode` is enabled, it runs its hook `python-mode-hook` which then calls the `focus-mode` function (which, in the case of minor modes, *enables* the mode).
I assumed that your specific file type here is a python file, but the mechanism is general and applicable to (almost?) all major modes.
---
Tags: auto-mode-alist
---
|
thread-31905
|
https://emacs.stackexchange.com/questions/31905
|
Wrong encoding in eshell when closing Emacs
|
2017-04-03T18:47:33.880
|
# Question
Title: Wrong encoding in eshell when closing Emacs
I have a lot of filenames in Russian in my file system. Every time I close Emacs if I had eshell opened, it shows a `*temp*` buffer with a list of directories. And asks 2 questions:
1. Select coding system (default utf-8):
I click enter
2. Selected encoding utf-8 disagrees with latin-2 specified by file contents. Really save (else edit coding cookies and try again)? (y or n)
I click "y", enter
What file cookies is he talking about? Where can I set it to utf-8, so this question is never asked again?
**Update**
I found the wrong file: `~/.emacs.d/eshell/lastdir`. I saved this: "яОяНяОяННяОуВяНЕяОяОяННяОяНОяОяНВяОяНА" instead of normal Russian name. Then it tries to save it again.
# Answer
> 1 votes
The file you mention is where Eshell saves the directory ring, which is basically a list of the directories that you've visited. Just like in most shells, you can use `cd -` to go back to the previous directory. `cd =` will display the contents, and so on (see the Eshell manual for all the details). Eshell saves this list to a file so that you'll still have it in your next session, and Emacs will always prompt the user when it things the coding system might be incorrect. I can see how it would be frustrating that it asks you all the time about a file you're not specifically editing. One way to control the coding system that Emacs uses is by setting a file-local variable, which is why the error message mentions them. (I think "cookie" is an older term for it, which adds to the confusion.)
The code that saves the list is `eshell-write-last-dir-ring` in em-dirs.el. As you can imagine, all it does is open a temporary buffer, insert every item in the list into the buffer, followed by a newline character, then write the buffer to the file. The error message itself comes from `select-safe-coding-system` in mule-cmds.el, which is horrible. Seriously, don't look at it. I don't know why this function is so complex, but I assume that it "gradually got so" (to coin a phrase).
I don't know what the best way to fix this will be, but the first thing that `select-safe-coding-system` does is compare the filename with the contents of the variable `auto-coding-alist`. You could add an entry for this specific file, which sets the desired coding system to `'utf-8`. As you can see from the error message, the contents look to Emacs like utf-8, but it thought for some other reason that it should be saved in latin1. Editing `auto-coding-alist` should fix that.
# Answer
> 0 votes
I was facing a similar problem i.e while closing the Emacs (my version 26.3), I was repeatedly prompted about the encoding: `Select coding system (default utf-8):`
I solved the problem by deleting some entries from `.emacs.d/ac-comphist.dat` file (in my case, the character is the lowercase lambda λ).
---
Tags: eshell, character-encoding
---
|
thread-33736
|
https://emacs.stackexchange.com/questions/33736
|
How can I run a command on several buffers / files?
|
2017-06-23T18:06:12.380
|
# Question
Title: How can I run a command on several buffers / files?
I'm working on some code that is spread across several files.
I keep finding myself doing `whitespace-cleanup` and `indent-region` (on the whole file), and having to do it on each of the six files.
Any way to say: 'do tidying up on all .c and .h files currently open',
or maybe use emacs in batch mode from the bash shell?
# Answer
One option would be to use `ibuffer`. You can mark the buffers you want to modify, then use `ibuffer-do-eval` (bound to `E`) to evaluate a command on all of them.
If you always run the same sequence of steps, you can define a command such as:
```
(defun my-clean-buffer ()
(interactive)
(whitespace-cleanup)
(indent-region (point-min) (point-max)))
```
Then use `E` `(my-clean-buffer)` as described above. Note that this leaves the buffers modified and not saved, so either include a save in your command or use `ibuffer-do-save` (bound to `S`) after the updates to save the marked buffers.
> 5 votes
# Answer
To apply an elisp function to multiple files without any packages you can use eshell.
Go to the directory containing files and run a create a bash-like expression to match the filenames like `*c`. Then create a for loop to open the file and apply the function and save the file.
```
~ $ for file in *c { (progn (find-file file) (whitespace-cleanup) (save-buffer)) }
```
> 3 votes
# Answer
You mention files, not buffers. And you say nothing about whether you care whether you visit the files in buffers or whether you are already visiting the files that you want to act on.
There are many ways to do such things. If you just want to act on a set of files, without caring whether you keep them visited in buffers, then yes, you can use Emacs in batch mode or just pass the file names to a shell script.
And you say nothing about how the set of files is chosen, e.g., whether the file names exist already as a list or you pick them interactively.
The question is really underspecified (too broad).
---
That said, here are a couple of possibilities that uses Dired, where you can choose the files by marking them in various ways (e.g., by extension, regexp, date, name).
Assuming that you have marked the files you want to act on:
* You can use **`!`** to apply a shell script or system command to each of them.
* If you use Dired+ then you can use **`@`** to apply a Lisp function to each of them. (E.g., apply the function posted by @glucas.)
`C-h f diredp-do-apply-function`:
> **`@`** runs the command **`diredp-do-apply-function`**, which is an interactive Lisp function in **`dired+.el`**.
>
> It is bound to `@`, `menu-bar operate diredp-do-apply-function`.
>
> `(diredp-do-apply-function FUNCTION &optional ARG)`
>
> Apply `FUNCTION` to the marked files.
>
> With a plain prefix `ARG` (`C-u`), visit each file and invoke `FUNCTION` with no arguments.
>
> Otherwise, apply `FUNCTION` to each file name.
>
> Any other prefix arg behaves according to the `ARG` argument of `dired-get-marked-files`. In particular, `C-u C-u` operates on all files in the Dired buffer.
You can also use **`M-+ @`** (`diredp-do-apply-function-recursive`) to act on all marked files in a Dired buffer plus all marked files in any marked subdirs of that buffer that have their own Dired buffers, etc., recursively. (No need to insert the subdirs.)
> 2 votes
---
Tags: buffers
---
|
thread-44875
|
https://emacs.stackexchange.com/questions/44875
|
How to open 3 emacs windows when debugging using gdb
|
2018-09-22T09:23:17.423
|
# Question
Title: How to open 3 emacs windows when debugging using gdb
I am debugging a program that outputs 8 or more lines of display and requires input. So my IO window has to be say 10 rows or so in height. But I also want to see the source code AND of course the gdb input window.
What is the easiest way to present this? To have 3 windows? 1 for gdb, 1 for console and the other for the source code? If so how do I get 3 windows?
Or if I could somehow get the gdb io window to be a separate console window that might be even better.
# Answer
> 1 votes
For anyone else's benefit, you can use gdb-many-windows like:
1. Compile your executable (don't forget to compile with the -g flag).
2. m-x gdb
3. m-x gdb-many-windows
You then get the same sort of environment as you would find in developer IDE's.
Some links: https://www.gnu.org/software/emacs/manual/html\_node/emacs/GDB-User-Interface-Layout.html https://undo.io/resources/gdb-watchpoint/using-gdb-emacs/
# Answer
> 0 votes
To create a new console window you can do `C-x 5 b` with an existing buffer or `C-x 5 f` to open a file. To switch between the different consoles you can do `C-x 5 o` You can then split each of the consoles into different frames horizontally by `C-x 2` or vertically by `C-x 3`
---
Tags: debugging, gdb
---
|
thread-60670
|
https://emacs.stackexchange.com/questions/60670
|
C++ lsp-mode: inconsistent behavior between remote and local projects
|
2020-09-15T15:45:36.597
|
# Question
Title: C++ lsp-mode: inconsistent behavior between remote and local projects
I've run into a bit of an odd problem trying to use lsp-mode.
My problem setup is as follows: I'm working on a C++ project on my computer, and I'd like to be able to use lsp-mode with it. The catch is that it's big, big enough that I can only build it on a remote VM with a bunch of resources.
The C++ lsp requires a `compile_commands.json` file, which needs to be generated by the build system. Our project is set up to build kinda weirdly, so I generate this file on the devbox via `bear`. At this point I should note that `lsp-mode` runs flawlessly if I ssh into the devbox and open emacs with `emacs -nw`.
Unfortunately, due to latency issues I really need to be able to edit the code locally and have all the nice lsp features while doing it. Therefore, I copy over the `compile_commands.json` to my local copy of the repo: it contains some absolute paths to the project on the devbox, so I update all of those via `sed` to point at the local copy.
I know this process *can* work, because I actually had it working flawlessly not two hours ago: complete parity with the `ssh + emacs -nw` experience. Unfortunately I kept messing around after that, checking out different branches, regenerating/copying the compile\_commands.json, minor stuff like that. Now the process isn't working nearly as well as it used to, even after bringing the local and remote repos to the same states and running the same commands as the time when it worked.
I know that my way of bringing in the compile\_commands.json is still doing *something* useful, because without it none of the lsp stuff works at all (as expected). However, the local lsp-mode is less functional than over `ssh + emacs -nw`, in at least a few ways
1. `lsp-find-references` wont find all, or sometimes even any, of the references to the symbol under point. In fact, if I try to find references to any member of a class it will just try to find references to the class itself: and even then it will only find the actual class definition itself, not even usages which I could detect via ctrl+f
2. `lsp-find-definition` sometimes just straight-up wont work: displaying the following error in the minibuffer `cl-no-applicable-method: No applicable method: xref-item-location, nil`
3. lsp spends a lot of time indexing in the background (updating with % progress in the minibuffer). This indexing takes a long time, and doesn't help at all once it has finished. Moreover, although the indexing creates a ".cache/clang" directory, every time I restart emacs it indexes the project all over again with no discernible performance improvement.
`ssh + emacs -nw` displays none of this behavior (it does create a cache dir but doesn't mentioning indexing in `*Messages*` at all, and quite frankly I'm baffled as to why.
---
The *only* difference I can think of in the one time I got it working was that `lsp` didn't auto-discover my local project- when I opened my first .cpp file, I got some sort of lsp menu at the bottom of my emacs window with four options asking me how to set the project root (I think I ended up hitting enter to take the default option). I have *never* seen that submenu again, despite having
1. Deleted and re-cloned the local project
2. Deleted all of my projectile projects
3. Deleted my `~/.emacs.d/.local/etc/lsp-session` file
4. Uninstalled and reinstalled lsp (I use doom, so I did this by commenting out the "lsp" layer, running a `doom sync`, uncommenting it, and then `doom sync`ing again)
Anyways, I was really hoping someone could help me out here. Figuring out how to properly delete all my lsp projects/caches and regenerate the project via that menu seems like a good starting point
# Answer
So in the meantime my OS actually died and I had to reinstall it, which involved re-installing things like Emacs. Fortunately my home folder was left intact, and I took this as an opportunity to try and get that menu again.
I ended up succeeding, though it didn't restore the missing functionality: that's probably all that anyone could have hoped to help me with anyways though :D
I'm sure all these steps aren't necessary, but I
1. Rebuilt emacs from source
2. Removed my ~/.emacs.d and re-cloned doom (I kept my old dotfiles though)
3. Renamed all the .git folder to make sure the project wasn't being discovered using those
4. Renamed the compile\_commands.json file so that the project couldn't be discovered with that (thanks to vidjuheffex on reddit for suggesting this)
Unfortunately, the LSP functionality was still broken, though in a slightly different way. It no longer goes through a long indexing process, which is good. Furthermore, I've just noticed (perhaps it was there all along, but I'm surprised that I didn't find it earlier if it was) an *lsp-log* buffer which is reporting a bunch of errors: all sensible, from what I can tell, and related to my not having copied over the build directory from the remote machine (not really an option, it's over 30gb)
I still have no idea how things were working so perfectly for a beautiful moment... that's just life I guess :/
> 0 votes
---
Tags: c++, lsp-mode, doom
---
|
thread-56133
|
https://emacs.stackexchange.com/questions/56133
|
Is there a way to use CTRL and SUPER key modifiers together in a key binding?
|
2020-03-13T19:54:29.183
|
# Question
Title: Is there a way to use CTRL and SUPER key modifiers together in a key binding?
I would like to be able to use CTRL and SUPER key modifiers together in a key binding. Since I'm on Mac OSX I use Command key for SUPER modifier.
I tried this:
```
(global-set-key (kbd "C-s-i") 'move-line-up)
(global-set-key (kbd "C-s-k") 'move-line-down)
```
but I get `<C-s-268632073> is undefined` message in the mini buffer when I press `C-s-i` combination.
Is there a way to use CTRL and SUPER key modifiers together in a key binding?
# Answer
> 1 votes
I've just upgraded Emacs from version 26.3 to 27.1 and the keybinding works just fine now.
# Answer
> 1 votes
Try this instead:
```
(global-set-key (kbd "s-C-i") 'move-line-up)
(global-set-key (kbd "s-C-k") 'move-line-down)
```
Dunno whether that works (I don't have a `<super>` key. The key description `C-s` means Control + `s` (character s, not super key).
Be aware, too, that `C-i` is the same as `TAB`.
---
Tags: key-bindings, osx, modifier-key
---
|
thread-60682
|
https://emacs.stackexchange.com/questions/60682
|
Interactively pass argument and use regex in find replace
|
2020-09-16T03:48:25.817
|
# Question
Title: Interactively pass argument and use regex in find replace
I have written the following code
```
(defun krmet-replace()
(interactive)
(save-excursion
(save-restriction
;; Narrow to the region
(narrow-to-region
(progn (search-forward "C %% MODULE %%")
(line-beginning-position))
(progn (search-forward "C %% END MODULE %%")
(line-end-position)))
;; Find Replace
(goto-char (point-min))
(while (search-forward "KRMET" nil t)
(replace-match "KR23" nil t)) ;; remove the hard coded replacement, use user input
(goto-char (point-min))
(while (search-forward "KR-MET" nil t)
(replace-match "KR-23" nil t))))) ;;;; remove the hard coded replacement, use user input
(global-set-key (kbd "C-c #") 'krmet-replace)
```
There are two things that I don not know how to do:
1. How to interactively pass a number, in this case it is "23". I want to replace `KRMET` with `KR23`. I modified the code like shown below
```
(defun krmet-replace (r)
(interactive "nRx # : ")
```
and used the `r` in replace match line like so
```
(replace-match (concat "KR" string(r)) nil t))
```
I get this error: `replace-match: Symbol’s value as variable is void: string`
**Answer Edit**:
I fixed the first problem like so using `number-to-string` function
```
(goto-char (point-min))
(while (search-forward "KRMET" nil t)
(replace-match (concat "KR" (number-to-string r)) nil t))
(goto-char (point-min))
(while (search-forward "KR-MET" nil t)
(replace-match (concat "KR-" (number-to-string r)) nil t)))))
```
2. How to replace string using regex? Like KRMET or KR-MET with KR`nn` or KR-`nn` where `nn` is the user provided number when running the function
# Answer
> 2 votes
Here's an example of using `format` as well as performing both sets of replacements in a single pass by matching a regular expression:
```
(goto-char (point-min))
(while (re-search-forward "\\(KR-?\\)MET" nil t)
(replace-match (format "%s%d" (match-string 1) r)
nil t))
```
Or adapting your concat approach:
```
(concat (match-string 1) (number-to-string r))
```
---
Edit...
Originally I suggested the regexp `"KR\\(-\\)?MET"` which complicated things slightly for the `format` case, as `match-string` returns `nil` if the sub-group didn't match anything, and `(format "%s" nil)` returns "nil" rather than "", so I needed to use `(format "KR%s%d (or (match-string 1) "") r)` to avoid that. Conversely `(concat "KR" (match-string 1) (number-to-string r))` was fine, as `nil` arguments to `concat` are ignored -- because in elisp `nil` is an empty list, so it's a list argument which doesn't add anything to the concatenation.
In any case, including the "KR" inside the sub-group ensures the group can't be `nil`, which simplifies things.
Using `"KR\\(-?\\)MET"` instead of `"KR\\(-\\)?MET"` would also have avoided the `nil` issue, as that would have caused the group to match the empty string when required.
---
Tags: regular-expressions
---
|
thread-60660
|
https://emacs.stackexchange.com/questions/60660
|
How to sort by KIND in helm-find-files (Emacs)
|
2020-09-15T03:22:15.933
|
# Question
Title: How to sort by KIND in helm-find-files (Emacs)
I know there is such a variable as helm-ff-initial-sort-method. However, it does not include KIND as a sorting method. Anybody know how to sort files in helm-find-file by KIND? Thank you!
# Answer
> 2 votes
Here is the code to add `Shift-F4` to sort by kind:
```
(define-advice helm-list-directory (:override (directory) add-sort-by-kind)
(let ((files (directory-files directory t directory-files-no-dot-files-regexp)))
(pcase helm-ff-initial-sort-method
('nil
files)
('newest
(sort files #'file-newer-than-file-p))
('size
(sort files #'helm-ff-file-larger-that-file-p))
('kind
(let-alist (seq-group-by #'file-directory-p files)
(nconc
.t ; folders
(sort
.nil ; files
(lambda (f1 f2)
(let ((ext1 (or (file-name-extension f1) ""))
(ext2 (or (file-name-extension f2) "")))
(if (equal ext1 ext2)
(string< f1 f2)
(string< ext1 ext2)))))))))))
(defun helm-ff-sort-by-kind ()
(interactive)
(unless (eq helm-ff-initial-sort-method 'kind)
(setq helm-ff-initial-sort-method 'kind)
(helm-force-update (helm-get-selection nil helm-ff-transformer-show-only-basename)))
(message "Sorting by kind"))
(put 'helm-ff-sort-by-kind 'helm-only t)
(define-key helm-find-files-map (kbd "S-<f4>") #'helm-ff-sort-by-kind)
```
Change `helm-ff-initial-sort-method` does not work for me, e.g., `(setq helm-ff-initial-sort-method 'size)`, that is, the initial sort is still by alpha instead of by size, I am not sure if I understand the user option correctly. However, `Shift-F1/F2/F3` work.
---
Tags: helm
---
|
thread-60693
|
https://emacs.stackexchange.com/questions/60693
|
Dealing with strange characters in org babel results
|
2020-09-16T11:45:56.783
|
# Question
Title: Dealing with strange characters in org babel results
I am playing with SaltStack configured by org babel source blocks. I try to pass output of salt fingerprint to minion configuration file. If I use one command direcly in bash I receive this output:
```
# salt-key -f master.pub
Local Keys:
master.pub: 66:bf:a3:8f:f5:09:01:78:dc:d7:34:80:42:d0:ab:b6:f1:f6:67:ee:dd:80:10:d6:90:58:71:48:fa:d9:24:2c
```
When I try to execute the same command in org babel I receive different result (I attach screen because my browser doesn't support this symbol):
```
#+begin_src sh :session master
salt-key --finger=master.pub
#+end_src
```
Because of this ^\[ characters I receive wrong while extracting value of master.pub key which I need in further processing:
```
#+begin_src sh :session minion :var FINGERPRINT=fingerprint[1,1]
echo $FINGERPRINT
#+end_src
#+RESULTS:
| |
| 66:bf:a3:8f:f5:09:01:78:dc:d7:34:80:42:d0:ab:b6:f1:f6:67:ee:dd:80:10:d6:90:58:71:48:fa:d9:24:2c;0m |
```
And because of the ";0m" at the end (I am not sure what it is) I can't copy and paste this value to configuration file. I tried different types of results (raw, table, list), but always I receive this characters. Anyone have idea how can I deal with this?
# Answer
> 0 votes
These are terminal escape codes to e.g. change colors and such. Usually, programs that do that have a --color=no or some similar option to turn this off. In fact, the salt-key manpage shows a `--no-color` option, so try adding that to the `salt-key` invocation.
---
Tags: org-babel
---
|
thread-60696
|
https://emacs.stackexchange.com/questions/60696
|
Make "org-latex-preview" load package so that it properly renders "tcolorbox" environments
|
2020-09-16T15:43:00.233
|
# Question
Title: Make "org-latex-preview" load package so that it properly renders "tcolorbox" environments
# The context
The following `org` buffer
```
* Random name
This is an equation
\begin{equation}
x = a + b
\end{equation}
This is a box
\begin{tcolorbox}
a
\end{tcolorbox}
```
is previewed as
# The question
Just as it is possible to preview the content of a `equation` environment. Is it possible to preview the content of the `tcolorbox` envionment?
It seems that Emacs is not loading the `tcolorbox` environment. Is there any way I can make Emacs load a given LaTeX package? so that when previewing a LaTeX code snippet that uses the `tcolorbox` environment, the actual content is displayed.
# Additional information
**Have you installed the `tcolorbox` package?**
Yes. I can confirm this because I've compiled several documents that uses the `tcolorbox` environment with `pdflatex` without any problems.
**Have you checked the variable `org-latex-packages-alist` contains the `tcolorbox` package?**
Yes. When describing the variable, I get the following value: `(("" "tcolorbox" t))`
**What's the value of the variable `org-preview-latex-default-process`?**
Its value is `dvipng`. This is the default value and I've not changed it.
**If you add `#+LATEX_HEADER: \usepackage{tcolorbox}` at the top of your Org mode file and export to PDF. Do you see the box?**
Yes, I can see the box in the generated PDF file but still can't see when executing `org-latex-preview` within a `tcolorbox` environment. `tcolorbox`es are still being previewed as tiny empty boxes.
I tested this when `org-latex-packages-alist` was equal to `nil`.
**if you try to export without the header, is there a `\usepackage{tcolorbox}` in the generated `.tex` file?**
Without the header and with `org-latex-packages-alist` equal to `nil`, there is no `\usepackage{tcolorbox}`. However, the environment `tcolorbox` is used within the `.tex` file. In the resulting PDF file, only the text within the `tcolorbox` is rendered as normal text but no box is rendered.
Without the header and with `org-latex-packages-alist` equal to `(("" "tcolorbox" t))`, `\usepackage{tcolorbox}` does appears within the document. In the resulting PDF file, the `tcolorbox` environment is properly displayed (i.e. its content and the actual box).
**Post screenshoots of the tiny empty box**
Actually, it is not a tiny empty box. I wrote that because I tested it with a black background. Actually, the text within the `tcolorbox` is rendered in the preview but the box is not. See how the following Org file is previewed
```
#+LATEX_HEADER: \usepackage{tcolorbox}
#+LATEX_HEADER: \usepackage{lipsum}
This is random text.
\begin{tcolorbox}
a b c d
\end{tcolorbox}
This is random text
\begin{tcolorbox}
\lipsum[1]
\end{tcolorbox}
This is random text.
```
Preview and resulting PDF of the Org mode file shown above
This was tested when these variables had the following values
* `org-latex-packages-alist`: `nil`
* `org-preview-latex-default-process`: `dvipng`
# Answer
Add the package to `org-latex-packages-alist`:
```
(with-eval-after-load 'org
(add-to-list 'org-latex-packages-alist '("" "tcolorbox" t)))
```
The `t` is important: it tells Org mode to include that package for LaTeX preview. Otherwise, it will only be included when you export the file to LaTeX/PDF, but not when previewing LaTeX fragments.
*EDIT*: There seem to be problems with the `dvipng` setting of `org-preview-latex-default-process` that require more investigation.
Setting the process to `imagemagick` with
```
(setq org-preview-latex-default-process 'imagemagick)
```
works out of the box for me (ImageMagick-6 on Fedora 31), but it did not work for the OP (ImageMagick-7 on Arch Linux). Apparently, the `/etc/ImageMagick-7/policy.xml` file imposed some restriction on permissions that prevented the conversion of the PDF file to a PNG file (the `imagemagick` process uses `pdflatex` to convert the TeX file to PDF and then uses the `convert` program from ImageMagick to convert the PDF to PNG). The OP reports that he was able to solve the problem from an answer to this question: this one.
*EDIT*: To debug problems:
* have you installed the `tcolorbox` package?
* check the value of `org-latex-packages-alist` \- does it contain the `tcolorbox` entry (with a `t` as shown above)? Use `C-h v org-latex-packages-alist RET` to get the value.
* check the value of `org-preview-latex-default-process` with `C-h v org-preview-latex-default-process` and update the question with it.
* add `#+LATEX_HEADER: \usepackage{tcolorbox}` at the top of your Org mode file and export to PDF. Do you see the box?
* if you try to export without the header, is there a `\usepackage{tcolorbox}` in the generated `.tex` file?
* check the `ltximg/` subdirectory for images and view each one. You might want to delete them and run the preview again: that's the only way to make sure they are up-to-date.
* use edebug or `M-x debug-on-entry` to stop execution at the beginning of `org-compile-file` and then step through it to figure out what Org mode is doing, so you can save the generated file(s) and you can try to reproduce the process by hand.
> 1 votes
---
Tags: org-mode, latex
---
|
thread-60690
|
https://emacs.stackexchange.com/questions/60690
|
Change font size globally with a shortcut
|
2020-09-16T09:09:47.527
|
# Question
Title: Change font size globally with a shortcut
When I need to change the font size I evaluate the following region:
```
(set-frame-font "JetBrains Mono-14")
```
This is far from optimal since it involves a lot of typing.
I'm looking for an interactive function that would ask me for the new font size and modify the numeric value passed to `set-frame-font`.
As a workaround I wrote the following function:
```
(defun change-font-size (new-size)
"Change the font size to the given value"
(interactive "sNew font size: ")
(set-frame-font (concat (face-attribute 'default :family) "-" new-size)
)
)
(bind-key "C-x f" #'change-font-size)
```
But I wonder if there's a better way of doing this.
The best solution for me would be to change the font size of emacs based in the monitor in which it is being displayed, but I could not find any satisfactory solution. I do not want to do busy waiting on my emacs, instead I'd like emacs listening to notifications of the windows manager. However I do not know whether this is possible.
*EDIT* using the suggestion in one of the answers I wrote this hook to resize the window based on the display emacs is in.
```
(defun my/adjust-font-size-based-on-display ()
(let ((display-width (nth 3 (assq 'geometry (frame-monitor-attributes))))
)
(change-font-size
(cond ((<= display-width 1920) 18) ;; HD
((<= display-width 2560) 11) ;; UWHD
((<= display-width 4096) 14) ;; 4K
)
)
)
)
(add-hook 'window-size-change-functions (lambda (frame) (my/adjust-font-size-based-on-display)))
(add-hook 'focus-in-hook 'my/adjust-font-size-based-on-display)
```
Suggestions on how to improve the hook above are welcome!
# Answer
> 2 votes
The `:height` attribute of a face is ten times the font size. You can directly set the height attribute:
```
(defun change-font-size (new-size)
"Change the font size to the given value"
(interactive "nNew font size: ")
(set-face-attribute 'default nil :height (* 10 new-size)))
```
Note that it needs a number, not a string, so I changed your interactive `s` to `n`.
For the second part, where you have it depend on monitor size,
```
(defun my/check-monitor ()
(change-font-size
(if (<= (display-pixel-width) 1440) 16 20)))
```
This will set the font size to 16 if the monitor width is up to 1440px and 20 if it's a wider monitor. You can extend this to include more logic depending on width and height.
I am not sure if emacs has any built in hooks to detect a monitor change, but if not, either find a way to send a command to emacs (e.g. run `emacsclient -e "(my/check-monitor)"` from a shell script), or have it check the monitor width occasionally in a timer, maybe with `run-with-idle-timer`.
# Answer
> 0 votes
I don't know if that will appeal to you but what I do is use `text-scale-increase` and `text-scale-decrease`. Putting them in a hydra like this:
```
(require 'hydra)
(defhydra hydra-zoom (global-map "<f2>")
"zoom"
("g" text-scale-increase "in")
("l" text-scale-decrease "out"))
```
then allows me to increase it a couple of times by typing `<F2> g g ...`, repeating the `g` (`g` for `greater` but suit yourself :-) ).
Although this is not a global change, I generally find that I don't need to *change* the font size globally: I set the font (including its size) once and for all in my init file to whatever I need for most of my work and then just use the above to change the size of the font in a buffer e.g. when presenting my screen in a meeting to make it readable.
---
Tags: fonts
---
|
thread-60681
|
https://emacs.stackexchange.com/questions/60681
|
ESS start process does not include new R version
|
2020-09-16T03:22:53.330
|
# Question
Title: ESS start process does not include new R version
I am using the windows version of emacs that includes AuTeX and ESS from Vincent Goulet. I was using an older version of this packaging with a couple different versions of R. I recently installed the new version of R (4.0.2) and am attempting to connect it to emacs. I have added the directory that contains the R version 4.0.2 to my path and also added the folder that contains the 3 different version of R that are installed on my machine. When I open a .R file and open an instance of R it opens an R version of 4.0.2. However, when I go to the ESS menu and try to start a new process (ESS\>Start Process\>Other\>) the options that I see are R-3.4.4-32bit, R-3.4.4-64bit, R-3.5.1-32bit, R-3.5.1-64bit. Similarly, if I try to complete `M-x R` the options do not include the R-4.0.2 version. Also when I tried `M-x R-newest` I got the error: *Symbol's function definition is void R-newest*. I have tried again to run `M-x R-newest` but now it stats *\[no match\]*.
I was previously using an older release version Vincent Goulet's emacs but updated it while attempting to fix this issue. The current version I am using is emacs 26.3 with ESS 18.10.2. I have tried changing the PATH variable in numerous ways to include/exclude the directory of the R verions for the older versions. I tried looking in the lisp and changing some custom variables in my .emacs file to no avail, such as
```
(custom-set-variables
'(ess-rterm-version-paths
(quote
("C:/Program Files/R/R-4.0.2/bin/x64/Rterm.exe" "C:/Program Files/R/R-4.0.2/bin/i386/Rterm.exe" "C:/Program Files/R/R-3.5.1/bin/i386/Rterm.exe" "C:/Program Files/R/R-3.4.4/bin/i386/Rterm.exe" "C:/Program Files/R/R-3.5.1/bin/x64/Rterm.exe" "C:/Program Files/R/R-3.4.4/bin/x64/Rterm.exe")))
)
```
How do I get ESS to recognize R-4.0.2 (both 32bit and 64bit) and add it to the list of available processes?
# Answer
> 0 votes
Check the value of `ess-r-runner-prefixes`. Until recently, it did not include `R-4`. You can customize it yourself, or if you install the latest/current version of ESS the default value should work.
See the responses to this email on the mailing list for more details:
https://stat.ethz.ch/pipermail/ess-help/2020-April/012729.html
# UPDATE
This is a known issue, and Vincent Goulet's latest release (as of September 17, 2020) includes a fix.
---
Tags: ess, r
---
|
thread-21066
|
https://emacs.stackexchange.com/questions/21066
|
Hide \author, \date, and \title when exporting to pdf with org-latex-export-to-pdf
|
2016-03-18T18:48:41.923
|
# Question
Title: Hide \author, \date, and \title when exporting to pdf with org-latex-export-to-pdf
I am very new to LaTeX and exporting org-mode files to pdf. When I run the command `org-latex-export-to-pdf` it adds a title, author name, and date to the top of the exported pdf. Looking at the generated LaTeX, I assume that comes from the lines:
```
\author{Ethan Skinner}
\date{\today}
\title{My Title}
```
How can I export a pdf without these properties? I have tried using both the `VISIBLE-ONLY` and `BODY-ONLY` arguments to `org-latex-export-to-pdf`, but this didn't work for me
# Answer
OK, thanks to @wvxvw putting me on the right track I figured it out.
You can get rid of the author and date with:
```
#+OPTIONS: author:nil date:nil
```
The Org Manual says that you can also toggle title with `title:nil` (`org-export-with-title`). However, this option didn't get rid of the title, and I couldn't find a variable or command `org-export-with-title`. However, from this thread I found that I can get rid of the title simply by adding: `#+TITLE:` and not entering a title. This does add an extra line to my document, and it seems like it would make more sense to do it in the `#+OPTIONS`, but this will do.
> 32 votes
# Answer
You can also redefine LaTeX's `\maketitle` to do nothing:
```
#+Title: Test title
#+Author: Test Author
#+Date: [2016-03-28 Mon]
#+LATEX_HEADER: \renewcommand\maketitle{}
* hello
test text
```
> 14 votes
# Answer
Setting
```
#+OPTIONS: title:nil
```
on top of your file makes the `\maketitle` macro not to be inserted into the generated `.tex` file which makes neither the author, date or title to be shown in the resulting PDF file.
> 2 votes
---
Tags: org-mode, latex, pdf
---
|
thread-60703
|
https://emacs.stackexchange.com/questions/60703
|
How are a daemon and a server different in Emacs?
|
2020-09-16T20:45:25.077
|
# Question
Title: How are a daemon and a server different in Emacs?
After running `(server-start)` in Emacs, I evaluated
```
(daemonp)
```
and
```
(server-running-p)
```
The first one returns `nil`, whereas the second one returns `t`. So, how are a daemon and a server different in Emacs? The official website http://www.nongnu.org/emacsdoc-fr/manuel/emacs-server.html does not seem be distinguish the two.
# Answer
There are two different and unrelated things, according to https://en.wikipedia.org/wiki/Daemon\_(computing)
> a daemon is a computer program that runs as a background process
according to (emacs) Emacs Server
> Emacs as an “edit server”, so that it “listens” for external edit requests and acts accordingly.
you can start Emacs server without daemon or daemon without Emacs server, however, if you start daemon without Emacs server, the daemon is useless, e.g.,
```
$ emacs --daemon
$ emacsclient --eval '(server-mode -1)'
```
the daemon is still running, but you can't ask it to do anything.
> 5 votes
---
Tags: emacsclient, emacs-daemon, daemon
---
|
thread-33631
|
https://emacs.stackexchange.com/questions/33631
|
How is it possible to sort todos by completion?
|
2017-06-18T15:59:43.517
|
# Question
Title: How is it possible to sort todos by completion?
How is it possible to sort todos by completion?
```
* Bar [0%]
** TODO Bar1
** TODO Bar2
* Foo [100%]
** DONE Foo1
CLOSED: [2017-06-18 So 17:51]
** DONE Foo2
CLOSED: [2017-06-18 So 17:51]
* Foo1 [0%]
** TODO Foo1
** TODO Foo2
```
For example I might constantly add new todos and finish other todos. How is it possible to sort the todos so that the todos with `100%` will stay at the bottom?
# Answer
> 1 votes
The following should work, at least with your example, but you'll need to add at least one new line before the first heading.
```
(defun my-sort-entries ()
(interactive)
(save-excursion
(goto-char (point-min))
(org-sort-entries nil ?f
(lambda ()
(let ((item (org-entry-get (point) "ITEM"))
(stats ".+\\[\\([0-9].+\\)%.+"))
(replace-regexp-in-string stats "\\1" item)))
'org-string-collate-greaterp nil t)))
```
---
Tags: org-mode, sorting
---
|
thread-60708
|
https://emacs.stackexchange.com/questions/60708
|
How to open a folder with a local file manager?
|
2020-09-17T09:45:52.710
|
# Question
Title: How to open a folder with a local file manager?
I use Emacs 26.3 on Ubuntu 20.04 and I often need to manipulate org files with Ubuntu file manager. It would save me a lot of time if I could open directories from emacs file links. For example, I would like to be able to open folder PRISM through the following link : \[\[./References/Deliverables/PRISM/proposal.org\]\[PRSM Proposal\]\].
# Answer
I don't know much about Ubuntu at the desktop level, but on my Gnome desktop, I can open a directory in the file manager from the command line, using the command `xdg-open /path/to/directory`. I assume there is something similar (or perhaps identical) to `xdg-open` on the Ubuntu desktop.
If so, all you have to do is write a function that parses the link at point, selects the directory part of the path (which may be the whole path, or it may be a prefix of the path, as in your example) and then calls `xdg-open` (or whatever the Ubuntu equivalent is) with that path as argument. Then you bind the function to a key and off you go.
Here's a function that looks at the link at point and calls `xdg-open` with the directory part of the path of the link.
```
#+begin_src emacs-lisp
(defun ndk/desktop-open-link-at-point()
(interactive)
(let* ((context
(org-element-lineage (org-element-context) '(link) t))
(type (org-element-type context))
(path (org-element-property :path context))
(dirpath (if (file-directory-p path)
path
(file-name-directory path))))
(shell-command (format "xdg-open %s" dirpath) nil nil)))
#+end_src
```
For convenience, bind the function to the key `<M-S-f12>` (i.e. Meta-Shift-FunctionKey12) or some other undefined key in your keymaps:
```
#+begin_src emacs-lisp
(define-key global-map (kbd "<M-S-f12>") #'ndk/desktop-open-link-at-point)
#+end_src
```
> 2 votes
---
Tags: org-mode
---
|
thread-60697
|
https://emacs.stackexchange.com/questions/60697
|
How to remap the search backwards evil-ex-search-previous command of evil?
|
2020-09-16T15:49:48.477
|
# Question
Title: How to remap the search backwards evil-ex-search-previous command of evil?
I want to remap evil-ex-search-previous to some other key than `,`. I tried
```
(define-key evil-motion-state-map "," 'evil-avy-goto-char-in-line)
(evil-define-key 'normal magit-mode-map "," 'evil-avy-goto-char-in-line)
(evil-define-key 'visual magit-mode-map "," 'evil-avy-goto-char-in-line)
```
However none of it worked. Using which key I see, that `,` is still bound to the old key. How can I change this?
# Answer
I asked on discord channel and after some thinking the working solution specific to doom-emacs which I received is
```
(map!
:nvm "," #'evil-avy-goto-char-in-line
:desc "go to next char")
```
> 0 votes
---
Tags: key-bindings, evil, doom
---
|
thread-60705
|
https://emacs.stackexchange.com/questions/60705
|
How can I preview LaTeX "#+BEGIN_EXPORT" blocks? Is it possible to accomplish this with "org-latex-preview"?
|
2020-09-17T05:18:47.093
|
# Question
Title: How can I preview LaTeX "#+BEGIN_EXPORT" blocks? Is it possible to accomplish this with "org-latex-preview"?
# The context
When editing Org mode files, I like editing code snippets in isolated buffers because that way I can use snippets and language dependent features in those buffers (something which is not possible out of the box in an Org mode buffer).
Because of this, I've decided to enclose every LaTeX environment within a `#+BEGIN_EXPORT` block because that ensures that when executing `org-edit-export-block` within that code block, I will be able to edit that code block in an isolated buffer and have all those features that are available on those buffers with `latex-mode` as major mode.
# The problem
The problem with this approach is that executing `org-latex-preview` (i.e. pressing `C-c C-x C-l`) does not show the preview `#+BEGIN_EXPORT` blocks as would occur with embedded LaTeX environments.
Here's a minimal working example. Let's assume we have the following Org mode file
```
* My heading
\begin{equation}
x = \frac{10}{10}
\end{equation}
#+begin_export
\begin{equation}
x = \frac{10}{10}
\end{equation}
#+end_export
```
Executing `org-latex-preview` within the `equation` environment which is outside the `#+BEGIN_EXPORT` block does show the preview, while executing `org-latex-preview` within the equation environment which is inside the `#+BEGIN_EXPORT` block does not show the preview of that `equation` environment but previews the other `equation` environment.
# The question
How can I make `org-latex-preview` preview the content of `#+BEGIN_EXPORT` code blocks?
If that's not possible, then how can I preview a given `#+BEGIN_EXPORT` code block whose language is LaTeX without exiting the current buffer? This behavior must be similar to previewing LaTeX environments with the `org-latex-preview` function.
# Answer
A feature request was published asking this in the mailing list in 2017, but it seems that it is still not possible to do this.
However, there is something you need to know: The reason why you have decided to enclose every LaTeX fragment in a `#+BEGIN_EXPORT` block is the fact that you can edit it the `#+BEGIN_EXPORT` block in an isolated buffer by executing `org-edit-export-block`. If this is the only reason, then you can accomplish this similar behavior without the usage of `#+BEGIN_EXPORT` code blocks.
As stated in the description of `org-edit-special` (i.e. the function bound to `C-c '`)
> When in a LaTeX environment, call ‘org-edit-latex-environment’.
executing `org-edit-latex-environment` opens the LaTeX fragment (if and only if it is a complete environment) in a new buffer.
# Limitations
This has some limitations which are described in this section
## `org-edit-latex-environment` is not "intelligent" enough
Consider this minimal working example
```
* My heading
\begin{tcolorbox}
\begin{tcolorbox}
\begin{tcolorbox}
a
\end{tcolorbox}
\end{tcolorbox}
\end{tcolorbox}'
```
executing `org-edit-latex-environment` within the parent `tcolorbox` environment shows the following in the opened buffer
```
\begin{tcolorbox}
\begin{tcolorbox}
\begin{tcolorbox}
a
\end{tcolorbox}
```
This doesn't occur when executing `org-edit-export-block` within a `#+BEGIN_EXPORT` code block with the same content.
```
#+begin_export latex
\begin{tcolorbox}
\begin{tcolorbox}
\begin{tcolorboox}
a
\end{tcolorbox}
\end{tcolorbox}
\end{tcolorbox}
#+end_export
```
## Not being able to edit multiple environments in a single buffer
Let's suppose you want to edit two `tabular` environments. What you would need to do is to execute `org-edit-latex-environment` in each environment to make the changes and then execute `org-latex-preview` in each of them.
```
\begin{tabular}
...
\end{tabular}
\begin{tabular}
...
\end{tabular}
```
This would be easily performed with a `#+BEGIN_EXPORT` block since you only need to insert both environments within a `#+BEGIN_EXPORT` block and then run `org-edit-export-block` (see below).
```
#+begin_export latex
\begin{tabular}
...
\end{tabular}
\begin{tabular}
...
\end{tabular}
#+end_export
```
As stated above, the problem is that you will not be able to preview the `#+BEGIN_EXPORT` block by executing `org-latex-preview`.
# The perfect solution
Here's a minimal working example (more details below the source code block)
```
#+LATEX_HEADER: \usepackage{tcolorbox}
#+BEGIN_SRC latex :results file raw :exports results :file tmp.png
\begin{tcolorbox}
\begin{tcolorbox}
\begin{tcolorbox}
a
\end{tcolorbox}
\end{tcolorbox}
\end{tcolorbox}
#+END_SRC
#+RESULTS:
[[file:tmp.png]]
```
Some details
* Make sure that `latex` has been passed as an argument to `org-babel-do-load-languages`. Thus, you will be able to evaluate `#+BEGIN_SRC` blocks whose language is LaTeX.
* In order to display the actual image, you need to toggle inline images. I toggled it by executing `org-toggle-inline-images`.
* Since you are exporting it as an image, the box will be displayed as an image in the resulting PDF. This is not what we want. The solution for this is explained below.
You can solve `#+BEGIN_SRC` LaTeX code blocks being exported as images in PDFs by modifying the header arguments for your LaTeX code blocks accordingly to your needs. For example, I don't usually export my Org files as PDFs; most of the time I edit my Org files and read them within an Emacs buffer. Because of this, I would set `((1))` on top of my file. Thus, each `#+BEGIN_SRC` LaTeX block would be shown within the Org buffer. Now, if I needed to export the Org file as a PDF, then I would comment `((1))` and comment out `((2))`. Thus, `#+BEGIN_SRC` latex code blocks would be shown in higher quality than embedded images.
```
# ((1)) Property for previewing LaTeX as images within an Org buffer
#+PROPERTY: header-args:latex :results file raw :exports results :file tmp.png
# ((2)) Property for exporting #+BEGIN_SRC blocks as actual LaTeX environments and not as images. This is what you might want when exporting your Org file as a PDF.
# #+PROPERTY: header-args:latex :exports results
#+LATEX_HEADER: \usepackage{tcolorbox}
#+BEGIN_SRC latex
\begin{tcolorbox}
\begin{tcolorbox}
\begin{tcolorbox}
a
\end{tcolorbox}
\end{tcolorbox}
\end{tcolorbox}
#+END_SRC
```
You can also bind a key to modify LaTeX header arguments by modifying the value of the `org-babel-default-header-args:latex` variable. This way, you avoid going to the top of the file in order to modify the `#+PROPERTY`s.
# Related information
Related discussion can be found in
> 4 votes
---
Tags: org-mode, latex, preview-latex
---
|
thread-60707
|
https://emacs.stackexchange.com/questions/60707
|
How to get the display dimensions of the display emacs is in?
|
2020-09-17T08:38:42.110
|
# Question
Title: How to get the display dimensions of the display emacs is in?
I tried querying the display width using:
```
(display-pixel-width)
```
however this reports the pixel width of my external monitor instead of the laptop's display, where emacs is.
Is there a way to show the information of the display where emacs currently is?
**Edit**: for the time being I'm using `frame-monitor-attributes` as follows:
```
(nth 3 (assq 'geometry (frame-monitor-attributes)))
```
This reports the display width of the monitor emacs is in, instead of always showing the width of the external monitor.
# Answer
> 1 votes
As @NickD said in a comment, `display-pixel-width` uses the current display/frame by default, but you can provide the one you want to consider as an argument.
There is also function **`display-monitor-attributes-list`**, which gives you quite a lot of info. `C-h f` tells us:
> **`display-monitor-attributes-list`** is a compiled Lisp function in `frame.el`.
>
> `(display-monitor-attributes-list &optional DISPLAY)`
>
> Return a list of physical monitor attributes on `DISPLAY`.
>
> `DISPLAY` can be a display name, a terminal name, or a frame. If `DISPLAY` is omitted or `nil`, it defaults to the selected frame's display. Each element of the list represents the attributes of a physical monitor. The first element corresponds to the primary monitor.
>
> The attributes for a physical monitor are represented as an alist of attribute keys and values as follows:
>
> ```
> geometry -- Position and size in pixels in the form of (X Y WIDTH HEIGHT)
> workarea -- Position and size of the work area in pixels in the form of (X Y WIDTH HEIGHT)
> mm-size -- Width and height in millimeters in the form of (WIDTH HEIGHT)
> frames -- List of frames dominated by the physical monitor
> name (*) -- Name of the physical monitor as a string
> source (*) -- Source of multi-monitor information as a string
>
> ```
>
> where `X`, `Y`, `WIDTH`, and `HEIGHT` are integers. `X` and `Y` are coordinates of the top-left corner, and might be negative for monitors other than the primary one. Keys labeled with (`*`) are optional.
>
> The "work area" is a measure of the "usable" display space. It may be less than the total screen size, owing to space taken up by window manager features (docks, taskbars, etc.). The precise details depend on the platform and environment.
>
> The `source` attribute describes the source from which the information was obtained. On X, this may be one of: `"Gdk"`, `"XRandr"`, `"Xinerama"`, or `"fallback"`.
>
> A frame is dominated by a physical monitor when either the largest area of the frame resides in the monitor, or the monitor is the closest to the frame if the frame does not intersect any physical monitors. Every (non-tooltip) frame (including invisible ones) in a graphical display is dominated by exactly one physical monitor at a time, though it can span multiple (or no) physical monitors.
---
Tags: display
---
|
thread-60717
|
https://emacs.stackexchange.com/questions/60717
|
Function like `setcar` that doesn't change the value of the input function?
|
2020-09-17T17:22:01.160
|
# Question
Title: Function like `setcar` that doesn't change the value of the input function?
Early beginner here. I'm looking for a function that takes a list and changes only its first element, using some function or other. I realize `setcar` sort of does that, but it also changes the initial list. Thus if I have
```
(setq mylist '("Red" "Green" "Blue"))
```
and then run
```
(setcar mylist (downcase (car mylist))
```
the value of `mylist` will change to `("red" "Green" "Blue")`.
What I'm looking for, though, is a function that only outputs the value that `setcar` will set `mylist` to but does not change the value of `mylist`.
I realize I could do, e.g.
```
(setq mynewlist mylist)
(setcar mynewlist (downcase (car mynewlist))
```
and get essentially the same result. But I wanted to know if this is the best way to do it.
# Answer
> 2 votes
I think you're asking for a function that returns a new list whose car is a value you provide and whose cdr is a copy of the cdr of the original list. That way, there is no modification of the original list, and the resulting list shares no structure with the original.
```
(defun foo (new-car-val xs)
"..."
(cons new-car-val (copy-sequence (cdr xs))))
(foo (downcase (car mylist)) mylist)
```
---
By the way, this is *not* what you want:
```
(setq mylist '("Red" "Green" "Blue"))
(setq mynewlist mylist)
(setcar mynewlist (downcase (car mynewlist)))
```
That modifies the original list, `mylist`, *and* `mynewlist`. They are the **same** list.
If you don't want to share list structure, use `copy-sequence`.
See nodes car, cdr, cons and List Implementation of manual *Intro to Emacs Lisp Programming*.
---
Update, from the comments:
Q: So am I right in thinking that `(setq var1 var2)` doesn't 'store' the current value of `var2` but rather 'tells' `var1` to always point to whatever `var2` is pointing to? Maybe I'm mixing too many metaphors here.
A: Yes, depending on what you mean. It sets the value of `var1` to whatever the value of `var2` is - the **actual thing**, not a copy. If the value of `var2` is a list, then the value of `var1` is set to that **same** list, not a copy.
---
Tags: list
---
|
thread-60719
|
https://emacs.stackexchange.com/questions/60719
|
Modify value of a variable by applying a function to it?
|
2020-09-17T19:26:34.827
|
# Question
Title: Modify value of a variable by applying a function to it?
Suppose one of the customizable variables in a package is `var`, and its default value is a list, `list`. I understand I can change the value of `var` to `mylist` using
```
(setq var mylist)
```
in my `init.el`.
Suppose though that I have a function `fun` and I want the value of `var` to be the result of applying `fun` to `list`. Can I simply do this?
```
(setq var (fun var))
```
I've done it and it seems to work as intended, but I want to make sure this is a good idea.
---
**EDIT**: My question was not very clear, so let me clarify the sort of thing I was worried about (this may be redundant in light of my comment to this answer by Drew. Suppose I add
```
(setq var (fun var))
```
to my `init.el`. How do I ensure that the default value of `var` has already been set when that line gets evaluated? Should I put this inside a `with-eval-after-load`? And how do I ensure that `M-x load-file ~/.emacs.d/init.el` won't result in `var` being set to the value of `(fun (fun var))`? Should I instead add the above line to something like `emacs-startup-hook` or `after-init-hook`?
I'm currently using a line in my `init.el` like the above for setting a variable to a value as a function of its default value. I'm relying on `use-package`, and in order to ensure that the default value of the variable had been set I had to put that line in the `:config` section of the relevant package, rather than in the `:custom` section (without `setq`). Also, the function I am currently using has the nice feature that `(fun (fun var))` yields the same output as `(fun var)`. So I have managed to get around both of my concerns.
Still, this seemed like an opportunity to try to understand how to do what I'm trying to do even if I'm not using `use-package` and if I have a function that's not idempotent.
# Answer
Yes. `setq` sets a variable to whatever value is returned by the second argument.
`(setq VAR VALUE)` sets variable `VAR` to whatever `VALUE` is, and the second argument, `VALUE` is always evaluated.
(The first argument, `VAR`, is never evaluated. For a function that evaluates both args, see `set`.)
> 1 votes
---
Tags: variables, setq
---
|
thread-60679
|
https://emacs.stackexchange.com/questions/60679
|
flyspell and ispell give too many spelling suggestions
|
2020-09-15T23:22:38.737
|
# Question
Title: flyspell and ispell give too many spelling suggestions
I'm using `flyspell` mode with `aspell` under the hood. Emacs 27.1 installed using Homebrew on macOS Mojave. This behavior happens both with my normal configuration as well as `emacs -Q`.
I looked through `M-x customize` as carefully as I could in the `flyspell` and `ispell` sections, but did not find anything useful.
When I right-click on a misspelled word, I get way more suggestions than I want:
I want maybe a dozen suggestions.
`M-x ispell-buffer` similarly gives too many suggestions.
This seems like an Emacs thing because running `aspell` on the same file in the terminal manually gives a much more reasonable number of suggestions (here, 8):
# Answer
Emacs is invoking `aspell` as:
```
aspell -a -m -B --encoding=utf-8
```
`-a` is “pipe mode”. Given this information, I can reproduce the behavior in the terminal:
```
$ echo dbux | aspell -a -m -B --encoding=utf-8
@(#) International Ispell Version 3.1.20 (but really Aspell 0.60.8)
& dbux 47 0: DBUS, Dix, debugs, dubs, debug, box, tux, DBMS, ibex, bxs, daubs, dibs, debuts, deluxe, dybbuks, Durex, Debs, boxy, bugs, dabs, debs, dobs, dub's, dybbuk, tubs, dab's, deb's, DCS, TWX, TeX, Tex, tax, tbs, tex, DC's, TB's, Tb's, daub's, debut's, dybbuk's, Debs's, dibs's, bug's, BC's, Bk's, tub's, Doug's
```
Using the “ultra” suggestion mode rather than the default “normal” gives five suggestions rather than 47:
```
$ echo dbux | aspell -a -m -B --encoding=utf-8 --sug-mode=ultra
@(#) International Ispell Version 3.1.20 (but really Aspell 0.60.8)
& dbux 5 0: DBUS, debugs, dybbuks, dybbuk's, debarks
```
This can be configured in Emacs by adding `--sug-mode=ultra` to `Ispell Extra Args` in `M-x customize`; it works for me:
I would still prefer to get the top dozen or so from normal mode, but this is probably better than it was.
> 3 votes
# Answer
Make sure you've installed aspell dictionary. I use `apt install aspell aspell-end` on Debian/Ubuntu.
Then use `M-x flyspell-buffer` to spell check the current buffer. Flyspell is a independent packages which uses a few APIs from ispell. Most user use flyspell instead of ispell these days.
See https://blog.binchen.org/posts/what-s-the-best-spell-check-set-up-in-emacs.html for the details.
You can create a plain text personal dictionary `~/.aspell.en.pws` for aspell,
Here is content of sample`~/.aspell.en.pws`,
```
personal_ws-1.1 en 3
ABN
AC
ACN
```
> 0 votes
---
Tags: flyspell, ispell, spell-checking
---
|
thread-60637
|
https://emacs.stackexchange.com/questions/60637
|
How to generate cited references with biber and xelatex
|
2020-09-13T10:57:56.023
|
# Question
Title: How to generate cited references with biber and xelatex
I would like to generate cited references and bibliography using biber and xelatex through org mode, but have not figured out how to do so.
I have to use xelatex because I am working with Chinese articles.
# Sample Document:
```
#+TITLE: How to Automate Footnote Citations in Org-Mode
#+AUTHOR: Sati Bodhi
* Cite Test
This is a statement with a footnote reference. [fn:2a55720f42c74dd:This is the footnote with a citation that is supposed to be formatted in Chicago-fullnote style. cite:Rogersbecoming1995。]
bibliography:thesis.bib
bibliographystyle:chicago-notes
```
# Bibtex Entry:
```
@book{Rogersbecoming1995,
title = {On Becoming a Person: A Therapist's View of Psychotherapy},
author = {Rogers, Carl R.},
year = {1995},
publisher = {{Houghton Mifflin}},
address = {{Boston, New York}},
abstract = {Collection of essays by American psychotherapist Carl Rogers written between 1951 and 1961, in which he put forth his ideas about self-esteem, flexibility, respect for self, and acceptance of others.},
isbn = {9780395755310},
keywords = {Client-centered psychotherapy},
language = {eng},
place = {;}
}
```
# Configuration:
```
(setq org-latex-classes
'(("article"
"
%\\documentclass[12pt,a4paper]{article}
\\documentclass[12pt,a4paper]{ctexart}
\\usepackage{xeCJK}
\\usepackage{zhnumber} % package for Chinese formatting of date time (use /zhtoday)
%\\usepackage[yyyymmdd]{datetime} % set date time to numeric
% For Generation of Citations and Bibliography
\\usepackage[backend=biber]{biblatex-chicago}
% Set Font.
\\setsansfont{Times New Roman}
\\setmainfont{Calibri} % Set serifed font to Calibri. Originally set to 'Times New Roman', but it cannot display certain characters such as ①②③.
\\setCJKmainfont{Songti TC}
\\setCJKsansfont{Kaiti TC} % Set Chinese font. NOTE: Remember to append CJK before of the font class. CJK HAS to be there for the font to show.
\\setCJKmonofont{PingFang TC}
% Set title font.
\\renewcommand{\\maketitlehooka}{\\sffamily}
% Set quotation font.
\\usepackage{etoolbox}
\\newCJKfontfamily\\quotefont{Kaiti TC}
\\AtBeginEnvironment{quote}{\\quotefont\\normalsize}
% Tweak default settings.
\\renewcommand{\\baselinestretch}{1.2} % Set line width.
%\\renewcommand{\\contentsname}{\\hfill\\bfseries\\Large 目\\hspace{0.5cm} 次\\hfill} % Translate content page title to Chinese.
%\\renewcommand{\\cftaftertoctitle}{\\hfill} % Center contents title.
% For text-boxes
\\usepackage{mdframed}
\\BeforeBeginEnvironment{minted}{\\begin{mdframed}}
\\AfterEndEnvironment{minted}{\\end{mdframed}}
% For tables
\\usepackage{float}
\\restylefloat{table}
% [FIXME] ox-latex 的設計不良導致 hypersetup 必須在這裡插入
\\usepackage{hyperref}
\\hypersetup{
colorlinks=true, %把紅框框移掉改用字體顏色不同來顯示連結
linkcolor=[rgb]{0,0.37,0.53},
citecolor=[rgb]{0,0.47,0.68},
filecolor=[rgb]{0,0.37,0.53},
urlcolor=[rgb]{0,0.37,0.53},
pagebackref=true,
linktoc=all,}
"
("\\section{%s}" . "\\section*{%s}")
("\\subsection{%s}" . "\\subsection*{%s}")
("\\subsubsection{%s}" . "\\subsubsection*{%s}")
("\\paragraph{%s}" . "\\paragraph*{%s}")
("\\subparagraph{%s}" . "\\subparagraph*{%s}"))
))
(setq org-latex-with-hyperref t)
(setq org-latex-default-packages-alist
'(("" "hyperref" nil)
("" "graphicx" t)
("" "longtable" nil)
("" "wrapfig" nil)
("" "rotating" nil)
("normalem" "ulem" t)
("" "amsmath" t)
("" "textcomp" t)))
;; Use XeLaTeX to export PDF in Org-mode
(setq org-latex-pdf-process
'("xelatex -interaction nonstopmode -output-directory %o %f"
"xelatex -interaction nonstopmode -output-directory %o %f"
"xelatex -interaction nonstopmode -output-directory %o %f"))
(require 'ox-latex)
(setq org-latex-inputenc-alist '(("utf8" . "utf8x")))
;; Use XeLaTeX to compile in Latex-mode
(setq tex-compile-commands '(("xelatex %r")))
(setq tex-command "xelatex")
(setq-default TeX-engine 'xetex)
```
# Generated Bibliography and Footnote:
---
# Update:
I've found my own solution. Because I cannot award myself the bounty, I would like to seek an explanation as to *why* the bibliography and style had to be hard-coded this way and whether, given the current working solution, there can be a more flexible way of dealing with this. The best answer would be awarded the bounty.
# Note:
The format used to specify the bibliography data source and its citation style in the question above was one offered by org-ref.
# Answer
> 2 votes
I've found my own solution. Here are the changes I've made to the source and configuration code that made this work.
# Source:
```
#+TITLE: How to Automate Footnote Citations in Org-Mode
#+AUTHOR: Sati Bodhi
#+BEGIN_abstract
This is the abstract.
#+END_abstract
* Cite Test
This is a statement with a footnote reference. [fn:2a55720f42c74dd:This is the footnote with a citation that is supposed to be formatted in Chicago-fullnote style. [[cite:Rogersbecoming1995][121-127]]。]
#+LATEX: \printbibliography
```
# Configuration:
```
% For Generation of Citations and Bibliography
\\usepackage[notes, isbn=false, backend=biber]{biblatex-chicago}
\\bibliography{/Users/satibodhi/Creation/notes/bibliography/thesis}
```
```
(setq org-latex-pdf-process
'("xelatex -interaction nonstopmode -output-directory %o %f"
"biber --output-directory %o $(basename %f .tex)"
"xelatex -interaction nonstopmode -output-directory %o %f"
"xelatex -interaction nonstopmode -output-directory %o %f"))
```
# Results:
---
Tags: org-mode, latex, bibtex
---
|
thread-60728
|
https://emacs.stackexchange.com/questions/60728
|
Combine two interactive functions
|
2020-09-18T17:06:00.937
|
# Question
Title: Combine two interactive functions
For example, I want to sort a file, then remove the duplicate lines. I run `M-x sort` followed by `M-x delete-duplicate-lines`. I wanted to combine them into a single interactive function. Here is an attempt at solving this.
```
(defun sort-and-dedup ()
""
(interactive)
(sort)
(delete-duplicate-lines)
)
```
This gives an error saying the underlying functions don't have sufficient number of arguments. I kind of get why that is the case (the interactive vs non-interactive argument, among a few others), but I don't know what to do exactly. Can you tell me how to correct this?
**Edit 1:**
The above code is wrong in many ways. Look at the accepted answer for information. And thanks for the help.
**Edit 2:**
This is what I intended to do.
```
(defun sort-and-dedup-region (beg end)
(interactive "r")
(sort-lines nil beg end)
(delete-duplicate-lines beg end nil t))
(defun sort-and-dedup ()
(interactive)
(sort-and-dedup-region
(point-min)
(point-max)))
```
# Answer
\[I believe you meant `sort-lines`, not `sort` \- that's the only way the question makes sense, so I am going to assume it.\]
Both `sort-lines` and `delete-duplicate-lines` operate on the *selected region*. You must select a region before calling them, otherwise they will complain that there is no region. So you are going to have to do the same thing in your function: assume that you are given a region and complain if there is none.
A region is specified by two positions in the buffer, conventionally named `BEG` and \`END. So your function will look like this:
```
(defun sort-and-dedup (beg end)
(interactive <mumble>)
(sort-lines nil beg end)
(delete-duplicate-lines beg end))
```
The first argument to sort lines tells it whether to sort in reverse order.
When you call the function interactively, you specify a region by setting a mark at one end and then moving point to the other end (or by starting at one end and dragging with the mouse to the other end). So how do you communicate those positions to the function? By giving an argument to `interactive`: if you look at its doc string (with `C-h f interactive RET`), you will find that `r` is what you need in order to specify a region - Emacs will arrange to translate the region you chose (however you chose it) into a pair of positions (BEG and END) that will be passed to your function.
So the function looks like this:
```
(defun sort-and-dedup (beg end)
(interactive "r")
(sort-lines nil beg end)
(delete-duplicate-lines beg end))
```
Alternatively, as @Dan suggests, you can use `call-interactively` and let each function figure out what it needs. But you will still have to specify a region beforehand:
```
(defun sort-and-dedup ()
(interactive)
(call-interactively #'sort-lines)
(call-interactively #'delete-duplicate-lines))
```
EDIT: incorporating @phil's suggestion (and now I see that you have actually implemented this and added it to your question), you can write a function that calls (the first definition of) `sort-and-dedup` with the necessary arguments to operate on the whole buffer:
```
(defun sort-and-dedup-whole-buffer()
(interactive)
(sort-and-dedup (point-min) (point-max)))
```
You can bind it to a key sequence if you are going to do that frequently:
```
(define-key global-map (kbd "M-S-<f10>" #'sort-and-dedup-whole-buffer)
```
although I would personally not do that: key sequences are a scarce commodity, so I would try it using `M-x sort-and-dedup-whole-buffer RET` for a while; if that becomes a nuisance, then I would bind it to a key sequence.
I also revisit all my key defs every couple of years and reclaim ones that I don't use any more. I keep them in their own file, loaded explicitly by my init file, so I can find and review them easily.
> 5 votes
---
Tags: functions, interactive
---
|
thread-43722
|
https://emacs.stackexchange.com/questions/43722
|
emacsclient -nw and strikethrough text in org mode
|
2018-07-21T03:31:51.230
|
# Question
Title: emacsclient -nw and strikethrough text in org mode
> https://orgmode.org/worg/org-tutorials/org4beginners.html You can make words `*bold*`, `/italic/`, `_underlined_`, `=code=` and `~verbatim~`, and, if you must, `+strike-through+`.
How to strikethrough a word, when writing something in org mode
my env: emacs latest, -nw mode, terminal.app, macOS
# Answer
Emacs 28 (master branch as of this writing) recently gained support for emitting the necessary ECMA-48 "Select Graphic Rendition" escape sequences in order to render faces with the 'strike-through' attribute on TTY frames.
If you're running a version of Emacs 28 that includes this commit, and your terminal's termcap/terminfo database entry has the `smxx` capability (included in more recent xterm terminfo sources) you should be able to see `+strike-through+` rendered properly in Org mode documents inside of TTY frames.
> 3 votes
# Answer
I want to supplement JaenPierre's answer.
The evaluation of the following elisp code in the `*scratch*` buffer gives stricken-through text in Emacs with a GUI and non-stricken-through text in Emacs in terminal mode.
```
(insert (propertize "hello world" 'font-lock-face '(:strike-through t)))
```
On the first glance it looks like `:strike-through` is not supported on `vt100` compatible terminals.
But in principle vt100 supports stricken-through text and the following elisp code returns `(("unspecified" . unspecified) ("t" . t) ("nil"))` in a `vt100` compatible terminal.
```
(face-valid-attribute-values :strike-through)
```
AFAIK the cons `("t" . t)` in the return value says that stricken-through text should be supported. So at the second glance it looks more like a bug in Emacs.
> 1 votes
# Answer
The appearance of text in emacs is controlled by *faces*, describing various aspects of the display of characters. The elisp manual says:
> ## 37.12.1 Face Attributes
>
> “Face attributes” determine the visual appearance of a face. The following table lists all the face attributes, their possible values, and their effects.
>
> ...
>
> Some of these attributes are meaningful only on certain kinds of displays. If your display cannot handle a certain attribute, the attribute is ignored.
>
> ...
>
> ‘:strike-through’ Whether or not characters should be strike-through, and in what color.
In your case the "display" is your text terminal and it seems to not support`:strike-through`. I don't know if any text terminal supports it, for example `xterm` does not.
> 0 votes
# Answer
You could mark a word or a sentence and press `C-c C-x C-f`. After that you can select your action. If you hit the `+` key, that selected word or sentence will be crossed out.
> 0 votes
---
Tags: org-mode, terminal-emacs
---
|
thread-60723
|
https://emacs.stackexchange.com/questions/60723
|
Convert region/subtree from Markdown to org
|
2020-09-18T09:27:04.737
|
# Question
Title: Convert region/subtree from Markdown to org
I often have Markdown text in my clipboard that I would like to insert into an org file. After pasting the text into my org-mode file, is there a quick way to convert it to org format? For example, invoke Pandoc on a selected region/subtree?
# Answer
You can select the pasted-in region (if you do it right after you paste it in, it should already be marked) and then run `pandoc` on the region with `C-u M-| pandoc -f markdown -t org RET`. The prefix argument says: "replace the region with the output of the command". This is a bit fragile: if you mistype, you might end up with the region erased, but you can always paste it in and try again.
> 5 votes
# Answer
This function executes the same command of NickD's answer, without the risk of mistype.
```
(defun my-md-to-org-region (start end)
"Convert region from markdown to org"
(interactive "r")
(shell-command-on-region start end "pandoc -f markdown -t org" t t))
```
> 3 votes
---
Tags: org-mode, markdown
---
|
thread-44743
|
https://emacs.stackexchange.com/questions/44743
|
Markdown-style block quotes in org-mode
|
2018-09-14T01:53:51.263
|
# Question
Title: Markdown-style block quotes in org-mode
I'm new to org-mode. I'm liking it so far. The one growing pain that I have is missing Markdown-style block quotes: I would like to start a line with `>` to quote it. How would I go about writing an extension (or better yet, finding one already written!) that would let me use that syntax?
# Answer
> 9 votes
UPDATE: As of org-mode 9.2, the org-structure-template system has changed. Inserting a template is now done via `C-c C-,`.
To add a shortcut for emacs-lisp in this new system, use the following snippet:
```
(add-to-list 'org-structure-template-alist
'("se" . "src emacs-lisp"))
```
---
Not really an answer to the question directly, but also too much for a comment:
I'd advise against modifying your `org-mode` setup like that. It moves away from what `org` is, and could lead to issues in the future.
You can, however, easily insert quotes by typing `<q` and hitting `TAB`, which expands a template. Many templates can be used this way, like `<s` for codeblocks.
Explore this functionality further with `C-h` `v` `org-structure-template-alist` `RET`.
Adding your own templates is a breeze as well. I added a template for an elisp codeblock like so:
```
(add-to-list 'org-structure-template-alist
'("se" "#+BEGIN_SRC emacs-lisp\n?\n#+END_SRC"))
```
The `?` indicates where the point should move upon expansion. Now `<se` `TAB` expands into such a block.
# Answer
> 2 votes
This answer is becoming more a comment (third edit). If you feel it should be deleted, I have no problem in doing that.
I was looking for this functionality, in order to do in org mode what I do in a web based email system: quick comments to fragments of a long text. As I was using the template expansion based on `<q`, I found slow to add `#+begin_quote ... #+end_quote` many times. I think, it was not possible to add (fast) "quote" markers to surround an existing text, a kill/yank was needed. However, in the current version of org mode (see EFLS answer), it's possible (just marking the existing text), it has a default key binding `C-x C-,`, and it's fast, :)
---
JFTR, someone could also found useful to add a colon and a space `:` to the beginig of each line, using `rectangle-mark-mode` and then `string-rectangle` or some of the "replace" functions. Then, interleave comments without the leading colon.
It exports in latex as a `verbatim` environment, and in HTML as a `pre` tag.
# Answer
> 1 votes
add `(require 'org-tempo)` to your `init.el` file
then use the following shortcuts by typing the less-than symbol `<`, `the letter` and then `TAB`:
```
a ‘#+BEGIN_EXPORT ascii’ … ‘#+END_EXPORT’
c ‘#+BEGIN_CENTER’ … ‘#+END_CENTER’
C ‘#+BEGIN_COMMENT’ … ‘#+END_COMMENT’
e ‘#+BEGIN_EXAMPLE’ … ‘#+END_EXAMPLE’
E ‘#+BEGIN_EXPORT’ … ‘#+END_EXPORT’
h ‘#+BEGIN_EXPORT html’ … ‘#+END_EXPORT’
l ‘#+BEGIN_EXPORT latex’ … ‘#+END_EXPORT’
q ‘#+BEGIN_QUOTE’ … ‘#+END_QUOTE’
s ‘#+BEGIN_SRC’ … ‘#+END_SRC’
v ‘#+BEGIN_VERSE’ … ‘#+END_VERSE’
```
see https://orgmode.org/manual/Structure-Templates.html
---
Tags: org-mode, markdown
---
|
thread-60735
|
https://emacs.stackexchange.com/questions/60735
|
Link to footnote export as non-superscript
|
2020-09-19T08:48:06.763
|
# Question
Title: Link to footnote export as non-superscript
Links to a footnote automatically exports as superscript in LaTeX.
# Source:
```
Lorem ipsum dolor sit amet, consectetur adipiscing elit. [fn:1685d75dd9ccdec5: This is a footnote.] In sed erat porta, sodales mauris congue, volutpat nisi. Integer in justo ac augue vehicula sodales ac quis enim. [fn:4194cf1977de9b2:Please refer to footnote [fn:1685d75dd9ccdec5].]
```
# TeX:
```
Please refer to footnote \textsuperscript{\ref{orge6f2964}}.
```
Is there a setting that can turn off this feature so that this specific link is exported normally?
```
Please refer to footnote \text{\ref{orge6f2964}}.
```
---
# Expected Results:
I would like links in the main text to remain super-scripted.
While those within footnotes to be in normal text. i.e. Please refer to footnote 2.
# Answer
You can redefine `org-latex-footnote-defined-format`. Its doc string says:
> org-latex-footnote-defined-format is a variable defined in ‘ox-latex.el’. Its value is "\textsuperscript{\ref{%s}}"
>
> You can customize this variable. This variable was introduced, or its default value was changed, in version 26.1 of Emacs.
>
> Documentation:
>
> Format string used to format reference to footnote already defined. %s will be replaced by the label of the referred footnote.
You can redefine it in your init file with
```
(eval-after-load 'ox-latex
(setq org-latex-footnote-defined-format "\\text{\\ref{%s}}"))
```
or if you prefer using a file local variable by adding something like this at the end of your file:
```
* Local customizations :noexport:
# Local Variables:
# org-latex-footnote-defined-format: "\\text{\\ref{%s}}"
# End:
```
> 1 votes
---
Tags: org-mode, latex, org-link
---
|
thread-60710
|
https://emacs.stackexchange.com/questions/60710
|
Is there any way of getting overview statistics for all checkboxes in a given org subtree?
|
2020-09-17T11:00:04.943
|
# Question
Title: Is there any way of getting overview statistics for all checkboxes in a given org subtree?
I have an org document with the following structure
```
* Tasks
** First category
- [X] Task
** Second Category
- [ ] Task
```
And I'd like to get statistics for both the overall completion and each subheading. If my tasks were TODO headings, I could get what I wanted by giving each heading a statistics cookie and setting the recursive property on the cookie, (or by setting `org-hierarchical-todo-statistics` to `nil`). That works as follows, and gives the expected result after updating all cookies:
```
* Headings and TODOs [1/2]
:PROPERTIES:
:COOKIE_DATA: todo recursive
:END:
** First category [1/1]
*** DONE Task 1
** Second Category [0/1]
*** TODO Task
```
If I try to do the same with the checkboxes, either by setting the recursive property on the cookie, or by looking at the variable `org-checkbox-hierarchical-statistics`, I get the following result
```
* Checkboxes [0/0]
:PROPERTIES:
:COOKIE_DATA: checkbox recursive
:END:
** First category [1/2]
- [X] Task
** Second Category [0/1]
- [ ] Task
```
Where the first line says `* Checkboxes [0/0]` instead of the expected `* Checkboxes [1/2]`
I therefore have two questions:
* Is this the intended behaviour, so that I'm misunderstanding how checkboxes and subheadings are supposed to interact? Does the "hierarchy" of hierarchical checkboxes only work in a single nested list and not across subheadings?
* How do I get the behaviour I do want? As a last resort I know I can just convert my document entirely to subheadings, but I'd rather not have to do that
# Answer
It seems I was right in my fear that there was no built-in way of getting the behaviour I wanted. I ended up designing the following solution:
* Add a non-inherited keyword "aggregate" to the COOKIE\_DATA property for the headings where I want special behaviour
* Whenever a checkbox is altered, and org recalculates the statistics cookie, see if the property is set on the current headline
* If it is, calculate the sum of all statistics cookies of the form \[n/m\] in the first level of children
* Replace the statistics cookie of the current headline if it's present
* Recurse up the tree and do the same thing.
I know this is a fairly brittle solution, and I can think of many ways things could go wrong. Fortunately, the only files I want to do this in are already highly structured, so hopefully it'll work as it should there. It's the first bit of elisp I've ever written that was more than just a 5 line toy function, and it ended up being a fun challenge.
```
(defun aggregate-org-cookies ()
(save-excursion
(org-back-to-heading t)
(let* ((prop (string-match "\\<aggregate\\>"
(or (org-entry-get nil "COOKIE_DATA") "")))
)
(if prop
(let* ((counts (aggregate-one-level))
(numerator (car counts))
(denominator (cadr counts))
(cookie-regex "\\[\\([0-9]*\\)/\\([0-9]*\\)\\]")
(new (format "[%d/%d]" numerator denominator)))
(re-search-forward cookie-regex (line-end-position) t)
(if (match-beginning 0)
(progn
(setq beg (match-beginning 0)
ndel (- (match-end 0) beg))
(goto-char beg)
(insert new)
(delete-region (point) (+ (point) ndel))
))))
(if (org-up-heading-safe)
(aggregate-org-cookies))
)))
(defun aggregate-one-level ()
(save-excursion
(let* ((current (point))
(next (save-excursion (outline-next-heading) (point)))
(numerator 0)
(denominator 0)
(cookie-regex "\\[\\([0-9]*\\)/\\([0-9]*\\)\\]")
)
(defun count-one ()
(re-search-forward cookie-regex (line-end-position) t)
(if (> (match-end 1) (match-beginning 1))
`(,(string-to-number (match-string 1))
,(string-to-number (match-string 2)))
(0 0 )))
(while (> next current)
(goto-char next)
(setq current next
next (save-excursion (org-forward-heading-same-level 1) (point))
current_total (count-one)
denominator (+ denominator (cadr current_total))
numerator (+ numerator (car current_total))))
`(,numerator ,denominator)
)))
(add-hook 'org-checkbox-statistics-hook (function aggregate-org-cookies))
```
> 2 votes
---
Tags: org-mode
---
|
thread-60721
|
https://emacs.stackexchange.com/questions/60721
|
Gnus fails opening larger imap group
|
2020-09-17T22:02:01.870
|
# Question
Title: Gnus fails opening larger imap group
If I try to open an larger imap group (a few thousand messages both read and unread) Gnus gives a warning: Wrong number of arguments: #, 2 And the Summary window is empty or it contains only some of the messages.
*Compile Log* shows: Warning: ‘not’ called with 2 args, but requires 1
If I limit the number of messages to fetch to e.g. 200 (C-u RET) it works fine. Limiting to 500 triggers the same warning.
The problem shows up with different imap servers, both for emacs 26 and 27. The gnus config is fairly basic, just nnimap sources with gnus-secondary-select-methods and gnus-posting-styles.
*imap log* shows: 23:56:34 \[poczta.agh.edu.pl\] 122 UID FETCH 107408,107410,107415,107424:107425,107431,107448:107449,107453,107463,107469:107470,107472:107473,107489,107495,107511,107519,107522,107524,107526:107542,107545:107547,107549:107553,107559:107561,107564,107569:107573,107576,107580,107586,107592,107594:107595,107629,107635:107638,107652:107655,107661,107664,107689,107695,107698:107699,107702,107706,107711,107716:107717,107723,107732,107746,107752:107755,107757,107773,107775,107779....,111987,111999:112015,112017:112050 (UID RFC822.SIZE BODYSTRUCTURE BODY.PEEK\[HEADER.FIELDS (Subject From Date Message-Id References In-Reply-To Xref To Newsgroups Cc)\])
Any thoughts on how to fix it or what's wrong?
# Answer
> 1 votes
It was my badly formed sort function. I had:
(setq gnus-thread-sort-functions '(not gnus-thread-sort-by-most-recent-date))
which should be:
(setq gnus-thread-sort-functions '((not gnus-thread-sort-by-most-recent-date)))
---
Tags: debugging, gnus, imap
---
|
thread-60734
|
https://emacs.stackexchange.com/questions/60734
|
Creating backup and auto-save files that are not hidden
|
2020-09-19T08:45:35.950
|
# Question
Title: Creating backup and auto-save files that are not hidden
I use the following code for backup and auto-save files:
```
(setq delete-old-versions -1)
(setq version-control t)
(setq vc-make-backup-files t)
(setq backup-directory-alist `(("." . "h:/saves")))
(setq auto-save-file-name-transforms '((".*" "~/.auto-save-list/" t)))
```
The backup files created are all hidden. I would like to change that so that they are made in a non-hidden format.
An example is: `!drive_c!home!.emacs.d!recentf.~2~`
# Answer
What do you mean by the files being "hidden"? Hidden where, how?
You can specify the file names you want for backup files, if something is causing them to be somehow "hidden" based on their names (use different names). See the Emacs manual, node Backup Names.
And if you're talking about auto-save files, then see node Auto Save Files.
Backup files and auto-save files are not the same thing.
---
**Update after a comment by OP**
If this is about **Dired** hiding files, please specify just what you mean by hiding.
1. If this is about hiding by *omitting*, then customize option **`dired-omit-files`**. `C-h v` tells us:
> **`dired-omit-files`** is a variable defined in `dired-x.el`.
>
> Its value is `"^\\.?#\\|^\\.$\\|^\\.\\.$"`
>
> Documentation:
>
> Filenames matching this regexp will not be displayed.
>
> This only has effect when `dired-omit-mode` is `t`. See interactive function `dired-omit-mode` (`C-x M-o`) and variable `dired-omit-extensions`. The default is to omit `.`, `..`, auto-save files and lock files.
>
> You can customize this variable.
Note that my value of this option includes auto-save files (which end in `#`).
If this is about Dired showing **ignored** files differently, then customize option `completion-ignored-extensions`. `C-h v dired-ignored-face` tells us:
> **`dired-ignored-face`** is a variable defined in `dired.el`.
>
> Its value is `dired-ignored`
>
> Documentation:
>
> Face name used for files suffixed with `completion-ignored-extensions`.
And `C-h v completion-ignored-extensions` tells us this:
> **`completion-ignored-extensions`** is a variable defined in `C source code`.
>
> Its value is shown below.
>
> Documentation:
>
> Completion ignores file names ending in any string in this list.
>
> It does not ignore them if all possible completions end in one of these strings or when displaying a list of completions. It ignores directory names if they match any string in this list which ends in a slash.
>
> You can customize this variable.
>
> Value:
>
> ```
> (".o" "~" ".bin" ".bak" ".obj" ".map" ".ico" ".pif" ".lnk" ".a" ".ln"
> ".blg" ".bbl" ".dll" ".drv" ".vxd" ".386" ".elc" ".lof" ".glo" ".idx"
> ".lot" ".svn/" ".hg/" ".git/" ".bzr/" "CVS/" "_darcs/" "_MTN/" ".fmt"
> ".tfm" ".class" ".fas" ".lib" ".mem" ".x86f" ".sparcf" ".dfsl" ".pfsl"
> ".d64fsl" ".p64fsl" ".lx64fsl" ".lx32fsl" ".dx64fsl" ".dx32fsl"
> ".fx64fsl" ".fx32fsl" ".sx64fsl" ".sx32fsl" ".wx64fsl" ".wx32fsl"
> ".fasl" ".ufsl" ".fsl" ".dxl" ".lo" ".la" ".gmo" ".mo" ".toc" ".aux"
> ".cp" ".fn" ".ky" ".pg" ".tp" ".vr" ".cps" ".fns" ".kys" ".pgs" ".tps"
> ".vrs" ".pyc" ".pyo")
>
> ```
Your current value is likely different from mine. Notice that mine includes **`"~"`**, which means that backup files are highlighted as being "ignored" files.
> 2 votes
---
Tags: auto-save, backup
---
|
thread-60653
|
https://emacs.stackexchange.com/questions/60653
|
How to set automatic indentation to move past numbers on first line?
|
2020-09-14T19:56:15.257
|
# Question
Title: How to set automatic indentation to move past numbers on first line?
I'm using `auto-fill-mode` with `indented-text-mode` to write numbered lists. I'm trying to figure out how to persuade the automatic indentation to move past an item number on the first line. I'm working with `emacs -q` and I have `fill-column` set to 70 (the default). I'm editing this line:
```
2. Every value-projection function in `value.h` fails in the same way: by
```
When I place the cursor at the end of the line and hit the space bar, I am hoping for the buffer to become like this, where the second line is indented past the `2.`:
```
2. Every value-projection function in `value.h` fails in the same
way: by
```
But instead, the second line is indented to the 2:
```
2. Every value-projection function in `value.h` fails in the same
way: by
```
I have gotten as far as discovering the existence of `adaptive-fill-first-line-regexp`, but I have not figured out how to use it effectively---and I have a sneaking suspicion that it is actually intended to solve another problem.
How can I customize the automatic indentation to work the way I want?
# Answer
I customized variable `adaptive-fill-regexp` by adding `0-9.` to the big character class. We'll see how it works out, but preliminary results look promising.
> 1 votes
---
Tags: auto-fill-mode, adaptive-fill-mode
---
|
thread-55528
|
https://emacs.stackexchange.com/questions/55528
|
Make Emacs systemd service kill when logging out/shutting down
|
2020-02-14T12:31:38.757
|
# Question
Title: Make Emacs systemd service kill when logging out/shutting down
I am trying to use desktop-save-mode together with emacs daemon.
```
;; save desktop before quitting
(add-hook 'kill-emacs-hook (lambda () (desktop-save "~/.emacs.d/")))
```
But when I log out of the graphical session (KDE/SDDM) or shut down/reboot, emacs doesn't automatically save current desktop, and leaves .emacs.desktop.lock intact.
I thought about defining a shortcut that execute "(kill-emacs)" and then bring leaving options up, but then I have to exclusively use this one to shutdown, which is not good in case other methods are needed. Or bind (kill-emacs) to a key, but sometimes I only temporarily close Emacs using meta + f4 or C-x C-c, then quitting without remembering to save the desktop.
Currently, I'm struggling to modify a systemd service as Arch Wiki suggests:
```
[Service]
Type=simple
ExecStart=/usr/bin/emacs --fg-daemon
ExecStop=/usr/bin/emacsclient --eval "(kill-emacs)"
Environment=SSH_AUTH_SOCK=%t/keyring/ssh
Restart=on-failure
[Install]
WantedBy=default.target
```
But "ExecStop" is executed only when the service is manually stopped, leaving desktop unsaved after logging out.
Or perhaps is there a way to save desktop every time a buffer is close? I tried
```
(add-hook 'kill-buffer-hook (lambda () (desktop-save "~/.emacs.d/")))
```
but it didn't work.
# Answer
> 1 votes
I am not quite sure about this answer, so I originally want to post it as a comment, but as you see, I don't have enough reputation to add a comment, so I have to post it as an answer.
Remember that I have made other changes to my .emacs.d, so it is possible that my answer is totally wrong. If it doesn't work for you, you may follow this link.
I have run into similar case as yours. I run emacs as daemon using systemd. And when I poweroff, recentf can't be save, but when I stop daemon manually, it can. Then I found something I ignored here.
To save time, the core is that Emacs built with gtk support is not a good choice when using Emacs as a daemon, because there is some bug.
You can also see Emacs itself say something about this, if you journalctl it:
> 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.
So the point is clear now. Don't build your Emacs with gtk when using it as daemon.
For the solution, I think it may be interrelated to your distribution. As for me, on Gentoo, it is to enable useflag "motif" and disable useflag "athena" "gtk" "Xaw3d".
For others distribution, you may find it yourself.
The link I found say this:
> USE flags for toolkits gtk, motif, athena, and aqua are mutually exclusive. Generally, USE="gtk" is a good choice. However, if intending to use Emacs as a daemon, USE="motif -athena -gtk -Xaw3d" or USE="athena Xaw3d -gtk -motif" is recommended instead because of bug #292471. USE="athena Xaw3d" resembles USE="gtk" very well. USE="aqua" is a special case applying only to Mac OS X.
---
Tags: emacs-daemon, desktop, daemon
---
|
thread-16567
|
https://emacs.stackexchange.com/questions/16567
|
Emacs can't save history of recent visited files opened in current session before shutdown
|
2015-09-12T20:03:59.923
|
# Question
Title: Emacs can't save history of recent visited files opened in current session before shutdown
I have a problem with emacs started as daemon using Systemd.
Every shutdown/reboot if I don't stop emacs daemon service manually, the history of recent opened files in current session is lost. I think this is because of the Systemd that can't properly kill Emacs when in a shutdown state.
What can I do to solve this problem?
My recentf config in init.el:
```
(use-package recentf
:config (progn (setq recentf-auto-cleanup 'never
recentf-max-menu-items 50
recentf-max-saved-items 400
recentf-save-file
(expand-file-name "temp/.recentf" user-emacs-directory))
(recentf-mode t)))
```
Systemd emacs service config:
```
[Unit]
Description=Emacs: the extensible, self-documenting text editor
[Service]
Type=forking
ExecStart=/usr/bin/emacs --daemon
ExecStop=/usr/bin/emacsclient --eval "(kill-emacs)"
Restart=always
User=%i
#WorkingDirectory=%h
[Install]
WantedBy=multi-user.target
```
# Answer
> 5 votes
You can save recent files just before shutdown by calling `recentf-save-list`
```
M-x recentf-save-list RET
```
This adds your recent files to recentf history.
If you dont want to do this manually, you can add a timer which will do that for you every 5 minutes.
```
(run-at-time (current-time) 300 'recentf-save-list)
```
Add this to your config. So whenever you open emacs, it will call the function and every 5 minutes(or 300 seconds) it will go on calling that function.
Source: https://emacs.stackexchange.com/a/15115/5187
# Answer
> 3 votes
I know this thread is old, but i came across the same problem in MS Windows (i.e. Windows does know how to exit Emacs daemon gracefully). I solved this for me by hooking `recentf-save-list` into `terminal-delete-functions`. So in my init file I have the following line:
```
(add-hook 'delete-terminal-functions (lambda (terminal) (recentf-save-list)))
```
Then the `recentf-list` of the current session is saved whenever you close Emacs client. This was enough for me, because I am used to closing Emacs before shutting down my PC.
# Answer
> 1 votes
Another solution is to save the list of recentf files every time that you visit a new file. The below lined added to the init file will do the job:
```
(add-hook 'find-file-hook 'recentf-save-list)
```
# Answer
> 0 votes
I know it is too late, but I want to share it with you. This answer is first posted here, to save your time, I copy it there.
I am not quite sure about this answer, so I originally want to post it as a comment, but as you see, I don't have enough reputation to add a comment, so I have to post it as an answer.
Remember that I have made other changes to my .emacs.d, so it is possible that my answer is totally wrong. If it doesn't work for you, you may follow this link.
I have run into similar case as yours. I run emacs as daemon using systemd. And when I poweroff, recentf can't be save, but when I stop daemon manually, it can. Then I found something I ignored here.
To save time, the core is that Emacs built with gtk support is not a good choice when using Emacs as a daemon, because there is some bug.
You can also see Emacs itself say something about this, if you journalctl it:
> 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.
So the point is clear now. Don't build your Emacs with gtk when using it as daemon.
For the solution, I think it may be interrelated to your distribution. As for me, on Gentoo, it is to enable useflag "motif" and disable useflag "athena" "gtk" "Xaw3d".
For others distribution, you may find it yourself.
The link I found say this:
> USE flags for toolkits gtk, motif, athena, and aqua are mutually exclusive. Generally, USE="gtk" is a good choice. However, if intending to use Emacs as a daemon, USE="motif -athena -gtk -Xaw3d" or USE="athena Xaw3d -gtk -motif" is recommended instead because of bug #292471. USE="athena Xaw3d" resembles USE="gtk" very well. USE="aqua" is a special case applying only to Mac OS X.
---
Tags: emacsclient, linux, recentf
---
|
thread-59748
|
https://emacs.stackexchange.com/questions/59748
|
Adding Spacemacs documented layers fails
|
2020-07-20T14:27:40.913
|
# Question
Title: Adding Spacemacs documented layers fails
Adding layers existing in the layer section of the .spacemacs documentation results in failed test in the *dot-test-results* buffer generated after reloading the .spacemacs file (with `SPC-f-e-R`).
increminated layers were : neotree ;; for filetree
notmuch ;; for emails
parinfer ;; clojure / lisp paren inference
pdf ;; pdf visualisation
prettier
The * spacemacs\* welcome screens gets some warnings but couldn't find any other error messages to help debug :
```
Warnings:
- Unknown layer neotree declared in dotfile.
- Unknown layer notmuch declared in dotfile.
- Unknown layer parinfer declared in dotfile.
- Unknown layer pdf declared in dotfile.
- Unknown layer prettier declared in dotfile.
- package twittering-mode not initialized in layer keyboard-layout, you
may consider removing this package from the package list or use the :toggle
keyword instead of a `when' form.
- package linum not initialized in layer nlinum, you may consider removing
this package from the package list or use the :toggle keyword instead of a `when' form.
- package linum-relative not initialized in layer nlinum, you may consider
removing this package from the package list or use the :toggle keyword
instead of a `when' form.
- More than one init function found for package helm-make. Previous owner was ivy,
replacing it with layer helm.
- More than one init function found for package smex. Previous owner was ivy,
replacing it with layer smex.
- package evil-nerd-commenter not initialized in layer evil-commentary, you may
consider removing this package from the package list or use the :toggle keyword
instead of a `when' form.
- package vi-tilde-fringe not initialized in layer vim-empty-lines, you may
consider removing this package from the package list or use the :toggle keyword
instead of a `when' form.
- tern binary not found!
```
my config : OS: mac osX Catalina 10.15.5
emacs : GNU Emacs 26.3 (build 1, x86\_64-apple-darwin18.5.0, Carbon Version 158 AppKit 1671.4) fetch with `brew install emacs-plus@26` IIRW
spacemacs à jour (latest)
271 packages loaded in 18.794s (e:202 r:2 l:18 b:49)
(this seems slow, may be because of spaceline-all-the-icons)
My .spacemacs is still a work in progress and thus not in a github repo yet so I attached a gist link below.
Thanks for any hits on how to get thos layers working.
Best Samusz
.spacemacs file: https://gist.github.com/samusz/2cfb1ced064276be06eee4488cc86788
```
```
# Answer
Found the issue for me... https://github.com/syl20bnr/spacemacs/issues/10840
It seems `pdf` used to be called `pdf-tools`. So I changed it to `pdf-tools` and it seems to work now.
---
**UPDATE:** *I was previously using the latest `master` but it looks like `master` is very old compared to `develop`. The latest release at the time **0.200** is even older. I've now moved branch to `develop` and the code seems to match the online documentation a lot better. It looks like the long time between releases has caused the documentation to diverge significantly from the latest release*
*So this is something else to check if you have this issue. It will hopefully get better when the upcoming **0.300.x** is released?*
> 1 votes
---
Tags: spacemacs, config
---
|
thread-60760
|
https://emacs.stackexchange.com/questions/60760
|
org-babel: Make results always quote the returned value in #+begin_example
|
2020-09-20T16:47:41.460
|
# Question
Title: org-babel: Make results always quote the returned value in #+begin_example
Github's org parser has a bug where they mistakenly show
```
#+begin_src bsh.dash :results verbatim :exports both
echo | time possiblycat 1000
#+end_src
#+RESULTS:
:
: possiblycat 1000 0.00s user 0.00s system 75% cpu 0.006 total; max RSS 1852
```
as
(I have reported this on Github.)
I want to workaround this by quoting the result:
```
#+RESULTS:
#+begin_example
...
#+end_example
```
How can I do this automatically?
# Answer
The `org-babel-min-lines-for-block-output` variable will help you accomplish this.
I've set the following in my configuration files in order to make `#+RESULTS` code blocks be always enclosed within `#+begin_example` blocks
```
(setq org-babel-min-lines-for-block-output 0)
```
Here's an example
```
#+begin_src cpp
#include <iostream>
int main() {
std::cout << "a";
return 0;
}
#+end_src
#+RESULTS:
#+begin_example
a
#+end_example
```
> 4 votes
# Answer
I found the answer:
```
#+begin_src bsh.dash :results verbatim :exports both :wrap "example"
echo | time possiblycat 1000
#+end_src
#+RESULTS:
#+begin_example
possiblycat 1000 0.00s user 0.00s system 68% cpu 0.005 total; max RSS 1888
#+end_example
```
> 6 votes
---
Tags: org-mode, org-babel, github
---
|
thread-60765
|
https://emacs.stackexchange.com/questions/60765
|
org-mode How to use latex nested environments?
|
2020-09-20T19:00:23.290
|
# Question
Title: org-mode How to use latex nested environments?
I want to use a `matrix` environment that is included in an outer environment, so:
```
Environment:
\begin{equation*}
\left|
\begin{matrix}
a_1 & b_1\\
a_2 & b_2
\end{matrix}
\right|
\end{equation*}
Display--math:
\[
\left|
\begin{matrix}
a_1 & b_1\\
a_2 & b_2
\end{matrix}
\right|
\]
Inline--math:
\(
\left|
\begin{matrix}
a_1 & b_1\\
a_2 & b_2
\end{matrix}
\right|
\)
```
But for the second and third cases (display-math and inline-math) the preview and export to latex are failed:
exported LaTeX:
```
Environment:
\begin{equation*}
\left|
\begin{matrix}
a_1 & b_1\\
a_2 & b_2
\end{matrix}
\right|
\end{equation*}
Display--math:
$\backslash$[
\left|
\begin{matrix}
a_1 & b_1\\
a_2 & b_2
\end{matrix}
\right|
$\backslash$]
Inline--math:
$\backslash$(
\left|
\begin{matrix}
a_1 & b_1\\
a_2 & b_2
\end{matrix}
\right|
$\backslash$)
\end{document}
```
org-mode preview:
Emacs 26.3
Org-mode 9.3.8
# Answer
So, this is not a bug:
nested `\begin{...}` should not start the line and therefore is not seen as starting a new LaTeX block:
```
Inline-math:
\(
\left|\begin{matrix}
a_1 & b_1\\
a_2 & b_2
\end{matrix}\right|
\)
```
> 2 votes
---
Tags: org-mode, org-export, latex, preview-latex
---
|
thread-60762
|
https://emacs.stackexchange.com/questions/60762
|
Make python code blocks format their results as Org tables
|
2020-09-20T17:00:33.823
|
# Question
Title: Make python code blocks format their results as Org tables
# The context
In `#+BEGIN_SRC` code blocks whose language is `cpp` or `sh`, the tab character is used as a delimiter for cells when using the `:results table` header argument (see examples below)
```
#+begin_src cpp :results replace output table
#include <iostream>
int main() {
std::cout << "a\ta\nbbbbb\tbbbbb" << std::endl;
return 0;
}
#+end_src
#+RESULTS:
| a | a |
| bbbbb | bbbbb |
```
```
#+begin_src sh :results replace output table
printf "%s\t%s\n" "a" "a" "bbbbbb" "bbbbbb"
#+end_src
#+RESULTS:
| a | a |
| bbbbbb | bbbbbb |
```
However, this same behavior is not present in `python` code blocks (see below)
```
#+begin_src python :results replace output table
print("a\ta\nbbbbb\tbbbbb")
#+end_src
#+RESULTS:
: a a
: bbbbb bbbbb
```
# The question
How can I make the output of `python` code blocks be displayed as Org tables. Isn't using those header arguments and make the output contain tab characters enough for the `#+RESULTS` to be formatted as an Org table?
# Answer
You can output formatted org tables by returning a list of lists as follows (notice no :results output):
```
#+begin_src python :results replace table
return (('a', 'a'), None, ('bbbbb', 'bbbbb'))
#+end_src
#+RESULTS:
| a | a |
|-------+-------|
| bbbbb | bbbbb |
```
a None row creates a separator line.
Here are some other examples using `:results output`
```
#+BEGIN_SRC python :results output table
print([['Number', 'Number * 10'], None, [1, 10], [2, 20]])
#+END_SRC
#+RESULTS:
| Number | Number * 10 |
|--------+-------------|
| 1 | 10 |
| 2 | 20 |
```
```
#+BEGIN_SRC python :results value table
return [['Number', 'Number * 10'], None, [1, 10], [2, 20]]
#+END_SRC
#+RESULTS:
| Number | Number * 10 |
|--------+-------------|
| 1 | 10 |
| 2 | 20 |
```
Note that when using `:results output`, a single `print` is included in the `#+RESULTS` code block.
```
#+BEGIN_SRC python :results output table
for i in range(5):
print([i, i**10])
#+END_SRC
#+RESULTS:
| 0 | 0 |
```
> 11 votes
---
Tags: org-mode, org-babel
---
|
thread-60769
|
https://emacs.stackexchange.com/questions/60769
|
Configure Flymake for proselint
|
2020-09-21T09:29:58.990
|
# Question
Title: Configure Flymake for proselint
proselint is a prose linter which returns error/warning messages like this:
```
2020-09-09-still-processing.md:18:14: typography.symbols.curly_quotes Use curly quotes “”, not straight quotes "".
```
I know there is a proselint checker in Flycheck, but I am trying to configure Flymake. For this task, I am using flymake-easy like this:
```
(defconst flymake-proselint-err-line-patterns
'(("^\\(.*\.md\\):\\([0-9]+\\):\\([0-9]+\\): \\(.*\\)$" 1 2 3 4)))
(defvar flymake-proselint-executable "proselint"
"The proselint executable to use for syntax checking.")
(defun flymake-proselint-command (filename)
"Construct a command that flymake can use to check Markdown in FILENAME."
(list flymake-proselint-executable filename))
(defun flymake-proselint-load ()
"Configure flymake mode to check the current buffer's ruby syntax."
(interactive)
(flymake-easy-load 'flymake-proselint-command
flymake-proselint-err-line-patterns
'tempdir
"md"))
(defun flymake-proselint-maybe-load ()
"Call `flymake-proselint-load' if this file appears to be Markdown."
(interactive)
(if (and buffer-file-name
(string= "md" (file-name-extension buffer-file-name)))
(flymake-proselint-load)))
```
I added `flymake-proselint-maybe-load` to `markdown-mode-hook` but `flymake-show-diagnostics-buffer` shows an empty buffer instead of the above-mentioned message from `proselint`.
My guess is I am setting `flymake-proselint-err-line-patterns`, but I am not sure if this is the problem.
# Answer
> 2 votes
I took another approach, using flymake-quickdef, so as to leverage `flymake-diagnostic-functions`:
```
(require 'flymake-quickdef)
(flymake-quickdef-backend
flymake-proselint-backend
:pre-let ((proselint-exec (executable-find "proselint")))
:pre-check (unless proselint-exec (error "proselint not found on PATH"))
:write-type 'pipe
:proc-form (list proselint-exec "-")
:search-regexp "^.+:\\([[:digit:]]+\\):\\([[:digit:]]+\\): \\(.+\\)$"
:prep-diagnostic
(let* ((lnum (string-to-number (match-string 1)))
(lcol (string-to-number (match-string 2)))
(msg (match-string 3))
(pos (flymake-diag-region fmqd-source lnum lcol))
(beg (car pos))
(end (cdr pos)))
(list fmqd-source beg end :warning msg)))
(defun flymake-proselint-setup ()
"Enable flymake backend."
(add-hook 'flymake-diagnostic-functions #'flymake-proselint-backend nil t))
```
Then it's just a matter of adding `flymake-proselint-setup` to `markdown-mode-hook`:
```
(add-hook 'markdown-mode-hook #'flymake-proselint-setup)
```
---
Tags: flymake
---
|
thread-60768
|
https://emacs.stackexchange.com/questions/60768
|
Cannot make `compile-command` buffer local
|
2020-09-21T09:22:21.103
|
# Question
Title: Cannot make `compile-command` buffer local
I've tried making `compile-command` buffer-local via
```
(defun compilation-make-locals (process)
(set (make-local-variable 'compile-command)
compile-command))
(add-hook 'compilation-start-hook 'compilation-make-locals)
```
but without success.
The variable `compile-command` is not updated the to latest value when I interactively set a new command when doing `M-x compile`.
# Answer
> ```
> (set (make-local-variable 'compile-command)
> compile-command))
>
> ```
The latter `compile-command` is evaluated after `(make-local-variable 'compile-command)` so this should be a no-op -- you're making the variable buffer-local, and then setting the buffer-local value to whatever the buffer-local value already was.
---
I'm unsure what you are *wanting* to happen here, though. What would "the latest value" be?
If it's the *global* value that you're wanting to copy to the buffer-local value, then you can obtain that with `(default-value 'compile-command)`
In the case where the buffer had a pre-existing buffer-local value, there may well be a difference between that and the global value.
> 1 votes
---
Tags: compilation, compile
---
|
thread-59930
|
https://emacs.stackexchange.com/questions/59930
|
Highlight parentesis in latex
|
2020-08-02T11:37:18.223
|
# Question
Title: Highlight parentesis in latex
the image is self explanatory, I recently switched to doom emacs and I'm still learning.
How can I fix this problem? I tried to switch off anything related to checkers in the init.el file but it doesn't help.
The problem is that rainbow-delimiters is recognizing (0,1\] as a "not matching parenthesis" in latex environment, so it is highlighting everything from that point on. Now I really tried to disable the whole package in doom-emacs but I failed. It can easily toggled off with M-x rainbow-delimiters , but I want it disabled by default
# Answer
I encountered the same problem. As suggested by @einfeyn496 you can use `M-x describe-mode` to find the problematic mode. In this case the offending party is rainbow-delimiters-mode. Simply disable it with `M-x rainbow-delimiters-mode` and the highlighted brackets will no longer show.
> 1 votes
---
Tags: latex, highlighting
---
|
thread-60778
|
https://emacs.stackexchange.com/questions/60778
|
Make output of source code blocks be inserted regardless of the exit status of the evaluation
|
2020-09-21T18:22:40.060
|
# Question
Title: Make output of source code blocks be inserted regardless of the exit status of the evaluation
# The context
When evaluating the following code block, the output is not inserted in the `#+RESULTS` code block. This happens because of the `return 1` statement.
```
#+begin_src cpp :results output
#include <stdexcept>
#include <iostream>
int main()
try {
throw std::runtime_error("A runtime error ocurred");
return 0;
}
catch(std::runtime_error& e) {
std::cout << "runtime_error: " << e.what() << '\n';
return 1;
}
#+end_src
#+RESULTS:
```
If I replace `1` with `0`, then the output is indeed shown in the `#+RESULTS` code block
```
#+RESULTS:
#+begin_example
runtime_error: A runtime error ocurred
#+end_example
```
# Additional context
Note that this behavior is also present in `#+begin_src` whose language is `sh`. Here's a minimal working example: Evaluating the following code block would result in
```
#+begin_src sh
f() {
return 1
}
printf "%s" "a"
f
#+end_src
#+RESULTS:
```
If the return value of the `f` function is changed to `0`, then the output of the `printf` is shown
```
#+begin_src sh
f() {
return 0
}
printf "%s" "a"
f
#+end_src
#+RESULTS:
#+begin_example
a
#+end_example
```
# The question
How can I make the output of the evaluated code block be inserted in its corresponding `#+RESULTS` code block regardless of the exit status of the evaluation?
# Answer
Hmm, the Org documentation isn't very clear on the intended behavior here. I'm looking at the Results of Evalution page.
But the workhorse function org-babel-eval is clear in its docstring that results only come back if the command succeeds. If the command fails, stdout is not returned and instead stderr is displayed in an error buffer.
`org-babel-eval` doesn't provide an easy way to change this behavior, so unfortunately I think the only way to get what you want right now is to redefine the function. A change to the following code at the end of the function seems to work on my setup:
```
(if (or (not (numberp exit-code)) (> exit-code 0))
(progn
... error processing stuff ...
nil) ; <-- replace nil with (buffer-string) and reevaluate the function
(buffer-string)))))
```
I don't work with babel enough to have strong feelings about the code, but you might want to raise a thread on the Org mailing list about your workflow and see if other folks would prefer this change as well.
> 2 votes
---
Tags: org-mode, org-babel, c++
---
|
thread-60779
|
https://emacs.stackexchange.com/questions/60779
|
How to delete all buffers in shell mode quickly
|
2020-09-21T19:47:33.553
|
# Question
Title: How to delete all buffers in shell mode quickly
Emacs 26.1
First I create several buffers in shell mode.
Then I open `ibuffer` (`C-x C-b`) and mark all shell buffers manually by pressing `D` to delete them.
It works, but it's very slow. Is there a quicker method for deleting all buffers in shell mode?
# Answer
A slightly quicker way that still uses IBuffer, is (from IBuffer) to use `% m shell` to mark all of the buffers in shell mode, and then press `D` to delete then all in one go. Depending on what other modes you've got open you might get away with using "sh" instead of shell. I use variations on this quite a lot to kill the many Ag and Dired buffers that I seem to typically end up with.
> 3 votes
# Answer
You may want to look into the customizable var `ibuffer-saved-filter-groups`, to sort your buffers into groupings based on mode (or any other criteria). Then you can mark a group at once by marking its heading. Right now, they're all in one group `[Default]`, but you could easily have `[Shells]`, etc.
> 2 votes
---
Tags: ibuffer
---
|
thread-60791
|
https://emacs.stackexchange.com/questions/60791
|
How can I prevent orgmode re-sorting all my headings when I enter a `.org` file? Org startup variables are ignored
|
2020-09-22T15:00:26.353
|
# Question
Title: How can I prevent orgmode re-sorting all my headings when I enter a `.org` file? Org startup variables are ignored
While trying to solve this problem, Iv'e followed this, running `cd ~/.emacs.d/elpa && find org*/*.elc -print0 | xargs -0 rm` and recompiling elpa. But the undesired behaviour is still there and now this error shows up:
```
File mode specification error: (wrong-number-of-arguments #[(arg &optional invisible-ok) \306=\203\0 \306=\204\0\307 \210\310
!\210 \211\311X\203 \0\312\313!\210\311V\203]\0
\314V\203]\0o\204]\0\211W\204S\0o\204S\0
\203G\0\315 \210\202K\0\316\311!\210 \211\2024\0)
S\202 \0)\317!\207 [this-command last-command invisible-ok outline-level start-level arg outline-up-heading push-mark outline-back-to-heading 1 error Already at top level of the outline 0 outline-previous-heading outline-previous-visible-heading looking-at level outline-regexp] 3 (/usr/share/emacs/26.3/lisp/outline.elc . 34670) p] 0)
```
How can I make org-mode open files in a folded state and not try to sort my headings when I open new files?
Using spacemacs 0.200.13 @ emacs 26.3. the relevant variables/settings are:
```
;; Org mode settings
(defun org-sort-headings-todo-prio ()
"sort org headings first by priority then by todo order"
(interactive)
(org-sort-entries t ?p )
(outline-up-heading)
(org-sort-entries t ?o ))
(setq org-image-actual-width 400
org-startup-with-inline-images t
org-directory "~/path/to/folder/"
org-default-notes-file (concat org-directory "organizer.org")
org-startup-folded t)
(add-hook 'org-mode-hook
(lambda ()
(yas-minor-mode)
(make-variable-buffer-local 'yas/trigger-key)
(setq yas/trigger-key [tab])
(add-to-list 'org-tab-first-hook 'yas/org-very-safe-expand)
(define-key yas/keymap [tab] 'yas/next-field)
(flycheck-mode 1)
(flyspell-mode-on)
(org-autolist-mode)
(org-bullets-mode)
(local-set-key (kbd "C-c C-x s") (org-sort-headings-todo-prio))))
(global-set-key (kbd "C-c o") (lambda () (interactive) (find-file org-default-notes-file)))
(global-set-key [c-x c-c c-r] 'org-preview-latex-default-process)
(global-set-key (kbd "C-c c") 'org-capture)
```
the whole config file can be seen here (just without the variable definitions at the end)
# Answer
The problem is apparently linked to the manner in which `local-set-key` is being used in conjunction with the `org-mode-hook`; i.e., `(local-set-key (kbd "C-c C-x s") (org-sort-headings-todo-prio))`
Emacs is being told to call the function `org-sort-headings-todo-prio` when running the `org-mode-hook`, instead of assigning `org-sort-headings-todo-prio` to a shortcut key. Try something like this instead:
```
(local-set-key (kbd "C-c C-x s") 'org-sort-headings-todo-prio)
```
> 1 votes
---
Tags: org-mode
---
|
thread-60732
|
https://emacs.stackexchange.com/questions/60732
|
How to add picture before a title in HTML exported by OrgMode
|
2020-09-19T03:39:23.200
|
# Question
Title: How to add picture before a title in HTML exported by OrgMode
I am writing an article in org mode to be exported to HTML for being published on the web. By looking at the documentation, I have not been able to find a way to insert an image *before* the title of the article.
So for instance, I would like my page to look like this (the black border indicates the computer screen)
How do I do this? Do I add some header information? Currently my header in the org file looks like this.
```
#+TITLE: Hello World
#+AUTHOR: A.U.Thor
#+EMAIL: hello.world@NOSPAM.outlook.com
#+HTML_HEAD: <link rel="stylesheet" type="text/css" href="style.css" />
#+OPTIONS: num:nil
```
Maybe the solution to this is to use CSS, by specifying that a certain figure element comes before the title? I am not very good at CSS but this is my best guess. Maybe the ORG guys have already developed some native (and easily remembered) syntax for this?
# Answer
> 1 votes
### Add `file:some-directory/image1.png` into `#+TITLE:`
I use this technique for exporting to HTML and for rendering org-mode pages in GitLab.
e.g.
```
#+TITLE: file:some-directory/image1.png My Long Title Preceded by Many Spaces
```
which exports to html
```
<title><img src="some-directory/image1.png" alt="image1.png"> My Long Title Preceded by Many Spaces</title>
```
Thanks for asking your question!
---
> **This answer was validated using:**
> **emacs version:** GNU Emacs 25.2.1
> **org-version:** 9.1.2
# Answer
> 2 votes
In addition to the answer of Melioratus which I accepted, I also noticed that I can embed native HTML code in the title via the inline HTML mechanism of org mode.
So for instance, this also works and allows me to add extra attributes like width and height.
```
#+TITLE: @@html:<img src="file:///home/pictures/bird.svg" alt="" / width="150px">@@ Hello World
```
This is more flexible but much cruftier than the neat syntax suggested by Melioratus that should work for most cases.
---
Tags: org-mode, html
---
|
thread-60787
|
https://emacs.stackexchange.com/questions/60787
|
Does org-mode support callouts like asciidoc?
|
2020-09-22T09:13:22.253
|
# Question
Title: Does org-mode support callouts like asciidoc?
I wonder if org-mode has a feature like asciidoc callouts, and if so what is the syntax?
Below is a explanation on what the callouts are and how it all looks when rendered
Thanks
# Answer
> 7 votes
Org Mode does support callouts. The documentation for it is hidden in the Literate Examples section of the manual, but does in fact apply to source code blocks.
Unlike AsciiDoc, Org Mode with Org Babel keeps the code and the documentation cleanly separated.
The example below uses Org Babel to generate a Ruby code file using the `:tangle` keyword. The Org export functions will generate HTML, much as AsciiDoc does.
Use the `(ref:name)` syntax to make callouts. The documentation can appear anywhere outside the code blocks. You can create the links easily using `C-c C-l` or `M-x org-insert-link`
The `-r` option in the code block strips the (ref:name) comments from the tangled source code.
The `-n` option adds line numbers when exporting.
```
* My example
#+begin_src ruby -r -n :tangle mysample.rb
puts 'Hi!' # (ref:puts)
print 'ram:' # (ref:print)
name = gets.chomp # (ref:gets)
puts "Hi! #{name}" # (ref:deref)
#+end_src
Code explanation:
+ [[(puts)]] puts the string to stdout
+ Remember the [[(print)][print]] function does not output a newline
+ In line #3, [[(gets)][gets]] reads from =stdin=
+ Finally, [[(deref)][#{name}]] replaces the variable =name= with its value
```
When you export the above Org Mode file to HTML and open it in a browser using the export dispatcher (\`C-c C-e h o) you can hover over the links to highlight the relevant code line.
---
Tags: org-mode
---
|
thread-54446
|
https://emacs.stackexchange.com/questions/54446
|
How to make flycheck checker 'ruby-rubocop' use 'bundle exec rubocop' as executable?
|
2019-12-18T17:33:41.563
|
# Question
Title: How to make flycheck checker 'ruby-rubocop' use 'bundle exec rubocop' as executable?
I want `ruby-rubocop` Flycheck syntax checker to execute `bundle exec rubocop` instead of just `rubocop`.
What I've tried:
1. `(setq flycheck-ruby-rubocop-executable "bundle exec rubocop")`
Results in following error:
```
Error while checking syntax automatically: (error "Output file descriptor of flycheck-ruby-rubocop is closed")
```
2. `(flycheck-set-checker-executable 'ruby-rubocop "bundle exec rubocop")`
I get error:
```
user-error: bundle exec rubocop is no executable
```
3. This answer:
```
(setq flycheck-command-wrapper-function
(lambda (command)
(append '("bundle" "exec") command)))
```
It broke all checkers, because now it appends "bundle exec" to all checkers, not only ruby-rubocop, and it didn't work in ruby buffer (it still used `rubocop` without `bundle exec`). I don't know how to make this variable buffer-local.
# Answer
> 4 votes
Use `setq-local` to make a variable buffer-local. It works well in a hook like this:
```
(add-hook 'ruby-mode-hook
(lambda ()
(setq-local flycheck-command-wrapper-function
(lambda (command) (append '("bundle" "exec") command)))))
```
# Answer
> 3 votes
I'll let someone else clear that issue up for Flycheck.
But for completeness' sake: if you install Emacs 27 (or newer) and enable `flymake-mode` in Ruby buffers, Rubocop integration is there, and it appends `"bundle exec"` when appropriate.
---
Tags: flycheck, ruby
---
|
thread-58552
|
https://emacs.stackexchange.com/questions/58552
|
unread-command-events and batch mode
|
2020-05-16T19:51:24.043
|
# Question
Title: unread-command-events and batch mode
I'm writing tests for an interactive function. I've been using the `unread-command-events` variable in conjunction with `call-interactively` to verify that it does the right thing.
However, I just discovered that this doesn't work in batch mode.
For example:
```
(defun my-dummy (s)
(interactive "sWrite something: ")
s)
(ert-deftest my-dummy-test ()
(let ((unread-command-events (listify-key-sequence "Hi!\n")))
(should (equal (call-interactively #'my-dummy)
"Hi!"))))
```
When running `ert` in interactive mode, this works. However, in batch mode, Emacs stops and read the keyboard without consuming input from `unread-command-events`.
In this a bug in batch mode or is this the expected behaviour?
Is there any other way to do this in batch mode?
# Answer
This is expected behavior, but you can circumvent this problem by let-binding `executing-kbd-macro` to `t`, which will convince the minibuffer commands to read from `unread-command-events` rather than from stdin.
> 1 votes
---
Tags: interactive, testing, events
---
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.