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-61152
|
https://emacs.stackexchange.com/questions/61152
|
How to configure printing?
|
2020-10-12T13:57:03.123
|
# Question
Title: How to configure printing?
I'm trying to get to grips with printing from emacs.
I've added the following to my .emacs file:
```
(add-to-list 'lpr-switches "-P HP_ENVY_Photo_6200_series_685E88_")
(add-to-list 'lpr-switches "-o sides=two-sided-long-edge")
(add-to-list 'lpr-switches "-o number-up=2")
```
When I try to print (so far I've only tried with M-x print-region), the following is written to * Messages * (after a prompt about printing to the default destination):
> Spooling with options -P HP\_ENVY\_Photo\_6200\_series\_685E88\_... user-error: Spooling with options -P HP\_ENVY\_Photo\_6200\_series\_685E88\_...done: /usr/bin/lpr: No such file or directory
If I cut the displayed command and paste it to the command line, prefixed by `lpr` and suffixed by a space and the name of an existing file, that file is printed without problem, which makes me think that I haven't mistyped the over-long printer name. What's going wrong?
I'm running Linux Mint Ulyana 20 and GNU Emacs 26.3 (build 2, x86\_64-pc-linux-gnu, GTK+ Version 3.24.14) of 2020-03-26, modified by Debian
## UPDATE
From * Help * in response to C-h v exec-path
> exec-path is a variable defined in ‘C source code’. Its value is ("/opt/Qt/Tools/QtCreator/bin" "/opt/chromedriver" "/opt/fossil" "/opt/ActiveTcl-8.6/bin" "/usr/local/sbin" "/usr/local/bin" "/usr/sbin" "/usr/bin" "/sbin" "/bin" "/usr/games" "/usr/local/games" "/snap/bin" "/usr/lib/emacs/26.3/x86\_64-linux-gnu")
From the command line:
> $ which lpr
> /usr/bin/lpr
# Answer
> 1 votes
`lpr-switches` is a list of arguments. So think of them as each element of the list being implicitly quoted. E.g.:
```
(setq lpr-switches
(append '("-P" "HP_ENVY_Photo_6200_series_685E88_"
"-o" "sides=two-sided-long-edge"
"-o" "number-up=2")
lpr-switches))
```
---
Tags: print
---
|
thread-61028
|
https://emacs.stackexchange.com/questions/61028
|
(Sudden) Weird behavior of M-q in auctex
|
2020-10-07T02:45:31.633
|
# Question
Title: (Sudden) Weird behavior of M-q in auctex
I very much enjoying using the auto fill functionality that the key binding `M-q` provides. However, starting recently, I am experiencing a small (but annoying) change in its behavior when in LaTeX mode. That is, now I have to explicitly mark the paragraph that I want to auto fill, whereas before it was good enough as long as the cursor is somewhere in the paragraph. For example, to format
```
Hello
World
```
to
```
Hello World
```
it was enough to hit `M-q` with my cursor somewhere in those two lines. Now I have to mark the two lines and then hit `M-q` to get the reformatting. I haven't installed anything new or touched my configuration file. I did update Emacs a couple days ago. Any advice will be greatly appreciated.
# Answer
> 1 votes
Entries in `LaTeX-indent-environment-list` control the filling behavior in environments. If you want the standard filling AUCTeX applies to environments, remove entries for your `appendices` from it and `M-q` should work again.
The `appendices` environment is provided by LaTeX package `appendix.sty`. In order to get auto-completion for it when you hit `C-c C-e`, you need a small AUCTeX style `appendix.el` which makes the addition to AUCTeX. Such a style can look like this:
```
(TeX-add-style-hook
"appendix"
(lambda ()
(TeX-add-symbols
"appendixpage"
"addappheadtotoc"
"noappendicestocpagenum"
"appendicestocpagenum"
"appendixname"
"appendixtocname"
"appendixpagename"
"appendixtocon"
"appendixtocoff"
"appendixpageon"
"appendixpageoff"
"appendixtitleon"
"appendixtitleoff"
"appendixtitletocon"
"appendixtitletocoff"
"appendixheaderon"
"appendixheaderoff"
"restoreapp"
"setthesection"
"setthesubsection")
(LaTeX-add-environments
'("appendices")
'("subappendices"))
;; Don't indent the content inside \(sub\)?appendices environments:
(unless (string-match "appendices" LaTeX-document-regexp)
(set (make-local-variable 'LaTeX-document-regexp)
(concat LaTeX-document-regexp "\\|\\(?:sub\\)?appendices"))))
LaTeX-dialect)
(defvar LaTeX-appendix-package-options '("toc" "page" "title"
"titletoc" "header")
"Package options for the appendix package.")
```
Set the variable `TeX-style-private` to a directory of your choice, e.g.
```
(setq TeX-style-private
'("~/.emacs.d/auctex-styles"))
```
and save the code above there as `appendix.el`. Now re-start Emacs and open your .tex file. If you have this in your init file as well
```
(setq TeX-parse-self t)
```
the auto-completion should be available directly.
---
Tags: auctex, formatting, fill-paragraph, auto-fill-mode
---
|
thread-61141
|
https://emacs.stackexchange.com/questions/61141
|
Why is my Imenu not showing function and class definitions?
|
2020-10-11T23:07:19.460
|
# Question
Title: Why is my Imenu not showing function and class definitions?
I feel like something is wrong with my Imenu setup, because here is what it shows on a simple Python script:
It seems to show some variable definitions, but doesn't have separate entries for the function definitions (the `def ...` lines), or the classes. What I want is an Imenu that shows just the function and class definitions, in the order in which they appear. So, I want to see something like:
```
Function: foo(x)
Class: Bar
Function: Bar / __init__(s)
Function: Bar / buz(x, y)
```
Is that possible at all? Semantic is not an option because it does not parse functions that are typed using Python's type annotations (e.g. a function like `def foo() -> None: ...` does not appear in the list).
# Answer
> 2 votes
For any imenu problem, check the buffer's how-to-generate-imenu status (which is usually modified by major-mode, sometimes also some minor modes), mostly variable `imenu-create-index-function` and `imenu-generic-expression`:
* if `imenu-create-index-function` is `imenu-default-create-index-function`, which is Emacs default, the imenu is generated by running the regexps in `imenu-generic-expression` against buffer content, then you only need to tweak the regexps.
* if `imenu-create-index-function` is NOT `imenu-default-create-index-function`, then you need to dive into the actual value of `imenu-create-index-function` (which is a function, probably written and set by major mode) to see what's actually going wrong.
# Answer
> 0 votes
This is lsp-mode issue, which was reported and closed as wont fix. I have a better idea of how to fix it, so you may open issue lsp-mode bug tracker.
---
Tags: python, imenu
---
|
thread-58387
|
https://emacs.stackexchange.com/questions/58387
|
bibtex customize sort-field in bibtex-entry-format
|
2020-05-09T07:50:49.680
|
# Question
Title: bibtex customize sort-field in bibtex-entry-format
I am trying to customize the behavior of `M-x bibtex-entry-format` function to reformat a bibtex entry in a bib file.
I want that the various fields in an entry are sorted to a given ordering. In my emacs init file I put this:
```
(setq bibtex-entry-format
`(page-dashes required-fields
numerical-fields whitespace last-comma delimiters
unify-case sort-fields))
```
so it applies `sort-fields` to its default behavior, however, I want to customize it. How can I set my `sort-field` own criteria?
# Answer
> 1 votes
Not tested, but looking at the docstring of `bibtex-entry-format`, it says:
> `bibtex-entry-format` is a variable defined in `bibtex.el`. Its value is
> `(opts-or-alts required-fields numerical-fields)`
>
> Documentation:
> Type of formatting performed by `bibtex-clean-entry`.
> It may be t, nil, or a list of symbols out of the following:
> ...
> `sort-fields` Sort fields to match the field order in `bibtex-BibTeX-entry-alist`.
My understanding is that you have to tweak `bibtex-BibTeX-entry-alist` and adapt it to your needs.
---
Tags: formatting, bibtex, reftex-mode
---
|
thread-60598
|
https://emacs.stackexchange.com/questions/60598
|
how to extract options I saved with customize and insert it inside use-package lines?
|
2020-09-11T05:53:58.133
|
# Question
Title: how to extract options I saved with customize and insert it inside use-package lines?
Suppose I did some customization through M-x `customize-mode` or something similar
```
'(org-agenda-custom-commands
'(("n" "Agenda and all TODOs"
((agenda "" nil)
(alltodo "" nil))
nil)
("i" "Urgent things" tags "URGENT" nil)))
```
they are inserted inside `(custom-set-variables`
Can I just cut the lines and put them inside
`(use-package org` ?
Actually do I need to? I thought it would be aethetically pleasing to see well cleaned up init.el file..
# Answer
> 0 votes
It's a matter of preference (or aesthetics) but if you are making frequent changes you'll appreciate having all the settings in one place. Using use-package can be helpful for keeping similar configs together and being explicit about how keyconfigs, hooks and dependencies (etc) are related to a package.
If you change something with the customize interface, you can just move it into your `init.el` file as needed.
With `use-package` you could try something like...
```
(use-package org
:config (setq org-agenda-custom-commands ...
```
# Answer
> 0 votes
> I thought it would be aethetically pleasing to see well cleaned up init.el file
Yes, and in my case I don't use the customize UI at all, all my config is out of the `custom-set-variables` region. `custom-set-variables` only contains assignments written by the packages I use.
If your `custom-set-variables` region is still in your init file, you may want to move it to another file, copying from my config copied from Purcell's config:
```
(setq custom-file (expand-file-name "custom.el" user-emacs-directory))
(unless (file-exists-p custom-file)
(write-region "" nil custom-file))
(when (file-exists-p custom-file)
(load custom-file))
```
One thing to note is that `custom-set-variables` can trigger the custom `set` behavior written by the package author, while `setq` cannot. Such behavior is defined in `:set` when using `defcustom` (read the doc of `defcustom` for more). use-package's `:custom`, obviously does trigger that, as its name states.
---
Tags: customize, use-package
---
|
thread-61132
|
https://emacs.stackexchange.com/questions/61132
|
How do I auto save evil buffers for specific file types?
|
2020-10-11T13:47:00.430
|
# Question
Title: How do I auto save evil buffers for specific file types?
I'm a new Doom Emacs user that can't get used to having to save files manually.
I found a way to auto save evil buffers, but the problem with this approach is that I'm not able step out of vterm (an Emacs terminal emulator) without Emacs prompting me to save the vterm buffer, which obviously doesn't make any sense.
```
(add-hook 'evil-insert-state-exit-hook
(lambda ()
(call-interactively #'save-buffer)))
```
I was thinking maybe I could save specific file types only, so Emacs doesn't try to save the vterm buffer, how would I modify the above elisp to auto save files only for specific file types?
# Answer
> 1 votes
You may want to try the package super-save, which auto saves files when idle or Emacs lose focus.
My own auto save function saving when idle or lose focus, built from Emacs built-ins (github link in case I'm missing anything):
```
(defvar jester-auto-save-idle 1 "Time in seconds before auto-saving all buffers.")
(run-with-idle-timer jester-auto-save-idle t #'jester/save-all-buffers)
;; (cancel-function-timers 'jester/save-all-buffers) ; for debugging
(add-hook 'focus-out-hook #'jester/save-all-buffers)
(defun jester/save-all-buffers ()
"Save all buffers."
;; yas overlay and company-select-next has problem with this.
(when (and (not yas--active-snippets)
(not company-candidates)
(not (eq major-mode 'snippet-mode)))
;; https://github.com/manateelazycat/lazycat-emacs/commit/da13a688ef89f8ab2c577a3e9d2a7bcf0ef9b71d
;; https://emacs-china.org/t/topic/7687/30?u=jjpandari
;; this prevents blink of eldoc
(with-temp-message
(with-current-buffer " *Minibuf-0*" (buffer-string))
;; this prevents blink of ivy
(let ((inhibit-message t))
(save-some-buffers t #'(lambda () (and (buffer-file-name) (buffer-modified-p))))))))
```
# Answer
> 1 votes
Emacs has some built in functionality for this already, so there is no need to write your own function. In case you do want to use your function, I would suggest adding a check for 'prog-mode. Programming modes should all be derived from prog-mode, so:
```
(when (derived-mode-p 'prog-mode)
;; Do stuff
)
```
or, to include text-mode (org-mode, md, etc.):
```
(when (or (derived-mode-p 'prog-mode)
(derived-mode-p 'text-mode))
;; Do stuff)
```
The built in way (I would recommend this) is using `auto-save-mode`. Let's say you're working on `test.py`; auto-save-mode will automatically save a copy of the buffer as `#test.py#` which will then be removed when you manually save the file. To auto save over `test.py` directly, use `auto-save-visited-mode`.
Something like this will work:
```
(add-hook 'prog-mode-hook
(auto-save-visited-mode))
```
---
Tags: evil, auto-save, doom
---
|
thread-61169
|
https://emacs.stackexchange.com/questions/61169
|
How do i remove the title of a specific org file in the agenda view?
|
2020-10-13T16:31:49.013
|
# Question
Title: How do i remove the title of a specific org file in the agenda view?
As it is now, i have my school schedule in an org file. When I use the agenda view, it says "Schedule" (the file name) in front of the schedule entries. I believe that it would look cleaner to remove the file name for that specific file in the agenda view but I can't figure it out.
# Answer
> 1 votes
In spite of appearances, that is not the file name: that is the `category`. You can set the category to something different (including the empty string), by adding a `#+CATEGORY` keyword at the beginning of your file. To set it to the emptry string, just say
```
#+CATEGORY:
```
See Categories in the manual.
`CATEGORY` can also be set at the header level via the `PROPERTIES` drawer, e.g.
```
* Foo
:PROPERTIES:
:CATEGORY: Bar
:END:
```
---
Tags: org-mode, org-agenda
---
|
thread-61174
|
https://emacs.stackexchange.com/questions/61174
|
Open current file in Vim
|
2020-10-13T20:16:21.183
|
# Question
Title: Open current file in Vim
I've got this from EmacsWiki:
```
(defun my/open-current-file-in-vim ()
(interactive)
(async-shell-command
(format "gvim +%d %s"
(+ (if (bolp) 1 0) (count-lines 1 (point)))
(shell-quote-argument buffer-file-name))))
```
I've tried replacing `gvim` with `vim` but it opens Vim within Emacs. Is it possible to open Vim in external terminal and not show `*Async Shell Command*` buffer at all?
# Answer
> 2 votes
Yes, just adjust the shell command string to actually invoke your terminal emulator. For example with xterm:
```
(defun my/open-current-file-in-vim ()
(interactive)
(async-shell-command
(format "xterm -e gvim +%d %s"
(+ (if (bolp) 1 0) (count-lines 1 (point)))
(shell-quote-argument buffer-file-name))))
```
---
Tags: shell-command
---
|
thread-61172
|
https://emacs.stackexchange.com/questions/61172
|
How to make dabbrev support CamelCase or a better auto-completion in java buffers
|
2020-10-13T17:55:35.870
|
# Question
Title: How to make dabbrev support CamelCase or a better auto-completion in java buffers
I use dabbrev as my auto-complete function (and since most of what I code is snake\_case it works well). However, I'm now doing a Java project and everything is CamelCase. How do I make dabbrev support CamelCase? Or is there a different auto-complete function I should be using in .java buffers?
In particular, if the text dabbrev is copying is in some form of CamelCase e.g.
```
GenericValue genericValue = new Ge...
```
and I type M-/ where the ... is, I'd like it to expand the rest of the text in CamelCase without touching the case of the letters currently typed and thus correctly cased. thus geM-/ -\> genericValue and GeM-/ -\> GenericValue.
I am willing to try another function to see if it works better. And, if I have to hack dabbrev, I can do that too.
# Answer
Since you seem to use dabbrev without `company` setting following 2 variables, could help:
```
(setq dabbrev-case-fold-search nil
dabbrev-case-replace nil)
```
To see documentation and other possible settings you could use:
```
M-x customize-group <RET> dabbrev <RET>
```
---
An alternative to dabbrev would be `hippie-expand`
> 3 votes
---
Tags: dabbrev
---
|
thread-61038
|
https://emacs.stackexchange.com/questions/61038
|
How does scoping work in emacs lisp
|
2020-10-07T13:10:03.747
|
# Question
Title: How does scoping work in emacs lisp
A lot of emacs configurations shared publicly have this format:
```
;; 01-something.el
(provide 'something)
;; init.el
(require 'something)
```
Suppose I'm writing a defun named "s-join" inside 01-something.el
Suppose somewhere during init.el initialization, magit.el loads up `s.el` \- the popular string utility package, which also has a defun named "s-join"
So now, in any given context, how do I know what gets executed when I do
```
(s-join)
```
?
# Answer
All functions and variables defined in a file that gets loaded are put into the global environment. Although Emacs has installable packages, those packages are not isolated from each other in any way. If two files define functions or variables with the same name then you'll get a warning when the second one is loaded.
You can find out where a function was defined by asking for help on the function with `C-h f`. It will prompt you for a function name. If the text at point looks like a valid lisp identifier, and a function by that name exists, that identifier will be the default value for the prompt. `C-h v` will do the same for variables. `C-h F` prompts for a function name and takes you to the info page where that function is documented, which may include more detailed information.
> 5 votes
# Answer
In Elisp, all functions names normaly (but not necessarily) reside as an entry in a global environment (obarray). In Elisp functions can be redefined. Which means the function definition which has been evaled (or loaded) last will be the only one, which is known and used.
This way you can change functions in your init file, you just need to be sure your function definition is evaled after the function you want to change.
But beware! If the original function changes in behavior or parameters, yours is not changing automatic, and so dependend functions could fail or misbehave.
---
Replying to those comments below, on how to avoid failure of using source code.
1. you should choose a function name which is unique to your own function to prevent this (i.e. prefix your function name)
2. you could write a guard around your function, to prevent your function definition overwriting some existing function (this does not help if your function gets overwritten, see next point)
```
(unless (fboundp 's-join)
(defun s-join ()
...))
```
3. you could use an `advice` at your function, and there check for characteristics of your function (i.e. parameters, or first sexp in body, etc.) IMO advices stay put even when the function gets redefined.
> 1 votes
# Answer
OP seems to be missing the point already clearly made in the two answers given: you *cannot* do what you are asking. Emacs uses a voluntary naming convention, not syntax or compilation rules, to define namespaces. It may sound like a recipe for chaos, but in practice it works very well.
What you are doing when you name your function `s-join` is (effectively) stealing the `s` package's namespace-identifying prefix, in breach of the convention. Don't do that. Name your function `anw/join-strings` or similar, as suggested above.
If you really, really need to temporarily replace an existing function, you can use `cl-flet` or `cl-labels`. See the Info node for the CL package.
> 1 votes
---
Tags: help, lexical-scoping, defun, dynamic-scoping, scope
---
|
thread-38252
|
https://emacs.stackexchange.com/questions/38252
|
`<dead-grave> is undefined`
|
2018-01-21T20:21:06.530
|
# Question
Title: `<dead-grave> is undefined`
for a few month, I use Emacs for Latex, and I am French.
today (for the first time) when I use `C-c `` to see my errors, Emacs answers
`<dead-grave> is undefined`
I try to add in my .emacs
`(global-set-key (kbd "<dead-grave>") "``")` (only one dead grave
And I also try `(require 'iso-transl)`
It doesn't work !
What can I do ? thank you for your help
# Answer
> 1 votes
I had the same problem.
First what you can do is set an alias for `emacs` in you `~/.bashrc` like so:
```
alias emacs="env XMODIFIERS= emacs"
```
This will fix it when you start emacs, but it won't fix it if you start it from clicking on a file, so what you can do if you have Ubuntu is:
```
cp /usr/share/applications/emacs25.desktop ~/.local/share/applications/emacs25.desktop
```
Then edit your new `emacs25.desktop` file to start a script instead of the actual emacs application:
```
[Desktop Entry]
Version=1.0
Name=GNU Emacs 25 (GUI)
GenericName=Text Editor
Comment=GNU Emacs is an extensible, customizable text editor - and more
MimeType=text/english;text/plain;text/x-makefile;text/x-c++hdr;text/x-c++src;text/x-chdr;text/x-csrc;text/x-java;text/x-moc;text/x-pascal;text/x-tcl;text/x-tex;application/x-shellscript;text/x-c;text/x-c++;
TryExec=/home/you/.local/share/applications/emacs.sh
Exec=/home/you/.local/share/applications/emacs.sh %F
Icon=emacs25
Type=Application
Terminal=false
Categories=Utility;Development;TextEditor;
StartupWMClass=Emacs
Keywords=Text;Editor;
```
And finally you create a script in the same folder `emacs.sh` to start emacs with your custom parameters:
```
#! /usr/bin/env sh
env XMODIFIERS= emacs "$@"
```
It might say that the shortcut isn't trusted, that can be fixed by `chmod +x emacs25.desktop` and don't forget to `chmod +x emacs.sh` also!
Hope this helps ;)
---
Tags: key-bindings, latex, debugging
---
|
thread-45494
|
https://emacs.stackexchange.com/questions/45494
|
Magit status is slow on Linux insided virtual machine but fast on native MacOS
|
2018-10-21T23:20:09.540
|
# Question
Title: Magit status is slow on Linux insided virtual machine but fast on native MacOS
In OSX El Capitan, I am using Magit 20171026.217, Git 2.10.1 (Apple Git-78), Emacs 25.1.1, darwin.
In CentOS Release 6.6, I'm using Magit 20180903.2339, Git 2.13.1, Emacs 26.1, gnu/linux.
For the same 40 MByte git repo, the magit status buffer requires 4 seconds to appear in linux but only 0.5 seconds in Mac OS. There was a one-line change in one file in the linux repo.
In CentOS, my .emacs contains the following commands from the magit performance page and elsewhere:
```
;; https://magit.vc/manual/magit/Performance.html
(setq magit-refresh-status-buffer nil)
(setq magit-diff-highlight-indentation nil)
(setq magit-diff-highlight-trailing nil)
(setq magit-diff-paint-whitespace nil)
(setq magit-diff-highlight-hunk-body nil)
(setq magit-diff-refine-hunk nil)
(setq magit-revision-insert-related-refs nil)
(remove-hook 'magit-refs-sections-hook 'magit-insert-tags)
(remove-hook 'server-switch-hook 'magit-commit-diff)
(setq vc-handled-backends nil)
(setq auto-revert-buffer-list-filter
'magit-auto-revert-repository-buffers-p)
;; https://williambert.online/2015/11/How-I-made-Magit-fast-again/
(setq magit-commit-show-diff nil)
(setq magit-revert-buffers 1)
(setq magit-refresh-verbose 1)
```
I used this code to profile magit-status on linux and macOS:
```
(defun profile-magit ()
(elp-instrument-package "magit")
(elp-reset-all)
(magit-status "pathToRepo")
(elp-results))
(profile-magit)
```
The results are shown below, first for CentOS (bad) and then for MacOS (great).
Any suggestions on speeding up the CentOS performance are greatly appreciated.
PROFILING RESULTS ON CENTOS (very slow):
```
magit-status 1 4.637725058 4.637725058
magit-run-section-hook 2 4.633367778 2.316683889
magit-process-file 26 4.408109038 0.1695426553
magit-status-internal 1 4.3173727809 4.3173727809
magit-mode-setup 1 4.317356942 4.317356942
magit-mode-setup-internal 1 4.31735279 4.31735279
magit-refresh-buffer 1 3.95782774 3.95782774
magit-status-refresh-buffer 1 3.957227878 3.957227878
magit-git-insert 13 2.124903824 0.1634541403
magit-git-str 23 1.4826771669 0.0644642246
magit-insert-status-headers 1 1.127880501 1.127880501
magit-rev-parse-safe 20 1.093782861 0.0546891430
magit-insert-unpushed-to-upstream-or-recent 1 1.082952769 1.082952769
magit-git-string 14 1.0594253679 0.0756732405
magit-insert-headers 1 0.982247303 0.982247303
magit-git-wash 4 0.82460503 0.2061512575
magit-insert-recent-commits 1 0.783410273 0.783410273
magit-insert-log 2 0.63769903 0.318849515
magit-rev-verify 4 0.601661585 0.1504153962
magit-git-exit-code 3 0.6005712080 0.2001904026
magit-rev-parse 3 0.4716020800 0.1572006933
magit-log-wash-log 1 0.46797409 0.46797409
magit-insert-tags-header 1 0.389292032 0.389292032
magit-git-items 2 0.386998803 0.1934994015
magit-insert-staged-changes 1 0.359801993 0.359801993
magit-abbrev-length 1 0.31824761 0.31824761
magit-toplevel 21 0.317811276 0.0151338702
magit-insert-unpulled-from-upstream 1 0.314986998 0.314986998
magit-insert-head-branch-header 1 0.302152539 0.302152539
magit-git-success 2 0.294809955 0.1474049775
magit-rev-format 2 0.293499864 0.146749932
magit-insert-upstream-branch-header 1 0.29064293 0.29064293
magit-insert-untracked-files 1 0.242863067 0.242863067
magit-display-buffer 1 0.212477492 0.212477492
magit-bare-repo-p 1 0.201640107 0.201640107
magit-rev-parse-true 1 0.201567176 0.201567176
magit-git-true 1 0.201562606 0.201562606
magit-git-output 1 0.201557613 0.201557613
magit-get-current-tag 2 0.196021831 0.0980109155
magit-get-next-tag 1 0.193064518 0.193064518
magit-insert-unstaged-changes 1 0.187144843 0.187144843
magit-git-dir 11 0.1754272640 0.0159479330
magit-insert-merge-log 1 0.174901715 0.174901715
magit-merge-in-progress-p 1 0.174897354 0.174897354
magit-insert-stashes 1 0.159585508 0.159585508
magit-wash-sequence 3 0.1505684099 0.0501894699
magit-log-wash-rev 10 0.149665603 0.0149665603
magit-get-current-branch 8 0.1476631309 0.0184578913
magit-format-ref-labels 10 0.147321033 0.0147321032
magit-status-mode 1 0.146352289 0.146352289
magit-rev-ancestor-p 1 0.146086039 0.146086039
magit-get-all 18 0.145360679 0.0080755932
magit-config-get-from-cached-list 19 0.145263918 0.0076454693
magit-load-config-extensions 1 0.144793241 0.144793241
magit-display-buffer-traditional 1 0.107423347 0.107423347
magit-section-ident 147 0.0021125400 1.437...e-05
magit-mode 1 0.000829181 0.000829181
magit-diff-wash-diffs 1 0.000642034 0.000642034
magit-get 17 0.0006312269 3.713...e-05
magit--safe-default-directory 9 0.0006285869 6.984...e-05
magit-section 19 0.0006018359 3.167...e-05
magit-diff-wash-diff 1 0.000599268 0.000599268
magit-section-cached-visibility 22 0.000589903 2.681...e-05
magit-insert-heading 7 0.00055112 7.873...e-05
magit-diff-insert-file-section 1 0.000520999 0.000520999
magit-maybe-make-margin-overlay 9 0.00050706 5.634...e-05
magit-file-accessible-directory-p 9 0.000468549 5.2061e-05
magit-section-match 10 0.0004680669 4.680...e-05
magit-maybe-save-repository-buffers 1 0.000440343 0.000440343
magit-save-repository-buffers 1 0.000433461 0.000433461
magit-get-push-branch 5 0.000421858 8.43716e-05
magit-get-section 22 0.000419913 1.908...e-05
magit-process-environment 26 0.0003858840 1.484...e-05
magit-section-match-1 51 0.0003856660 7.562...e-06
magit-get-push-remote 5 0.0003759310 7.518...e-05
magit-rebase-in-progress-p 2 0.000323864 0.000161932
magit-section-show 7 0.000277453 3.963...e-05
magit-diff-wash-hunk 1 0.00026903 0.00026903
magit-insert-rebase-sequence 1 0.000250239 0.000250239
magit-insert-sequencer-sequence 1 0.00024326 0.00024326
magit-log-format-margin 10 0.0002284770 2.284...e-05
magit-mode-get-buffer 1 0.000188089 0.000188089
magit-get-upstream-branch 2 0.000178769 8.93845e-05
magit-bisect-in-progress-p 3 0.0001767080 5.890...e-05
magit--process-coding-system 26 0.0001568349 6.032...e-06
magit-insert-child-count 20 0.000139597 6.979...e-06
magit-diff-expansion-threshold 22 0.000138593 6.299...e-06
magit-insert-bisect-output 1 0.000132705 0.000132705
magit-process-git-arguments 26 0.000132603 5.100...e-06
magit-cherry-pick-in-progress-p 1 0.000122953 0.000122953
magit-insert-am-sequence 1 0.000115193 0.000115193
magit-revert-in-progress-p 1 0.000114903 0.000114903
magit-am-in-progress-p 1 0.000111797 0.000111797
magit-insert-unpushed-to-pushremote 1 0.00010976 0.00010976
magit-section-update-highlight 1 0.000108693 0.000108693
magit-section-match-assoc 5 0.000100528 2.01056e-05
magit-expand-git-file-name 11 9.6376e-05 8.761...e-06
magit-insert-push-branch-header 1 9.618e-05 9.618e-05
magit-make-margin-overlay 16 9.1406e-05 5.712875e-06
magit-delete-line 15 8.555...e-05 5.703...e-06
magit-preserve-section-visibility-cache 19 7.8316e-05 4.121...e-06
magit-insert-unpulled-from-pushremote 1 7.3261e-05 7.3261e-05
magit-file-section-p 22 7.145...e-05 3.248...e-06
magit-file-section 2 6.5891e-05 3.29455e-05
magit--age 10 6.1487e-05 6.1487e-06
magit--assert-default-directory 1 6.0568e-05 6.0568e-05
magit-section-match-2 45 4.7839e-05 1.063...e-06
magit-log-propertize-keywords 12 4.7763e-05 3.980...e-06
magit-diff-highlight 1 4.1871e-05 4.1871e-05
magit-section-goto-successor 1 3.9938e-05 3.9938e-05
magit-set-buffer-margin 1 3.2258e-05 3.2258e-05
magit-insert-bisect-rest 1 2.7742e-05 2.7742e-05
magit-hunk-section 1 2.7432e-05 2.7432e-05
magit-section-hide 2 2.6654e-05 1.3327e-05
magit-insert-bisect-log 1 2.4944e-05 2.4944e-05
magit-refresh-get-relative-position 1 2.3263e-05 2.3263e-05
magit-section-maybe-cache-visibility 9 2.139...e-05 2.377...e-06
magit-get-boolean 1 1.782e-05 1.782e-05
magit-margin-option 11 1.307...e-05 1.188...e-06
magit-process-unset-mode-line-error-status 1 1.2741e-05 1.2741e-05
magit-ignore-submodules-p 2 1.253e-05 6.265e-06
magit-diff-scope 1 1.0888e-05 1.0888e-05
magit-insert-diff-filter-header 1 1.0598e-05 1.0598e-05
magit-repository-local-get 1 9.41e-06 9.41e-06
magit-section-highlight 1 9.284e-06 9.284e-06
magit-current-section 5 8.803...e-06 1.760...e-06
magit-set-window-margin 1 7.655e-06 7.655e-06
magit-save-window-configuration 1 7.348e-06 7.348e-06
magit-diff-type 1 6.795e-06 6.795e-06
magit-maybe-set-dedicated 1 6.511e-06 6.511e-06
magit-repository-local-exists-p 1 5.645e-06 5.645e-06
magit-auto-revert-mode-enable-in-buffers 1 5.231e-06 5.231e-06
magit-log-margin-width 1 5.01e-06 5.01e-06
magit--tramp-asserts 1 4.475e-06 4.475e-06
magit-hunk-section-p 1 4.097e-06 4.097e-06
magit-section-make-overlay 1 2.431e-06 2.431e-06
magit-region-sections 1 2.136e-06 2.136e-06
magit-auto-revert-mode-cmhh 1 2.103e-06 2.103e-06
magit-decode-git-path 2 2.044...e-06 1.022...e-06
magit-repository-local-repository 1 1.555e-06 1.555e-06
magit-xref-setup 1 1.51e-06 1.51e-06
magit-insert-error-header 1 1.505e-06 1.505e-06
magit-turn-on-auto-revert-mode-if-desired 1 1.046e-06 1.046e-06
magit-file-mode-turn-on 1 9.83e-07 9.83e-07
magit-buffer-margin-p 1 9.05e-07 9.05e-07
magit-cancel-section 2 0.0 0.0
```
PROFILING RESULTS ON MACOS (very fast):
```
magit-status 1 0.584569 0.584569
magit-process-file 26 0.5628430000 0.0216478076
magit-status-internal 1 0.510929 0.510929
magit-mode-setup 1 0.510912 0.510912
magit-mode-setup-internal 1 0.510904 0.510904
magit-refresh-buffer 1 0.485749 0.485749
magit-status-refresh-buffer 1 0.484318 0.484318
magit-run-section-hook 1 0.430791 0.430791
magit-git-insert 13 0.2643129999 0.0203317692
magit-git-str 24 0.2187900000 0.0091162500
magit-insert-status-headers 1 0.160217 0.160217
magit-rev-parse-safe 20 0.15506 0.007753
magit-insert-headers 1 0.139779 0.139779
magit-insert-head-branch-header 1 0.139406 0.139406
magit-git-string 12 0.134189 0.0111824166
magit-insert-unpushed-to-upstream-or-recent 1 0.109471 0.109471
magit-insert-recent-commits 1 0.082984 0.082984
magit-git-exit-code 3 0.082196 0.0273986666
magit-insert-remaining-headers 1 0.07875 0.07875
magit-toplevel 17 0.0727460000 0.0042791764
magit-rev-verify 4 0.0676649999 0.0169162499
magit-insert-log 2 0.066954 0.033477
magit-git-wash 4 0.06692 0.01673
magit-git-items 2 0.064539 0.0322695
magit-rev-format 2 0.056975 0.0284875
magit-log-wash-log 1 0.04906 0.04906
magit-insert-tags-header 1 0.048515 0.048515
magit-rev-parse 3 0.045511 0.0151703333
magit-insert-untracked-files 1 0.043747 0.043747
magit-abbrev-length 1 0.032661 0.032661
magit-insert-unpulled-from-upstream 1 0.032577 0.032577
magit-insert-staged-changes 1 0.031339 0.031339
magit-insert-upstream-branch-header 1 0.03007 0.03007
magit-git-success 2 0.0290969999 0.0145484999
magit-get-current-tag 2 0.028617 0.0143085
magit-status-mode 1 0.022703 0.022703
magit-get-all 14 0.0214800000 0.0015342857
magit-config-get-from-cached-list 15 0.0213949999 0.0014263333
magit-load-config-extensions 1 0.021059 0.021059
magit-get-next-tag 1 0.019779 0.019779
magit-insert-unstaged-changes 1 0.019263 0.019263
magit-get-current-branch 6 0.017693 0.0029488333
magit-git-dir 11 0.017037 0.0015488181
magit-insert-merge-log 1 0.016681 0.016681
magit-wash-sequence 1 0.016351 0.016351
magit-insert-stashes 1 0.016344 0.016344
magit-log-wash-rev 11 0.016312 0.0014829090
magit-bare-repo-p 1 0.016012 0.016012
magit-rev-parse-p 1 0.015726 0.015726
magit-git-true 1 0.01572 0.01572
magit-format-ref-labels 11 0.014966 0.0013605454
magit-rev-ancestor-p 1 0.013539 0.013539
magit-maybe-save-repository-buffers 1 0.001332 0.001332
magit-save-repository-buffers 1 0.001325 0.001325
magit-mode 1 0.001204 0.001204
magit--safe-default-directory 9 0.001082 0.0001202222
magit-file-accessible-directory-p 9 0.0009219999 0.0001024444
magit-display-buffer 1 0.000802 0.000802
magit-rebase-in-progress-p 2 0.00054 0.00027
magit-get 13 0.0004720000 3.630...e-05
magit-insert-heading 5 0.000455 9.1e-05
magit-display-buffer-traditional 1 0.0004 0.0004
magit-format-ref-label 14 0.0003319999 2.371...e-05
magit-insert-rebase-sequence 1 0.000295 0.000295
magit-section-show 16 0.000288 1.8e-05
magit-get-push-branch 3 0.000285 9.499...e-05
magit-insert-sequencer-sequence 1 0.000253 0.000253
magit-log-format-margin 11 0.000248 2.254...e-05
magit-maybe-make-margin-overlay 6 0.000239 3.983...e-05
magit-get-push-remote 3 0.000234 7.8e-05
magit-mode-get-buffer 1 0.000201 0.000201
magit-section-match-1 32 0.000183 5.71875e-06
magit-file-lines 1 0.000176 0.000176
magit-section-match 7 0.000175 2.5e-05
magit-bisect-in-progress-p 3 0.000173 5.766...e-05
magit-get-upstream-branch 2 0.000171 8.55e-05
magit-section-ident 65 0.0001589999 2.446...e-06
magit-cherry-pick-in-progress-p 1 0.000135 0.000135
magit-section-set-visibility-from-cache 19 0.0001229999 6.473...e-06
magit-process-git-arguments 26 0.0001229999 4.730...e-06
magit-insert-bisect-output 1 0.000119 0.000119
magit-insert-unpulled-from-pushremote 1 0.000117 0.000117
magit-insert-am-sequence 1 0.000117 0.000117
magit-revert-in-progress-p 1 0.000113 0.000113
magit-am-in-progress-p 1 0.000113 0.000113
magit-insert-unpushed-to-pushremote 1 0.000106 0.000106
magit--process-coding-system 26 9.300...e-05 3.576...e-06
magit-insert-push-branch-header 1 9.2e-05 9.2e-05
magit-make-margin-overlay 17 8.9e-05 5.235...e-06
magit-delete-line 11 8.300...e-05 7.545...e-06
magit-section-update-highlight 1 7.5e-05 7.5e-05
magit-section-visibility-ident 35 6.999...e-05 1.999...e-06
magit-get-section 20 6.8e-05 3.4e-06
magit-expand-git-file-name 11 5.900...e-05 5.363...e-06
magit-diff-highlight 1 5.1e-05 5.1e-05
magit--age 11 5e-05 4.545...e-06
magit-cygwin-env-vars 26 4.699...e-05 1.807...e-06
magit-section-update-visibility-cache 16 4.499...e-05 2.812...e-06
magit-diff-expansion-threshold 19 3.799...e-05 2e-06
magit-set-buffer-margin 1 3.6e-05 3.6e-05
magit-insert-bisect-log 1 3.1e-05 3.1e-05
magit-insert-bisect-rest 1 3e-05 3e-05
magit-margin-option 12 1.9e-05 1.583...e-06
magit-diff-scope 1 1.7e-05 1.7e-05
magit-log-propertize-keywords 11 1.600...e-05 1.454...e-06
magit-auto-revert-mode-enable-in-buffers 1 1.5e-05 1.5e-05
magit-save-window-configuration 1 1.5e-05 1.5e-05
magit-get-boolean 1 1.5e-05 1.5e-05
magit-current-section 5 1.400...e-05 2.800...e-06
magit-section-match-2 29 1.4e-05 4.827...e-07
magit-section-goto-successor 1 1.4e-05 1.4e-05
magit-insert-child-count 16 1.100...e-05 6.875...e-07
magit-section-highlight 1 1.1e-05 1.1e-05
magit-set-window-margin 1 9e-06 9e-06
magit-refresh-get-relative-position 1 8e-06 8e-06
magit-auto-revert-mode-cmhh 1 5e-06 5e-06
magit-log-margin-width 1 4e-06 4e-06
magit-insert-error-header 1 2e-06 2e-06
magit-maybe-set-dedicated 1 2e-06 2e-06
magit-buffer-margin-p 1 2e-06 2e-06
magit-section-make-overlay 1 2e-06 2e-06
magit-diff-type 1 2e-06 2e-06
magit--tramp-asserts 1 2e-06 2e-06
magit-region-sections 1 1e-06 1e-06
magit-turn-on-auto-revert-mode-if-desired 1 1e-06 1e-06
magit-diff-use-hunk-region-p 1 1e-06 1e-06
magit-insert-diff-filter-header 1 1e-06 1e-06
magit-xref-setup 1 1e-06 1e-06
magit-cancel-section 3 0.0 0.0
```
# Answer
> 2 votes
The opposite of your problem used to be a common problem: Magit was slow on macOS but fast on a proper Unix. That issue was due to an Emacs bug and updating to Emacs 26.1 fixes it.
There are many differences between the two "situations". The only way to figure out which of these differences makes the difference is to eliminate the differences one by on.
I understand you might not be inclined to update the Magit used in the fast situation as that might very well result in that becoming slow too. But that would be a good thing because then we would know that there is some performance regression and could rule out the other potential issues.
You might want to create a copy of `~/.emacs.d/elpa/` (or just the relevant packages) and then reinstall all packages. That way you could go back to the known good version if it so happens that there indeed is a performance regression.
---
As far as I can gather from a distance, the problem is the virtual machine. That doesn't *have* to be slow; other users have reported that running Magit in a virtual machine is *faster* than running natively on Windows for example. So it probably is something specific to the virtual machine that you are using, such as the file system you use inside that. I cannot help with that though, as I likely know less about it than you do.
# Answer
> 0 votes
Have you figure out the reason? I met with similar problem, and I found that it is because git is slow on my server. A single git command may take tens of millisecond on Mac OS, but it may take hundreds of millisecond on the server. This difference is negligible using command line, but Magit may execute a lot of git commands and you can notice the difference.
I recompiled git and installed it in my local directory and the problem is solved.
---
Tags: magit
---
|
thread-61186
|
https://emacs.stackexchange.com/questions/61186
|
View a history of commands
|
2020-10-14T09:16:45.193
|
# Question
Title: View a history of commands
While in web-mode, when I type `{{` emacs will add `}}` to the end, and when I press `SPC` it will then add another `}}` to the end with a space either side and one extra space to the right, so it looks like this `{{ | }}}}`. Apparently there are two commands that are working together to "help" me, I want to disable one of them.
I am trying to find the source of the problem, so is there a way I can view the commands that caused this issue so I can fix it myself?
I am using Doom Emacs
# Answer
Type `C-h``l` to run `view-lossage` which will show you the last several keystrokes, and which commands they are bound to in the current buffer (which *might* not be the same as the commands they were bound to in the buffer which was active when they keys were typed -- only the keystrokes themselves are actually recorded).
n.b. Older Emacsen will display *only* the key sequences.
> 2 votes
---
Tags: commands, doom
---
|
thread-61189
|
https://emacs.stackexchange.com/questions/61189
|
Org macros misbehave in include file
|
2020-10-14T11:23:22.160
|
# Question
Title: Org macros misbehave in include file
I am using org-reveal for presentation
It has a `#+BEGIN_NOTES` for creating speaker notes
Tried to shorten with this macro `n` following this suggestion
```
#+MACRO: n (eval "\n#+BEGIN_NOTES\n$1\n#+END_NOTES\n")
```
It works if I use `{{{n(some notes)}}}` in a single file
But if the file `#+Include:` some other file I get strange errors on export:
```
eval: Wrong number of arguments: eval, 5
```
This is org mode version 8.3beta
When I switched to 9.3.8 I got an eval error in the outside file itself
And org 9.4 doesnt load at all so I assumed its too bleeding edge and hurriedly went back
Yeah my emacs is a bit old: 24.5.1; can't afford an upgrade at this point
---
# Added later in response to @NickD
I tried digging... And found that
`org-export-expand-as` doesn't seem to be used in org-reveal.
So I did the following
* Moved the macro out from the org into lisp and removed the `eval`
```
(setq org-export-global-macros '(("n" . "\n#+BEGIN_NOTES\n$1\n#+END_NOTES\n")))
```
* Ran
```
M-: (org-export-expand-include-keyword)
M-: (org-macro-replace-all org-export-global-macros)
```
After this reveal exporter works
Unfortunately my simplistic try at automating the above doesnt work
```
(defun mymacro-expand ()
(widen)
(let ((c (buffer-substring-no-properties (point-min) (point-max))))
(with-temp-file "ttt.org"
(insert c)
(org-export-expand-include-keyword)
(org-macro-replace-all org-export-global-macros))
))
```
3. I guess I should file a org-reveal bug report
But if you can suggest an alternative to above using org-expand-as that'd be great!
---
# Addition 2
Downloaded and compiled emacs
Now its at version 28.0.50
Org version 9.4
It now seems that the `$1` inside the string breaks whereas the `format` version doesn't.
Error message is `eval: Wrong number of arguments: eval, 4`
Can you try with these two files?
```
$ cat foo.org
#+TITLE: Some title
#+MACRO: n (eval "\n#+BEGIN_NOTES\n$1\n#+END_NOTES\n")
* Outside heading
#+Include: bar.org
$ cat bar.org
* Inside heading
Some text
{{{n(internal note)}}}
Some more text
```
# Answer
The following seems to work on fairly recent Org mode and Emacs: Org mode version 9.4 (release\_9.4-3-ge6021b @ /home/nick/elisp/org-mode/lisp/) - GNU Emacs 28.0.50 (build 1, x86\_64-pc-linux-gnu, GTK+ Version 2.24.32, cairo version 1.16.0) of 2020-06-15).
* foo.org:
```
#+MACRO: n (eval (format "\n#+BEGIN_NOTES\n%s\n#+END_NOTES\n" $1))
* Link
https://emacs.stackexchange.com/questions/61189/org-macros-misbehave-in-include-file
* foo
#+include: bar.org
{{{n(foo)}}}
```
* bar.org:
```
{{{n(bar)}}}
```
Result of exporting `foo.org`to LaTeX is:
```
% Created 2020-10-14 Wed 09:30
% Intended LaTeX compiler: pdflatex
\documentclass[11pt]{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{graphicx}
\usepackage{grffile}
\usepackage{longtable}
\usepackage{wrapfig}
\usepackage{rotating}
\usepackage[normalem]{ulem}
\usepackage{amsmath}
\usepackage{textcomp}
\usepackage{amssymb}
\usepackage{capt-of}
\usepackage{hyperref}
\usepackage{minted}
\author{Nick Dokos}
\date{\today}
\title{}
\hypersetup{
pdfauthor={Nick Dokos},
pdftitle={},
pdfkeywords={},
pdfsubject={},
pdfcreator={Emacs 28.0.50 (Org mode 9.4)},
pdflang={English}}
\begin{document}
\tableofcontents
\section{Link}
\label{sec:org59c7ca7}
\url{https://emacs.stackexchange.com/questions/61189/org-macros-misbehave-in-include-file}
\section{foo}
\label{sec:org8b3fe52}
\begin{NOTES}
bar
\end{NOTES}
\begin{NOTES}
foo
\end{NOTES}
\end{document}
```
Result of exporting it to HTML using the `ox-reveal` library from MELPA (only the `<body>...</body>` part of the file is shown to save some space):
```
<body>
<div class="reveal">
<div class="slides">
<section id="sec-title-slide"><h2 class="author">Nick Dokos</h2><p class="date">Created: 2020-10-14 Wed 13:08</p>
</section>
<section id="table-of-contents"><div id="table-of-contents">
<h2>Table of Contents</h2>
<div id="text-table-of-contents">
<ul>
<li><a href="#/slide-org4e9fdef">1. Link</a></li>
<li><a href="#/slide-org464c226">2. foo</a></li>
</ul>
</div>
</div>
</section>
<section>
<section id="slide-org4e9fdef">
<h2 id="org4e9fdef"><span class="section-number-2">1</span> Link</h2>
<p>
<a href="https://emacs.stackexchange.com/questions/61189/org-macros-misbehave-in-include-file">https://emacs.stackexchange.com/questions/61189/org-macros-misbehave-in-include-file</a>
</p>
</section>
</section>
<section>
<section id="slide-org464c226">
<h2 id="org464c226"><span class="section-number-2">2</span> foo</h2>
<aside class="notes">
<p>
bar
</p>
</aside>
<aside class="notes">
<p>
foo
</p>
</aside>
</section>
</section>
</div>
</div>
<script src="./reveal.js/js/reveal.js"></script>
<script>
// Full list of configuration options available here:
// https://github.com/hakimel/reveal.js#configuration
Reveal.initialize({
multiplex: {
secret: '', // null if client
id: '', // id, obtained from socket.io server
url: '' // Location of socket.io server
},
// Optional libraries used to extend on reveal.js
dependencies: [
{ src: './reveal.js/lib/js/classList.js', condition: function() { return !document.body.classList; } },
{ src: './reveal.js/plugin/markdown/marked.js', condition: function() { return !!document.querySelector( '[data-markdown]' ); } },
{ src: './reveal.js/plugin/markdown/markdown.js', condition: function() { return !!document.querySelector( '[data-markdown]' ); } },
{ src: './reveal.js/plugin/zoom-js/zoom.js', async: true, condition: function() { return !!document.body.classList; } },
{ src: './reveal.js/plugin/notes/notes.js', async: true, condition: function() { return !!document.body.classList; } }]
});
</script>
</body>
```
> 1 votes
---
Tags: org-mode, org-reveal
---
|
thread-31495
|
https://emacs.stackexchange.com/questions/31495
|
how do I customize spacemacs default buffer
|
2017-03-16T09:57:09.663
|
# Question
Title: how do I customize spacemacs default buffer
I would like to make some change on spacemacs's default buffer `*spacemacs*`,like move recently files and projects to left and show my TODO list in the right or bottom from another file
# Answer
Use emacs-dashboard ? It is
> A shameless extraction of Spacemac's startup screen
that
> * Displays an awesome Emacs banner!
> * Recent files
> * Bookmarks list
> * Recent projectile projects list (Depends on `projectile` package)
they're working to make it easily customisable, AFAIK.
> 3 votes
# Answer
It seems like you're looking for something more along the lines of **`Workgroups2`**, a session manager for emacs that saves and restores open buffers along with thier locations and sizes. Also supports multiple workspaces.
Comprehensive info is available at readthedocs: Workgroups2 - Emacs Session Manager
And git: Workgroups for Emacs
* Emacs works differently than other editors you may have used in the past and Spacemacs is really "just" a configuration of layers and extensions that make Emacs more accessible to new users. A key difference, as Dan points out, is that *everything* begins in a buffer... and is only later written to a file type.
* For instance, having the Scratch buffer always available is very handy. One can immediately enter anything here (an org TODO, a Clojure script, a LISP fragment).
* It only *becomes* something else when you *do* something *to* the buffer; that is, when you save it to a file (foo.org, foo.clj, foo.lisp, etc). Saving a buffer *as* something changes its nature from general to specific, from potentiality to actuality.
> This has interesting philosophical considerations!
> 1 votes
# Answer
I also wanted to change the startup buffer (or spacemacs-buffer as it is called) and I found https://www.reddit.com/r/spacemacs/comments/55p1td/dont\_like\_the\_new\_footer\_or\_customizing\_your/ where basically says that the design of the page is done in spacemacs/core/core-spacemacs-buffer.el (https://github.com/syl20bnr/spacemacs/blob/master/core/core-spacemacs-buffer.el). And I did so, I didn't want to see the release-notes (they are meaningles because now all the development is done in the development branch) and I wrote
> (defun spacemacs-buffer//notes-insert-release-note ())
in my .spacemacs file in section dotspacemacs/user-config
> 0 votes
---
Tags: spacemacs
---
|
thread-61190
|
https://emacs.stackexchange.com/questions/61190
|
Cannot bind Meta + Shift + Character
|
2020-10-14T11:45:26.910
|
# Question
Title: Cannot bind Meta + Shift + Character
I am not able to bind Meta + Shift + any character.
I do not experience these problems with other key combinations (such as Control + Shift + Key).
Below is the specific case that I cannot get to work:
```
(global-set-key (kbd "M-S-Z") 'zap-up-to-char-backward)
(defun zap-up-to-char-backward (char)
(interactive "cZap up to char (backward): ")
(zap-up-to-char -1 char))
```
# Answer
`M-S-Z` would mean Meta + Shift + `Z`. But `Z` (uppercase) is itself what Emacs uses for `Shift>` \+ `z`.
There's likely no key on your keyboard corresponding to `S-Z`. That's why you say it doesn't work.
If you use `C-h b` you'll find your key binding listed OK. And if you use `C-h w zap-up-to-char-backward` you'll see that it says it's bound to `M-S-Z`.
The problem is that you have no way of typing such a key sequence with your keyboard.
`C-` is special, in that `C-Z` is interpreted as the Control character `C-z`, that is, ASCII Control Z.
---
It's unclear what you really want to do. Do you want to bind keyboard key combination `Meta` \+ `Shift>` \+ `z`? If so, use `(kbd "M-Z")`, not `(kbd "M-S-z")` or `(kbd "M-S-Z")`.
> 5 votes
---
Tags: key-bindings
---
|
thread-61191
|
https://emacs.stackexchange.com/questions/61191
|
Implement modal interface in a major mode
|
2020-10-14T12:43:18.547
|
# Question
Title: Implement modal interface in a major mode
I am creating a major mode, and would like to have modal interface (such as vi) on it.
I want to have a **special key** that toggles the behaviour on arrow keys.
So, for example, if the special key is hit, arrows move the char underneath.
And when the special key is hit again, arrows behave as normally.
How can I implement such thing?
I suspect it could work creating two different keymaps for the mode.
And then switching from one to the other after the special key press. But not really sure if that would be the way to do it.
And honestly, I do not really know how to make that *special key*, so it can rebind other keys on the fly.
Hmmm... I should probably look for the code of a mode that implements a modal interface...
# Answer
You could create a minor mode that binds the arrow keys to the functions you want. Then your 'special' key only needs to toggle the minor mode on and off. You would bind the 'special' key in your major mode map, and make the minor mode buffer-local, so it would only change the behaviour in files in that major mode.
> 2 votes
# Answer
So, following @Tyler advice I came with this:
```
;; Major mode
(defvar pletter-mode-keymap (make-sparse-keymap))
(define-key pletter-mode-keymap (kbd "C-q") 'move-pletter-mode)
(define-derived-mode pletter-mode fundamental-mode "pletter"
"pletter-mode is a major mode for playing with letters and words.
\\{pletter-mode-map}"
(use-local-map pletter-mode-keymap) ;; not needed
)
;; Minor mode
(defvar move-pletter-mode-keymap (make-sparse-keymap))
(define-key move-pletter-mode-keymap (kbd "<left>") 'movechar-to-left)
(define-key move-pletter-mode-keymap (kbd "<right>") 'movechar-to-right)
(define-minor-mode move-pletter-mode
"Minor mode to toggle arrows bindings for pletter-mode."
nil " move" move-pletter-mode-keymap
(message "Toggle move-pletter"))
(provide 'pletter-mode)
```
which seems to work for me.
> 0 votes
---
Tags: key-bindings, major-mode
---
|
thread-24453
|
https://emacs.stackexchange.com/questions/24453
|
Weird shell output when using IPython 5
|
2016-07-08T14:16:26.150
|
# Question
Title: Weird shell output when using IPython 5
I just upgraded to the latest version of IPython and now something is wrong when using it in emacs.
When using it in a regular terminal it works fine (colors, tab-completion, etc.), however either in `M-x eshell` or `M-x shell`, instead of outputing `In [1]:`, it actually outputs `[?12l[?25h` and `Out[1]` outputs to `[J[?7h[?12l[?25h[?2004l[?7hOut[1]:`.
Maybe it's some feature of the terminal not available on emacs used by IPython, but I'd like to know which one it is.
Terminal.app:
```
In [1]: 2+2
Out[1]: 4
```
Emacs
```
[?12l[?25h2+2
[J[?7h[?12l[?25h[?2004l[?7hOut[1]: 4
```
# Answer
> 48 votes
IPython 5 has a new terminal interface, which is not compatible with Emacs' inferior shells. To fix it, add the `--simple-prompt` flag to the IPython command:
```
(setq python-shell-interpreter "ipython"
python-shell-interpreter-args "--simple-prompt -i")
```
From the documentation:
> The new interface is not compatible with Emacs ‘inferior-shell’ feature. To continue using this, add the `--simple-prompt` flag to the command Emacs runs. This flag disables most IPython features, relying on Emacs to provide things like tab completion.
Reference: http://ipython.readthedocs.io/en/stable/whatsnew/version5.html#id1
# Answer
> 1 votes
The **error** I got was similar garbled (wierd) text when I opened IPYTHON with `C-c C-p` on my simple python file `print("hello World")`.
```
ppppprrrrriiiiinnnnnttttt((((("""""HHHHHeeeeellllllllllooooo
WWWWWooooorrrrrlllllddddd""""")))))))))))))))
Hello World
```
**Solution** verbatim as per @ricardoLima's answer above didn't work for me. I had to write it as follows.
```
(setq python-shell-interpreter "/path/to/bin/ipython")
(setq python-shell-interpreter-args "--simple-prompt -i")
```
**TIP:**
Just use `emacs -q` in the terminal to open a no-init emacs and run these commands with `M-:`. `M-x run-python` and you are good to go.
**P.S.**
Emacs: "This is GNU Emacs 25.3.2 (x86\_64-pc-linux-gnu, GTK+ Version 3.18.9) of 2019-12-24"
Ubuntu: 16.04
python and Ipython from Anaconda
Python: 3.7.6
IPython: 7.12.0
# Answer
> 1 votes
Simply using `M-x term` instead of `M-x shell` or `M-x eshell` solved my similar problem. The interface is actually better than `eshell` or `shell`. For example, for repeating the previous command just need the up key; Auto-completion works smoothly (but editing multi-lines is not as nice as `eshell` or `shell`).
I should also add that, for me the solution mentioned above by Ricarod did not help (adding the `--simple-prompt` flag to the IPython command)
# Answer
> 0 votes
There's a way to open IPython in emacs shell without using --simple-prompt
```
1. pip install rlipython
2. Open IPython in terminal
3. Run import rlipython; rlipython.install()
```
After this, you should be able to open ipython directly in emacs shell without experiencing the display problem.
There's one more issue in my case though: For some reason, even after display became correct, I still couldn't directly copy-paste some multi-line class definitions into ipython in emacs shell. My current solution is to use the Ipython %paste command. If you have better approaches, please let me know.
PS: I'm using Ubuntu 16.04. Someone uses MacOS says it breaks IPython.
---
Tags: shell, eshell, ipython
---
|
thread-12878
|
https://emacs.stackexchange.com/questions/12878
|
How to change style of hyperlinks within PDF published from org-mode document?
|
2015-06-03T15:36:47.690
|
# Question
Title: How to change style of hyperlinks within PDF published from org-mode document?
I'm exporting (publishing) an org-mode document to PDF, and the results look great except for the hyperlinks. They look *terrible*.
Hyperlinks to the Web look the same, only with a pale blue outline. How can I control the style of links in the exported PDF document? (I don't know LaTeX, but can make simple configuration changes in LaTeX if necessary).
# Answer
Hyperlinks in pdfs exported from org documents are generated by the LaTeX hyperref package. This package is included by default, and options can be set in the customize interface for `org-latex-default-packages-alist`.
For example, adding the option `colorlinks=true` to the entry for hyperref will switch from boxed links to coloured links. There are quite a few options you can set, listed in the hyperref manual.
> 20 votes
# Answer
While the previous answers are helpful, I'll add a bit more of an explicit recipe for Org mode.
By default, Org mode adds a rather unhelpful `hypersetup` section. You can prevent this addition by adding the following line to your `.emacs` file:
```
(customize-set-value 'org-latex-with-hyperref nil)
```
In addition, if you want to pass any options to `hyperref` or `url` (which is loaded automically by `hyperref`), then you can use a command of the form (notice the escaped backslash):
```
(add-to-list 'org-latex-default-packages-alist "\\PassOptionsToPackage{hyphens}{url}")
```
This particular command directs the `url` package to break long URLs at the end of the page over hyphens.
Then, in the Org document itself, we can add the following lines:
```
#+LaTeX_HEADER: \usepackage[x11names]{xcolor}
#+LaTeX_HEADER: \hypersetup{linktoc = all, colorlinks = true, urlcolor = DodgerBlue4, citecolor = PaleGreen1, linkcolor = black}
```
The first line adds the `xcolor` package with X11 color names, and the second line specifies several options for the `hyperref` package, with the relevant option for this question being `colorlinks = true`.
See the *Package Options* section of the hyperref documentation, and the *Colors By Name* section of the xcolor documentation for more information on the available `hyperref` settings and X11 color names, respectively.
> 18 votes
# Answer
Here's what worked for me.
```
\usepackage{xcolor}
\PassOptionsToPackage{hyperref,x11names}{xcolor}
\definecolor{electricblue}{HTML}{05ADF3}
\usepackage{tocloft}
\renewcommand{\cftsecleader}{\cftdotfill{\cftdotsep}}
\usepackage[breaklinks=true,linktocpage,xetex]{hyperref}
\hypersetup{colorlinks, citecolor=electricblue,filecolor=electricblue,linkcolor=electricblue,urlcolor=electricblue}
```
> 4 votes
# Answer
I know this is old and the existing answers are already great. But in case anyone is searching for this and needed a bit more control, here's how to change the `hyperref` template.
```
(customize-set-value 'org-latex-hyperref-template "
\\hypersetup{\n pdfauthor={%a},\n pdftitle={%t},\n pdfkeywords={%k},
pdfsubject={%d},\n pdfcreator={%c},\n pdflang={%L},\n colorlinks=true}\n")
```
The format elements, as found in `ox-latex.el`:
```
%a for AUTHOR keyword
%t for TITLE keyword
%s for SUBTITLE keyword
%k for KEYWORDS line
%d for DESCRIPTION line
%c for CREATOR line
%l for Language keyword
%L for capitalized language keyword
%D for DATE keyword
```
> 4 votes
---
Tags: org-mode, org-export, pdf
---
|
thread-61184
|
https://emacs.stackexchange.com/questions/61184
|
Beginner: Doom Emacs, or Emacs in general: Which program is used for spellcheck-as-you-write in text mode and how to change its dictionary
|
2020-10-14T08:47:41.610
|
# Question
Title: Beginner: Doom Emacs, or Emacs in general: Which program is used for spellcheck-as-you-write in text mode and how to change its dictionary
I am learning how to work with Emacs on Ubuntu 20.04. After going through Tutorial and using default key-bindings for some time, I have decided to test more ergonomic (at least for me) setup - that is how I ended up in Doom Emacs.
First time using Doom Emacs, I am writing notes for usage in simple text mode. I write in my native (czech) language. All text I write is highlighted as spelling error, which is kind-of annoying. Which external program is responsible for that in Doom Emacs and how can I change its spelling dictionary??
In Doom Emacs I have enabled all `:checkers` options (`grammar`, `spell`, `syntax`). I have also followed this question solution: Ispell Spellcheck ; installed appropriate `ispell` dictionary from `apt` and restarted Emacs. I have also tryed to stop `flyspell-mode` (if this would be caused by `flyspell`), but the misspelling markings still persist in viewed text.
I have also tryed to `flyspell-buffer`, but with no success.
When I was learning Emacs, I have been doing the same with vanilla Emacs and I have used GUI-top bar menu to set language (not sure if it was for buffer or whole application) and everything worked as expected, there were no spurious misspellings detected.
Which program is responsible in Doom Emacs, or Emacs in general, for spellchecking on-the-fly and how can its dictionary be changed?
If this site is not the right place to ask (and I should adress author directly), please, let me know in comments. My reason asking here is because I think this is not a bug in Doom Emacs, but that it is my lack of knowledge how to work with Emacs.
# Answer
The dictionary used is controlled by the variables `ispell-dictionary` and `ispell-local-dictionary`. Where the first is the default and the second is buffer local so different files can have different languages for spell-check. There is a helpful function `ispell-change-dictionary` that will set them for you. You can run it in a buffer with `M-x ispell-change-dictionary`, select your language and hit `[return]`
To change the default permanently, add `(ispell-change-dictionary "czech" t)` (the second argument means to set it globally for all buffers) to your `.emacs`.
> 1 votes
# Answer
Accepted answer helped me to precisely locate the issue: It is `spell-fu` Emacs package, which is used by Doom Emacs to do on-the-fly spellchecking by default.
In my case, it seemed contrary to its documentation to not respond to setting `M-x ispell-change-dictionary`; however, I was able to make `spell-fu` accept czech dictionary by editing the config file.
After some time searching, I have hit upon this issue on Doom Emacs GitHub repo:
Make spell-fu optional
Which adresses my issue. However, for me is good enough to turn off the `spell-fu` mode by `<Space> t s` and spellcheck my buffer with flyspell by means of `M-x flyspell-buffer` whenever I want.
> 1 votes
---
Tags: flyspell, ispell, spell-checking
---
|
thread-61180
|
https://emacs.stackexchange.com/questions/61180
|
macos environment variables?
|
2020-10-13T23:10:35.267
|
# Question
Title: macos environment variables?
I'd like to set things up so that I can use emacs on multiple computers, with the .emacs.d directory shared amongst them (via DropBox).
My solution so far has been to use environment variables which are then read in my init.el. The computer-specific environment variable then tells me where to find the computer-specific recentf file, etc, etc. On Windows this works great because one can set environment variables via a control panel option.
**I'm trying to figure out how to get computer-specific environment variables to work in emacs on MacOS**. Ideally, I'd like to be able to launch emacs from both Spotlight and from a terminal window (iTerm2, specifically).
I found a StackOverflow answer about getting environment variables into GUI apps but it doesn't seem to work (emacs still has troubles loading the computer-specific files because the environment variable doesn't appear to be set in the init.el).
I'd like to avoid setting up .bash\_profile to set the environment variables so that I can share my .bash config files through DropBox, as well
# Answer
Maybe in your case the best option si to cook up your own solution. E.g. set your machine-specific env-vars in your own invented file, say `~/.mylocal-settings.sh`, where you could use a subset of `sh` syntax, like:
```
# Place where I keep my foos.
FOOVAR=/foo/bar
# Extra dirs to add to $PATH
MYEXTRAPATH=$HOME/myextra/bin:/myopt/bin
...
```
then in your `~/.bashrc` or `~/.bash_profile` you can just do:
```
source ~/.mylocal-settings.sh
```
and then in your `~/.emacs` you could do:
```
(defun my-read-local-settings ()
(with-temp-buffer
(insert-file-contents "~/.mylocal-settings")
(dolist (line (split-string
(substitute-env-vars (buffer-string))
"\n"))
(cond
((not (string-match "\\`\\(?:#.*\\|[ \t]*\\|\\([^ ]+\\)=\\(.*\\)"
line))
(message "Can't parse line: %S" line))
((not (match-beginning 1)) nil) ;; Comment or empty line.
(t
(setenv (match-string 1 line) (match-string 2 lines)))))))
(my-read-local-settings)
```
This way you can keep `~/.bashrc` and friends identical between hosts as well.
> 1 votes
---
Tags: init-file, osx, environment
---
|
thread-61183
|
https://emacs.stackexchange.com/questions/61183
|
How to move the cursor to the end of the read only text?
|
2020-10-14T06:34:16.827
|
# Question
Title: How to move the cursor to the end of the read only text?
Say I have text:
`This read only text ends here>*********************|`
The `This read only text ends here>` is read only while the asterisks are are not. When the `(move-to-read-only-end)` is called, I want the cursor to move right after the `>`. Like this:
`This read only text ends here>|*********************`
How can the `(move-to-read-only-end)` be written?
EDIT: Adding comment here per advice,
"In eshell, the prompt is read only but when you write commands those are not. So, I want to be able to move at the end of the prompt and the start of the commands."
# Answer
Since you're asking about `eshell` specifically, you should be able to use the command `eshell-bol`, which is bound to `C-a` by default. It moves the cursor to the end of the prompt on the current line.
> 1 votes
# Answer
Maybe something like this:
```
(defun move-to-read-only-end ()
"..."
(interactive)
(goto-char (or (next-single-property-change (point) 'read-only)
(line-end-position))))
```
Here, function `next-single-property-change` gives you the first position where property `read-only` changes its value. Or it gives you `nil`, in which case you go to the end of the line.
> 0 votes
---
Tags: motion
---
|
thread-61207
|
https://emacs.stackexchange.com/questions/61207
|
Some commands in init.el don't run on startup, but others seem to run fine
|
2020-10-15T00:43:41.273
|
# Question
Title: Some commands in init.el don't run on startup, but others seem to run fine
I am having a very weird issue with my init.el file. At startup, some of the commands in it run fine (so I know Emacs is able to pick the correct file), but others only run when I manually load the file using `M-x load-file RET ~/.emacs.d/init.el RET` (so I know those commands are syntactically correct as well). Here is a working example:
```
(setq package-enable-at-startup nil)
(setq doc-view-continuous t)
(package-initialize)
(unless (package-installed-p 'use-package)
(package-refresh-contents)
(package-install 'use-package))
(eval-when-compile
(require 'use-package))
(use-package yasnippet
:config
(yas-reload-all)
(yas-minor-mode 1)
:ensure t)
(use-package auto-complete
:ensure t
:config
(auto-complete-mode 1)
)
; The following command is not run at startup. But runs when I load the file manually.
(setq line-spacing 0.3)
(yas-minor-mode 1)
(global-display-line-numbers-mode)
;If I remove the next command, startup line numbers are no longer relative, but they are with it.
(setq display-line-numbers-type 'relative)
```
I tried removing the top commands (all upto to line-spacing), but on removing them even the line numbers were no longer working on startup.
I am using Mac OS X Mojave. `M-x emacs-version RET` gives the following: `GNU Emacs 26.3 (build 1, x86_64-apple-darwin18.2.0, NS appkit-1671.20 Version 10.14.3 (Build 18D109)) of 2019-09-02`. I had installed it along with AucTex.
I am fairly new with Emacs and Lisp, so please let me know if I should provide some more information.
# Answer
> 4 votes
All of your code is running. The trouble is, `line-spacing` is a buffer-local variable. From the help for this variable (which I found by `C-h v line-spacing`):
> Automatically becomes buffer-local when set.
That means changing the value of the variable only effects line spacing in the current buffer, not all buffers.
In order to change the default value of `line-spacing`, you need to change it using the Customization interface: `M-x customize-variable lines-spacing`.
---
Tags: init-file
---
|
thread-61211
|
https://emacs.stackexchange.com/questions/61211
|
perform shell variable substitution when using find file at point (ffap)
|
2020-10-15T12:39:45.373
|
# Question
Title: perform shell variable substitution when using find file at point (ffap)
> **Question:** is there a way to convince `ffap` to perform variable substitution on environment variables before attempting to resolve the file path?
---
I often have lines in shell scripts that read:
```
variable="${ENV_VAR}/path/to/file"
```
When I use `ffap` on the above, it is unaware of what `${ENV_VAR}` means. Assume `ENV_VAR` is properly defined via
```
export ENV_VAR="/path/to/dir"
```
in one of the shell's init-files and it can be found in the output of `env`. Is there a way we can trick `ffap` to do the variable substitution?
# Answer
You can redefine `ffap-file-finder`. This is normally set to `find-file`, which doesn't do env variable expansion. So define a function like `find-file` that *does* do env variable expansion:
```
(defun find-file-env (fname)
(find-file (substitute-in-file-name fname)))
```
and assign it to `ffap-file-finder`:
```
(setq ffap-file-finder #'find-file-env)
```
> 2 votes
---
Tags: shell-mode, ffap
---
|
thread-61210
|
https://emacs.stackexchange.com/questions/61210
|
Replacing text with svg image via font lock
|
2020-10-15T12:13:17.077
|
# Question
Title: Replacing text with svg image via font lock
I've made small function to create SVG tags (see below) and I would like to use the image property of faces to replace some keywords. I'm not sure how to do that and if it is possible. For example, any `:NOTE:` would be replaced by the image returned by the (tag "NOTE") call. From Replacing a string with symbols using font-lock?, it seems possible but I'm not sure how to adapt the code for image.
**Code**:
```
(require 's)
(require 'svg)
(defface tag-face
'((t :foreground "white" :background "orange" :box "orange"
:family "Roboto Mono" :weight light :height 120))
"Face for default tag" :group 'tag)
(defun tag (text &optional face inner-padding outer-padding radius)
(let* ((face (or face 'tag-face))
(foreground (face-attribute face :foreground))
(background (face-attribute face :background))
(border (face-attribute face :box))
(family (face-attribute face :family))
(weight "light") ;; (face-attribute face :weight))
(size (/ (face-attribute face :height) 10))
(tag-char-width (window-font-width nil face))
(tag-char-height (window-font-height nil face))
(txt-char-width (window-font-width))
(txt-char-height (window-font-height))
(inner-padding (or inner-padding 1))
(outer-padding (or outer-padding 0))
(text (s-trim text))
(tag-width (* (+ (length text) inner-padding) txt-char-width))
(tag-height (* txt-char-height 0.9))
(svg-width (+ tag-width (* outer-padding txt-char-width)))
(svg-height tag-height)
(tag-x (/ (- svg-width tag-width) 2))
(text-x (+ tag-x (/ (- tag-width (* (length text) tag-char-width)) 2)))
(text-y (- tag-char-height (- txt-char-height tag-char-height)))
(radius (or radius 3))
(svg (svg-create svg-width svg-height)))
(svg-rectangle svg tag-x 0 tag-width tag-height
:fill border
:rx radius)
(svg-rectangle svg (+ tag-x 1) 1 (- tag-width 2) (- tag-height 2)
:fill background
:rx (- radius 1))
(svg-text svg text
:font-family family
:font-weight weight
:font-size size
:fill foreground
:x text-x
:y text-y)
(svg-image svg :ascent 'center)))
(insert-image (tag "INFO")) ;; Type C-x C-e here to see the tag
```
**Result**:
**Update**:
Something like this almost works but the call is not evaluted:
```
(add-to-list 'font-lock-extra-managed-props 'display)
(font-lock-add-keywords nil
'(("\\(\:TODO\:\\)" 1 '(face nil display (tag "TODO")))))
```
# Answer
> 0 votes
This is how to do it:
```
(add-to-list 'font-lock-extra-managed-props 'display)
(font-lock-add-keywords nil
'(("\\(\:TODO\:\\)" 1 `(face nil display ,(tag "TODO")))))
```
---
Tags: faces, font-lock, images
---
|
thread-61218
|
https://emacs.stackexchange.com/questions/61218
|
How can i make org mode export latex file with a custom language?
|
2020-10-15T19:13:35.043
|
# Question
Title: How can i make org mode export latex file with a custom language?
I need romanian for my school reports, i want to write them in org mode.
Is there some `#+LANG` attribute? Do i need to set some emacs variables? I'd really like a per-file solution more
# Answer
I needed to add the following code to make `#+LANGUAGE` work:
```
#+LATEX_HEADER: \usepackage[romanian]{babel}
#+LANGUAGE: ro
```
I don't know why, but removing the `[romanian]` breaks it. It can be any language because the only thing that matters is the `#+LANGUAGE` value now.
> 0 votes
---
Tags: org-export, latex
---
|
thread-41409
|
https://emacs.stackexchange.com/questions/41409
|
Emacs 25.3.2: reverse windows on files opening
|
2018-05-09T15:17:31.050
|
# Question
Title: Emacs 25.3.2: reverse windows on files opening
If I open 2 files by command line:
```
emacs file1 file2
```
in `Emacs 25.3.2`, `file2` is opened in the **upper** window and `file1` in the **lower**.
This didn't happen in previous versions of `Emacs` that had the correct (in my opinion) behaviour (`file1` was open in the upper window and `file2` in the lower).
Can I restore the old behaviour?
# Answer
> 0 votes
Add the following to you init.el file.
```
;; 15-Oct-20 wr open first file in left window
(defun my-startup-layout ()
(let ((buffers (mapcar 'window-buffer (window-list))))
(when (= 2 (length buffers))
(delete-other-windows)
(set-window-buffer (split-window-horizontally) (cadr buffers))))
)
(add-hook 'emacs-startup-hook 'my-startup-layout)
(add-hook 'emacs-startup-hook 'next-multiframe-window)
;; end of customization to open first file on left
```
---
Tags: window, command-line-arguments
---
|
thread-61181
|
https://emacs.stackexchange.com/questions/61181
|
Scheduling in Org mode without using mouse or track pad
|
2020-10-14T01:14:52.510
|
# Question
Title: Scheduling in Org mode without using mouse or track pad
I'm scheduling items according to instructions here: https://orgmode.org/manual/Inserting-deadline\_002fschedule.html#Inserting-deadline\_002fschedule
I have pain in my hands that is exacerbated especially by using pointing devices such as a mouse or track pad. I can still tolerate typing pretty well. So far, Org-mode is the least mouse intensive organization tool I've found.
It looks like scheduling will require some mouse or track pad use. (ouch!) It looks like there isn't any way to specify a date in the future (after entering C-c C-s) other than with a pointing device or touch screen. I could make the touch screen work, but I'd prefer to keep my hands on the key board.
# Answer
> 1 votes
Three ways to do this.
1. `C-c C-s <RET>` inserts the present date. Edit the date in the file buffer. `C-c C-s <RET>` will then change the day of the week to match the new date. Cumbersome, but what I figured out on my own after asking the question.
2. As Tyler suggested, use `Shift-<arrows>` to navigate around in the calendar Org-mode displays. Use `<RET>` to select the marked date.
3. `C-c C-s`, type the desired date in the echo area, `<RET>`. Thanks Fran.
---
Tags: org-mode, mouse
---
|
thread-61229
|
https://emacs.stackexchange.com/questions/61229
|
Company-yasnippet doesn't see yasnippet template in lisp
|
2020-10-16T03:50:36.443
|
# Question
Title: Company-yasnippet doesn't see yasnippet template in lisp
Config:
```
(use-package yasnippet
:ensure t
:hook
(prog-mode . yas-minor-mode)
)
(use-package yasnippet-snippets
:ensure t
:after yas)
(use-package common-lisp-snippets
:ensure t
:after yas
:hook lisp-mode-hook)
(use-package slime-company
:ensure t
:after (slime company)
:hook
(lisp-mode
. (lambda ()
(set (make-local-variable 'company-backends)
'((company-slime company-yasnippet company-semantic)))))
(slime-editing-mode-hook
. (lambda ()
(set (make-local-variable 'company-backends)
'((company-slime company-yasnippet company-semantic)))))
:config
(setq slime-company-completion 'fuzzy
slime-company-after-completion 'slime-company-just-one-space))
```
In a lisp file, "defpackage"(imported by common-lisp-snippets) is show when using:
```
yas-insert-snippet
```
but company doesn't show for it. How to config company-yasnippet to find it?
# Answer
> 1 votes
Firstly, `(make-local-variable 'company-backends)` is outdated, with newest company and other packages, we only need to set one global `company-backends`.
That's because all backends do check whether it's the right major-mode etc. for it to take responsibility. In other words, `company-slime` checks whether it's in common lisp code, and step out of the way if not, so it's fine to just put it in a global `company-backends`.
To find out why `company-yasnippet` isn't working, check whether it's really in the backends, with `describe-variable`. Also see whether some other backend is giving some unhelpful candidates while `company-yasnippet` is queued after that. (if any backend gives any result, the ones after it won't be used at all.) (with newest company you can see the current candidate-giving backend in the completion UI.)
You may want to mix results of two or more backends, you can refer to the document for how to do this. But it's usually unnecessary, because you likely just need to put lightweight backend before others and they'll work only when it really think it should (`company-files` for example)
---
Tags: yasnippet, common-lisp, company
---
|
thread-61236
|
https://emacs.stackexchange.com/questions/61236
|
Why Emacs cannot display emojis
|
2020-10-16T09:15:45.553
|
# Question
Title: Why Emacs cannot display emojis
Sorry if this was answered somewhere else, but I could not find an answer.
All the text editors installed in my system can display emojis except Emacs (version 27), even if they use the same font.
As an example, I configured both Emacs and Gedit to use the JetBrains Mono font. Gedit can display the shrug emoji but Emacs cannot.
It seems, this can be workaround by specifying a fallback font that will display these symbols:
```
(set-fontset-font t nil "Symbola" nil 'append)
```
However other editors do not require such trick (although maybe they use a similar mechanism by default).
Are editors like Gedit or Visual Studio using a some trick to display emojis that Emacs does not?
# Answer
> 3 votes
This question is based on a false premise: Jet Brains Mono does not contain emoji characters at all. Unless your text editor performs automatic font fallback to fill in missing glyphs not provided by the chosen font, you will not see any emoji whatsoever. Therefore there's the following two camps they usually fall into:
* Perform automatic font fallback using a library such as fontconfig: Many editors do that and automatically pick a suitable font. The downside of this approach is that the automatic choice may not be what the user wanted and therefore requires extra tweaking, such as by editing fontconfig's configuration files or in the case of special applications (mobile apps, browsers, ...) bundling a special emoji font.
* Perform manual font fallback: Emacs does this for the greatest possible customizability independent of the operating system (see also urxvt for another example). Ironically Emacs *does* use fontconfig when available to select the most suitable font per script family; an unusual, but supported usecase. More fine-grained setup is performed in `fontset.el`. I've handed in a bug about this behavior in 2015 and as a result of this Emacs defaults to falling back to Symbola for the emoji range. Therefore I find it hard to believe you need the above line, unless that font triggers another bug inside Emacs (the debbugs thread suggests some tricks for debugging such issues).
To summarize: The trick is doing things in the simplest supported way while disregarding compatibility across operating systems. Emacs neither does things the simple way (at least not when it would impede customizability) nor has the luxury of dropping any code it accrued over many years.
---
Tags: fonts
---
|
thread-61227
|
https://emacs.stackexchange.com/questions/61227
|
Emacs fails to load org-id at start
|
2020-10-16T02:54:01.583
|
# Question
Title: Emacs fails to load org-id at start
When I start the emacs and try to customize variable `org-id-locations-file` it can't find it.
But I can describe variable `org-id-locations-file`. After describing the variable, if I run customize variable again on the same variable, now it finds it.
So my issue is, any variable with prefix `org-id-` is not found when trying to customize variable until I first describe it.
Customizing `org-id` group works.
Thinking back to what I have changed, I set `org-id-extra-files` to `nil` from a variable.
PS. By describing variable I mean: `M-x describe-variable` and by customize variable I mean `M-x customize-variable`.
PS I fixed this problem by adding `(require 'org-id)`. Now I need to see if linking by id works as expected.
# Answer
`describe-variable` was enhanced a few releases back so as to try and automatically load the corresponding package (after guessing which one it is). But this mechanism has not (yet) been applied to `customize-variable`, so please do `M-x report-emacs-bug` to request that new feature.
> 1 votes
---
Tags: org-mode
---
|
thread-61078
|
https://emacs.stackexchange.com/questions/61078
|
How to copy the search result (using Swiper) from search buffer in doom emacs?
|
2020-10-09T04:23:27.250
|
# Question
Title: How to copy the search result (using Swiper) from search buffer in doom emacs?
I search the line containing rowid in the buffer, and want to copy all the lines in the result window. How to do that?
# Answer
From the swiper search, type `C-c C-o`
That will open a separate buffer with the search results. From there you can copy whatever you like just like you can from any other buffer.
> 3 votes
---
Tags: doom, swiper
---
|
thread-17813
|
https://emacs.stackexchange.com/questions/17813
|
How do I import a Day One journal into orgmode?
|
2015-11-02T16:57:28.143
|
# Question
Title: How do I import a Day One journal into orgmode?
I have been using Day One for a while but I dislike it being Mac only. I have a capture template in orgmode that creates new journal entries in a tree.
Example:
\*2015
\**2015-11 November.
\***2015-11-2 Monday
\**** My journal entry.
Day One can export to markdown. The format is like this:
Date: June 2, 2010 at 11:11 PM Location: My location, City, Country Weather: 45° Clear
Text entry.
What would be the best way to I import this into my orgmode journal?
# Answer
> 1 votes
I ended up doing this because dayone exports with tabs:
```
\t\Date:\t
```
Replace with:
```
***
```
Then creating years and moving stuff manually. Titles don't have the same exact format that orgmode journal creates but who cares.
# Answer
> 0 votes
You can do this quickly with regex search & replace, M-C %. Replace ^Date: with \*** to create your headlines, and repeat for other elements as necessary. Since you'll only likely do this once, a few rounds of search & replace is probably going to be faster than writing code.
# Answer
> 0 votes
My elisp is too bad to make the converter inside emacs, but I whipped up a Ruby script to do it for you.
Converts a Day One plain text export (Journal.txt) into org-mode journal format. It does ...
* Markdown image conversion from to \[\[thepath.jpg\]\]
* Extraction of images from the front of an entry; moves it right after the property drawer.
* Creation of nested year/month/day date sections (see example below)
That means you get a nested outline like this
```
* 2020
** 2020-03 March
*** 2020-03-14 Saturday
**** Here's a diary entry imported from Day One.
:PROPERTIES:
:CREATED: [2020-03-14 Sat 14:33]
:END_PROPERTIES:
**** And another one from the same day.
:PROPERTIES:
:CREATED: [2020-03-14 Sat 19:12]
:END_PROPERTIES:
** 2020-06 June
*** 2020-06-22 Monday
**** Year, month, and day sections are created automatically.
:PROPERTIES:
:CREATED: [2020-06-22 Mon 08:06]
:END_PROPERTIES:
```
## Script source
See the public Gist or the following code: https://gist.github.com/DivineDominion/f7be383776bef5a57a4a812fabc4e8b7
```
#!/usr/bin/env ruby
#
# convert_dayone_to_org.rb
# Copyright © 2020 Christian Tietze. All rights reserved. Distributed under the MIT License.
#
# TODOs:
# - changing the image directory name during import using an option
# - changing the hash-based image file names to date-time format
#
# Usage:
#
# ./convert_dayone_to_org.rb Journal.txt output.org
require "date"
input, output, *rest = ARGV
if input.nil?
STDERR.puts "Usage: #{__FILE__} DAYONE_INPUT_PATH ORG_OUTPUT_PATH"
STDERR.puts "Missing input file path"
exit 1
elsif output.nil?
STDERR.puts "Usage: #{__FILE__} DAYONE_INPUT_PATH ORG_OUTPUT_PATH"
STDERR.puts "Missing output file path"
exit 1
end
File.open(output, "w") do |out|
# Cached values to make sub-headings
year = nil
month = nil
day = nil
props = {}
File.readlines(input).each do |line|
if /\A\t(?<key>\w+):\t(?<value>.*+)$/ =~ line
# Collect metadata in `props` dictionary
case key
when "Date"
date = DateTime.parse(value)
props["Created"] = date.strftime("[%Y-%m-%d %a %H:%M]")
# Convert date lines to new entries in org
# Output: "* 2020"
if year != date.year
out.puts "* #{date.year}"
year = date.year
month = nil
end
# Output: "** 2020-03 March"
if month != date.month
out.puts "** #{date.strftime("%Y-%m %B")}"
month = date.month
end
# Output: "*** 2020-03-12 Thursday"
this_day = date.strftime("%Y-%m-%d %A")
if day != this_day
out.puts "*** #{this_day}"
end
else
props[key] = value
end
elsif !props.empty?
# Produce entry title and metadata
if line.strip.empty?
# Skip empty line separator after metadata
else
# Add entry heading, handling leading entry images
cached_image = nil
if /\A!\[]\((?<path>.+)\)(?<rest>.*)$/ =~ line
cached_image = "[[./#{path}]]"
out.puts "**** #{rest}"
else
out.puts "**** #{line}"
end
# Append property drawer
out.puts ":PROPERTIES:"
out.puts(props.map { |key, value| ":" + key.upcase.to_s + ": " + value.to_s }
.join("\n"))
out.puts ":END_PROPERTIES:"
props = {}
if !cached_image.nil?
out.puts ""
out.puts cached_image
end
end
else
line = line.gsub(/!\[\]\((.+)\)/) { "[[./#{$1}]]" }
out.puts line
end
end
end
```
(Also posted more details on my blog for this https://christiantietze.de/posts/2020/10/export-day-one-journal-to-org-mode/)
---
Tags: org-mode
---
|
thread-61179
|
https://emacs.stackexchange.com/questions/61179
|
lsp mode does not recognize standard library
|
2020-10-13T22:47:43.313
|
# Question
Title: lsp mode does not recognize standard library
Today I did two things:
* I upgraded some emacs packages (don't know which ones)
* I installed in addition to emacs 27.1, emacs 28 with native compilation
I built the "gccemacs" in a separate folder but started with the same config I use for emacs 27. But then I realized, lsp-mode (I am using it with ccls) does **not recognize** libraries like `iostream` or `cstdint`. So I wanted to use emacs 27.1 again but emacs 27.1 shows now the same behavior. Things like lsp-diagnose look fine. When I switch to a new project the echo area shows `LSP :: CCLS:XXXX initialized successfully`
Now when installing gccmacs I also installed gcc-9 and g++-9 and used the following commands:
```
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-9 90 --slave /usr/bin/g++ g++ /usr/bin/g++-9 --slave /usr/bin/gcov gcov /usr/bin/gcov-9
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-7 70 --slave /usr/bin/g++ g++ /usr/bin/g++-7 --slave /usr/bin/gcov gcov /usr/bin/gcov-7
```
What weird is, is that I can use `lsp-find-definition` for libraries that get included via the compiler flags like e.g. armadillo library. If I use the command, I jump to `/usr/include/armadillo` but `iostream` or `cmath` **can not be found.** So this shows at least some minimal amount of functionality is there. Everything else looks fine, I don't get errors only a couple of warnings from other packages after the first byte compilations but that was the case before and it did work this morning. For some reason lsp-mode is not recognizing the standard library. Maybe I setup the new compiler version wrong? I switched back to gcc-7 anyways and `gcc --version` also tells that this is the case (same with g++). And yes, I can compile my programs and I use bear to execute a make file and generate the necessary .json file. Any ideas of what could be the cause of this issue?
**EDIT1:** Ok, some times when moving around in the buffer I get the echo message `LSP :: Error from Language Server: not indexed (Invalid Request)` I think this error also showed when it was working, but just in case.
**EDIT2:** I commented everything ccls related and used clangd instead but the issue persists. I then delete my `.emacs.d` folder and installed all packages from scratch with lsp-mode using only melpa-stable but the issue persists.
**EDIT 3:** I think I have come closer to a solution. It seems like lsp-mode or ccls/clangd does not recognize that I want to code c++ but c. I can include `math.h` but not `cmath` (without an error). Same behavior with `iostream` and `stdio.h` can I somehow tell lsp-mode to recognize c++?
**EDIT 4:** In the ccls faq is written, that the header file issue might occur if you e.g. have installed gcc-9 but not g++-9. But for me this is not the case. I have installed gcc-9, g++-9 and libstdc++-9 is installed as well. What I also realized is, that I can do: `include <c++/7/iostream>` without error because g++-7 is installed. Unfortunately, the ccls or lsp-mode does still complain about std:: (undeclared identifiert).
# Answer
> 2 votes
I solved the issue. It was not an emacs-ccls or lsp-mode issue but a clang issue. The issue started when I installed gcc-9 on Ubuntu-18.04 using the toolchain-r/test repo:
```
sudo add-apt-repository ppa:ubuntu-toolchain-r/test
```
I also noticed that I could not even compile a simple hello-world program using clang++. When compiling with the `-v` invocation it turned out that clang was looking for gcc-10 even though it was not installed:
```
[...]
Selected GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/10
[...]
```
Installing `libstdc++-10` solved the issue.
---
Tags: lsp-mode, ccls
---
|
thread-61246
|
https://emacs.stackexchange.com/questions/61246
|
Open a wildcard-link directly rather than through dired
|
2020-10-16T17:15:57.507
|
# Question
Title: Open a wildcard-link directly rather than through dired
In Org mode, when I open a link (`C-c C-o`) to a file such as `file:something.pdf`, the file is opened with my system PDF viewer. However, if the link contains a wildcard, such as `file:3_o*.pdf`, Emacs opens it through `dired` instead (also mentioned in https://emacs.stackexchange.com/a/51365), and selecting the pdf opens it within Emacs.
I would instead have it open the first match of that pattern in the system application - and don't highlight it in red. I'd also be fine with a custom link type if this can't be done otherwise.
# Answer
> 2 votes
Emacs lisp newbie here. As far as I know there are two ways to change this behaviour without changing Org's source code: either a custom link type, or an advice around `org-link-open` (see `(elisp) Advising Functions`).
# Custom link type
I've opted for the former, as the latter changed between Org versions (you need an advice around `org-link-open` in Org 9.3.6 an and advice around `org-open-at-point` in 9.1.9):
```
(require 'org)
(org-add-link-type "first" 'org-first-open)
(defun org-first-open (pattern)
"Open the first file that matches PATTERN.
PATTERN should match at least one file."
(let ((candidates (file-expand-wildcards pattern)))
(if candidates (org-open-file (car candidates))
(error "No file matches \"%s\"" pattern))))
```
You can now use `first:3_o*.pdf` to get the first result of the wildcard expansion.
The manual has some more information on custom types, for example customization options. Note that the current guide uses plists to define the link type via `org-add-link-type`, but that's a recent(?) addition. I opted for the earlier, still valid syntax from 9.1.
# Advice for `org-link-open`
This advice was tested in Org version 9.3.6 and 9.4-19. It will definitely not work in 9.1.9. Other versions are untested.
```
(defun my-org-expand-file-link (link)
"Expand a pattern in LINK to the first matching file.
Returns the original LINK if no file matches the pattern in LINK or if it is not
a link of type 'file:'. See info node `(org)External links' for more information."
(let ((type (org-element-property :type link))
(path (org-element-property :path link)))
(cond
((equal type "file")
(let ((candidates (file-expand-wildcards path)))
(if candidates
(org-element-put-property (org-element-copy link) :path (car candidates))
link)))
(t link))))
(defun my-org-link-open-advice (orig-fun link &rest args)
"Advice for ORIG-FUN that expands patterns in 'file:' LINKs.
See `my-org-expand-file-link' for more information.
Optional argument ARGS are passed as-is."
(apply orig-fun (my-org-expand-file-link link) args))
(advice-add 'org-link-open :around #'my-org-link-open-advice)
```
---
Tags: org-mode, dired, org-link, wildcard
---
|
thread-39283
|
https://emacs.stackexchange.com/questions/39283
|
How to syntax highlight Python f-strings so {...} uses regular code colors?
|
2018-03-07T00:13:22.623
|
# Question
Title: How to syntax highlight Python f-strings so {...} uses regular code colors?
## Update, Emacs 28 supports f-stings
---
Python 3.6 supports F strings, eg:
So:
```
print(f'Test {} me!'.format(2 + 2))
```
Can be written as:
```
print(f'Test {2 + 2} me!')
```
Which print's `Test 4 me`, Is there a way to adjust emacs syntax highlighting so the text between the `{...}` shows using regular code syntax-highlighting (instead of the same highlighting as a string).
# Answer
FWIW, I just pushed support for "proper" highlighting of f-strings in Emacs's master branch, so it will be available in Emacs-28 when that gets released (and is available in GNU ELPA's python package as of version 0.27, for older Emacsen).
> 6 votes
# Answer
The mentioned bug thread provides a workaround hack, which works on some simple cases. I extended that hack a bit, to better address my use cases:
```
(defconst brace-regexp
"[^{]{[^{}]*}")
(defconst python-f-string-regexp
"f\\('.*?[^\\]'\\|\".*?[^\\]\"\\)")
(defun python-f-string-font-lock-find (limit)
(while (re-search-forward python-f-string-regexp limit t)
(put-text-property (match-beginning 0) (match-end 0)
'face 'font-lock-string-face)
(let ((start (match-beginning 0)))
(while (re-search-backward brace-regexp start t)
(put-text-property (1+ (match-beginning 0)) (match-end 0)
'face 'font-lock-type-face))))
nil)
(with-eval-after-load 'python
(font-lock-add-keywords
'python-mode
`((python-f-string-font-lock-find))
'append))
```
Good stuff:
* Only applied on f-strings, not on string literals. This is the main feature, it prevents real bugs by capturing visually when I forget to add the `f`.
* works with (almost) arbitrary expressions within the `{}`
* `{{` does not trigger highlighting Bad stuff:
* still hacky, I'm not elisp literate
* if the expression within `{}` contains a `}`, then expression highlight will be cut off there
* expressions within `{}` get all the same colour (I arbitrarily picked the 'type' face because it contrasts well with strings on my system)
> 2 votes
# Answer
Try https://github.com/karlotness/tree-sitter.el , works perfectly for me.
```
;; Core APIs.
(straight-register-package
'(tsc :host github
:repo "ubolonton/emacs-tree-sitter"
:files ("core/*.el")))
;; Base framework, syntax highlighting.
(use-package tree-sitter
:straight (:host github
:repo "ubolonton/emacs-tree-sitter"
:files ("lisp/*.el"))
:diminish (tree-sitter-mode)
:hook ((after-init . global-tree-sitter-mode)
(tree-sitter-after-on . tree-sitter-hl-mode)))
;; Language bundle.
(use-package tree-sitter-langs
:straight (:host github
:repo "ubolonton/emacs-tree-sitter"
:files ("langs/*.el" "langs/queries"))
:demand t
:after tree-sitter)
```
> 0 votes
---
Tags: python, syntax-highlighting
---
|
thread-61045
|
https://emacs.stackexchange.com/questions/61045
|
Does anyone have any good tips for starting to use emacs?
|
2020-10-07T15:38:11.610
|
# Question
Title: Does anyone have any good tips for starting to use emacs?
I have heard good things about emacs and have dabbled in a bit of vim/neovim. I was wondering if anyone has any good tips for starting to use emacs! I am using emacs 27.1 for Windows 10.
# Answer
# Do you want to jump right in, or want to take your time configuring?
## Distros/Starter Kits
If you want to get productive right away, it's highly recommended to start with an Emacs Distro, as it would usually have a lot of saner defaults, with some even geared towards different types of workflows.
Want a batteries-included experience that's highly-optimized for VIM-emulation? Try Spacemacs!
Want something more minimal than that? Prelude!
There's something in there for everyone. Go check them out.
## Roll-your-own
If you're the type that can spare the time to learn about the internals of the tools you're using, you're in for a treat, as Emacs is the `self-documenting, extensible editor`. This graphic by Sacha Chua is a good place to start
Few key things to remember:
The key conventions in Emacs are different, `C` is for `<Ctrl>`, `M` is for `<Meta>/<Alt>`, etc.
Closing Emacs - `C-c C-k` | `<Ctrl>+c, <Ctrl>+k`
Cancelling commands/Emacs is "stuck" - `C-g` | `<Ctrl>+g`
Open the help menu - `C-h C-h` | `<Ctrl>+h <Ctrl>+h`
---
Whatever path you choose, I hope you have fun, and happy hacking
> 3 votes
# Answer
Emacs comes with a comprehensive manual which you can open with `C-h r`. It also has an interactive tutorial which you can start with `C-h t`.
> 2 votes
# Answer
This is one of these topics with no right or wrong answers. Fortunately, you didn't ask which editor is the best one. :-) I myself have been using Emacs for almost 10 years and would still consider myself advanced beginner. As some people say, Emacs isn't an editor, it's a lifestyle. There's truth in this quote, and if you don't get greedy and allow yourself some time to learn things, you will be rewarded with a fascinating piece of software.
There is an awful lot of information, and unless you like to suffer, it's getting overwhelming pretty soon. You can follow these tutorials that explain how to move the cursor in four different ways, but this is probably not what you are looking for. Telling you that there is virtually *nothing* that you can't do with Emacs won't help you either. Here's how I wished I started years ago.
First, try out some Emacs distributions and stay a while with the one or another. The 'Awesome Emacs' list will give you an overview, have a look at the Starter Kit section.
**Find yourself a use case.** What do you want to do? Write texts? Develop software? Let's assume you want to produce elegant presentations or get a bit more organized in your everyday life: then org mode is your friend. (A lot of people came to Emacs just because of org-mode.) At some point you want to export your document, maybe you want to give a presentation. This will lead you to beamer or org-reveal. The more you want, the more you (will have to) learn. The reactions of your colleagues will be priceless when you tell them how you did it.
**Allow yourself some time to learn.** Using Emacs isn't just about how to do this or that, but to learn how this beast works and how to customize it so that it becomes your everyday tool for a growing number of tasks. This requires some healthy amount of curiosity, because you will have to deal with Emacs Lisp if you want to customize Emacs. Some resources for starters: 'Mastering Emacs' started as a series of tutorials and is a book now: highly recommended. Here's an article for beginners. Xah Lee's website tutorial is perhaps a bit opinionated, but nonetheless helpful. And here's a beautifully designed manual (especially the 'Mini Manual'). If you're into org-mode, try these examples.
The more you learn, the more you'll appreciate sites like Endless Parentheses or Emacs Rocks! Have a look at M-x emacs-reddit \- there's always something new. You will learn what this .emacs file (or .emacs.d directory) is used for and you'll discover a lot of cool lisp code.
Emacs is an experience that will keep you busy for a while. There is no shame in failing: but if you really want to use and master it, it will change some of the ways you'll look at and deal with things.
> 1 votes
# Answer
**Note:** *This answer is a community wiki, everyone is encouraged to contribute.*
* Stay informed
Emacs is constantly evolving: some features are deprecated, new ideas emerge, new applications are created...
* Discover the helper functions
The GNU website has some useful information. The documentation is often available in the Info format: mastering the Emacs Info reader is an undeniable asset. Browsing the built-in documentation is useful to discover some hidden features (see `C-h C-h`) and become proficient.
* Know the key concept for the configuration
One of the major challenges is to be able to launch commands and configure applications while maintaining control over the editor. One can quickly be completly amazed or perplexed by the multitude of functions (and other Lisp concepts), commands, user options (parameters), extensions (packages or libraries). Knowing the key concepts also helps to simplify complexity.
* Relativize and keep in mind than nothing is perfect
New features may be developed or existing features may be improved but some are substituted or hard to modify. The pros and cons must also be weighed in order to make wise *or* essential decisions.
> 0 votes
# Answer
(I can't believe this question hasn't been closed. It's far too general for this Q&A site. A question here should not just be *fishing* for general "tips". Anyway...)
**Emacs Wiki is your friend.**
Start with the links under Learning Emacs on the first page.
The best link there is Emacs Newbie.
The next-best link there is the page that deals with Emacs Help.
That will get you started, and more. Come back to Learning Emacs for more.
Emacs Wiki will point you to Emacs's own information about learning Emacs, in particular how to "ask Emacs" itself - the Emacs help system and manuals. And how to learn Emacs Lisp.
> 0 votes
# Answer
Don't get discouraged, it has a very steep learning curve. If you stick with it, it pays very high dividends.
Start with the manual: https://www.gnu.org/software/emacs/manual/html\_node/emacs/index.html
once you get a bit comfortable (you don't have to get all the way through in one go) you should consider learning how to customize it: https://www.gnu.org/software/emacs/manual/html\_node/eintr/index.html
It is built around lisp, which is well known in academic computer science circles, but, looks a little odd to programmers who only know javascript. Try to keep an open mind (meta-programming macros will *blow your mind*). A great intro to lisp (really scheme, but, they are all related) is: https://mitpress.mit.edu/books/little-schemer-fourth-edition
The greatest thing about emacs is that you can edit the editor while you are editing (without restarting!).
> 0 votes
# Answer
If you are a new user and still have to learn all the key-bindings you should consider doom emacs or the already mentioned spacemacs. Doom emacs and Spacemacs allow you to use vim-keybindings (using evil-mode) instead of emacs keybindings. You can setup everything yourself but I think it is still worth checking out the distros first. To be clear, I use standard emacs keybindings but I tend to believe that vim keybindings are the better choice. The problem is, if you are already used to the keybindings it can be bothersome to learn new ones. Especially if your muscle memory is well trained. Imho the keybinding question is an important one and should be asked in the very beginning (event though you might not find an answer to it).
**Emacs keybindings:** In emacs, keybindings are mostly like in many other programs (just a lot more of them). You have the two modifier keys `ctrl` and `alt` (meta-key) and you have to use them a lot. For example: `C-x C-s` to save the buffer, `C-x C-f` to open a file, `C-f` move pointer **f**orward, `C-b` to move pointer **b**ackward, `C-p` to move pointer to **p**revious line and `C-n` to move the **n**ext line. You get the idea. With the constant use of `ctrl` and also `shift` there will be a lot of strain on your pinky, which can lead to the infamous emacs-pinky. If you still want to choose classic emacs keybindings consider remapping the `ctrl` to the `capslock` button. Also Xah Lee has some additional tips.
If you have already played around with Vim, you'll know it uses the concept of modal editing where you switch between command mode and insert mode. I am not experienced with vim but I do consider switching to evil mode because of the following reasons:
1. Less strain the fingers. No emacs pinky.
2. I do not have any prove for this, but from my general understand after reading up on it, is that vim keybinding are more efficient.
3. vi is installed on every linux machine, so you will always feel at home.
**Why then use emacs and not vim?** Well, I bet Vim is great but I cannot tell you how great it is because I never really used it. But I can tell how great emacs is. You can configure emacs to be everything you want. You can use it as an IDE for almost every programming language, you can use it as a Latex-Editor, you have org-mode (which you should definitely check out!), you can use it for reading and writing emails and so on and so on. For me, configuring emacs is kinda a hobby of mine and I think one should see it as that. It is for people who like to play around.
> 0 votes
# Answer
Read phils's advice: through a simple example (disable the beep) he explains essential concepts.
> 0 votes
---
Tags: learning
---
|
thread-61259
|
https://emacs.stackexchange.com/questions/61259
|
Limiting the number of lines of org babel result
|
2020-10-17T07:24:01.453
|
# Question
Title: Limiting the number of lines of org babel result
Is there an easy method to limit the number of lines in org-babel results?
For example: I have the following org-babel block:
```
#+begin_src js :exports both :results output
for (let i = 1; i <= 100; i++) {
if (i % 3 === 0 && i % 5 === 0) {
console.log("FizzBuzz");
} else if (i % 3 === 0) {
console.log("Fizz");
} else if (i % 5 === 0){
console.log("Buzz");
} else {
console.log(i);
}
}
#+end_src
```
This creates the following output:
```
#+RESULTS:
#+begin_example
1
2
Fizz
4
Buzz
Fizz
7
8
Fizz
Buzz
11
Fizz
13
14
FizzBuzz
16
17
Fizz
19
Buzz
Fizz
22
23
Fizz
Buzz
26
Fizz
28
29
FizzBuzz
31
32
Fizz
34
Buzz
Fizz
37
38
Fizz
Buzz
41
Fizz
43
44
FizzBuzz
46
47
Fizz
49
Buzz
Fizz
52
53
Fizz
Buzz
56
Fizz
58
59
FizzBuzz
61
62
Fizz
64
Buzz
Fizz
67
68
Fizz
Buzz
71
Fizz
73
74
FizzBuzz
76
77
Fizz
79
Buzz
Fizz
82
83
Fizz
Buzz
86
Fizz
88
89
FizzBuzz
91
92
Fizz
94
Buzz
Fizz
97
98
Fizz
Buzz
#+end_example
```
Is there an easy way to limit this long output to just 10 lines and add "..." at the end? Thanks.
# Answer
<sup>This is a literate org-mode answer. Copy the whole answer into an Emacs buffer, run `M-x org-mode` and experiment with the code blocks.</sup>
You can use a `[[info:org#Results of Evaluation][:post]]` processing step to limit the number of lines (or list items).
The following emacs-lisp snippet takes either a string or a sequence. If DATA is a string, it will split DATA by newlines, take LINES lines and glue them together with SEP.
If DATA is a sequence, then the first LINES elements get returned instead. This enables you to use `=:post=` with `=:result=` being `=list=` or a newline separated string.
```
#+NAME: head
#+begin_src emacs-lisp :var data="" :var sep="\n" :var lines=10 :exports code
(cond
((stringp data) (mapconcat #'identity (seq-take (split-string data "[\n]") lines) sep))
((seqp data) (seq-take data lines)))
#+end_src
```
Here's an example that creates a FizzBuzz string, separated by newline. Try to change the `=:results=` field for some experimentation:
```
#+begin_src emacs-lisp :exports both :wrap example :results value :post head(*this*,lines=20)
(defun fizzbuzz (number)
(cond ((= 0 (% number 15)) "FizzBuzz")
((= 0 (% number 5)) "Buzz")
((= 0 (% number 3)) "Fizz")
(t (number-to-string number))))
(mapconcat 'fizzbuzz (number-sequence 1 100) "\n")
#+end_src
```
> 2 votes
---
Tags: org-mode, org-babel, formatting
---
|
thread-61253
|
https://emacs.stackexchange.com/questions/61253
|
Why isn't org-agenda skipping DONE tasks?
|
2020-10-16T20:17:00.000
|
# Question
Title: Why isn't org-agenda skipping DONE tasks?
I'm trying to set up a planning process for the day (like in http://newartisans.com/2007/08/using-org-mode-as-a-day-planner/), but my org-agenda keeps showing DONE tasks, even though I set org-agenda-skip-deadline-if-done and org-agenda-skip-scheduled-if-done in the init.el:
My current init.el file is available at https://github.com/aylons/emacsd/blob/master/init.el
# Answer
Quoting from my comment:
> Judging from the fact that the DONE face and the TODO face look the same above, I'm guessing that your org-todo-keywords are screwed up, so Org mode does not know that it is done.
So I checked your init file and I see this:
```
...
'(org-todo-keywords
'((sequence "TODO(t)" "DONE(d)" "WAITING(w)" "SOMEDAY(s)" "NEXT(s)")))
...
```
So indeed your `org-todo-keywords` setting is wrong: you need to move the `DONE` entry to the last place:
```
...lang-el
...
'(org-todo-keywords
'((sequence "TODO(t)" "WAITING(w)" "SOMEDAY(s)" "NEXT(s)" "DONE(d)")))
...
```
The doc string for `org-todo-keywords` (`C-h v org-todo-keywords RET`) says:
> Each sequence starts with a symbol, either ‘sequence’ or ‘type’, indicating if the keywords should be interpreted as a sequence of action steps, or as different types of TODO items. The first keywords are states requiring action - these states will select a headline for inclusion into the global TODO list Org produces. If one of the "keywords" is the vertical bar, "|", the remaining keywords signify that no further action is necessary. If "|" is not found, the last keyword is treated as the only DONE state of the sequence.
So to be absolutely sure, it's probably best to include a "|" element in the list. That's necessary if you have more than one `DONE` state, but it's good practice in general:
```
...
'(org-todo-keywords
'((sequence "TODO(t)" "WAITING(w)" "SOMEDAY(s)" "NEXT(s)" "|" "DONE(d)")))
```
> 1 votes
---
Tags: org-mode, init-file, org-agenda
---
|
thread-51993
|
https://emacs.stackexchange.com/questions/51993
|
Alternative keyboards in Spacemacs
|
2019-08-04T13:52:08.220
|
# Question
Title: Alternative keyboards in Spacemacs
Update 2020-12-22: I have answered the question. Please see below.
---
I have `fcitx` installed on a Linux environment. According the to `fcitx-diagnose` it is correctly installed.
I am using the `us-alt-intl` keyboard to access diacritics in other language as a default keyboard. But it imposes extra-typing in standard vim or evil mode. Typically,accessing registers or moving to marks adds an extra space, which on extensive usage is somewhat a burden.
I'd like to switch back to a standard us keyboard when not in insert mode. As it turns out that is a common issue for CJK users.
The Chinese layer and the `mozc` package relies on `fcitx` to do that job. First, I have not been able to make them work on my installation.
I have attempted to create a layer to that intent.
Being new to layer creation, I have followed the is my `packages.el`:
```
(setq fcitx-packages
'((fcitx :toggle fcitx-enable-fcitx)
org))
(defun fcitx/init-fcitx ()
(use-package fcitx
:init (fcitx-evil-turn-on)
:config
(progn
(setq fcitx-active-evil-states '(insert emacs hybrid))
(fcitx-default-setup)
(fcitx-prefix-keys-add "M-m" "C-M-m")
(when fcitx-fcitx-use-dbus
(setq fcitx-use-dbus t)))))
```
This is probably overkill as adding the `fcitx` package to the `.spacemacs` file could perhaps be enough
```
dotspacemacs-additional-packages '(fcitx
mozc
mozc-im
mozc-popup)
```
How can I add the keyboards in that code (which is faulty anyway).
# Answer
I finally took time to review this by myself. I decided on a solution (provided here) that works reasonably for me but there are many alternatives to tackle that feature. They have obvious trade-offs and I do not claim the solution I settled on in the end is optimal.
Besides, input methods and languages are used in different contexts that requires potentially different solutions.
You may be a native English speaker that needs to write occasionally and in given circumstances in a foreign language.
You may be a native of a foreign language who relies on ANSI English for mostly her professional life but otherwise for anything private writes in her own language.
You may be switching between two languages only. Or you may have to juggle with several languages, themselves having several alphabets or syllabics.
First, to avoid duplication of effort for a potential reader, here is a survey of the situation as of recently.
## Input methods, Input sources, keyboard layouts and spac/emacs
'Input method' is the name of the software piece that translates a key stroke into an output on your file system. 'Input source' is the Mac OS name of this functionality. It roughly covers what people understand as 'Keyboad layout'. One of its most conspicuous use is to write the symbols of written version of the different languages in the world.
Input methods and keyboard layouts can be handled at two levels from an spac/emacs user's point of view. Within Emacs or at the OS system level.
### Defining my own specific need
I use the evil mode in space/macs. My native language and the languages I use on a regular basis require either:
* an extension of the strict ANSI character sets
* or a completely different alphabet or type of characters (e.g. Serbian cyrillic and latin) Using the US international keyboard allows to address several European language needs while retaining most of the kwertiop layout. Some features of vi though (register, jumps) requires keys that in the US international keyboad are used as so called "dead keys", keys which when pressed once do not output a character but modify the next input. The ñ in the spanish word niña est produced for example by type '~' then 'n'. Note that '˜'in command mode in vi is a shorthand for 'capitalize'. So in command mode with a US International keyboard, to capitalise I need to type '˜' then 'SPC'. That is still acceptable. Accessing the current register requires /'"/ that is ' followed by ". This requires now two extra-spaces. Manipulation of surroundings is a particular pain in this model. cs5w"' to change the string bracket from " to ' makes you pause before execution.
If you are in an entirely different keyboard layout for english (dvorak or colemak) or for another language, this is not even a starter.
One solution is to switch back to a standard US English (Qwertyop) layout when in command mode then back to... another keyboard layout in input mode.
How this is can be achieved is the purpose of the rest of this post.
### Native emacs solution
Emacs has by itself the capacity to manage input methods natively. That is it has the capability to encode keystrokes and translates them into characters within the application independently of the OS.
```
M-x list-input-methods
```
is your friend. Here are references I found related to emacs input methods. https://www.reddit.com/r/spacemacs/comments/8lu5kd/change\_keyboard\_layout\_only\_in\_insert\_mode/
https://clarkgrubb.com/personal-keyboard#latin
https://arenzana.org/2019/01/emacs-locale-management-and-input-methods/
https://charalambosthemistocleous.com/emacs,/writing/2017/12/13/emacs-input.html
Quoting from the last reference:
> If you switched the layout using emacs itself, not the system it'll work as you would expect, so the keybinding for it is "C-" it'll show you a helm autocomplete to choose your layout, this layout will be used only in Insert mode, and you can always switch back and forth between the English layout and in my case the Arabic layout using "C-"
This is a perfectly valid approach that I contemplated. I am not spending all my life in spac/emacs (yet). So it makes often sense to have the current input language carried over system-wide.
## OS native approach
Emacs will use by default the input method currently active on your OS. Unless you explicitly asked it to switch to a native one, that is.
Another approach is thus to switch from Emacs the OS input method.
This requires two pieces of software:
1. an external executable as there is currently no direct high level API to the input methods in any of the major OS'.
2. some e-list code to manipulate the previous.
The coupling between these two pieces of software can vary. They may have been produced by a single author that has ignored the rest of the echo system. In the latest development though several "backends" have been planned as well as functionality to extend to new ones (this is the case of https://github.com/laishulu/emacs-smart-input-source for example).
## OS input switcher binaries
It turns out there are score of input switcher provided by the community as open software. They may be available only on a specific OS flavour or may have been compiled on several OS. Here are a few candidates.
1. fcitx-remote:
https://github.com/xcodebuild/fcitx-remote-for-osx https://github.com/cute-jumper/fcitx-remote-for-windows
2. im-select
https://github.com/daipeihust/im-select
3. input source switcher
https://gist.github.com/ghost355/a967417bb7e826e833d4
4. swim
https://github.com/mitsuse/swim
5. macsim Of not EMP (Emacs Mac OS X Port) has its own input switcher embeded.
You will often need to install them on your OS. On Linux, the situation seems slightly better than on Mac OS X and Windows but I have been using a Mac OS X for the past few months and have not tested the machinery on my usual distribution.
### e-lisp interfaces
1. fcitx.el https://github.com/cute-jumper/fcitx.el/blob/master/fcitx.el This package provides a set of functions to make fcitx work better in Emacs. This is originally designed to be used along with \`fcitx' on Linux, but it can also be used on other platforms with other input methods. Targeted OS:
* For OSX users, see \[fcitx-remote-for-osx\]
* For Windows users, see \[fcitx-remote-for-windows\]
* For users who want to add support for other input methods, see the following section: *Work with Other Input methods*
2. im-switch https://gist.github.com/penn201500/fd445603ea05faef4c9f5b2e102613ad with im-select: https://github.com/daipeihust/im-select OS:
* windows
* mac
* Linux ?
3. sis This one looks very good but I could not make it work: https://github.com/laishulu/emacs-smart-input-source
Theoretically it works with any underlying input switcher that works as follows:
* YOUR\_ISM:
+ Run =YOUR\_ISM= will output the current input source
+ Run =YOUR\_ISM INPUT\_SOURCE\_ID= will select INPUT\_SOURCE\_ Targeted OS:
* Mac OS X: with either Emacs Mac Port (EMP) or macsim
* Windows: im-select par exemple
* linux: fcitx
4. EmacsAutoKbdSwitch.el
old works with issw: https://github.com/vovkasm/input-source-switcher Only for mac os X.
# My current solution
I ended up with input-switch.el not entirely as a deliberate choice. I was already fairly engaged into making it work when I stumble upon /sis/, if memory serves me well.
It has been working well for me. I tweak one of the 3 or 4 versions of the script floating on the cloud because I had specific needs. I wanted in particular to be able to switch from within emacs to several keyboard layouts. I mapped these functions in spacemacs to: =o i i= (switch input mode to US international) and =o s= (switch to serbian: latin and cyrillic).
Here is my modified code:
```
(message "-- im-switch.el --")
;; switch to english input method when switching to normal mode
;; and switch back when entering insert/replace modes
;; need external script support, currently mac-only
;; https://gist.github.com/celadevra/7ae45920e2494fbc38ef
(defvar default-im "com.apple.keylayout.US" "Default ascii-only input method")
(defvar usint-im "com.apple.keylayout.USInternational-PC" "US International input method")
(defvar srlat-im "com.apple.keylayout.Serbian-Latin" "Apple Serbian Latin input method")
(defvar sr-im "com.apple.keylayout.Serbian" "Serbian input method")
(defvar prev-im usint-im "IM that I use when starting Emacs and exiting insert mode")
(defun im-use-english ()
"Switch to english input method on a Mac. im-select is a tool
provided at https://github.com/daipeihust/im-select"
(interactive)
(cond ((eq system-type 'darwin)
(call-process-shell-command (concat "/usr/local/bin/im-select " default-im)))))
(defun im-use-usint()
"Switch to Serbian Latin input method on a Mac. im-select is a tool
provided at https://github.com/daipeihust/im-select"
(interactive)
(cond ((eq system-type 'darwin)
(setq prev-im usint-im))))
(defun im-use-sr()
"Switch to Serbian Latin input method on a Mac. im-select is a tool
provided at https://github.com/daipeihust/im-select"
(interactive)
(cond ((eq system-type 'darwin)
(setq prev-im sr-im))))
(defun im-use-srlatin()
"Switch to Serbian Latin input method on a Mac. im-select is a tool
provided at https://github.com/daipeihust/im-select"
(interactive)
(cond ((eq system-type 'darwin)
(setq prev-im srlat-im))))
(defun im-remember ()
"Remember the input method being used in insert mode,so we can switch to it in other modes."
(interactive)
(cond ((eq system-type 'darwin)
(setq prev-im (substring (shell-command-to-string "/usr/local/bin/im-select") 0 -1)))))
;; (defun im--list()
;; "Remember the input method being used in insert mode,so we can switch to it in other modes."
;; (interactive)
;; (cond ((eq system-type 'darwin)
;; (shell-command-to-string "/usr/local/bin/im-select")))
;; )
;; (defun im-choose ()
;; "Remember the input method being used in insert mode,so we can switch to it in other modes."
;; (interactive)
;; (cond ((eq system-type 'darwin)
;; (call-process-shell-command concat)) (substring (shell-command-to-string "/usr/local/bin/im-select") 0 -1)))
(defun im-use-prev ()
"Use previous input method.
If previous input method is not defined, use default method"
(interactive)
(cond ((eq system-type 'darwin)
(if prev-im
(call-process-shell-command (concat "/usr/local/bin/im-select " prev-im))
(call-process-shell-command (concat "/usr/local/bin/im-select " default-im))))))
(add-hook 'evil-normal-state-entry-hook 'im-use-english)
(add-hook 'evil-insert-state-entry-hook 'im-use-prev)
(add-hook 'evil-insert-state-exit-hook 'im-remember)
(add-hook 'evil-replace-state-entry-hook 'im-use-prev)
(add-hook 'evil-replace-state-exit-hook 'im-remember)
(add-hook 'evil-emacs-state-entry-hook 'im-use-english)
(add-hook 'minibuffer-setup-hook 'im-use-prev)
(message "-- im-switch key oii oisc oisl--")
(spacemacs/set-leader-keys "oii" 'im-use-usint)
(spacemacs/set-leader-keys "oisc" 'im-use-sr)
(spacemacs/set-leader-keys "oisl" 'im-use-srlatin)
(provide 'im-switch)
;;;im-switch.el ends here
```
> 1 votes
# Answer
If your purpose is to input Chinese, you could use https://github.com/tumashu/pyim
A native Emacs input method written in pure Emacs Lisp. I just add a new backend `pyim-dregcache` to `pyim`. So it requires much less resource and is still fast enough.
The setup is minimum,
```
(eval-after-load 'pyim
'(progn
(setq pyim-dcache-backend 'pyim-dregcache) ; use memory efficient pyim engine
;; common setup for pyim ...
))
```
> 1 votes
---
Tags: spacemacs, keyboard
---
|
thread-61261
|
https://emacs.stackexchange.com/questions/61261
|
Display summary information on command when running Meta-x
|
2020-10-17T11:37:42.737
|
# Question
Title: Display summary information on command when running Meta-x
Since I'm new to `GNU Emacs` (version 26.1 running on `Debian Stable`) I'd like to get some information when invoking a command using `Meta-x`. Currently I'm only able to see a list of possible completions but I have to guess what the commands are actually doing (although, to be honest, many of them are named very intuitively).
As an explanation: when I'm running
`pac` `<tab>` `li` `<tab>` `<tab>`
the following lines are shown in my minibuffer
```
Possible completions are:
package-list-packages
package-list-packages-no-fetch
```
but I'd like the following functionality
```
Possible completions are:
package-list-packages Display a list of packages.
package-list-packages-no-fetch Display a list of packages.
```
or something similar.
Is there a way to get this option? Additionally: can I do this without installing additional packages?
# Answer
> 2 votes
You may want to try ivy \+ ivy-rich.
The relevant section of the documentation has this screenshot:
You need to include the following lines in your `init.el`:
```
(require 'ivy)
(ivy-mode 1)
(require 'ivy-rich)
(ivy-rich-mode 1)
(setq ivy-use-virtual-buffers t)
(setq enable-recursive-minibuffers t)
(global-set-key (kbd "M-x") 'counsel-M-x)
```
# Answer
> 0 votes
With Icicles such info is available anytime during completion (including for `M-x`), at the press of a key.
This feature, getting help on individual completion candidates, is described here.
Short summary: Use `C-M-mouse-2` to show help on the completion candidate you click in buffer `*Completions*`. Or cycle to a candidate and use `C-M-RET` to show help on it.
In addition, short help for the current candidate (e.g. during cycling) is shown in the mode-line. This is typically the first line of its doc string, or other relevant short info.
You can also show the full help on candidates (in buffer `*Help*`) as you cycle, by cycling with `C-M-down` or `C-M-up`, instead of just `down` or `up`.
---
Tags: completion, commands, help, m-x
---
|
thread-61258
|
https://emacs.stackexchange.com/questions/61258
|
Adding keywords programmatically using the display property
|
2020-10-17T05:59:23.840
|
# Question
Title: Adding keywords programmatically using the display property
I've added some keywords using the following construct (where `tag-todo` and `tag-note` are variable holding a SVG image and `tag-key ()` is a function returning a SVG image):
```
(font-lock-add-keywords nil
'(("\\(\:TODO\:\\)" 1 `(face nil display ,tag-todo))
("\\(\:NOTE\:\\)" 1 `(face nil display ,tag-note))
("\\(=[0-9a-zA-Z- ]+?=\\)" 1
`(face nil display ,(tag-key (match-string 0))))))
```
This works great (see reddit post) but I would like now to do the same using a list of regexp / tag (or function):
```
(setq tags '((":TODO:" . tag-todo)
(":NOTE:" . tag-note)
("=[0-9a-zA-Z- ]+?=" . tag-key)))
```
I can iterate over the list using `dolist` but then I'not sure how to write the actual call to `font-lock-add-keywords` (building the regexp and make sure the tag variable (or function) is called):
```
(dolist (item tags)
(let ((regexp (car item))
(tag (cdr item)))
(message (format "%s : %s" regexp tag))
;; HOW TO CALL font-lock-add-keywords with regexp and tag ?
))
```
**Update**
I've tried using mapcar, but the `(cdr item)` does not evaluate to the actual tag content.
```
(defun f (item)
`( ,(concat "\\(" (car item) "\\)") 1
`(face nil display (cdr item))))
(mapcar 'f tags)
```
# Answer
> 1 votes
This may get you there. (Do you really want/need a `\` before each colon (`:`)?)
```
(defun foo ()
"..."
(font-lock-add-keywords nil (mapcar 'bar tags)))
(defun bar (pat.fac)
"..."
(let ((pat (format "\\(%s\\)" (car pat.fac)))
(fac (cdr pat.fac)))
(when (eq fac 'tag-key) (setq fac '(tag-key (match-string 0))))
(setq fac ``(face nil display ,,fac))
`(,pat 1 ,fac)))
```
`(mapcar 'bar tags)` returns this:
```
(("\\(:TODO:\\)" 1
`(face nil display ,tag-todo))
("\\(:NOTE:\\)" 1
`(face nil display ,tag-note))
("\\(=[0-9a-zA-Z- ]+?=\\)" 1
`(face nil display ,(tag-key (match-string 0)))))
```
The key to the trouble you were having, I think, is to use two levels of backquoting.
---
Tags: font-lock, backquote
---
|
thread-61256
|
https://emacs.stackexchange.com/questions/61256
|
Setting the value of a variable in Org babel system-wide header arguments
|
2020-10-17T00:54:08.927
|
# Question
Title: Setting the value of a variable in Org babel system-wide header arguments
# The context
I always experiment with commands in the following path `$HOME/trash/experimental`. For this reason, I wanted to make all `shell` code blocks to use that directory as the default directory. I've already accomplished that by setting the following in my configuration
```
$ cat ~/.emacs.d/init.el
(org-babel-do-load-languages
'org-babel-load-languages '((shell . t)))
(setq org-babel-default-header-args:shell '((:dir . "~/trash/experimental")))
```
Sometimes I also play with the `zsh` and the `dash` shell so I would also make the previous mentioned directory as the default one for code blocks whose language is any of those shells. Similarly, I can accomplish that by setting the following in my `init.el` file.
```
$ cat ~/.emacs.d/init.el
(org-babel-do-load-languages
'org-babel-load-languages '((shell . t)))
(setq org-babel-default-header-args:shell '((:dir . "~/trash/experimental")))
(setq org-babel-default-header-args:dash '((:dir . "~/trash/experimental")))
(setq org-babel-default-header-args:zsh '((:dir . "~/trash/experimental")))
```
As seen above, the path is repeated three times. In order to avoid that I defined a variable that stores the path where I experiment with commands (i.e. `~/trash/experimental`). Thus, my configration file looks like
```
$ cat ~/.emacs.d/init.el
(org-babel-do-load-languages
'org-babel-load-languages '((shell . t)))
(setf path/experiments "~/trash/experimental")
(setq org-babel-default-header-args:shell '((:dir . path/experiments)))
(setq org-babel-default-header-args:dash '((:dir . path/experiments)))
(setq org-babel-default-header-args:zsh '((:dir . path/experiments)))
```
This is where the problem comes.
# The problem
When evaluating code blocks whose language is `shell`, `dash` or `zsh`, I get the following error
```
Wrong type argument: stringp, path/experiments
```
# The question
How can I use the value of a variable so that it affects all code blocks whose language is `zsh`, `dash` or `shell`?
# Answer
You can accomplish this by using the concept of backquoting. Consider the following minimal configuration. Note the usage of ``(...)` and `,` within ``(...)`
```
$ cat ~/.emacs.d/init.el
(org-babel-do-load-languages
'org-babel-load-languages '((python . t) (shell . t)))
(setq my/path/experiments "~/trash/experimental")
(defun path/experiments (&optional file)
(if file
(concat my/path/experiments "/" file) my/path/experiments))
(setq org-babel-default-header-args:sh
`((:dir . ,(path/experiments))
(:tangle . ,(path/experiments "sh.sh"))))
$
```
This would cause the following behavior in an Org file
```
* My heading
** My subheading
#+begin_src sh
pwd
#+end_src
#+RESULTS:
: /home/myname/trash/experimental
#+begin_src python :results output
import os
print(os.getcwd())
#+end_src
#+RESULTS:
: /home/myname/location/of/this/file
```
Note that this configuration file would evaluate the expression once Emacs reaches the `setq` statements. This implies that if you change the value of the variable `my/path/experiments`, then that value will not be evaluated when obtaining the header arguments for `sh` code blocks. What I state can also be proved because of the fact that the value of `org-babel-defaul-header-args:sh` stores strings instead of expressions. As far as I know, those strings are set once Emacs reaches that statement in your configuration file or when you evaluate it.
```
org-babel-default-header-args:sh is a variable defined in ‘ob-shell.el’.
Its value is
((:dir . "~/trash/experimental")
(:tangle . "~/trash/experimental/sh.sh"))
```
If you want to change the value of the variable, you would need to evaluate the expression that sets the header arguments again
```
(setq org-babel-default-header-args:sh
`((:dir . ,(path/experiments))
(:tangle . ,(path/experiments "sh.sh"))))
```
> 0 votes
---
Tags: org-mode, org-babel
---
|
thread-61276
|
https://emacs.stackexchange.com/questions/61276
|
Why does use-package considers "emacs" as a package?
|
2020-10-17T21:19:37.177
|
# Question
Title: Why does use-package considers "emacs" as a package?
In the `use-package` documentation https://github.com/jwiegley/use-package#diminishing-and-delighting-minor-modes there is an example that considers **emacs** as a package(i.e `(use-package emacs)`)
Usually the installed packages reside in the subdirectory of '~/.emacs.d/...'. How does use-package handle the package **emacs** ? Is it handled as a special case ?
# Answer
It is not packages that `use-package` loads but *features* (which are things you can `require` and test for with `featurep`). From this point of view, `use-package` is essentially a fancy wrapper for `require`.
While `use-package` can often seem like magic, you can demystify by placing point after a `use-package` stanza and doing `M-x pp-macroexpand-last-sexp`. In the case you reference, macro-expanding
```
(use-package emacs
:delight
(auto-fill-function " AF")
(visual-line-mode))
```
yields
```
(if
(not
(require 'emacs nil t))
(display-warning 'use-package
(format "Cannot load %s" 'emacs)
:error)
(if
(fboundp 'delight)
(delight
'((auto-fill-function " AF" emacs)
(visual-line-mode nil emacs)))))
```
wrapped in some error-checking, messages and timing.
This is helpful: you can use the nice `use-package` interface to configure built-in things like `dired`.
> 8 votes
---
Tags: use-package
---
|
thread-61284
|
https://emacs.stackexchange.com/questions/61284
|
Can not read dir-local variable from a hook function
|
2020-10-18T10:08:40.577
|
# Question
Title: Can not read dir-local variable from a hook function
hope you are all well.
Before stating problem, let me tell you my setup. I am using `Emacs 27.1`, using `pyvenv`, `projectile`, `lsp-mode`, `lsp-python-ms` for `python-mode`. I have set `WORKON_HOME` environmental variable to `~/.pyenv/versions` and created an env named `venv3.8`. I can activate the venv using `<M-x> pyvenv-workon <RET> venv3.8 <RET>`. After that i can start lsp with `lsp` command.
My idea was to set virtualenv (using `pyvenv-workon`) automatically upon opening a project (python project) or opening a python script (not part of a project). So the concept was like this -
1. If a project is opened, meaning `projectile-project-name` is available first check if there is a virtualenv with the same name, if thats available activate it. If thats not available check a special variable (which i set with `defcustom`) name `python-env-name` for a hint, now if the specified env is available then activate it. Else do nothing.
2. If a standalone script is opened, then check if `pyhton-env-name` for a hint, if the specified env is available, activate it. Else do nothing.
3. After activating the virtualenv, start lsp-mode.
The custom variable `python-env-name` is supposed to be available to set in a `.dir-local.el` so that i can easily set per project venv if necessary.
Here is my current code -
```
(defcustom python-env-name "venv"
"Set the virtualenv name to be used.
The virtualenv name is the folder name of a virtualenv
located under WORKON_HOME directory. It is set to be
~/.pyenv/versions."
:type 'string
:tag "Python Virtual Environment Name"
:group 'python
:safe 'stringp)
(defun my/log (message)
"Log MESSAGE to *my-logs* buffer.
MESSAGE is string value."
(interactive "sMessage: ")
(if (stringp message)
(with-current-buffer (get-buffer-create "*my-logs*")
(insert message))))
(defun my/activate-venv-for-project ()
"Activates virtualenv for current project."
(let ((project-venv-path (concat (getenv "WORKON_HOME") "/"
projectile-project-name))
(default-venv-path (concat (getenv "WORKON_HOME") "/"
(buffer-local-value 'python-env-name (current-buffer)))))
(my/log (format "Project venv: %s, found: %s\n" project-venv-path
(file-directory-p project-venv-path)))
(my/log (format "Default venv: %s, found: %s\n" default-venv-path
(file-directory-p default-venv-path)))
(if (file-directory-p project-venv-path)
(pyvenv-workon projectile-project-name)
(if (file-directory-p default-venv-path)
(pyvenv-workon python-env-name)))))
(defun my/activate-venv-for-script ()
"Activate virtualenv for a standalone script."
(let ((default-venv-path (concat (getenv "WORKON_HOME") "/"
(buffer-local-value 'python-env-name (current-buffer)))))
(my/log (format "Script default venv: %s, found: %s\n" default-venv-path
(file-directory-p default-venv-path)))
(if (file-directory-p default-venv-path)
(pyvenv-workon python-env-name))))
(defun my/setup-python-environment ()
"Setup the python virtual env for project or python script.
This function first checks if we opened a project, if so either the
virtualenv named as the projectile-project-name or the value of
python-env-name will be used to activate virtualenv. If none are
aviable no virtualenv will be activated. If we didnt open any
project, then simply check the python-env-name variable, if
the env is available then activate it or not. Afterwards it will
start up lsp-mode."
(interactive)
(hack-local-variables-apply)
(hack-dir-local-variables)
(if (bound-and-true-p projectile-project-name)
(my/activate-venv-for-project)
(my/activate-venv-for-script))
(require 'lsp-python-ms)
(lsp))
(add-hook 'python-mode-hook 'my/setup-python-environment)
```
As you can see, i tried to show some message while setting up the environment. Then i opened a python project (using projectile), and opened a python file. I have already set the `python-env-name` in a dir-local file as follows -
```
((python-mode . ((python-env-name . "venv3.8"))))
```
Here is the text from `*my-logs*` buffer -
```
Project venv: ~/.pyenv/versions/python-check, found: nil
Default venv: ~/.pyenv/versions/venv, found: nil
```
So clearly, the dir-local value is not used in the `my/setup-python-environment`. But if i put the cursor at the python file and run `<M-x> eval-expression <RET> python-env-name <RET>` it shows `"venv3.8"` in the minibuffer. So the dir local variables are read. What am i doing wrong? Please help. Forgive my if i am doing anything wrong as i am very new to elisp. Thanks in advance. I hope i was clear enough.
# Answer
Local variables are set after hooks are run. Try using a timer:
```
(let ((buf (current-buffer)))
(run-with-timer 0.01 nil
(lambda ()
(with-current-buffer buf
(if (bound-and-true-p projectile-project-name)
(my/activate-venv-for-project)
(my/activate-venv-for-script))
(require 'lsp-python-ms)
(lsp)))))
```
> 1 votes
---
Tags: directory-local-variables, local-variables
---
|
thread-5705
|
https://emacs.stackexchange.com/questions/5705
|
Use Super in emacs -nw in linux
|
2014-12-24T15:12:20.603
|
# Question
Title: Use Super in emacs -nw in linux
I have been struggling to find a simple and direct question to the answer and therefore I have decided to ask here.
**Q:** Is there a way to use Super in Emacs launched in a Terminal in Linux?
**P.S**: I read a lot of information about `xmodmap` but I think the key is that the terminal emulator cannot represent the Super key. However, `(kbd "s-SPC")` returns something and I was thinking of using the translation facility of `.Xdefaults/X`. Am I on the right path? Given the result of `kbd`, what do I need to put as XTerm.VT100.translations?
# Answer
> 22 votes
You will be more comfortable in an X11 Emacs, which can receive keyboard input and display text without going through encoding and decoding for the terminal. The main reason to use a text mode editor is to run it inside screen or tmux on a remote machine, but thanks to Tramp, it's usually easier to edit the remote file in your local Emacs. That being said, you can do what you want as long as your terminal emulator cooperates, which is the case with Xterm.
When you press a key or key combination in a terminal, it is transmitted to the application running in the terminal as a sequence of one or more characters. For example, when you press `a`, the application receives `a`. When you press `Enter`, the application receives the character `CR` (a.k.a. `^M` (pronounced “control-emm”), a.k.a. character number 13, a.k.a. `\r` or `\015`). Key combinations involving `Alt` are typically transmitted as the character `ESC` (a.ka. `^[` a.k.a. `\e` or `\033`) followed by the sequence for the key or key combination without `Alt`. Function keys and other key combinations are transmitted as escape sequences beginning with `\e[` or `\eO`.
The escapes sequences are not fully standardized, and terminals typically ignore certain attributes for certain keys. For example, the hyper and super modifiers are usually ignored. You can see what your terminal sends for a key combination by pressing `Ctrl`+`V` followed by that key combination in a shell prompt, or `C-q` or `C-h c` followed by the key combination in Emacs.
Xterm lets you configure the escape sequences for each key through X resources. Most setups read resources from `~/.Xresources` when X starts, and you can load the file manually with `xrdb -merge ~/.Xresources`.
```
XTerm.VT100.translations: #override \n\
Ctrl ~Shift ~Meta <Key> Return: string("\033[73;5~") \n\
Ctrl Shift ~Meta <Key> percent: string("\033[37;6~")
```
A common convention uses escape sequences of the form `ESC [ number1 ; number2 ~` for function keys with modifiers. `number1` indicates the function key (`15` to `24` for `F5` to `F12` — for historical reasons, F1 through `F4` have different escape sequences) and `number2` indicates the modifier (`2` for `Shift`, `5` for `Ctrl`, `3` for `Meta`, `8` for `Ctrl`+`Meta`, and add 1 for +`Shift` — no, it isn't very consistent).
You'll have to specify the Hyper and Super modifiers through their number, as `Mod1` through `Mod5`. Run `xmodmap -pm` to see the mapping of keysyms to modifiers. For example, if `Super_L` is bound to Mod5, then the following line (use this exact case) defines a binding for `Super`+`Space`:
```
~Ctrl ~Meta Mod5 <Key> space: string("\033[32;16~") \n\
```
Emacs translates escape sequences into its internal key representation through `input-decode-map` or `local-function-key-map` (or `function-key-map` before Emacs 23).
```
(define-key local-function-key-map "\033[32;16~" [(super ?\ )])
```
<sub> This post is made of 80% recycled material from Are there any linux terminals which can handle all key combinations? </sub>
# Answer
> 1 votes
If you're willing to install an Emacs package and configure your terminal, I wrote an Emacs package which can teach Emacs and terminals how to properly recognize all PC keyboard keys and modifier key combinations:
https://github.com/CyberShadow/term-keys
Encoding the Super modifier is not enabled by default, but the package is customizable and allows configuring which modifier key combinations are encoded. To enable encoding key combinations that include the Super modifier, set `term-keys/want-key-p-func` to a function which returns `t` when `(elt mods 3)` is non-nil (see the default implementation for an explanation).
# Answer
> 1 votes
I have the following in my init files:
```
(global-set-key [f7] nil)
(global-set-key [f8] nil)
(define-key function-key-map [(f7)] 'event-apply-super-modifier)
(define-key function-key-map [(f8)] 'event-apply-hyper-modifier)
```
This allows me to send super and hyper keys using the function keys.
# Answer
> 0 votes
Short answer: use `Konsole`.
Explanation:
* Emacs' `local-function-key-map` has an entry mapping `C-x @ s` to `event-apply-super-modifier`.
* `Konsole` maps `Super` (the Windows logo key) to the escape sequence `^X@s` (which doesn't seem to be documented anywhere, I discovered it by chance). You can try this by opening `Konsole` and pressing e.g. `Ctrl-v` `Win-o`.
# Answer
> 0 votes
Inspired from @ubolonton's answer, I was able to bind `Super` and `Hyper` (and add a supplementary Meta key) in urxvt with those 4 lines of `~/.Xdefaults`:
```
URxvt.keysym.XF86AudioPlay: string:\030@m
URxvt.keysym.Menu: string:\030@s
URxvt.keysym.Muhenkan: string:\030@h
```
and out of luck I dind't had to touch anything else to make it work.
Explanation:
On my keyboard (a TypeMatrix), under `Shift_L, z, x, c` I have: `ctrl, XF86AudioPlay, Menu, Muhenkan` (weird keyboard), so by binding the strings `C-x @ m` to `XF86AudioPlay`, `C-x @ s` to `Menu` and `C-x @ h` to `Muhenkan`, I have, from the left to the right: Ctrl, Meta, Super, Hyper.
(If you have the exact same keyboard as mine and want to try it out, you first need to set your keyboard to its 106-keys layout by pressing `Fn-F3`, else the 4th key is bound to `Meta-tab`.)
---
Tags: key-bindings, linux, term, terminal-emacs
---
|
thread-61219
|
https://emacs.stackexchange.com/questions/61219
|
Custom made rgrep via ack stopped working
|
2020-10-15T19:15:01.820
|
# Question
Title: Custom made rgrep via ack stopped working
I used to use the function below to call ack as a fast, recursive grep, but for whatever reason it stopped working. More precisely it returns no result. It probably happened when I updated Emacs or macOS, hard to say.
The ack is working from terminal without any issues.
Does anyone have any idea how to fix it? I also considering alternatives, but hopefully not too slow for big folders.
```
(defun my/rgrep ()
(interactive)
(if (executable-find "ack")
(let* ((regexp (grep-read-regexp))
(dir (read-directory-name "Base directory: " nil default-directory t))
(command (concat "ack '" regexp "' " dir)))
(unless (file-accessible-directory-p dir)
(error (concat "directory: '" dir "' is not accessible.")))
(compilation-start command 'grep-mode))
))
```
---
EDIT: Sadly even rgrep doesn't work when evaluated as `(progn (grep-compute-defaults) (rgrep "foo" "*.txt" "/Volumes/RAM_Disk/test"))` where that folder has only one txt file with text "foo" it returns no matches. The generated find command below:
```
find . -type d \( -path \*/SCCS -o -path \*/RCS -o -path \*/CVS -o -path \*/MCVS -o -path \*/.src -o -path \*/.svn -o -path \*/.git -o -path \*/.hg -o -path \*/.bzr -o -path \*/_MTN -o -path \*/_darcs -o -path \*/\{arch\} \) -prune -o \! -type d \( -name .\#\* -o -name \*.o -o -name \*\~ -o -name \*.bin -o -name \*.lbin -o -name \*.so -o -name \*.a -o -name \*.ln -o -name \*.blg -o -name \*.bbl -o -name \*.elc -o -name \*.lof -o -name \*.glo -o -name \*.idx -o -name \*.lot -o -name \*.fmt -o -name \*.tfm -o -name \*.class -o -name \*.fas -o -name \*.lib -o -name \*.mem -o -name \*.x86f -o -name \*.sparcf -o -name \*.dfsl -o -name \*.pfsl -o -name \*.d64fsl -o -name \*.p64fsl -o -name \*.lx64fsl -o -name \*.lx32fsl -o -name \*.dx64fsl -o -name \*.dx32fsl -o -name \*.fx64fsl -o -name \*.fx32fsl -o -name \*.sx64fsl -o -name \*.sx32fsl -o -name \*.wx64fsl -o -name \*.wx32fsl -o -name \*.fasl -o -name \*.ufsl -o -name \*.fsl -o -name \*.dxl -o -name \*.lo -o -name \*.la -o -name \*.gmo -o -name \*.mo -o -name \*.toc -o -name \*.aux -o -name \*.cp -o -name \*.fn -o -name \*.ky -o -name \*.pg -o -name \*.tp -o -name \*.vr -o -name \*.cps -o -name \*.fns -o -name \*.kys -o -name \*.pgs -o -name \*.tps -o -name \*.vrs -o -name \*.pyc -o -name \*.pyo \) -prune -o -type f \( -iregex \*.txt \) -exec grep -i -nH --null -e foo \{\} +
```
After more pondering on this, I found that there is also a problem with running rgrep or any alternative in tramp.
I think of making a universal my/rgrep function that will use default strategy like ack, and fallback to another strategy like ag and find/grep if the previous one wasn't found. Also making it work with tramp.
Because I already have defined config for ack that works well from the terminal I would put ack on the front of that list, but it shouldn't matter which one we put first.
Does anyone of you have this problem solved already, or at least have configured tramp to work well with rgrep?
# Answer
Thanks for suggestions in comments, especially by Firmin Martin, I managed to find an answer to the problem. It turned out that the variable `find-name-arg` was set to `-iregex` which caused the issue in rgrep, no matter if used with ack or with regular `grep`. After brinding is back to default `-iname` the rgrep works fine.
> 1 votes
---
Tags: rgrep
---
|
thread-56214
|
https://emacs.stackexchange.com/questions/56214
|
Use the terminal background color for the emacs -nw
|
2020-03-18T11:55:52.733
|
# Question
Title: Use the terminal background color for the emacs -nw
I am looking for a way to force "emacs -nw" to use the same background color that the terminal uses. (just like vim does). By default, every emacs theme has its own default background color. Whiteboard mode has white that is not the same white as my terminal.
# Answer
It seems that setting the background color of the default font to an undefined value turns off any customization. This feels like a hack, and there might be a better way to do this, but this worked for me:
```
;; init.el
(set-face-background 'default "undefined")
```
Of course, if "undefined" will ever be defined (haha) in the color palette, this will break.
> 6 votes
# Answer
You can also use `custom-set-faces` to just NOT set properties when using a tty, and then have other defaults for other types.
With the following, the `default` face gets foreground and background set unless the display type is `tty`, as it is when you run `emacs -nw`.
For some other things, I generally like the defaults, especially when using X11. I override a handful of those when type is `tty`, and leave them alone otherwise.
Note that the `comment-face` is always set ... brightgreen for terminals, green1 otherwise (X11).
```
(custom-set-faces
;; custom-set-faces was added by Custom.
;; If you edit it by hand, you could mess it up, so be careful.
;; Your init file should contain only one such instance.
;; If there is more than one, they won't work right.
'(default ((((type tty)))
(t (:background "#6F4700" :foreground "yellow" :slant normal :weight normal :width normal :foundry "default" :family "monospace"))))
'(font-lock-comment-face ((((type tty)) (:foreground "brightgreen"))
(t (:foreground "green1"))))
'(font-lock-builtin-face ((((type tty)) (:foreground "color-250"))))
'(minibuffer-prompt ((((type tty)) (:foreground "cyan"))))
'(font-lock-string-face ((((type tty)) (:foreground "orange")))))
```
> 1 votes
---
Tags: terminal-emacs, colors
---
|
thread-24826
|
https://emacs.stackexchange.com/questions/24826
|
Emac in Terminal opens in unusable green background
|
2016-07-25T17:39:35.517
|
# Question
Title: Emac in Terminal opens in unusable green background
\[OS X 10.11, MacPorts Emacs 24.5, OS X Terminal, lots of stuff in emacs and shell init files\]
I almost always use Emacs.app (GUI). Sometimes I want to open Emacs in a terminal. When I open Emacs from a terminal I get a bright green background that in combination with my usual theme is unusable -- I can't even read the messages at the bottom of the window.
I have tried this with various Terminal Profiles but they all do the same. I have tried `emacs -bg while` but that doesn't work either.
How do I control the background color of Emacs opened from the terminal?
# Answer
Few themes work well with emacs run within a terminal because you are dealing with a much smaller color palette. Unless you have enabled 256 colors in your terminal, you are likely working with just 8 colors when you fire up emacs in a terminal. An easy way around this issue is to conditionally load your color theme selections only when you are working with the gui version of emacs. The `window-system` variable contains the info you want, however use of that variable in situations such as this is deprecated in favor of the function `display-graphic-p`.
In your `.emacs` file try guarding your color theme initialization using something like the following:
```
(when (display-graphic-p)
; color theme initialization code goes here
)
```
`display-graphic-p` returns non-nil if the current display is a graphic display, and it returns nil if it is a terminal. See the docs if you are interested: `C-h f display-graphic-p`. For more info on `window-system` variable: `C-h v window-system`.
Doing this will cause the default color theme to be loaded when you start Emacs in a terminal. While not very pretty, it works with 8 and 256 colors.
> 4 votes
# Answer
Something like this in your ~/.emacs will leave the terminal foreground and background untouched, i. e. emacs will use your terminal colors:
```
(custom-set-faces
;; custom-set-faces was added by Custom.
;; If you edit it by hand, you could mess it up, so be careful.
;; Your init file should contain only one such instance.
;; If there is more than one, they won't work right.
'(default ((((type tty))))))
```
This basically says that when the display type is tty, don't set attributes on the default face.
You can use this more generally to pick different attributes for X11 vs. terminal:
```
(custom-set-faces
;; custom-set-faces was added by Custom.
;; If you edit it by hand, you could mess it up, so be careful.
;; Your init file should contain only one such instance.
;; If there is more than one, they won't work right.
'(default ((((type tty)))
(t (:background "#6F4700" :foreground "yellow" :slant normal
:weight normal :width normal :height 140 :foundry "default"
:family "monospace"))))
'(font-lock-comment-face ((((type tty)) (:foreground "brightgreen"))
(t (:foreground "green1")))))
```
> 0 votes
---
Tags: terminal-emacs, colors
---
|
thread-61280
|
https://emacs.stackexchange.com/questions/61280
|
How to get the value of a variable inside an org-mode file from command line?
|
2020-10-18T02:15:27.497
|
# Question
Title: How to get the value of a variable inside an org-mode file from command line?
Is there a reliable way to get the value of a variable defined inside an org-mode file from the UNIX shell (bash)?
For example, if I have the following inside an org mode file `test.org`:
```
#+NAME: foo
| bar |
```
, is it possible to write a shell script to get the value of `foo`?
I know how to extract the value of a variable inside the org file, but just couldn't find a way to retrieve the value externally from the command line.
(This is with the org mode shipped with Emacs 26 in Ubuntu 20.04 LTS)
# Answer
The general answer consists of two parts: 1) you write a Lisp function that extracts the value of interest and 2) you arrange a command-line invocation that calls that function and gives you the value on its standard output, so that it can be incorporated in a shell script.
The second part is an invocation of `emacsclient` with the appropriate arguments. You can capture its stdout by using the `$(some_command)` syntax of bash (and other shells, but the exact syntax depends on the shell - I am assuming `bash` from now on).
E.g. assuming that you have Emacs running and that you have started a server with `(server-start)`, the invocation
```
$ emacsclient -e "(+ 1 2)"
3
```
will send the string to the server and ask it to evaluate it. The evaluation results in the value `3` which is sent back to `emacsclient` and is printed on its stdout.
So a simple bash program that would make use of that output would be something like
```
echo The value that emacs returned was $(emacsclient -e "(+ 1 2)")
```
The first part involves writing a function to retrieve the value of some property that is found under some headline in some file. The function takes the pathname of the file, the headline and the property name as arguments and it should return the value of the property. The following is an initial attempt at that (it does not deal with errors, but it should be good enough to experiment with):
```
(defun ndk/get-headline-property-from-file (fname headline prop)
"Open the file, search for the headline and retrieve the value
of the property. FNAME is the path of the file to be searched,
HEADLINE is the headline under which the property is looked up
and PROP is the name of the property. The value of the property
is returned. If no value is found, the empty string is
returned (IOW, the function does not distinguish between a
non-existent property and a property whose value is empty)."
(save-excursion
(with-current-buffer (find-file-noselect fname)
(goto-char (point-min))
;; search for the headline
(if (re-search-forward (format org-complex-heading-regexp-format
(regexp-quote headline))
nil t)
(beginning-of-line)
(goto-char (point-max)))
;; try to get the property
(let ((val (org-entry-get (point) prop)))
(if (not val)
""
val)))))
```
Make sure that your emacs knows about this function before going further: add it to your init file and (re)start emacs. And don't forget to start the emacs server: add `(server-start)` to your init file as well.
Now you can put the two parts together:
```
echo $(emacsclient -e '(ndk/get-headline-property-from-file "./test.org" "My headline" "var1")'
```
with `test.org` (assumed to be in the current directory) containing:
```
* Some headline
...
* My headline
:PROPERTIES:
:var1: baz
:END:
stuff
* Another headline
...
```
The `echo` should echo `baz`.
> 2 votes
---
Tags: org-mode, bash
---
|
thread-61293
|
https://emacs.stackexchange.com/questions/61293
|
Git commit multiple files
|
2020-10-19T03:24:02.810
|
# Question
Title: Git commit multiple files
When I go to commit my changes VC seems only allows me to commit one file at a time via `C-x v v`. Is there a way for VC to commit more than 1 file at a time?
# Answer
See `C-h``i``g` `(emacs)VC With A Merging VCS`
If you open `vc-dir` with `C-x``v``d` you can mark files with `m` -- or `M` to mark *all* files in a particular state -- and then `C-x``v``v` will act on all of those files.
For Git specifically, Magit provides a nicer UI than VC. If you use Git a lot, then definitely check it out -- it's well worth learning to use.
> 2 votes
---
Tags: magit, git
---
|
thread-61237
|
https://emacs.stackexchange.com/questions/61237
|
How to create a initial collapsed/hidden block in org exported HTML?
|
2020-10-16T09:27:17.683
|
# Question
Title: How to create a initial collapsed/hidden block in org exported HTML?
I'd like to create a collapsible block (examples, quotes, codes, ...) when exporting an org file to HTML. Also I'd like to have a way to show the block(button? keystroks?). How can I do this?
Thanks!
# Answer
Found a possible solution by using https://alhassy.github.io/org-special-block-extras/#Folded-Details
```
#+begin_details "Click to see dummy code"
#+begin_src elisp
(message "Dummy code")
#+end_src
#+end_details
```
> 4 votes
---
Tags: org-mode, org-export, org-babel
---
|
thread-61299
|
https://emacs.stackexchange.com/questions/61299
|
Regular expressions tool example explanation
|
2020-10-19T08:29:06.693
|
# Question
Title: Regular expressions tool example explanation
Reading the section regular expressions in EmacsWiki appears this:
```
You can use a tool to construct regexps. For example, you can use ‘rx’ like this:
(rx (or (and "\*" (*? anything) "*/") (and "//" (*? anything) eol)))
To produce this regexp (which matches C-style multiline and single line comments):
\\*\\(?:.\\|\n\\)*?\\*/\\|//\\(?:.\\|\n\\)*?$
```
I get the `or` will match either C-style multiline or C/C++ single line comments.
But I do not get the `and` parts.
1. I am not sure how `anything` works and am assuming that will match any char.
It might be something equivalent to `.*`. Is it?
2. If I got it right, `*?` is the non-greedy variant of `*` operation.
Which really confuses me... The smallest possible match for `anything`?
3. Why the C-style multi-line opening is shown as **"\\\*"**? I suspect it is a typo on EmacsWiki and it should be **"/\*"**.
# Answer
> 1 votes
`anything` matches any character, while regexp `.` matches any character **except** a newline, the rx representation is `not-newline`.
`*?` matches zero-or-more, non-greedy. Let's extract comment from C code:
```
/* comment */ char *s = "*/";
```
```
;; * is zero-or-more, greedy
(let ((string "/* comment */ char *s = \"*/\""))
(when (string-match (rx "/*" (* anything) "*/") string)
(match-string 0 string)))
;; => "/* comment */ char *s = \"*/"
;; *? is zero-or-more, non-greedy
(let ((string "/* comment */ char *s = \"*/\""))
(when (string-match (rx "/*" (*? anything) "*/") string)
(match-string 0 string)))
;; => "/* comment */"
```
Check the doc via C-h f rx or (info "(elisp) Rx Notation").
---
Tags: regular-expressions, rx
---
|
thread-60746
|
https://emacs.stackexchange.com/questions/60746
|
Is there a way to attach hidden/invisible data to a place in text?
|
2020-09-19T14:52:24.943
|
# Question
Title: Is there a way to attach hidden/invisible data to a place in text?
I want to keep track of some stuff happening in the buffer, with elisp, and display indicators depending on that stuff. To that end, I need to cache calculated data for different parts of the file, and then quickly access and update that data. Specifically, this will be going on in Org-mode, and my data is associated with individual headings.
The conundrum here is, how do I best store this data, in memory, so it's associated with headings but not visible and not written to the file? I.e. when I insert or remove text in one place, points later in the file need to keep data associated with them—I can't just use text positions as keys in a dictionary (not without lots of hassle). It's also preferable that hidden data is *not* copied around together with yanked text.
To clarify, I'm aware that I can add properties on Org headings, or create IDs and associate my data with them—but I want to do this without any changes to the content.
So far it seems that ‘text properties’ might vaguely be what I want—if I can add my own custom fields in properties on headings. Elisp documentation notes that these properties are copied when text is yanked, and suggests putting them on an overlay instead. I'm rather hazy yet on how overlays function at all (though will probably need them for the indicators). Is this the best route, or maybe I'm looking in an entirely wrong place? Any nice rakes here for me to step on or shoot my feet?
Meanwhile, ‘invisible text’, popular in web search results, is *not* the thing I need—as afaict it's written to the file.
# Answer
John Kitchin wrote a package called ov-highlighter that makes highlighting persistent. IIRC, it has a hook that update after each file saving a local variable storing a list of region and propertized string. I suggest you to read his post, then you can move to the source code to read the two relevant functions `ov-highlight-load` and `ov-highlight-save` to see how that is done.
A second idea may be using something like l3kn/org-el-cache to cache Org mode data. I didn't try it, but AFAIK it is used in l3kn/org-zettelkasten.
> 1 votes
# Answer
I believe you're looking for "overlays":
> You can use overlays to alter the appearance of a buffer’s text on the screen, for the sake of presentation features. An overlay is an object that belongs to a particular buffer, and has a specified beginning and end. It also has properties that you can examine and set; these affect the display of the text within the overlay.
> 0 votes
---
Tags: text-properties
---
|
thread-61316
|
https://emacs.stackexchange.com/questions/61316
|
Why has my .custom file changed between `(quote` syntax and the `'` syntax and how to convert between the two?
|
2020-10-20T07:47:17.200
|
# Question
Title: Why has my .custom file changed between `(quote` syntax and the `'` syntax and how to convert between the two?
I use the same `.custom` file on different machines syncronised via a git repo.
I just noticed that suddenly the `.custom` file from one machine uses the `(quote` syntax while in the past the `'` syntax was used (or vice versa). Two questions:
1. Why is this happening? Is there a change in, say, Emacs 27? (On *one* machine I have upgarded to 27.)
2. How can I convert manually between the two syntaxes, so that I can diff teh files sensibly?
# Answer
It's a change in emacs-27, from etc/NEWS:
```
** 'print-quoted' now defaults to t, so if you want to see
'(quote x)' instead of 'x you will have to bind it to nil where applicable.
```
So binding `print-quoted` to your desired value and then saving a customization should be enough.
> 3 votes
---
Tags: customize, quote
---
|
thread-10955
|
https://emacs.stackexchange.com/questions/10955
|
Customize vc-mode appearance in mode-line
|
2015-04-27T11:27:18.997
|
# Question
Title: Customize vc-mode appearance in mode-line
I use `vc-mode` to show information about the current VC state in my mode line, like this:
```
(setq mode-line-format '(… (vc-mode vc-mode) …))
```
However, I find the default format of `vc-mode` pretty verbose. Notably, it includes the name of the current VC backend, which is not particularly interesting to me—I usually know which VCS the current buffer as, and I don’t really use any VCS other than Git anyway.
How can I customize the appearance of `vc-mode`? Ideally, I’d hide the name of the backend, and show just the name of the current branch (or probably something similar to `git describe`).
Alternatively, if `vc-mode` can’t be customized, can I somehow get the current branch name from VC, for use in a custom `(:eval …)` construct?
# Answer
> How can I customize the appearance of `vc-mode`? Ideally, I’d hide the name of the backend, and show just the name of the current branch.
That's pretty much what smart-mode-line does. You can give it a try, or you can just copy the advice that it uses:
```
(defadvice vc-mode-line (after strip-backend () activate)
(when (stringp vc-mode)
(let ((noback (replace-regexp-in-string
(format "^ %s" (vc-backend buffer-file-name))
" " vc-mode)))
(setq vc-mode noback))))
```
Note that this is a streamlined version of it. You can find the full code for the advice here, which also applies different faces depending on the state of the branch.
---
As an alternative, here's an even more streamlined version that doesn't use an advice.
```
(setcdr (assq 'vc-mode mode-line-format)
'((:eval (replace-regexp-in-string "^ Git" " " vc-mode))))
```
> 6 votes
# Answer
I was not happy with the default behavior either. I could never keep the vc info characters straight— ":" for edited, "@" for added, etc. You can feel free to use my method.
I defined several custom faces to display the statuses in various colors. Then I wrote a function to translate the default vc info into a string to insert into the mode line. Then I added a `:eval` line in my mode line definition to show it.
```
;; Define faces.
(defface my/mode:vc-added
`(
( ((class color))
(:background "#FFAA55" :foreground "black") )
( t
(:weight bold :underline t) )
)
"VC status tag face for files that have just been added to
version-control."
:group 'MY/mode)
(defface my/mode:vc-edited
`(
( ((class color))
(:background "#F05B80" :foreground "black") ) ; "#F04040" maybe?
( t
(:weight bold :underline t) )
)
"VC status tag face for files that are under version control
but which have been edited."
:group 'MY/mode)
(defface my/mode:vc-in-sync
`(
( ((class color))
(:background "#60CC60" :foreground "black") )
( t
(:weight bold :underline t) )
)
"VC status tag face for files that are under version control
and which are in sync with the respository."
:group 'MY/mode)
(defface my/mode:vc-none
`(
( ((class color))
(:background "#70A0D0" :foreground "black") )
( t
(:weight bold :underline t) )
)
"VC status tag face for files that are not under version
control"
:group 'MY/mode)
(defface my/mode:vc-unknown
`(
( ((class color))
(:background "#FF0000" :foreground "white") )
( t
(:weight bold :underline t) )
)
"VC status tag face for files whose version-control status
cannot be determined."
:group 'MY/mode)
(defvar my-vc-mode-attrs
'(("" . (" NoVC " my/mode:vc-none))
("-" . (" VC = " my/mode:vc-in-sync))
(":" . (" VC > " my/mode:vc-edited))
("@" . (" VC + " my/mode:vc-added))
("?" . (" ?VC? " my/mode:vc-unknown))
)
"Lookup table to translate vc-mode character into another string/face."
)
;; This function helps me understand the version-control status.
(defun my-mode-line-vc-info ()
"Return version-control status information about the file in
the current buffer, as a fontified string.
The mode-line variable `vc-mode' is nil if the file is not under
version control, and displays a hyphen or a colon depending on whether
the file has been modified since check-in. I can never keep those
straight.
This function returns \"NoVC\" if the file is not under version
control. It displays a string with an = sign if the file is in sync
with its version control, and a string with a > sign if the file has
been modified since its last check-in."
(let* ((class
(cond
;; If not under version-control
((not vc-mode)
"")
;; If under version-control decode the -:@ character
((string-match "\\` ?\\(?:CVS\\|Git\\)\\([-:@]\\)\\([^^:~ \x00-\x1F\\\\/]+\\)?" vc-mode)
(match-string-no-properties 1 vc-mode))
;; Otherwise, indicate confusion
(t
"?")
))
(branch
(if (any class '("-" ":" "@"))
(concat " " (match-string-no-properties 2 vc-mode))
""))
;; Fetch properties list for the class character above
(props (cdr (assoc class my-vc-mode-attrs)))
)
(concat (propertize (car props) 'face (cadr props))
branch)))
(set-default 'mode-line-format
'(
...
(:eval (my-mode-line-vc-info))
...))
```
> 4 votes
# Answer
I don't use anything else than GIT as well so i have this advice specific to `vc-git`
```
(advice-add #'vc-git-mode-line-string :filter-return #'my-replace-git-status)
(defun my-replace-git-status (tstr)
(let* ((tstr (replace-regexp-in-string "Git" "" tstr))
(first-char (substring tstr 0 1))
(rest-chars (substring tstr 1)))
(cond
((string= ":" first-char) ;;; Modified
(replace-regexp-in-string "^:" "⚡️" tstr))
((string= "-" first-char) ;; No change
(replace-regexp-in-string "^-" "✔️" tstr))
(t tstr))))
```
This would simply look like this to me in my mode-line (I use an emacs distro that supports OSX emojis) :
> 2 votes
---
Tags: mode-line, git, vc
---
|
thread-61297
|
https://emacs.stackexchange.com/questions/61297
|
How to filter the package list by package name part or regex
|
2020-10-19T07:03:16.510
|
# Question
Title: How to filter the package list by package name part or regex
Via `M-x list-packages` I can view a list of installable and installed packages. Great! But how can I filter this list by a portion of the package *name*?
---
PS: I know about `package-menu-filter`, but for me this command filters only on the package *description*, not the package *name*. E.g. when I filter on `lsp-mode` I get packages like `lsp-scala`, etc, but *not* what I was looking for, namely `lsp-mode`...
# Answer
`/ n` (M-x package-menu-filter-by-name) does exactly what you want, it filters only the package name, e.g., `/ n lsp-mode` gets only the lsp-mode package.
> / n runs the command package-menu-filter-by-name (found in package-menu-mode-map), which is an interactive compiled Lisp function in \`package.el'.
>
> It is bound to / n, .
>
> (package-menu-filter-by-name NAME)
>
> Filter the "*Packages*" buffer by NAME.
> Show only those items whose name matches the regular expression NAME. If NAME is nil or the empty string, show all packages.
You can clear the filter via `/ /`.
I'm testing with Emacs 27.1. Not sure which version of Emacs added the feature.
> 1 votes
# Answer
Try `C-h P` (M-x describe-package), it allows you filter by package names through the minibuffer. If you use helm-mode, it looks like
And in the `*Packages*` buffer, use Isearch and/or Occur, for example, to search packages start with lsp, use
```
M-s o ^ +lsp
```
M-s o is M-x occur.
> 1 votes
---
Tags: package, list-packages, filtering
---
|
thread-61325
|
https://emacs.stackexchange.com/questions/61325
|
dired by name - change directory and create new file
|
2020-10-20T13:21:41.403
|
# Question
Title: dired by name - change directory and create new file
I want to open a new file in a different directory than the current one.
Pressing `C-x C-f` -\> I could enter a file name. But I don't.
Pressing `RET`
The directory listing (mode `(dired by name)`) comes up and I can navigate through it by using the cursor and `RET`. No problem.
I navigate to the existing directory I want to create the new file in.
How can I enter the name of the new (nonexisting) file in that case?
*EDIT*: Because I am quite new to *emacs*: How could I answer such simple questions to my self?
# Answer
Answer based on StackOverflow answer.
Press `C-x C-f` and you are back to the minibuffer and can enter a filename.
> 1 votes
---
Tags: dired, find-file
---
|
thread-61324
|
https://emacs.stackexchange.com/questions/61324
|
How to protect myself from my own mistakes?
|
2020-10-20T13:11:03.387
|
# Question
Title: How to protect myself from my own mistakes?
I use Emacs for programming and also read mail in Gnus. My problem is that I'm typing fast, switching buffers and Windows etc, and too often accidentally hit some key that is bound to some command that screws everything up. And I have no idea what I did hit.
Could be harmless things like suddenly my summary buffer in Gnus start to line wrap. But also serious things that screws up the Gnus information about mailboxes and mails, and I have to spend hours to try find a backup of those files and get things to a reasonable state again.
So first the simple question, is there a way to let emacs produce a "command log"? I.e. I can go into a log file and see that I accidentally hit `gnus-do-something-unwanted` so I can more easily find out how to get back to where I was before the incident?
Now, is there a way to globally in Emacs set so that all commands but those I have specified gives a dialog `Do you really want to..?`. While I use Emacs most of the day I only use a subset of all commands. And maybe I could list them in a `.emacs.what.i.use.el` file so that any emacs command outside those would bring me a dialog? This way preventing the disaster caused by a single accidental keystroke in Gnus or other mode?
If not possible, maybe there is a way to unbind all keys beside those I really use in Gnus? Lik `(gnus-unbind-all-keys-beside ....)`? :)
# Answer
> 3 votes
You can see what you've done with `C-h l` (aka `M-x view-lossage`).
As for putting a kind of "safety fence", it should be fairly easy to do, by placing an appropriate function of `pre-command-hook`. You could start with something like:
```
(defvar my-fence-let-pass
'(self-insert-command next-line previous-line right-char left-char
handle-select-window handle-switch-frame my-fence-mode))
(defun my-fence--check ()
(cond
((memq this-command my-fence-let-pass) nil)
((y-or-n-p (format "Do you really want to `%s`? " this-command))
(push this-command my-fence-let-pass))
(t (error "Abort"))))
(define-minor-mode my-fence-mode
"Add a safety fence around the known commands."
:global t
(if my-fence-mode
(add-hook 'pre-command-hook #'my-fence--check)
(remove-hook 'pre-command-hook #'my-fence--check)))
```
but you'd probably want to improve it so it saves the list of acceptable commands to file or something like that.
---
Tags: key-bindings, gnus
---
|
thread-61326
|
https://emacs.stackexchange.com/questions/61326
|
How to get the mode-specific help information or help files
|
2020-10-20T13:23:52.387
|
# Question
Title: How to get the mode-specific help information or help files
No matter in which mode I am currently in, is there a general way / key combination to open the help file related to the currently active mode?
# Answer
> 1 votes
There's `M-x describe-mode`, which is bound to `C-h m` by default. It shows the current major mode, as well as all current minor modes.
If you want to jump directly to the description of your current major mode, then either evaluate `(describe-function major-mode)` (via `M-:`) or bind it to a key, for example:
```
(defun my/describe-current-major-mode ()
"Describe the current major mode via `describe-function'"
(interactive)
(describe-function major-mode))
(global-set-key (kbd "<f5>") #'my/describe-current-major-mode)
```
---
Tags: major-mode, minor-mode, help
---
|
thread-61315
|
https://emacs.stackexchange.com/questions/61315
|
User input - How to use predefined list
|
2020-10-20T05:29:12.653
|
# Question
Title: User input - How to use predefined list
While there are org-templates creating entire bullet points with content, what I am looking for is a simple user query (similar to `read-string`) where the user can use a pre-defined list of words/phrases to choose from (up/down or left/right arrow keys).
Background:
I am with our IT department and among other things order hardware for our users. Once an order is out I would like to tell them when their hardware is expected to arrive. The general text stays the same, but I would like to choose the week's workdays from a list to complete this text snippet. Plus points, if I can have a second choice based on the first to choose this or next week. This means when I choose "today" or "tomorrow", it shall not ask for the week. Likewise choosing "Monday" or "Tuesday" shall fix the second choice to "next week" (since otherwise I could have chosen "today" or "tomorrow" if it were this week).
Simplified result (with choices highlighted):
I ordered your hardware and it is estimated to arrive `Wednesday` `next week`.
Currently I realize that snippet with a script inside the aging AutoKey GTK application, but would love to consolidate what I have there into Emacs. I already have my phrase templates as well as full-auto scripts in Emacs, but I am struggling to get the user input stuff to work the way I would like to have it.
`read-string` has a history argument, but I am not sure if one can misuse(?) that for what I intend. Being still fairly new to elisp, maybe there are better or more sophisticated ways to do so. Since Emacs' built-in help as well as most online resources are notoriously sparse on examples to demonstrate its capabilities, an example would go a long way.
# Answer
> 2 votes
This sounds like `completing-read`, maybe via `ivy`. Here's a quick snippet that reuses `calendar-day-name-array` to get the usual names, but you can use your usual service days instead:
```
(require 'calendar) ; for calendar-day-name-array
(defun my/arrival ()
"Place an arrival date"
(interactive)
(let ((choice (completing-read "Arrival: " (append calendar-day-name-array '("today" "tomorrow")))))
(pcase choice
("today" choice) ; Return today and tomorrow as-is
("tomorrow" choice)
(other
(let ((week (completing-read (format "Which %s? " choice) '("this week" "next week"))))
(format "%s %s" choice week))))))
```
For more flexibility, you can customize the possible arrival days and also add a function to insert your choice at point:
```
(require 'calendar)
(defcustom my/arrivaldays
(append
(or calendar-day-name-array
'("Monday" "Tuesday" "Wednesday" "Thursday" "Friday")) nil)
"The possible arrival dates of hardware."
:type '(repeat string))
(defun my/arrival ()
"Ask for an arrival date"
(interactive)
(let ((choice (completing-read "Arrival: " (append my/arrivaldays '("today" "tomorrow")))))
(pcase choice
("today" choice) ; Return today and tomorrow as-is
("tomorrow" choice)
(other
(let ((week (completing-read (format "Which %s? " choice) '("this week" "next week"))))
(format "%s %s" choice week))))))
(defun my/arrival-insert ()
"Insert an arrival date at point"
(interactive)
(insert (my/arrival)))
```
---
Tags: completing-read
---
|
thread-61333
|
https://emacs.stackexchange.com/questions/61333
|
tools for camelcase and other means of word separation
|
2020-10-20T17:17:26.330
|
# Question
Title: tools for camelcase and other means of word separation
Often I am involved with transforming text with one system of word separation (e.g., camelcase) into another system (e.g., hyphen separation, space separation, underscore separation. For example, if I am transforming from camelcase separation to hyphen separatio, and there's a phrase of words separated by camelcase boundaries, e.g., TimeOfDay, I will may have to change it to time-of-day, or search for time-of-day, etc. Or I might have to go back and forth, or deal with multiple systems together.
What does Emacs have in terms of packages or modes or tools for dealing with these systems. It seems like a triviality, but it's kind of pain that something I take so for granted, like Meta-F moving to forward from the beginning of "time-of-day" to the end of the word "time", is totally useless to moving past the first word in "TimeOfDay", since it would move you to the end of the word "day".
# Answer
> 1 votes
You can use the elisp functions `s-upper-camel-case` or `s-lower-camel-case` like so:
```
(s-lower-camel-case "camel-case")
(s-upper-camel-case "camel-case")
```
@Tyler's comment above provides a way to un-camelize strings.
```
(defun un-camelcase-string (s &optional sep start)
"Convert CamelCase string S to lower case with word separator SEP.
Default for SEP is a hyphen \"-\".
If third argument START is non-nil, convert words after that
index in STRING."
(let ((case-fold-search nil))
(while (string-match "[A-Z]" s (or start 1))
(setq s (replace-match (concat (or sep "-")
(downcase (match-string 0 s)))
t nil s)))
(downcase s)))
```
---
Tags: search, words, fuzzy-matching
---
|
thread-57450
|
https://emacs.stackexchange.com/questions/57450
|
resizing frame by window manage under AnyDesk disassociates emacs buffers' dimensions
|
2020-03-29T20:15:06.363
|
# Question
Title: resizing frame by window manage under AnyDesk disassociates emacs buffers' dimensions
I'm trying a new (to me) remote desktop tool AnyDesk (v.5.5.4). I'm attaching to Ubuntu18 system at work from a Ubuntu19 system at home. When I resize an emacs frame with the mouse, the menu bar, the mode line and mini-buffer and text area do not resize.
None of the resizing commands I've tried have had any effect. At root I think it's a failing of AnyDesk but I'm not having any luck at that end and am hoping there's a manual resizing within emacs which might counter the AnyDesk issue.
# Answer
> 0 votes
I had a similar problem on my windows machine. I was not able to resize the anydesk window on my external monitor and it occupied the whole screen without any resize option.
Workaround:
This issue is due to scaling of your os(in my case windows)
Go to display setting scale the windows to 110% or more and then you should be able to resize the anydesk window.
Hope this helps!
---
Tags: frames, remote, x-window
---
|
thread-61332
|
https://emacs.stackexchange.com/questions/61332
|
Strange Color Issues
|
2020-10-20T16:51:59.027
|
# Question
Title: Strange Color Issues
I've been playing around with Emacs for the first time this week, and I've been having some issues with the color scheme. This post was prompted by getting some weird when using helm. I've also noticed that when I load emacs without any init file, it opens up with a dark background instead of a white background that everyone else mentions.
Here's a picture of Emacs loaded without any init file:
And here is how helm looks.
At this stage, I have not loaded any theme. I checked this with the disable-theme command, and no theme was loaded.
Adding a theme does not fix issues either. Here it is with the deeper blue theme loaded
Again, I ensured that only a single theme was loaded using the disable-theme command.
I saw this thread from the past, which presented with similar issues as I have, however he was able to change versions
Some context:
* **OS:** Linux Mint 19.2 Tina
* **Windows Manager:** i3 version 4.18.2
* **Emacs Version:** GNU Emacs 27.1
I saw this thread from the past, which presented with similar issues as I have, however he was able to change versions which fixed the issue. I tried purging all emacs stuff on my system and deleting my local ~/.emacs.d directory (there was no ~/.emacs file -- everything was in ~/.emacs.d/init.el), and downgraded to version 26. Unfortunately, the color issues with helm were not fixed. My emacs background remained dark when loaded without any init file as well.
I should probably mention that at one point I had installed Doom Emacs, and my color schemes with both Helm and Ivy working as expected then (though the default background was still dark). This was also using GNU Emacs 27.1. However, I decided to go back to vanilla emacs to try and learn how to configure the software myself, and have been getting issues
The entirety of my init.el is posted below. I generate my system's color scheme using wal, and run XRDB on a colors.Xresources file that it creates. I've attached that below as well, just in case it is the cause of any problems. Any suggestions would be appreciated.
init.el
```
(package-initialize)
(require 'package)
(require 'use-package)
(add-to-list 'package-archives '("gnu" . "http://elpa.gnu.org/packages/"))
(add-to-list 'package-archives '("melpa" . "http://stable.melpa.org/packages/"))
(use-package evil
:ensure t)
(evil-mode 1)
(use-package org
:ensure t)
(use-package helm
:ensure t)
(require 'helm-config)
(setq helm-split-window-in-side-p t
helm-move-to-line-cycle-in-source t)
(helm-mode 1)
;; List Buffers ( Emacs way )
(global-set-key (kbd "C-x b") 'helm-buffers-list)
;; List buffers ( Vim way )
(define-key evil-ex-map "b" 'helm-buffers-list)
;; Bookmarks menu
(global-set-key (kbd "C-x r b") 'helm-bookmarks)
;; Finding files with Helm
(global-set-key (kbd "C-x C-f") 'helm-find-files)
(define-key evil-normal-state-map (kbd "SPC .") 'helm-find-files)
(global-set-key (kbd "M-x") 'helm-M-x)
(global-set-key (kbd "M-y") 'helm-show-kill-ring)
;backups settings
(setq backup-directory-alist `(("." . "~/.emacs.d/.backups")))
(setq backup-by-copying t)
```
colors.Xresources
```
urxvt*font: xft:DejaVu Sans Mono:size=9
! X colors.
! Generated by 'wal'
*foreground: #e3e1de
*background: #1f1b1d
*.foreground: #e3e1de
*.background: #1f1b1d
URxvt*foreground: #e3e1de
XTerm*foreground: #e3e1de
UXTerm*foreground: #e3e1de
URxvt*background: [90]#1f1b1d
XTerm*background: #1f1b1d
UXTerm*background: #1f1b1d
URxvt*cursorColor: #e3e1de
XTerm*cursorColor: #e3e1de
UXTerm*cursorColor: #e3e1de
URxvt*borderColor: [90]#1f1b1d
! Colors 0-15.
*.color0: #1f1b1d
*color0: #1f1b1d
*.color1: #BF9A71
*color1: #BF9A71
*.color2: #697991
*color2: #697991
*.color3: #AB9C93
*color3: #AB9C93
*.color4: #D1AC9E
*color4: #D1AC9E
*.color5: #D4C4B7
*color5: #D4C4B7
*.color6: #B3C8C8
*color6: #B3C8C8
*.color7: #e3e1de
*color7: #e3e1de
*.color8: #9e9d9b
*color8: #9e9d9b
*.color9: #BF9A71
*color9: #BF9A71
*.color10: #697991
*color10: #697991
*.color11: #AB9C93
*color11: #AB9C93
*.color12: #D1AC9E
*color12: #D1AC9E
*.color13: #D4C4B7
*color13: #D4C4B7
*.color14: #B3C8C8
*color14: #B3C8C8
*.color15: #e3e1de
*color15: #e3e1de
! Black color that will not be affected by bold highlighting.
*.color66: #1f1b1d
*color66: #1f1b1d
! Xclock colors.
XClock*foreground: #e3e1de
XClock*background: #1f1b1d
XClock*majorColor: rgba:e3/e1/de/ff
XClock*minorColor: rgba:e3/e1/de/ff
XClock*hourColor: rgba:e3/e1/de/ff
XClock*minuteColor: rgba:e3/e1/de/ff
XClock*secondColor: rgba:e3/e1/de/ff
! Set depth to make transparency work.
URxvt*depth: 32
urxvt.scrollBar: false
```
# Answer
> 1 votes
Ok, so there were, I think, two separate issues.
One, to fix the default, no-init-script background color I removed the following lines from my Xresources file:
```
*foreground: #e3e1de
*background: #1f1b1d
*.foreground: #e3e1de
*.background: #1f1b1d
```
To fix the color issues in helm, I downloaded the doom themes. Using a doom theme seemed to fix the issues with the weird colors in helm.
---
Tags: colors
---
|
thread-61323
|
https://emacs.stackexchange.com/questions/61323
|
How to set smerge-command-prefix to "\C-cv"
|
2020-10-20T13:09:48.787
|
# Question
Title: How to set smerge-command-prefix to "\C-cv"
I find the default prefix for smerge-mode `C-c^` and I have following setup:
```
(setq smerge-command-prefix "\C-cv")
(setq smerge-command-prefix "\C-c\C-v")
```
Also `C-c ^` runs the command icicle-search-keywords (found in icicle-mode-map), so its prefix is overwritten by icicle.
But when I try them, still they are undefined:
```
C-c C-v is undefined
C-c v is undefined
```
Is there any way to force to set operation ?
# Answer
> 2 votes
*First:* a variable can not have two different values at the same time.
> (setq smerge-command-prefix "\C-cv")
> (setq smerge-command-prefix "\C-c\C-v")
*Second:* to use this prefix the above variable has to be set before `smerge-mode` is loaded. So either ensure that `(setq smerge-command-prefix "\C-cv")` is eval'd before you use (or `require`) `smerge-mode` the first time. Or set and save this variable through `customize` and restart emacs.
Or you could simply use
```
(eval-after-load 'smerge-mode
(lambda ()
(define-key smerge-mode-map (kbd "C-c v") smerge-basic-map)
(define-key smerge-mode-map (kbd "C-c C-v") smerge-basic-map)))
```
*note:* I got most of that information by looking at smerge-mode's source code.
---
Tags: key-bindings, magit
---
|
thread-61336
|
https://emacs.stackexchange.com/questions/61336
|
Error replacing %n escapes with nth %^{...} string in emacs org capture
|
2020-10-20T18:01:57.410
|
# Question
Title: Error replacing %n escapes with nth %^{...} string in emacs org capture
I am trying to write a custom `org-capture` template, but I get an error if I try to use the `%\N` functionality to insert the N-th prompt. The relevant excerpt of my `org-capture-templates` variable is
```
("ao" "Other meeting" entry
(file+headline "~/org/meeting.org" "Meetings")
"* %^{meeting date}u Meeting with %^{meeting with}
:PROPERTIES:
:MEETWITH: %\\2
:DESCRIPTION: %\\3
:END:
Created on %U
Description: %^{description}
%?" :jump-to-captured t :empty-lines 1)
```
When I try to capture, everything goes fine until I `C-c C-c` the note. Then, the new note fails to save due to the following error:
> org-capture: Capture abort: Wrong type argument: stringp, nil
This error only occurs when I try to use the `%\N` functionality, not otherwise. I assume the issue must be somehow related to the relevant section of `org-capture-fill-template`, but I am unable to discern what could be causing this errant behaviour. That section of code is as follows (from `org-capture.el`).
```
;; Replace %n escapes with nth %^{...} string.
(setq strings (nreverse strings))
(save-excursion
(while (re-search-forward "%\\\\\\([1-9][0-9]*\\)" nil t)
(unless (org-capture-escaped-%)
(replace-match
(nth (1- (string-to-number (match-string 1))) strings)
nil t))))
```
**Note:** I have `org-roam` and `org-roam-bibtex` installed. Could this have anything to do with it?
# Answer
> 2 votes
Apparently, the `%^{meeting date}u` does not count as a prompted entry (perhaps because of the `u`? I'm not really sure). So it thinks there are only *two* prompted entries: `%^{meeting with}` and `%^{description}` so the template should look like this:
```
("ao" "Other meeting" entry
(file+headline "~/org/meeting.org" "Meetings")
"* %^{meeting date}u Meeting with %^{meeting with}
:PROPERTIES:
:MEETWITH: %\\1
:DESCRIPTION: %\\2
:END:
Created on %U
Description: %^{description}
%?" :jump-to-captured t :empty-lines 1)
```
EDIT: I looked at the code (in org-capture.el:org-capture-fill-template) more carefully. The only time when prompted entries are saved for later use with `%\N` constructs is when they are *not* decorated with a key (`CgGLptTuUptTuU`). So the diagnosis above is correct: the `u` causes the entry not to be remembered for further use with `%\N`.
This seems deliberate so it's probably not a bug, but a design decision. In particular, the doc string for `org-capture-templates` says:
> %\1 ... %\N Insert the text entered at the nth %^{prompt}, where N is a number, starting from 1.
Note that it does not mention the `%^{prompt}<key>` form at all.
---
Tags: org-mode, org-capture
---
|
thread-61341
|
https://emacs.stackexchange.com/questions/61341
|
Selecting a directory like counsel-find-file
|
2020-10-20T21:43:45.250
|
# Question
Title: Selecting a directory like counsel-find-file
I would like to write a function that would prompt the user to select a directory, using an UI like that presented by `counsel-find-file`.
The starting directory should be an arbitrary directory passed to this function as an argument.
This function should only show the user directories, not files, and the user should be able to navigate up and down the filesystem just as in `counsel-find-file`.
When the user makes their selection by hitting the `RETURN` key, the path to the selected directory should be returned to the calling function.
# Answer
> 3 votes
I just figured this out myself (using `counsel-dired` as a model):
```
(defun my-counsel-find-directory (&optional start-dir)
"Return a directory chosen by the user.
The user is prompted to choose a directory starting with START-DIR."
(let ((ivy-read-prompt "Choose directory: ")
(counsel--find-file-predicate #'file-directory-p)
(default-directory (or start-dir default-directory)))
(ivy-read
ivy-read-prompt
#'read-file-name-internal
:matcher #'counsel--find-file-matcher)))
```
---
Tags: ivy, directories, counsel, completing-read
---
|
thread-61337
|
https://emacs.stackexchange.com/questions/61337
|
how to open a network folder in dired?
|
2020-10-20T18:11:18.967
|
# Question
Title: how to open a network folder in dired?
Unfortunately, I'm stuck on Windows. I have a network folder under this PC. Is there a way to navigate into it with dired without mounting it as another drive?
# Answer
> 1 votes
If the remote directory is not mapped to a drive letter, you can use `dired`, with the UNC path replacing backslashes with forward slashes, e.g. if in explorer the path is `\\server\share` the sequence of command in @Drew answer becomes
```
C-x d
Dired (directory):
Dired (directory): //server/share RET
```
# Answer
> 0 votes
Yes, use the usual Dired command (`dired`, bound to `C-x d`).
At the prompt for a directory, just enter the drive name that you want (which can be a network folder), followed by `:/`. For example:
```
C-x d
Dired (directory):
Dired (directory): d:/ RET
```
---
If you use Dired+ (download) then you can also get a buffer that lists all of your MS Windows drives, which you can navigate through Dired. Command **`diredp-w32-drives`** (bound to **`:/`** in Dired, but usable from anywhere) gives you a Dired buffer listing your drives.
---
Tags: dired, microsoft-windows
---
|
thread-61349
|
https://emacs.stackexchange.com/questions/61349
|
Javascript mode mixes tabs and spaces for indent
|
2020-10-21T09:06:14.687
|
# Question
Title: Javascript mode mixes tabs and spaces for indent
My javascript mode indents with a mix of tabs and spaces. I'm ok with the mix if spaces are used for cosmetic alignment, but this is just wrong:
First level of indentation is spaces, second is tab, third is tab and spaces.
I tried looking for relevant variables. `js-indent-level` is 4.
This is this way with `emacs -q` as well (just using my config above for illustration purpose).
How do I fix this, preferably using spaces only?
Emacs 25.2.2
---
EDIT: Yeah, so I can set `indent-tabs-mode` to `nil`, but isn't the behavior with it at `t` still wrong?
# Answer
> 0 votes
> How do I fix this, preferably using spaces only?
```
(setq indent-tabs-mode nil)
```
> Yeah, so I can set indent-tabs-mode to nil, but isn't the behavior with it at t still wrong?
Emacs tries to insert the *"the shortest possible series of tab and space characters"*. This usually means that as soon as you cross 8 characters (the default `tab-width`), you end up with a mixture of tabs and spaces.
> Normally, ***indentation commands insert (or remove) the shortest possible series of tab and space characters so as to align to the desired column.*** Tab characters are displayed as a stretch of empty space extending to the next “display tab stop”. By default, there is one display tab stop every ‘`tab-width`’ columns (the default is 8). \[emphasis mine\]
See `(emacs) Just Spaces` for more information (`C-h r m Just Spaces RET`).
---
Tags: indentation, javascript, align
---
|
thread-61347
|
https://emacs.stackexchange.com/questions/61347
|
How to open org files with some, but not all headings expanded?
|
2020-10-21T08:11:08.103
|
# Question
Title: How to open org files with some, but not all headings expanded?
I have an org file which looks like this:
```
* Chores
#:PROPERTIES:
#:VISIBILTY: showall
#:END:
# STARTUP: showeverything # no + so this does nothing right now
** NEXT Brush Teeth in Day
SCHEDULED: <2020-10-22 Thu +1d>
** NEXT Brush & Floss Teeth at Night
SCHEDULED: <2020-10-21 Wed +1d>
* Math...
* English...
* Geology...
```
What I want is open up my file, and immediately see "Chores" ' direct children expanded (everything underneath Chores is also fine I guess).
Right now when I open up the org file, I get everything collapsed. How can I see just *some* headings immediately expanded? I looked at some other questions on this StackExchange community but I didn't find my answer.
In the manual, I found something close to what I'm looking for: Initial Visibility. This mentions one of the STARTUP options that you can have, where you have these possible options:
```
#+STARTUP: overview
#+STARTUP: content
#+STARTUP: showall
#+STARTUP: showeverything
```
I tried to set this option underneath the "Chores" heading to set it locally, but that expanded all the headings instead of just "Chores". I tried also to set the `VISIBILITY` property mentioned in the manual entry, but that does not seem to have any effect at all.
Is there a way that I can achieve this behaviour?
# Answer
> 2 votes
Try with the following file:
```
#+STARTUP: overview
* Chores
:PROPERTIES:
:VISIBILITY: all
:END:
** NEXT Brush Teeth in Day
SCHEDULED: <2020-10-22 Thu +1d>
** NEXT Brush & Floss Teeth at Night
SCHEDULED: <2020-10-21 Wed +1d>
* Math
math
* English
english
* Geology
geology
```
Save the file, close it and reopen it: I believe that will do what you want.
Note that:
* the `PROPERTIES` drawer must *NOT* be commented out (as it was in your example).
* `VISIBILITY` was spelled incorrectly.
* `VISIBILITY` values are: `folded`, `children`, `content`, and `all` \- in particular, they are *NOT* the same as the values required in the `#+STARTUP:` keyword line. See Initial Visibility.
* the `#+STARTUP:` keyword setting is global for the file - it is good practice to put it at the top of the file. And note how it is spelled: the `#+` prefix for keywords is essential.
EDIT: The manual has a lot of information, including what the `#+STARTUP:` values mean. Even though I provide a link to the appropriate section here, the best way to navigate the manual (not only the Org mode manual, but also the Emacs manual and eventually the Emacs Lisp manual and all the other manuals that come with Emacs and any other manuals in Info format that you might add), is to do it in Emacs itself. Say `C-h i m Org M<TAB> RET` and search the index for `#+STARTUP` (`i startup RET`). It says there are 23 places in the manual where that term occurs and you can see the current one and move to the next one with `,` (and the previous one with `l`). The third one shows this:
```
‘#+STARTUP:’
Startup options Org uses when first visiting a file.
The first set of options deals with the initial visibility of the
outline tree. The corresponding variable for global default
settings is ‘org-startup-folded’ with a default value of
‘showeverything’.
‘overview’ Top-level headlines only.
‘content’ All headlines.
‘showall’ No folding on any entry.
‘showeverything’ Show even drawer contents.
```
which is what I linked to above. That takes care of one of your questions. The VISIBILITY values basically mean the same thing, but they modify the global setting for the subtree with that property (as I showed in the main answer).
In general, the manual is the best source of information, but you have to spend a little time to learn how to navigate in it - btw, to do *that*, the best way is to read the Info manual! Kill the buffer with the Org mode manual and say `C-h i m info RET` and spend some time with it. You should also familiarize yourself with the help system: Emacs is self documenting, so you can ask it a whole lot of questions about things - start with `C-h ?`.
---
Tags: org-mode
---
|
thread-61348
|
https://emacs.stackexchange.com/questions/61348
|
Show line at opening brace when cursor is after the closing brace (Perl)
|
2020-10-21T08:39:01.743
|
# Question
Title: Show line at opening brace when cursor is after the closing brace (Perl)
Something I like in Emacs is positioning the cursor after the closing brace/paren highlights the opening brace/paren.
Even better, like in `Emacs-Lisp` mode, the opening `(` line is displayed in the minibuffer. This is convenient when that line is too high up and cannot be seen in the display.
In `Perl` and `CPerl` mode, however, the opening `{` line is not shown in the minibuffer. Is there a way to have it shown?
*Edit* Tried to rename my .emacs / .emacs.d (in case the long config wrote a long time ago would interfere), but that didn't improve anything in these Perl modes.
(*using Emacs 26.3 GUI on Ubuntu 18.04 & 20.04*)
# Answer
I tried it with `emacs -Q` on version 26.3 and it works for me: it moves the cursor for a second to the matching opening brace if that is visible and it prints the matching line in the echo area if it is not.
Check the value of `post-self-insert-hook` with `C-h v post-self-insert-hook RET` \- my setting is:
```
(electric-indent-post-self-insert-function blink-paren-post-self-insert-function)
```
If yours is missing the `blink-paren-...` function, you can add it with
```
(add-hook 'post-self-insert-hook #'blink-paren-post-self-insert-function)
```
somewhere in your init file. But you should investigate *why* you are not getting that: AFAICT, it should be the out-of-the-box default.
The OP indicates that this is already the case in their setup, so we'll have to dig one level deeper. The variable `blink-paren-function` is used by `blink-paren-post-self-insert-function` \- doing `C-h v blink-paren-function RET` shows:
> Its value is ‘blink-matching-open’
in my case. Now if I place my cursor after the closing brace and do `M-x blink-matching-open RET` I see the matching line in the echo area.
So check that the variable is set to the function - if not, set it:
```
(setq blink-paren-function #'blink-matching-open)
```
and also execute `blink-matching-open` with the invocation above and check that it produces the appropriate indications
BTW, all of the above was done in a GUI instance of emacs: I did not test in terminal emacs.
> 1 votes
---
Tags: minibuffer, perl, pairing
---
|
thread-61075
|
https://emacs.stackexchange.com/questions/61075
|
In EXWM `split-window-right` followed by immediate `windmove-right` swaps order of buffers
|
2020-10-08T22:30:34.200
|
# Question
Title: In EXWM `split-window-right` followed by immediate `windmove-right` swaps order of buffers
I have a function
```
(defun bad-fn ()
(interactive)
(split-window-right)
(windmove-right)
)
```
If I go to a frame with just one window visiting EXWM buffer A (and buffer B is next), and call
* `split-window-right`
* `windmove-right`
Manually with M-x, I have A to the left of B, and B is the selected window.
If I use the above function, I have B to the left of A, and A is the selected window.
Changing the above to
```
(defun bad-fn ()
(interactive)
(split-window-right)
(sit-for 0.5)
(windmove-right)
)
```
fixes things.
Emacs version info: "GNU Emacs 27.1 (build 1, x86\_64-pc-linux-gnu, GTK+ Version 3.24.22, cairo version 1.17.3) of 2020-08-28"
As a note, I don't think this happened in Emacs 26.3.
# Answer
> 2 votes
You may have more control, no timing issues and fewer layers of debugging to do using built-in functions.
My equivalent to your function is something I use every day in EXWM.
```
(defun gjg/split-window-right ()
"Split window right, switch to the new window AND switch buffer in that window"
(interactive)
(split-window-right)
(other-window 1)
(switch-to-buffer (other-buffer)))
```
---
Tags: window, window-splitting, exwm
---
|
thread-5843
|
https://emacs.stackexchange.com/questions/5843
|
Org headlines are never exported to \paragraph in LaTeX
|
2014-12-28T19:05:18.707
|
# Question
Title: Org headlines are never exported to \paragraph in LaTeX
I want to export an Org file into PDF, with any depth titles showed in TOC; however, cannot works. Even though adding `\setcounter{tocdepth}{5}`, TOC still only contains the title of 3rd depth (`\subsubsection`).
I check the TeX file it exported: org-export seemed to ignore my setting for `org-latex-classes`, and just convert `****` into `'\item` instead of `\paragraph`. But I cannot find some worked solution for this...
Following is my `org-latex-classes`:
```
(setq org-latex-classes
'(("article" "
\\documentclass[10pt,a4paper]{article}
\\usepackage[margin=2cm]{geometry}
\\usepackage{fontspec}
\\XeTeXlinebreakskip = 0pt plus 1pt
\\linespread{1.36}
\\setcounter{tocdepth}{5}
\\usepackage{multicol}
\\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}"))
)
)
```
# Answer
Try something like this:
```
;; This buffer is for notes you don't want to save, and for Lisp evaluation.
;; If you want to create a file, visit that file with C-x C-f,
;; then enter the text in that file's own buffer.
(let ((org-latex-classes
'(("my-article" "
\\documentclass[10pt,a4paper]{article}
\\usepackage[margin=2cm]{geometry}
\\usepackage{fontspec}
\\XeTeXlinebreakskip = 0pt plus 1pt
\\linespread{1.36}
\\setcounter{tocdepth}{5}
\\usepackage{multicol}
\\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}")))))
(with-temp-buffer
(insert
(mapconcat 'identity
'("#+LATEX_CLASS: my-article"
"#+OPTIONS: h:5 num:3"
"* section"
"** subsection"
"*** subsubsection"
"**** paragraph"
"***** subparagraph")
"\n"))
(org-latex-export-as-latex nil nil nil t)))
```
=\>
```
\section{section}
\label{sec-1}
\subsection{subsection}
\label{sec-1-1}
\subsubsection{subsubsection}
\label{sec-1-1-1}
\paragraph*{paragraph}
\label{unnumbered-1}
\subparagraph*{subparagraph}
\label{unnumbered-2}
```
For more info see http://orgmode.org/org.html#Export-settings.
> 3 votes
# Answer
In org mode manual, LaTeX-header-and-sectioning
> The LaTeX export back-end converts the **first three** of Org’s outline levels into LaTeX headlines. *The remaining Org levels are exported as lists.* To change this globally for the cut-off point between levels and lists, (see note Export Settings).
In Export-Settings, this is the setting to change the levels to be converted.
> H
> Set the number of headline levels for export (‘org-export-headline-levels’). Below that level, headlines are treated differently. In most back-ends, they become list items.
so, you could add this at the beginning of your org file, so the 4th level to be exported would be (in your case) `\paragraph`
```
#+OPTIONS: H:5
```
> 3 votes
---
Tags: org-mode, latex, org-export
---
|
thread-48843
|
https://emacs.stackexchange.com/questions/48843
|
How to store an eshell alias in `init.el`?
|
2019-04-09T23:04:06.010
|
# Question
Title: How to store an eshell alias in `init.el`?
I like to keep my configuration as self-contained as possible, and I'm wondering whether there's a way to manage `eshell` aliases in my `.emacs` file. Is it possible to set up aliases with a function call kept in my `.emacs` rather than a separate file in `.emacs.d/eshell/aliases`?
The problem I am ultimately trying to solve is to get `ff` when entered in command position in `eshell` to reliably behave identically to `find-file`. *I am assuming that the easiest, most direct way to do this is an eshell alias*.
The alias below, with single quotes, exactly as written, does the trick and behaves like `find-file` does. I'm just trying to manage my aliases in the same place as the rest of my customization.
```
alias ff 'find-file $1'
```
---
Here are some attempted solutions to the problem that don't work and the steps to reproduce. The fact that they don't Just Work suggests to me that some work is needed to "wire up" a function so that it's usable from `eshell`.
### Non-Solution 1, `eshell/ff` function
1. `$ emacs -q -no-site-file`
2. within emacs, `C-x b *scratch* C-m`
3. write wrapper function in scratch buffer.
```
(defun eshell/ff (&rest args)
(apply #'find-file args))
```
4. `C-x h M-x eval-region C-m` then `C-g` to deselect
5. `C-h f` `eshell/ff` to verify that the function exists.
6. `M-x eshell C-m`
7. within `eshell`, type `find-file /etc/hosts` and visit the buffer. Then go back to eshell
8. within `eshell`, type `ff /etc/hosts`. The error message below shows us that `eshell` found our definition, but is *somehow* treating it differently than `find-file`.
```
~ $ ff /etc/hosts
Wrong number of arguments: (1 . 2), 0
```
### Non-Solution 2 `(defalias 'ff 'find-file)`
1. `$ emacs -q -no-site-file`
2. within emacs, `C-x b *scratch* C-m`
3. write wrapper function in scratch buffer.
```
(defalias 'ff 'find-file)
```
4. `C-x h M-x eval-region C-m` then `C-g` to deselect
5. `C-h f` `eshell/ff` to verify that the function exists.
6. `M-x eshell C-m`
7. within `eshell`, type `find-file /etc/hosts` as before to verify that `find-file` still works
8. within `eshell`, type `ff /etc/hosts`. The error message is the same as in `Non-Solution 1`.
# Answer
> 2 votes
As pointed out by @npostavs in a comment underneath the original question, the following solution proposed by the original poster *should* work -- at least in a current version of Emacs that is -- tested with Emacs 26.1:
```
(defun eshell/ff (&rest args)
(apply #'find-file args))
```
---
**Alternative Solution**:
```
(defun eshell-add-aliases ()
"Doc-string."
(dolist (var '(("ff" "find-file $1")
("wget" "/Users/HOME/.0.data/.0.emacs/.0.macports/bin/wget $*")
("cvs" "/Users/HOME/.0.data/.0.emacs/.0.macports/bin/cvs $*")
("curl" "/Users/HOME/.0.data/.0.emacs/.0.macports/bin/curl $*")
("git" "/Users/HOME/.0.data/.0.emacs/.0.macports/bin/git $*")))
(add-to-list 'eshell-command-aliases-list var)))
(add-hook 'eshell-post-command-hook 'eshell-add-aliases)
```
Please be aware that this answer defies the admonishment in the doc-string. \[Therefore, this solution is only for the rebellious / adventurous souls....\]
```
eshell-command-aliases-list is a variable defined in ‘em-alias.el’.
Its value is
(("git" "/Users/HOME/.0.data/.0.emacs/.0.macports/bin/git $*")
("curl" "/Users/HOME/.0.data/.0.emacs/.0.macports/bin/curl $*")
("cvs" "/Users/HOME/.0.data/.0.emacs/.0.macports/bin/cvs $*")
("wget" "/Users/HOME/.0.data/.0.emacs/.0.macports/bin/wget $*")
("ff" "find-file $1"))
This variable may be risky if used as a file-local variable.
Documentation:
A list of command aliases currently defined by the user.
Each element of this alias is a list of the form:
(NAME DEFINITION)
Where NAME is the textual name of the alias, and DEFINITION is the
command string to replace that command with.
Note: this list should not be modified in your init file.
Rather, any desired alias definitions should be declared using
the ‘alias’ command, which will automatically write them to the
file named by ‘eshell-aliases-file’.
```
# Answer
> 0 votes
eshell looks for its aliases in the directory specified by the `eshell-aliases-file` variable, which by default is `$HOME/.emacs.d/eshell/alias`
In that file, you can just write:
```
alias foo bar
```
Then, either start a new eshell instance, which will read in your aliases from the alias file on startup, or you can issue the `eshell-read-aliases-list` command from within eshell and it will re-read the alias file.
---
Tags: init-file, eshell
---
|
thread-61374
|
https://emacs.stackexchange.com/questions/61374
|
Is there a way to see a pull-request review status in magit?
|
2020-10-22T16:54:50.093
|
# Question
Title: Is there a way to see a pull-request review status in magit?
I see I can view the github pull requests assigned to me with `forge-list-requested-reviews`. Is there a way to see the status of each review? For example I've approved some of the pull requests that are in that list, and requested changes on others, but I can't tell which without going to the GitHub web interface.
# Answer
Not yet, but probably soonish.
> 3 votes
---
Tags: magit
---
|
thread-35023
|
https://emacs.stackexchange.com/questions/35023
|
Get filename from dired using elisp
|
2017-08-20T22:54:20.857
|
# Question
Title: Get filename from dired using elisp
Using elisp, I call this function `(dired "~")`, for example, to get to my Home directory in dired mode. When I press `RET` on one of the files, I want to capture the file path and store it in a variable instead of opening the file.
In other words, if the function `dired` did actually return the file name of the selected file using `RET`, I want to do something like this:
`(setq file-name (dired "~"))`
Where `file-name` would be the full path of the file that the user selected and pressed `RET` on.
Any ideas?
---
**Update**:
Just a little clarification of what I wanted to achieve:
1. Find the function that will get me the file name from `point` in a Dired buffer (The answer to that is what @phils said).
2. Bind `RET` to store the file name in a variable (The answer to that was provided by @Drew in the comments of @phils answer).
Cheers!
# Answer
> 5 votes
I imagine the function `dired-get-filename` is what you're looking for?
Or perhaps `dired-get-file-for-visit` would be more useful (being a wrapper which handles some common errors).
# Answer
> 0 votes
This is an older post but I was recently looking for something similar and stumbled upon this. My goal was: "use `dired` to retrieve a file's name". As mentioned in this post's Accepted Answer's comments, `dired` doesn't seem to be made for this.
I'm new to `elisp` so there might be plenty of better ways than my approach demonstrates, but I hope that it is helpful for anyone trying to do something similar.
My solution was to use `completing-read` and `directory-files` to get something close to this behaviour:
```
(defun find-in-directory (path)
"Find file in directory."
(interactive)
(let ((filename
(completing-read "File: " (directory-files-recursively path "\\.txt$"))))
filename))
```
`completing-read` provides the auto-complete functionality using `directory-files` (here, `directory-files-recursively`) as the source (i.e., what can be selected or auto-completed on). I've also included a `"\\.txt$"` argument to limit the extensions of the returned files, demonstratively, though it isn't neccessary per OP's use-case.
---
Tags: dired, files
---
|
thread-61359
|
https://emacs.stackexchange.com/questions/61359
|
How to specify a directory to tangle all code blocks into
|
2020-10-21T17:47:10.683
|
# Question
Title: How to specify a directory to tangle all code blocks into
I am writing a report in latex, many of which contain code blocks which will be rendered with asymptote.
Since all the scripts will be tangled into the same subdirectory `asyscripts`, I don't want to have to write code like this
```
#+BEGIN_SRC asy :tangle asyscripts/test.asy
write("Hello World!");
#+END_SRC
```
Specifying `asyscripts` every time is just too tedious. Any way I can specify globally which directory all the code blocks must be tangled into? (Each code block will be in general tangled into a different script. )
# Answer
I could not find any header args to do this (I thought that `:dir` would be the one, but it does not make any difference in tangling). But you can use the post-tangle hook, `org-babel-post-tangle-hook`, to manipulate the tangled files after they are produced. Here is a test file:
```
#+PROPERTY: dest ./tangled/
* Link
* TODO foo
#+BEGIN_SRC asy :tangle test.asy
write("Hello World!");
#+END_SRC
#+BEGIN_SRC asy :tangle test2.asy
write("Good-bye World!");
#+END_SRC
* Code :noexport:
#+begin_src emacs-lisp
(setq ndk/tangle-dir (org-entry-get nil "dest" t))
(defun ndk/org-babel-tangle-rename ()
(let ((tangledir ndk/tangle-dir)
(tanglefile (buffer-file-name)))
(rename-file tanglefile tangledir t)))
(add-hook 'org-babel-post-tangle-hook #'ndk/org-babel-tangle-rename)
#+end_src
```
The code consists of three things:
* the setting of a global variable `ndk/tangle-dir` to the directory path where you want the tangled files to end up. You could hardwire this into the function, but I made it a bit more flexible by defining a global `#+PROPERTY` called `dest` whose value is the path (N.B. The path *MUST* end with a slash). We retrieve the value of the `dest` property with `org-entry-get` and set `ndk/tangle-dir` to that value.
* a function that will be called through the hook on every file that is tangled. The function is run in a buffer that contains the tangled output. We retrieve the file name from the buffer, and then we call `rename-file` to move that file to the destination directory. The `t` argument means it's OK to move it there even if a file with the same name exists in that directory already.
* adding the function above to the `org-babel-post-tangle-hook`.
If you create an Org mode file with the contents above, and create the destination directory, you should be able to open the Org mode file, `C-c C-c` on the source code block, `C-c C-v C-t` to tangle the two blocks in the `foo` section and then check out the contents of the destination directory: the two tangled files should be there.
You probably want to remove the function from the hook afterwards, otherwise all files you tangle will end up in that directory:
```
(remove-hook 'org-babel-post-tangle-hook #'ndk/org-babel-tangle-rename)
```
For another example of the use of this hook, see this recent question. As you can see, it's pretty flexible!
> 1 votes
# Answer
Have you tried adding in this Header property at the top of your org file? This is what I add to most of my org files that I want tangled to a specific directory.
```
#+PROPERTY: header-args:emacs-lisp :noweb yes :tangle emacs.d/init.el
```
just replace the emacs.d/init.el with the location of where you want your tangle files to be located. You can drop the ":emacs-lisp" and the ":noweb yes" if you don't need them. So to just recap, you can try just adding this to the top of your file:
```
#+PROPERTY: header-args :tangle "asyscripts/test.asy"
```
and it should tangle your source blocks to that location. (I'm using emacs 25.3.1 and Org mode version 9.2.3 (9.2.3-13-g727c3f-elpa if that helps, I've been using this tag back from org mode version 9.1.10)
> 1 votes
---
Tags: org-mode, tangle
---
|
thread-61384
|
https://emacs.stackexchange.com/questions/61384
|
how to go to the first definition with xref-find-definitions, do not show all options?
|
2020-10-23T00:11:03.453
|
# Question
Title: how to go to the first definition with xref-find-definitions, do not show all options?
When I press `gd` to go to the definition of a class in C++, Emacs splits the screen and shows me two definition options that I need to click on with one of them. I'm used to `coc.nvim` where I would just go for the first option at once. How do I do this in Emacs?
# Answer
You may want to use package ivy-xref or helm-xref to replace the "window-ish" selector with popular completion framework like ivy or helm (so it feels better when picking a definition). Sure you also need ivy/helm themselves. It's easy if you already use one of them, otherwise have a try.
If you insist... Digging down into `xref-find-definitions`, it's this function who does the most work:
```
(defun xref--show-xrefs (xrefs display-action &optional always-show-list)
(cond
((and (not (cdr xrefs)) (not always-show-list))
(xref-push-marker-stack)
(xref--pop-to-location (car xrefs) display-action))
(t
(xref-push-marker-stack)
(funcall xref-show-xrefs-function xrefs
`((window . ,(selected-window))
(display-action . ,display-action))))))
```
We can see the first branch of `cond` is when there's only one candidate, just jump to it. The second branch (the `t` part) is that when there are more than 1, we show them with the value of the variable `xref-show-xrefs-function`. **So you need to customize the value of `xref-show-xrefs-function`** to make the function do the same as the first branch of the above `cond`. Something like this (not tested):
```
(setq xref-show-xrefs-function 'my/xref-just-jump-to-first)
(defun my/xref-just-jump-to-first (xrefs alist)
"However many candidates, just jump to the first."
(xref-push-marker-stack)
(xref--pop-to-location (car xrefs) nil))
```
> 0 votes
---
Tags: ctags, tags, xref, etags
---
|
thread-61385
|
https://emacs.stackexchange.com/questions/61385
|
Why unicode (poker card) can't be properly displayed in GUI but fine in TUI?
|
2020-10-23T02:59:22.717
|
# Question
Title: Why unicode (poker card) can't be properly displayed in GUI but fine in TUI?
I'm having a hard time getting unicode to properly displayed in GUI.
I'm trying to type poker cards unicode inside emacs GUI, for instance. I would like to use font "Ubuntu Mono",
NOT Symbola.
Here's what's really weird:
1. Symbola works fine in GUI, as long as I have it installed.
2. If I remove Symbola from my system, GUI will only show ugly hex-code block, which is glyphless fallback.
3. TUI emacs is fine and shows the non-Symbola version. (Needless to say can be properly displayed in terminal vim as well) Also, gedit and gvim works fine also. LibreOffice works fine as well.
To sum up, on my setting, I'm only experiencing problem with GUI emacs, which is really weird, since plenty of fonts installed on Ubuntu by default can display .
I'm wondering if there's some problem with my system setting or my build of emacs. Also, this link doesn't work for me. I'm getting `display: no font available` on my GUI.
```
position: 1 of 1384 (0%), column: 0
character: (displayed as ) (codepoint 127145, #o370251, #x1f0a9)
charset: unicode (Unicode (ISO10646))
code point in charset: 0x1F0A9
script: playing-cards
syntax: w which means: word
category: .:Base
to input: type "C-x 8 RET 1f0a9" or "C-x 8 RET PLAYING CARD NINE OF SPADES"
buffer code: #xF0 #x9F #x82 #xA9
file code: #xF0 #x9F #x82 #xA9 (encoded by coding system utf-8-unix)
display: no font available
Character code properties: customize what to show
name: PLAYING CARD NINE OF SPADES
general-category: So (Symbol, Other)
decomposition: (127145) ('')
There is an overlay here:
From 1 to 3
face hl-line
priority -50
window #<window 3 on test.el>
There are text properties here:
fontified t
[back]
```
Tested environment:
```
Ubuntu 16.04 / 18.04
emacs 27.1
Spacemacs develop / emacs -Q
```
---
Edit:
A few details in the comment below.
When `Symbola` is installed, the following can be observed.
```
;; C-x C-e turns into ugly hex-code
(set-fontset-font nil ? "Ubuntu Mono")
;; C-x C-e turns into what's shown in the Symbola image
(set-fontset-font nil ? "Symbola")
;; This line actually works, but I have no idea why
(set-fontset-font nil 'playing-cards (font-spec :script 'playing-cards))
```
# Answer
Sorry, I'll rewrite my answer entirely from the beginning.
Sometimes, a script is a clue to find the need font for Emacs. You can check which script a codepoint belongs to by follwing:
```
(aref char-script-table ?)
playing-cards
```
By specifying the script in `font-spec`, you may find the fonts, but it often fails because the script that is not contained in `script-representative-chars` is not reliable, and font does not necessarily contain the glyph for specific codepoints.
```
(list-font (font-spec :script 'playing-cards))
(find-font (font-spec :script 'playing-cards))
```
`font-spec` function returns `<font-spec>` objects that is just an query of the fonts, and `list-font` and `find-font` function return `<font-entity>` objects that are abstract pointers to the installed fonts. Both types can be specified to `set-frame-font` and `set-face-font` functions, while only `<font-spec>` can be specified to `set-fontset-font` function. Emacs will not generate actual glyph images for fonts unless `open-font` function is called to `<font-entity>` object.
More assured way to find the font that contains the glyph for specific codepoint is just try to get the glyph from the candidate font.
```
(let ((font (open-font (find-font (font-spec :family "Ubuntu Mono")))))
(font-get-glyphs font 0 1 [?]))
[nil] ; This font does not contain glyph for ''.
(let ((font (open-font (find-font (font-spec :family "DejaVu Sans")))))
(font-get-glyphs font 0 1 [?]))
[[0 0 127145 5795 2 0 2 2 1 nil]] ; This font does contain glyph for ''.
```
By `cl-loop`ing all installed font families (that can be obtained by `(list-fonts (font-spec :weight 'normal))`) for this test, I found that in my Linux system, there are only follwing three fonts that contain glyph for ''.
```
Noto Sans Symbols2 = [[0 0 127145 1646 1 0 2 2 0 nil]]
LastResort = [[0 0 127145 143 1 0 2 1 1 nil]]
DejaVu Sans = [[0 0 127145 5795 2 0 2 2 1 nil]]
```
Also, you can try `cl-loop`ing the above test from the codepoint `#x0020` to `#x3ffff` to find the coverage of codepoints for specific font, such as "Ubuntu One", that is found to cover the following codepoint ranges.
```
00020-0007e
000a1-0024f
002bc-002c7
....
0f507-0f511
0f80b-0f81d
```
Therefore, it seems that in my Linux & Emacs system, "Ubuntu One" does not cotain the glyph for ''. It may be a fault of my Emacs font engine, or that my "Ubuntu One" font is different from yours...
Now you can use `set-fontset-font` to current fontset to specify the fonts for specific codepoints.
```
(set-fontset-font nil (#x1f0a0 . #x1f0ff) "Noto Sans Symbols2")
(set-fontset-font nil 'playing-cards "Noto Sans Symbols2")
```
or for default fallback fontset,
```
(set-fontset-font t 'playing-cards "Noto Sans Symbols2")
```
Note: there are (in some way) three layers of font API in Emacs.
* Upper :: `set-face-font`, `set-frame-font`
* Middle :: `new-fontset`, `set-fontset-font`, `query-fontset`
* Lower :: `find-font`, `open-font`, `font-get-glyphs`
If you need to deal with single font, upper API can handle it. If you need to handle multiple fonts with codepoints in mind, middle API is needed. To access font directly, you may need to use lower layer API.
But lower API sometimes behaves differently by the operating systems, window systems or font engines.
If you access upper API, the fontset is automatically adjusted, and is named something like `fontset-autoXX`, which you can get by `(face-attribute 'default :fontset)`.
> 5 votes
---
Tags: unicode, gui-emacs
---
|
thread-61390
|
https://emacs.stackexchange.com/questions/61390
|
How can I save a function defintion
|
2020-10-23T07:08:15.923
|
# Question
Title: How can I save a function defintion
I want to extend a standard Emacs function (`package--save-selected-packages`), but to cover my tracks I want to save the old defintion under a new name and then redintion teh standard function.
I tried `fset` but that creates rather something like an *alias* from a new name to the old name, but it does not save the old definition...
# Answer
> 1 votes
You can use `symbol-function` to obtain the current function slot value for a given symbol, which is typically what you'd be after here.
You can store that value anywhere you want, and restore it later (perhaps with `fset`).
> I tried `fset` but that creates rather something like an *alias* from a new name to the old name, but it does not save the old definition...
If you did something like `(fset 'foo 'bar)` then you are only storing the *name* of the function, rather than the function value associated with the name. Function indirection would therefore return whatever the *current* value associated with that name happens to be.
---
Tags: functions, defun, symbol-function
---
|
thread-30893
|
https://emacs.stackexchange.com/questions/30893
|
How to disable noweb prefix lines?
|
2017-02-20T15:24:46.227
|
# Question
Title: How to disable noweb prefix lines?
This says that
> Noweb insertions now honor prefix characters that appear before `<<reference>>`.
And because of that trying to use
```
#+BEGIN_SRC clojure :noweb-ref dep-cljsbuild
[lein-figwheel "0.5.9"]
[lein-cljsbuild "1.1.5" :exclusions [[org.clojure/clojure]]]
#+END_SRC
```
with
```
:plugins [<<dep-cljsbuild>>]
```
gives me
```
:plugins [[lein-figwheel "0.5.9"]
:plugins [[lein-cljsbuild "1.1.5" :exclusions [[org.clojure/clojure]]]]
```
which is obviously not what I want. I can workaround issue by moving `<<dep-cljsbuild>>` to the new line, but it looks ugly.
Could you recommend any proper way to point org-mode that in particular place I don't want prefixes to be preserved? (Or at least how to disable it globally)
# Answer
There is another workaround: remove newlines from the referenced code block.
According to the Org manual
> Since this change does not affect noweb replacement text without newlines in them, inline noweb references are acceptable.
Here is a minimal example:
```
#+TITLE: Example
#+BEGIN_SRC clojure :noweb-ref dep-cljsbuild
[lein-figwheel "0.5.9"] [lein-cljsbuild "1.1.5" :exclusions [[org.clojure/clojure]]]
#+END_SRC
#+BEGIN_SRC clojure :noweb yes
:plugins [<<dep-cljsbuild>>]
#+END_SRC
```
Previewing the second snippet when expanded using `C-c C-v v` shows:
```
:plugins [[lein-figwheel "0.5.9"] [lein-cljsbuild "1.1.5" :exclusions [[org.clojure/clojure]]]]
```
> 1 votes
# Answer
```
#+BEGIN_SRC bash :noweb yes :results verbatim
echo \
<<example>>
#+END_SRC
```
> 0 votes
---
Tags: org-mode, org-babel, noweb, tangle
---
|
thread-61389
|
https://emacs.stackexchange.com/questions/61389
|
Binding XF86Cut and XF86Copy to Emacs Commands
|
2020-10-23T05:10:39.393
|
# Question
Title: Binding XF86Cut and XF86Copy to Emacs Commands
I have a keyboard with dedicated keys for XF86Cut, XF86Copy, XF86Paste. I want to bind these to Emacs commands. The goal is get the usual behavior for cut-and-paste between Emacs, my terminal, and my browser Firefox with a common set of keys.
FWIW, XF86Paste works seems to work just fine with zero configuration. However, Emacs cannot see the key presses for the other keys. I verified this using `M-x describe-key` followed by a key press. For XF86Copy and XF86Paste, Emacs behaves as if no key was pressed
Both XF86Copy and XF86Paste work in the terminal. (However, XF86Cut doesn't.) How can I bind XF86Cut and XF86Copy to commands within Emacs?
This is how I start Emacs: `emacsclient -a "" -t`
I'm using:
* Emacs 27.1
* Alacritty 0.5.0 (a6681e3a)
* xmonad 0.15
* X.Org Server 1.20.9-2
* Linux 5.9.1.arch1-1
# Answer
> 1 votes
With a sun keyboard, for me, it works quite straight forward.
```
(global-set-key (kbd "<XF86Paste>") 'yank)
(global-set-key (kbd "<XF86Copy>") 'kill-ring-save)
(global-set-key (kbd "<XF86Cut>") 'kill-region)
```
For the terminal integration, that's related to the OS itself and how it manage the keyboard input, this article may help
---
Tags: key-bindings, copy-paste, linux, x11
---
|
thread-61379
|
https://emacs.stackexchange.com/questions/61379
|
How to script a bookmark-jump call
|
2020-10-22T21:25:11.853
|
# Question
Title: How to script a bookmark-jump call
I am trying to write a function which will perform a bookmark-jump but then reset the the bookmark line to the top of the screen. So far I have:
```
(defun foo ()
(interactive)
(bookmark-jump)
(evil-scroll-line-to-top nil)
)
(define-key evil-normal-state-map [f9] 'foo)
```
But hitting F9 gives this message. What am I doing wrong please?
# Answer
> 0 votes
Your command needs to call `bookmark-jump` interactively, so it can prompt for the bookmark you want to jump to. It requires a bookmark, to know where to take you.
```
(defun foo ()
(interactive)
(call-interactively #'bookmark-jump)
(message "XXXXXXXXXX"))
```
On the other hand, if you always want `foo` to jump to the same bookmark, and you know which bookmark that is:
```
(defun foo ()
(interactive)
(bookmark-jump "my-bookmark-name")
(message "XXXXXXXXXX"))
```
---
Tags: commands, interactive, bookmarks, call-interactively
---
|
thread-18101
|
https://emacs.stackexchange.com/questions/18101
|
Org-mode multi-line emphasis and bold
|
2015-11-15T07:39:59.707
|
# Question
Title: Org-mode multi-line emphasis and bold
Is there any sort of markup in org-mode to get multiple lines of text to be bold, italics, etc?
```
*This is what I want to be bold and I only want lines to
be a certain length so that this doesn't work.*
```
---
I know about using `visual-line-mode` as an alternative to `fill-paragraph` which would solve this problem, but I like `M-q` too much and I want to try and keep my files at a certain width.
Snippets welcome. I don't know Elisp so I can't do it myself. But I guess this would ruin export too.
I'm thinking something like:
```
#+BEGIN_BOLD
All my text in here would be super bold
and would be very nice.
#+END_BOLD
```
# Answer
```
(with-eval-after-load 'org
;; Allow multiple line Org emphasis markup.
;; http://emacs.stackexchange.com/a/13828/115
(setcar (nthcdr 4 org-emphasis-regexp-components) 20) ;Up to 20 lines, default is just 1
;; Below is needed to apply the modified `org-emphasis-regexp-components'
;; settings from above.
(org-set-emph-re 'org-emphasis-regexp-components org-emphasis-regexp-components))
```
Source: https://ox-hugo.scripter.co/test/posts/multi-line-bold/
> 4 votes
# Answer
As per the answer from nicael's comment on the question:
> By default, org-mode allows a single newline. So if you want to be able to add markup to text that spans more than two consecutive lines, you'll need to modify this entry.
>
> ```
> (setcar (nthcdr 4 org-emphasis-regexp-components) N)
>
> ```
>
> ... where N is the number of newlines you want to allow.
Higher up in the same answer, it says that you need to add the line:
> ```
> (org-set-emph-re 'org-emphasis-regexp-components org-emphasis-regexp-components)
>
> ```
after the line above.
> 3 votes
# Answer
`org-emphasize` in org-mode does this. From https://orgmode.org/worg/doc.html#org-emphasize:
> Insert or change an emphasis, i.e. a font like bold or italic. If there is an active region, change that region to a new emphasis. If there is no region, just insert the marker characters and position the cursor between them.
Select the regions and then run `org-emphasize` with `C-c C-x C-f`. You will be prompted for the bracketing character to use in the emphasis (\* for bold, / for italics, etc.). Entering a space removes existing emphasis.
> 2 votes
---
Tags: org-mode
---
|
thread-61372
|
https://emacs.stackexchange.com/questions/61372
|
Number of line as you'd get moving down the buffer with C-n
|
2020-10-22T16:20:01.400
|
# Question
Title: Number of line as you'd get moving down the buffer with C-n
In a buffer in Emacs, a line is the text you get from the first character after you press "Enter" to the last character before the next "Enter". And so, this is the line numbers one gets to the left of the buffer when you are in the display-line-numbers-mode.
Is there any way to get not these line numbers, but the "number of line" you get by counting the number of times you press C-n when moving down the buffer from the beginning? Namely, counting the numbers of lines (as I see in the screen) from the beginning of the buffer till the current position, and showing them in the screen as display-line-numbers-mode does.
I have tried using M-q on the line, but this is not what I am looking for as this command truncates the line into multiple lines.
\[Edited in order to make the question clearer.\]
I'd like to get the kind of thing you get when (in the windowed version of Emacs) you activate "Options → Show/Hide → Line Numbers for All Lines → Visual Line Numbers". But I don't quite understand this option, because it's not counting the lines from the first one in the buffer. Instead, the number in front of each line changes depending on the line in which the cursor is.
\[Edit 2\]
Example:
In this image I have two lines (I am using word wrapping). Well, the idea is that I'd like to show a number in each line I see, that is, from 1 (at the beginning) to 12 (at the end of the buffer). Of course, if I change the width of the window I'd get a different number of lines.
# Answer
There is no built-in functionality to provide line numbers based on visual lines. First of all, compared to buffer lines (e.g. `\n`, `\r\n`), visual lines need to get recounted on *every* window width-change, which can bring Emacs down to its knees. Compared to normal buffer lines, visual lines are only second-class citizens in that regard.
However, the old `linum-mode` provides a starting point to get your desired behaviour. We can change `linum-mode` in a way that counts visual line modes, but we will disregard some warnings.
Here are the necessary steps:
1. Copy `linum.el` to another file. For this demonstration, let's call it `vinum.el`
2. Open `vinum.el` and `M-x `replace-string` RET `linum` RET `vinum` RET`
3. Replace `forward-line` with `next-line` (**warning:** `next-line` is only meant for interactive use, however, `C-n` is `next-line` and you want to use its behaviour)
4. `M-x eval-buffer`
5. Open a buffer with long lines and enable both `visual-line-mode` and `vinum-mode`.
This will still use the correct line number for the first line. If you always want to start the numbers by `1`, then replace `(line-number-at-pos)` by `1`. If you want to count **all** visual lines, then replace `(window-start win)` by `(point-min)` and `(window-end win t)` by `(point-max)` **instead**.
> 2 votes
---
Tags: line-numbers, visual-line-mode
---
|
thread-61408
|
https://emacs.stackexchange.com/questions/61408
|
How do I search/replace with case sensitive search?
|
2020-10-25T04:26:33.977
|
# Question
Title: How do I search/replace with case sensitive search?
In emacs I'm using `M-%` to replace occurrences of `b_abcd` (of which there are only a few) with `B_abcd` (of which there are very many). Currently Emacs asks if it's OK to replace at each `B_abcd`, which takes a lot of time to wade through all `B_abcd`s it finds.
How can I make Emacs ask only about replacing `b_abcd` occurrences?
# Answer
Bind or set `case-fold-search` to `nil`.
`C-h k M-%` tells us:
> **`M-%`** runs the command `query-replace` (found in `global-map`), which is an interactive compiled Lisp function in `replace.el`.
>
> It is bound to `M-%`, `<menu-bar> <edit> <replace> <query-replace>`.
>
> `(query-replace FROM-STRING TO-STRING &optional DELIMITED START END BACKWARD REGION-NONCONTIGUOUS-P)`
>
> Probably introduced at or before Emacs version 1.3.
>
> Replace some occurrences of `FROM-STRING` with `TO-STRING`.
>
> As each match is found, the user must type a character saying what to do with it. For directions, type `C-h` at that time.
...
> **Matching is independent of case if both `case-fold-search` and `search-upper-case` are non-`nil` and `FROM-STRING` has no uppercase letters; if `search-upper-case` is `nil`, then whether matching ignores case depends on `case-fold-search` regardless of whether there are uppercase letters in `FROM-STRING`. Replacement transfers the case pattern of the old text to the new text, if both `case-fold-search` and `case-replace` are non-`nil` and `FROM-STRING` has no uppercase letters. (Transferring the case pattern means that if the old text matched is all caps, or capitalized, then its replacement is respectively upcased or capitalized.)**
If your string to replace had uppercase letters and you wanted to always respect case then you would set `case-fold-search` to non-`nil` and `search-upper-case` to `nil`. In your case the string to replace has no uppercase letters, so it's sufficient to set `case-fold-search` to non-`nil`.
You can *customize* either or both of these variables (options), to make them have the values you want most often by default. That way, you will only need to set or bind them occasionally, for your less frequent uses. To customize them, use `M-x customize-option`.
> 1 votes
# Answer
Use isearch (`C-s`), turn on case sensitivity (`M-c`) then launch replace (`M-%`) from there.
* `M-c` runs the command `isearch-toggle-case-fold`
* `M-%` runs the command `isearch-query-replace`
> 6 votes
---
Tags: search, replace, query-replace, case-folding
---
|
thread-61411
|
https://emacs.stackexchange.com/questions/61411
|
"Tramp: Opening adb shell connection...failed" + extra characters ^[7 and ^[8 present
|
2020-10-25T11:17:15.507
|
# Question
Title: "Tramp: Opening adb shell connection...failed" + extra characters ^[7 and ^[8 present
It happens when I try to connect from emacs-26.3/tramp-2.3.5.26.3 onto my sgs5's lineageos14.1 adb shell.
`*tramp/adb d73896d9*` buffer contents is the following:
```
nv COLUMNS=1 ls -d -l /; echo tramp_exit_status $?^M
/system/bin/sh: nv: not found
tramp_exit_status 127
klte:/ $ ^[[K^Mklte:/ $ ^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H
```
from `*debug tramp/adb d73896d9*`, I can see following command is used by tramp: `adb -s d73896d9 shell`.
Following is the output from manual run:
```
prompt$ adb -s d73896d9 shell
^[7
```
Session DOES NOT end here, it's functional - the only strange thing here is that funny prompt.
pressing enter adds `^[8klte:/ $` to the output so that the full output from very beginning looks like following:
```
prompt$ adb -s d73896d9 shell
^[7
^[8klte:/ $
```
subsequent presses of ENTER just adds `klte:/ $` prompts so that full output looks like following:
```
prompt$ adb -s d73896d9 shell
^[7
^[8klte:/ $
klte:/ $
klte:/ $
```
Is the `^[7` and and `^[8` main player here? That's why we do have `nv COLUMNS=1 ls -d -l /` instead of `env COLUMNS=1 ls -d -l /` above (`e` is swallowed by `^[7` somehow?).
when I run `adb shell` from non-emacs terminal or from `M-x term`, I get correct prompt immediatelly, ie no extra `^[7` and `^[8` characters are present + no extra empty line is produced later down between subsequent prompts.
please help.
# Answer
Hard to say where it comes from. The sequences look like ansi escape sequences, but they are not complete. For further analysis, I would need the complete Tramp debug buffer (`tramp-verbose` shall be set to 10). But this cannot be analyzed here on sx. Perhaps, you ask on the Tramp mailing list?
It turned out that whatever the problem was, upgrading to Tramp 2.4.4.2 fixed it.
> 1 votes
---
Tags: tramp, android
---
|
thread-61397
|
https://emacs.stackexchange.com/questions/61397
|
org-agenda-todo-ignore-scheduled set to 'future seems to work for TODOs that have only a date and not a time
|
2020-10-23T13:10:01.567
|
# Question
Title: org-agenda-todo-ignore-scheduled set to 'future seems to work for TODOs that have only a date and not a time
I use `org-agenda-todo-ignore-scheduled` set to 'future to ignore / not show TODOs in the global todo list that are scheduled in the future.
`org-agenda-todo-ignore-scheduled` set to 'future seems to work for TODOs that have only a date and not a time.
E.g. if today is Oct 23 2020 at 10 am and a TODO has a timestamp of e.g.:
```
SCHEDULED: <2020-10-24 Sat .+1d>
```
then it is not shown.
BUT a TODO with:
```
SCHEDULED: <2020-10-23 12:00 Fri .+2h>
```
is shown in the Global todo list even though it is scheduled for 2 hours into the future.
I have been searching for a variable or setting that could make the global todo list also ignore TODOs that are x hours into the future but have not been able to find anything.
Is there any way to do this?
# Answer
* Do `C-h v org-agenda-todo-ignore-time-comparison-use-seconds` and click `customize`.
* Click Value menu.
* Set it to `Compare time with seconds`.
* Save
* Restart emacs
This changes the comparison from the default value which is days.
> 2 votes
---
Tags: org-mode, org-agenda
---
|
thread-61413
|
https://emacs.stackexchange.com/questions/61413
|
Cannot create org-babel matlab source block with vector input arguments
|
2020-10-25T14:01:43.210
|
# Question
Title: Cannot create org-babel matlab source block with vector input arguments
I want to create a re-usable matlab org-babel source block `vectsb` (say), which takes two vectors from a call statement, performs some operations with them, and returns the result in the call statement. A MWE is as follows
```
#+NAME: vectsb
#+begin_src matlab :var a=[0], b=[0] :session
a+b
#+end_src
#+CALL: vectsb(a=[1,2,3],b=[3,2,1])
#+RESULTS:
| 1040 | 650 |
```
I am getting this type of errors in the input arguments
```
a=[1 (, 2) (, 3)];
|
Error: Invalid expression. When calling a function or indexing a variable, use
parentheses. Otherwise, check for mismatched delimiters.
```
No matter how much I read the org-babel manual I can't figure out what I am doing wrong. Partly because there are few examples for Matlab.
# Answer
Here's a version that seems to work (discovered by trial-and-error; and BTW it is using octave, since I don't have matlab):
```
#+NAME: vectsb
#+begin_src octave :var a=[0] :var b=[0] :session
a+b
#+end_src
#+RESULTS: vectsb
: 0
#+CALL: vectsb(a=[1 2 3],b=[3 2 1])
#+RESULTS:
| 4 | 4 | 4 |
```
The `org-babel` section of the Org mode manual contains very little about individual languages, which are decribed in a bit more detail in Worg. Unfortunately, the octave/matlab page is very rudimentary: if you are going to work with octave/matlab, you might want to request edit rights to Worg and improve it.
> 1 votes
---
Tags: org-mode, org-babel, matlab
---
|
thread-3375
|
https://emacs.stackexchange.com/questions/3375
|
Loading bibtex file in org-mode file
|
2014-11-11T11:28:10.893
|
# Question
Title: Loading bibtex file in org-mode file
I'm trying to use `org-mode` to do almost everything. In my scientific writing activity, I would like to sketch a whole paper in an `.org` file and then export in LaTeX. I don't want to load the `.bib` bibtex file in the `init.el` as I could have multiple ones. For now, I've added this at the head of my `.org` file:
```
#+BEGIN_SRC elisp
(setq reftex-default-bibliography '("./references.bib"))
#+END_SRC
```
But I have to execute it manually every time. Is there any way to make it automatic? The optimal would be to have a directive at the beginning of each `.org` file saying emacs: "ok, now you should load *this* `.bib` file". Any hint? Thanks.
# Answer
> 23 votes
Adding a line like the following is enough to tell `org-mode` which `.bib` file to consult:
```
#+BIBLIOGRAPHY: refs plain
```
`refs` is the name of the BibTeX file (`.bib` extension omitted), and `plain` is the `bibliographystyle`.
You can then call `org-reftex-citation` (bound to `C-c C-x [` by default) to insert references.
From the documentation:
> `(org-reftex-citation)`
>
> Use `reftex-citation` to insert a citation into the buffer. This looks for a line like
>
> `#+BIBLIOGRAPHY: foo plain option:-d`
>
> and derives from it that `foo.bib` is the bibliography file relevant for this document. It then installs the necessary environment for RefTeX to work in this buffer and calls `reftex-citation` to insert a citation into the buffer.
>
> Export of such citations to both LaTeX and HTML is handled by the contributed package `ox-bibtex` by Taru Karttunen.
As the last sentence suggests, you'll need to add
```
(require 'org)
(require 'ox-bibtex)
```
to your init-file to make sure references get exported to LaTeX properly. When I set this up for myself, I found that I also needed to customize `org-latex-pdf-process` in order to make PDF exports work:
```
(setq org-latex-pdf-process '("texi2dvi -p -b -V %f"))
```
### Addendum
If you don't want to use the default binding for `org-reftex-citation`, you can set up a custom key binding for it. For example, the following binds `org-reftex-citation` to the default binding for `reftex-citation`:
```
(define-key org-mode-map (kbd "C-c [") 'org-reftex-citation)
```
# Answer
> 4 votes
It seems that ox-bibtex is not included in the latest org package (8.2.10-34-gc41bbc-elpa). So I searched it online and put into directory /org/lisp/ once downloaded. But I ran into the following error when trying to do an export involving some bibtex.
> Symbol's function definition is void: org-element-insert-before
Then I check the file 'org-element.el', of course there is no such function predefined. But why isn't there? The online API document of org-element mentioned it in once.
So I guess currently it is impossible to use RefTeX as the way the document describes unless you are willing to switch to the beta version or some older one. See
Here I share my way to use the beta version
1. `git clone git://orgmode.org/org-mode.git`
2. Move the folder to `~/.emacs.d/` and name it as `org-beta`
3. Modify `load-path`, let the beta version shadow other version, and include the user contribute directory
```
(add-to-list 'load-path (expand-file-name "org-beta\\lisp" user-emacs-directory))
(add-to-list 'load-path (expand-file-name "org-beta\\org-contrib\\lisp" user-emacs-directory))
```
(optional) you can use make command to compile the source file and build the doc
4. Now you can `(require 'ox-bibtex)`. I prefer to write like this: `(eval-after-load 'org (require 'ox-bibtex))`
5. In order to generate reference list at the right place, put something like `#+BIBLIOGRAPHY: your_bib_lib_name plain option:-d` to the end of the org file. More options please refer to the help document in `ox-bibtex.el`
6. To make the HTML export part work right, you may need the latest bibtex2html, i.e., 1.98. To build it from source, download it from github, and follow the instruction in the 'README' help document.
If you are using windows like me, use Cygwin64 with all the devel packages. Using Cygwin64, cd to the dir of bibtex2html, and type `./configure`, wait finish, then type `make`, wait finish. Now in this dir, you will get `bib2bib.exe`, `bibtex2html.exe` and `aux2bib`. Copy them to some dir in your environment var `PATH`. Test it by typing `bibtex2html` in the cmd.
I have to do the above job because I use texlive2014. If you are a miktek user, bibtex2html 1.95 may just work well, which can be easily installed with a windows installer.
7. To make the PDF export part work right, use the following code to initialize your org-mode:
```
(setq org-latex-pdf-process
'("xelatex -shell-escape -interaction nonstopmode -output-directory %o %f"
"bibtex %b"
"xelatex -shell-escape -interaction nonstopmode -output-directory %o %f"
"xelatex -shell-escape -interaction nonstopmode -output-directory %o %f"))
```
It is the 'bibtex' part that does the job. I use the shell escape command for minted package of latex.
# Answer
> 0 votes
For some reasons, using `#+BIBLIOGRAPHY: refs plain` did not work for me, but, after enabling `org-ref`:, I can just do:
```
I can also try to include citation cite:SM20.
bibliographystyle:alpha
bibliography:ref.bib
```
---
Tags: org-mode, reftex-mode, bibtex
---
|
thread-60962
|
https://emacs.stackexchange.com/questions/60962
|
Indentation by using AST from external program
|
2020-10-02T22:20:27.180
|
# Question
Title: Indentation by using AST from external program
I'm pondering over doing indentation by using an AST created with an external (non-emacs) tool. But so far I do not really know where to start. Are there emacs packages which already did this? Any tips and hints are welcome.
# Answer
> 1 votes
You could try to implement the LSP (language Server protocol) and use lsp-mode in conjunction with this. lsp-mode brings support for many languages already, but I'm not sure, if the LSP interface supports indentation.
# Answer
> 0 votes
There is emacs-tree-sitter, which is a package that uses tree-sitter a parser generator tool that can be use to get a AST of some supported languages. Also emacs-tree-sitter support the option of get the AST of some languages so you can manipulate it and get some info, the documentation is interesting.
Good luck!
---
Tags: indentation
---
|
thread-10960
|
https://emacs.stackexchange.com/questions/10960
|
One yasnippet snippet for multiple modes
|
2015-04-27T14:00:26.110
|
# Question
Title: One yasnippet snippet for multiple modes
I have the following snippet:
```
# -*- mode: snippet -*-
# contributor: Song Qiang <tsiangsung@gmail.com>
# key: m
# group: Math
# name: Inline math \( ... \)
# --
\\($1\\)$0
```
and I want it to be available for both `latex-mode` and `org-mode`. How can this be achieved? I could symlink, but I'm trying to find a smarter way.
# Answer
> 25 votes
The Yasnippet documentation explains that you will need to include a `.yas-parents` file with the parent modes:
> It's very useful to have certain modes share snippets between themselves. To do this, choose a mode subdirectory and place a `.yas-parents` containing a whitespace-separated list of other mode names. When you reload those modes become parents of the original mode.
```
.
|-- c-mode
| |-- .yas-parents # contains "cc-mode text-mode"
| `-- printf
|-- cc-mode
| |-- for
| `-- while
|-- java-mode
| |-- .yas-parents # contains "cc-mode text-mode"
| `-- println
`-- text-mode
|-- email
`-- time
```
Hence, you could, for example, put your snippet in a `text-mode` directory, and then, in the `latex-mode` and `org-mode` directories, include a `.yas-parents` file that include the text `text-mode`.
# Answer
> 2 votes
A few more approaches for sharing snippets between modes:
1. Let's say you want certain snippets to be shared in *both* modes: `html-mode` & `css-mode`:
You need to create a separate folder and give it a unique name like `html-css-mode` where you put the snippets you want to reuse.
Once that's done you need to require this virtual mode in `html-mode` & `css-mode` folders by creating a `.yas-parents` file with `html-css-mode` content matching your virtual mode name.
2. If your snippet belongs to more that one mode or you're want to take a lazy approach - you can put your snippets into `fundamental-mode` folder which is available in all modes.
---
Tags: yasnippet
---
|
thread-30877
|
https://emacs.stackexchange.com/questions/30877
|
How to use org-capture without creating ID property?
|
2017-02-19T23:08:17.433
|
# Question
Title: How to use org-capture without creating ID property?
Whenever I create `org-mode` entries using `org-capture` they automatically get an ID property. Is it possible to disable that? I'm using org mode version 9.0.5.
# Answer
Setting `org-id-link-to-org-use-id` to `create-if-interactive` will prevent `org-capture` from creating links, thus prevent creating the ID drawer.
```
(setq org-id-link-to-org-use-id 'create-if-interactive)
```
The documentation for `org-id-link-to-org-use-id` says:
```
create-if-interactive
If org-store-link is called directly (interactively, as a user
command), do create an ID to support the link. But when doing the
job for capture, only use the ID if it already exists. The
purpose of this setting is to avoid proliferation of unwanted
IDs, just because you happen to be in an Org file when you
call org-capture that automatically and preemptively creates a
link. If you do want to get an ID link in a capture template to
an entry not having an ID, create it first by explicitly creating
a link to it, using C-c l first.
```
EDIT: this feature seems to exist since 2008. See this commit: https://code.orgmode.org/bzg/org-mode/commit/ac83bc01d7c5b8d625e1a61ecb0f759f49e85c65
> 1 votes
# Answer
So I think I've found a way, but its not very elegant:
```
(defun org-remove-id-from-last-capture ()
"Remove ID property from last `org-capture' entry, save capture buffer."
(let* ((properties (org-entry-properties org-capture-last-stored-marker))
(file (cdr (assoc "FILE" properties))))
(when (org-entry-delete org-capture-last-stored-marker "ID")
(with-current-buffer (get-file-buffer file)
(save-buffer)))))
(add-hook 'org-capture-after-finalize-hook #'org-remove-id-from-last-capture)
```
> 0 votes
# Answer
Sorry this answer may be better go to comment but I don't have enough reputation.
Short Version: It there any possibility that you used any package related with bookmarks or global-jump to org heading? If so, then trying to disable them may be helpful.
Long Version: I happened to have the same problem that an ID will be attached and stop the clock-in timer if there is any.
Following steps are done for a capture to finalize: (would be incomplete):
1. Insert the capture content to target location
2. Save a bookmark called "org-capture-last-stored" to your Bookmarks
3. Save the target file
And in my case, I found no function related to org-id in step 1 and 3 but in step 2, there is one package called "org-bookmark-heading" which is used to jump to a heading from bookmark. It will take over when creating a bookmark and generate the ID.
In all, I would suggest to check any packages related to bookmarks, head creation and save-hook.
> 0 votes
---
Tags: org-mode, org-capture
---
|
thread-61428
|
https://emacs.stackexchange.com/questions/61428
|
How to call Elisp functions from my own implementation of a shell?
|
2020-10-26T13:05:31.740
|
# Question
Title: How to call Elisp functions from my own implementation of a shell?
I'm writing my own shell which can handle most of the GNU/Linux system calls now. So I was wondering if I could make this shell call Elisp functions too. Is it possible to do so? Is so, how do I get started?
Basically, I want the shell to do what both Bash and Eshell can do.
# Answer
> 2 votes
I do this from `M-x shell` by defining functions that pass command line arguments to emacsclient. For example:
```
function ff() {
emacsclient -e "(find-file \"$@\")"
}
function man() {
emacsclient -e "(man \"$@\")"
}
```
This allows me to open a file from the Emacs shell command line with `ff filename`, or open a man page in Emacs' man mode with `man command`.
I haven't tried using this from a stand-alone terminal, but you could extend this by defining a command that would evaluate any elisp:
```
function el(){
emacsclient -e "$@"
}
```
Depending on your use-case, you will probably want to define some helper functions in your Emacs configuration, to make it easier to accomplish whatever it is you normally do with elisp.
This assumes you run emacs in server/daemon mode.
---
Tags: eshell, shell-command, linux
---
|
thread-61431
|
https://emacs.stackexchange.com/questions/61431
|
Only run a function if it is a new session
|
2020-10-26T15:04:52.627
|
# Question
Title: Only run a function if it is a new session
In my `init.el` file, I have a hook to setup my workspace when I open a particular type file. Specifically, when I open an R file (i.e., `*.R`) and ESS-mode starts, a couple of other windows open with `vterm` and `R` in them. My Elisp code looks like this:
```
;; R setup
(require 'ess-site)
(add-hook 'ess-mode-hook
(lambda()
(set-window-buffer (selected-window)
(file-name-nondirectory (car (last command-line-args))))
(split-window-horizontally)
(other-window 1)
(vterm)
(split-window-vertically)
(R)
(other-window 1)
))
```
When I open a file, say `emacs myfile.R`, this works as expected. I run into a problem, however, if I open a file once Emacs is already up and running. For example, I run `emacs myfile.R` and then do `C-x C-f myfile2.R` then this causes more windows to open.
**Q:** Is there a way to only run this startup function when there isn't an existing emacs session?
# Answer
> 0 votes
I think I have a solution. I define my setup in a function that is *only* called at startup, like so:
```
;; Define R setup function
(defun R_setup()
"Setup R"
(set-window-buffer (selected-window)
(file-name-nondirectory (car (last command-line-args))))
(split-window-horizontally)
(other-window 1)
(vterm)
(split-window-vertically)
(R)
(other-window 1)
)
;; Startup hook for R
(add-hook 'emacs-startup-hook
(lambda()
(if (equal (file-name-extension (car (last command-line-args))) "R")
(R_setup))
))
```
This way I only check that it is an R file at startup and if it is then perform my setup. When Emacs is already up and running, no such check is performed, so no setup is performed.
---
Tags: init-file, ess
---
|
thread-61424
|
https://emacs.stackexchange.com/questions/61424
|
regexp-filter just searches headlines (org agenda view)
|
2020-10-26T06:50:15.067
|
# Question
Title: regexp-filter just searches headlines (org agenda view)
I have a problem with the filtering function `org-agenda-filter-by-regexp`:
It just searches the headlines of the entries not the whole entry text.
Example:
```
* title :work:
text
```
Searching for the tag 'work' gives the correct and only headline 'title' in the 'Org Agenda' buffer. But after the regexp-filtering with (= text) the headline disappears because(?) 'text' isn't part of the headline.
I know I can start with the function for 'Search for keywords' (usually C-c a s) and then filter by the tag 'work' but mostly I start with tag searching and then look for keywords.
The documentation says: "only show agenda **entries** matching the regular expression the user entered." But it seems that it searches only the **headlines** of the entries.
---
EDIT: Not a solution, just a suggestion. Maybe it helps somebody. If you want to search for a keyword "text" and you know it will have to many results you can add the tag as an additional *keyword*: `:work:` -- but in this case only the direct tag of the headline can be taken into account.
# Answer
> 1 votes
"Entry" is used ambiguously in the documentation:
* an Org mode entry consists of a headline, scheduling information, optional drawers and the body of entry (text, possibly followed by subentries).
* an agenda entry consists of some agenda information (the category, scheduling information, possibly some other things controlled by the variable `org-agenda-prefix-format`) and the headline from an Org mode entry.
IOW, the agenda does not display the full Org mode entry, just its headline, so there is no way to search directly the agenda buffer for text that occurs in the body of an Org mode entry.
But you can use `C-c a /` to use `org-occur-in-agenda-files` to search for text using a regular expression in all the files that the agenda uses, i.e. all the files in `org-agenda-files`.
EDIT: Try using a tag search (`C-c a m <tag> RET`) and then in the resulting buffer do `M-x org-search-view RET {<regexp>} RET` and see if that works for you. If it does, you might want to add a binding for `org-search-view` in the `org-agenda-mode-map` to make it easier to invoke - there is is very little left free, but `Z` was not defined in my case, so I use it here as an example:
```
(define-key org-agenda-mode-map (kbd "Z") #'org-search-view)
```
With this key binding, the work flow would be: `C-c a m <tag> RET Z {<regexp>} RET`.
EDIT 2: Unfortunately, as the OP points out in a comment, this does not work: the `org-search-view` is done from scratch, not in the context of the previous tag search.
---
Tags: org-mode, org-agenda, filtering
---
|
thread-61426
|
https://emacs.stackexchange.com/questions/61426
|
How to redefine prefix key in org mode?
|
2020-10-26T11:04:43.140
|
# Question
Title: How to redefine prefix key in org mode?
I have rebound C-u to another function, and try to use C-j for the prefix, but now it seems I cannot use the prefix in org-mode. It does seem to work in other modes though.
```
; This is the relevant part of my current config (I think)
(global-set-key "\C-j" 'universal-argument)
(define-key universal-argument-map "\C-j" 'universal-argument-more)
(define-key universal-argument-map "\C-u" nil)
(define-key global-map "\C-u" nil)
(use-package org
:bind
(:map org-mode-map
("C-e" . next-line))
)
```
How can I make C-j the prefix in org-mode?
# Answer
> 2 votes
Your code will work for any mode that **doesn't** bind `C-j` for some purpose. `orgmode` binds `C-j` to `org-return-indent` in the org-mode keymap. The major-mode keymap takes precedence over the global keymap, so your modifications have no effect.
To make this work in org-mode, you'll need to bind `C-j` specifically in the orgmode keymap:
```
(define-key org-mode-map "\C-j" 'universal-argument)
```
You will run into the same problem in any mode that uses `C-j` for something. You might find some useful ideas in this answer.
---
Tags: org-mode, prefix-keys
---
|
thread-61432
|
https://emacs.stackexchange.com/questions/61432
|
How to insert a new heading from a collapsed heading?
|
2020-10-26T16:31:48.523
|
# Question
Title: How to insert a new heading from a collapsed heading?
Here, two headings are collapsed, but they do have some content represented by org's s`...`
```
* Heading 1...
* Heading 2...
```
How can I insert a heading right below `Heading 2`, including below all its content? My cursor is at caret when I do `M-RET`: `Heading 2^...`. As example:
```
* Heading 1...
* Heading 2...
* Heading 3...
```
Right now, it seems the behaviour is kind of buggy, where pressing `M-RET` on the previous heading's `...` will lead move all the content below the heading? Unfortunately this isn't the behaviour that I want..
```
* Heading 1...
* Heading 2
* ...
```
# Answer
> 2 votes
You are probably looking for `C-u M-RET` which calls `org-insert-heading` with a prefix argument. The doc string for `org-insert-heading` says:
> With a ‘C-u’ prefix, set ‘org-insert-heading-respect-content’ to a non-nil value for the duration of the command. This forces the insertion of a heading after the current subtree, independently on the location of point.
So if you are in the first-level subtree, it will go to the end of the subtree and insert a first-level heading, but if you are in a second-level subtree, it will go to the end of that and insert a second-level heading. In this second case, there is no way to guess that you want a first level heading, so you'll have to adjust the level with `M-<left>` or `M-<right>` as I mentioned in the comment.
If you really want a first-level heading at the end of the current subtree, you can define a function and bind it to a key (but IMO, that's a waste):
```
(defun ndk/org-insert-top-level-heading-at-end-of-current-subtree ()
(interactive)
(org-insert-heading '(4) nil t))
(define-key 'org-mode-map (kbd "S-<f12>") #'ndk/org-insert-top-level-heading-at-end-of-current-subtree)
```
The `'(4)` makes `org-insert-heading` behave the same way that it would if it were called interactively with a `C-u` prefix and the `t` forces it to insert a first-level headline instead of what it normally would. I bound it to `S-<f12>` because that is likely unused but you can suit yourself.
---
Tags: org-mode
---
|
thread-61427
|
https://emacs.stackexchange.com/questions/61427
|
Defining keyboard shortcuts from an argument in a function
|
2020-10-26T12:21:35.913
|
# Question
Title: Defining keyboard shortcuts from an argument in a function
I would like to write a command that defines key bindings for me, so that I can feed in key `y` (for example) and have it define key bindings for `M-y`, `C-y` etc.
I'm trying to `concat` the command argument into a string, but it gives me the error `Invalid modifier in string`.
```
(defun my/keypress-definer (keypress)
(interactive)
(concat "\C-" keypress))
(my/keypress-definer "a")
```
Is there any way to achieve this?
# Answer
The `concat` function takes a list of SEQs and returns a string.
To get the string that describes your key sequence, you would simply write
```
(concat "C-" keypress)
```
Use the `kbd` function to return the actual key representation. I think you may end up with something like the following
```
(defun my/keypress-definer (keypress)
(define-key my-key-map
(kbd (concat "C-" keypress)) 'my/ctl-function)
(define-key my-key-map
(kbd (concat "M-" keypress)) 'my/meta-function))
Documentation:
- [Creating Strings][1]
- [Key Sequences][2]
[1]: https://www.gnu.org/software/emacs/manual/html_node/elisp/Creating-Strings.html
[2]: https://www.gnu.org/software/emacs/manual/html_node/elisp/Key-Sequences.html
```
> 2 votes
---
Tags: key-bindings, string
---
|
thread-61439
|
https://emacs.stackexchange.com/questions/61439
|
How to write a basic org-babel-execute function for a new language?
|
2020-10-26T22:26:01.313
|
# Question
Title: How to write a basic org-babel-execute function for a new language?
What I'm trying to achieve is very simple: take a source block, write it to a temp file, pass the file name as an argument to an executable which will run it, and then include the output in the `#RESULTS` block. The snippet below seems close, but when I try to execute the code block the executable (`nim`) complains that it expected a file name so I guess it passes the block body via `stdin` instead of temp file:
```
(defun org-babel-execute:nim (body params)
"Execute a block of Nim code with org-babel."
(message "executing Nim source code block")
(org-babel-eval "nim r " body))
```
Second attempt, based on @NickD's comment and `org-babel-execute:dot`:
```
(defun org-babel-execute:nim (body params)
"Execute a block of Nim code with org-babel."
(message "executing Nim source code block")
(let* (in-file (org-babel-temp-file "nim-")))
(with-temp-file in-file
(insert body))
(org-babel-eval (format "nim r %s" (org-babel-process-file-name in-file))))
```
When trying to execute a code block, getting "Symbol's value as variable is void: in-file"
# Answer
> 11 votes
You need to define `org-babel-execute:nim`:
```
(defun org-babel-execute:nim (body params)
"Execute a block of Nim code with org-babel."
```
While we *could* use `nim` via STDIN, it will clutter the current working directory. Therefore, let us use a temporary file instead. `nim` also needs files to start with a letter and end with `.nim`, so we adjust the arguments to `org-babel-temp-file`. For some less noise, let's also change the default verbosity, but make it adjustable:
```
(let ((in-file (org-babel-temp-file "n" ".nim"))
(verbosity (or (cdr (assq :verbosity params)) 0)))
(with-temp-file in-file
(insert body))
```
Last but not least, we call `org-babel-eval`. Since we supplied the original `body` in our `in-file`, we can keep the `body` argument of `org-babel-eval` empty. One could probably also change the working directory to a temporary directory instead, but I'm not familiar with `nim`, at all.
```
(org-babel-eval
(format "nim compile --verbosity=%d --run %s" verbosity
(org-babel-process-file-name in-file))
"")))
```
Here's all at once:
```
(defun org-babel-execute:nim (body params)
"Execute a block of Nim code with org-babel."
(let ((in-file (org-babel-temp-file "n" ".nim"))
(verbosity (or (cdr (assq :verbosity params)) 0)))
(with-temp-file in-file
(insert body))
(org-babel-eval
(format "nim compile --verbosity=%d --run %s" verbosity
(org-babel-process-file-name in-file))
"")))
```
And here's an example:
```
#+begin_src nim
var name : string = "Woof"
echo "Hi, ", name, "!"
#+end_src
#+RESULTS:
: Hi, Woof!
```
---
Tags: org-babel
---
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.