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-56011
|
https://emacs.stackexchange.com/questions/56011
|
Insert an arbitrary timestamp
|
2020-03-09T10:59:47.680
|
# Question
Title: Insert an arbitrary timestamp
`C-c .` could insert the timestamp of the current date and `C-u C-c .` insert the current datetime.
I find it very difficult to insert an arbitrary datetime.
Operations over Calendar are invalid since the focus stay on the mini-buffer.
A work-around solution to insert \<2019-08-09 Fri\>
1. M-x calendar to select year 2019, month of August, Day of 09
2. C-x o switch to other buffer from the calendar
3. C-c \< (org-date-from-calendar)
Is there a handy way to insert a specified timestamp? or how could scroll the Calendar after strike `C-u C-c .`?
# Answer
To insert a timestamp four months from today, press: `C-c . +4m RET` and the +4m cookie shifts the date for you. Likewise, use -4m to insert four months *before* today (y, m, w, and d letters are all valid).
Use `S-arrows`, `<`, and `>` for navigation. See the manual for more information.
> 6 votes
# Answer
I wrote this for one of my libraries. It returns a string formatted as an Org time stamp.
```
defun my-org-time-stamp (&optional time inactive)
"Return an Org time stamp.
TIME is specified as (HIGH LOW USEC PSEC), as returned
by `current-time' or `file-attributes'. The
`org-current-time' is used unless non-nil.
INACTIVE means use square brackets instead of angular
ones, so that the stamp will not contribute to the agenda.
Examples:
(my-org-time-stamp nil t)
\"[2020-01-27 Mon 21:37]\"
(my-org-time-stamp nil nil)
\"<2020-01-27 Mon 21:38>\""
(let ((time (or time (org-current-time))))
(if inactive
(org-format-time-string "[%F %a %H:%M]" time)
(org-format-time-string "<%F %a %H:%M>" time))))
```
Using this, you could create a function which prompts for the time and then inserts the resulting time stamp.
> 1 votes
# Answer
@jagrg has helpfully answered the question you probably really meant to ask, namely "how do I enter the date exactly seven months ago?" You should and did accept that answer.
For completeness, to answer the question as asked, typing the following 15 individual keystrokes in order:
```
C-c
.
1
9
-
8
-
9
SPC
1
2
:
3
4
RET
```
will insert `<2019-08-09 Fri 12:34>`.
Notes:
* In this case, the calendar's default three-month display is no help. In other cases, you should use the calendar window for reference, not input. Or simply ignore it; I rarely even glance at the calendar when entering dates and times.
* Entering a time works even without the `C-u` prefix; the only difference is that the initial suggested completion does not display a time.
> 1 votes
# Answer
jajrg has the info you want.
but just to add a small detail:
`C-c .` prompts you to insert a active timestamp. it appears in your agenda and is surrounded by `<` `>`.
`C-c !` prompts you to insert an inactive timestamp. it doesn't appear in your agenda and is surrounded by `[` `]`.
once created, you can also change the date by ensuring point is on the timestamp and using `S-<right>` and `S-<left>` to shift back/forward by one day, and `S-<up>` `S-<down>` do move by one unit of whatever point is currently over (year, month, or day, also hour and minute if you have them).
(full info: https://orgmode.org/manual/Creating-Timestamps.html#Creating-Timestamps.)
> 0 votes
---
Tags: org-mode, time-date
---
|
thread-56015
|
https://emacs.stackexchange.com/questions/56015
|
Orphaned source `org-edit-src-code` buffers
|
2020-03-09T12:14:50.500
|
# Question
Title: Orphaned source `org-edit-src-code` buffers
I regularly use `org-tree-to-indirect-buffer` to edit an org-mode entry in a separate buffer. I also have `org-indirect-buffer-display` set to `current-window` so that `org-tree-to-indirect-buffer` automatically kills an old indirect buffer before creating a new one.
The problem is that sometimes I would be editing a source-code block using `org-edit-src-code`, but then forget to press `C-c C-c` to accept the changes. If I then call `org-tree-to-indirect-buffer` on another entry, the old indirect buffer is killed and the source buffer that `org-edit-src-code` created is orphaned. Pressing `C-c C-c` on that buffer returns "Source buffer disappeared. Aborting". Is there a way to make it so that source code buffers are automatically closed when the original buffer is killed?
TLDR, how can I automatically close `Org Src` created by `org-edit-src-code` when the original org buffer is killed?
# Answer
The following Elisp code adds a function `org+-kill-orphaned-edit-buffers` to the special hook `kill-buffer-query-functions` buffer-locally in Org buffers.
That function scans the Org buffer for overlays with `edit-buffer` property and looks whether that buffer is a live `org-src-edit` buffer. If that is the case it tries to kill the source edit buffer.
The true/false-value of the option `org+-query-before-kill-edit-buffer` determines whether you should be asked for confirmation if a modified source buffer is going to be killed.
If some modified source buffer is not killed then the original Org buffer is also not killed.
But, if `org+-query-before-kill-edit-buffer` is nil (the default case) source edit buffers are killed unconditionally. So you only need to confirm killing if the Org buffer itself is modified.
```
(require 'cl-lib)
(defcustom org+-query-before-kill-edit-buffer nil
"Query when killing an edited org src buffer."
:type 'boolean
:group 'org-src)
(defun org+-kill-orphaned-edit-buffers (&optional b e)
"Close orphaned source edit buffers in the region from B to E.
B defaults to `point-min' and E defaults to `point-max'.
In interactive calls B and E are the boundaries of the region
if it is active."
(interactive (when (region-active-p)
(list (region-beginning)
(region-end))))
(unless b (setq b (point-min)))
(unless e (setq e (point-max)))
(cl-loop with buf
for ol being the overlays from b to e
if (and (setq buf (overlay-get ol 'edit-buffer))
(org-src-edit-buffer-p buf))
unless (with-current-buffer buf
(when
(or (null org+-query-before-kill-edit-buffer)
(null (buffer-modified-p))
(save-window-excursion
(display-buffer (current-buffer))
(y-or-n-p (format "Buffer %s modified; kill anyway? " (buffer-name)))))
(set-buffer-modified-p nil)
(kill-buffer)))
return nil
finally return t))
(defun org+-kill-edit-buffers-at-kill-buffer ()
"Close source edit buffer when the current Org buffer is killed."
(add-hook 'kill-buffer-query-functions #'org+-kill-orphaned-edit-buffers t t))
(add-hook 'org-mode-hook #'org+-kill-edit-buffers-at-kill-buffer)
```
> 1 votes
---
Tags: org-mode
---
|
thread-56007
|
https://emacs.stackexchange.com/questions/56007
|
How to Run a Context Sensitive Compile?
|
2020-03-09T05:21:39.910
|
# Question
Title: How to Run a Context Sensitive Compile?
When working on projects which use multiple kinds of build-systems, sometimes I want to run a make command based on the project, without having to manually setup project spesific hooks.
Is there a good way to perform this in Emacs?
---
To expand on this question to give some context,
I might have many projects on my computer and load a C file from a project that uses `GNUMakefiles`, then another project that uses `CMake`, and a third project that uses `Meson`.
Along with this, I might also have some documentation in `reStructuredText` or `Markdown` that has a `GNUMakefile`, which is useful to run to build the documentation.
Neither major-modes have anything to do with `GNU Make`, it's just convenient to use a `GNUMakefile` sometimes.
By knowing the language is `C` or the document is `reStructuredText` doesn't give me a hint as to the build system, so I would like a way to detect this.
# Answer
> 2 votes
did you try with .dir-locals.el file? something along the lines
```
((c++-mode . ((compile-command . "make -j 4")
;; other customisation
))
;; other modes
)
```
see (info "(emacs)Directory Variables")
# Answer
> 1 votes
This is a solution which searches up the parent directories for common build system filenames, and runs the appropriate build-command.
Posting here since it works, although better methods may exist.
```
(defun my-compile-context-sensitive--locate-dominating-file-multi (dir compilation-filenames)
"Search for the compilation file traversing up the directory tree.
DIR the base directory to search.
COMPILATION-FILENAMES a list pairs (id, list-of-names).
Note that the id can be any object, this is intended to identify the kind of group.
Returns a triplet (dir, filename, id) or nil if nothing is found.
"
;; Ensure 'test-dir' has a trailing slash.
(let ((test-dir (file-name-as-directory dir))
(parent-dir (file-name-directory (directory-file-name dir))))
(catch 'mk-result
(while (not (string= test-dir parent-dir))
(dolist (test-id-and-filenames compilation-filenames)
(pcase-let ((`(,test-id ,test-filenames) test-id-and-filenames))
(dolist (test-filename test-filenames)
(when (file-readable-p (concat test-dir test-filename))
(throw 'mk-result (list test-dir test-filename test-id))))))
(setq test-dir parent-dir)
(setq parent-dir (file-name-directory (directory-file-name parent-dir)))))))
(defun my-compile-context-sensitive ()
(interactive)
(let* ((mk-reference-dir (expand-file-name "."))
(mk-dir-file-id
(my-compile-context-sensitive--locate-dominating-file-multi
(directory-file-name mk-reference-dir)
(list
'("make" ("Makefile" "makefile" "GNUmakefile"))
'("ninja" ("build.ninja"))
'("scons" ("SConstruct"))))))
(if mk-dir-file-id
(pcase-let ((`(,dir ,file ,id) mk-dir-file-id))
;; Ensure 'compile-command' is used.
(let ((compilation-read-command nil)
(compile-command
(cond
((string= id "make")
(concat "make -C " (shell-quote-argument dir)))
((string= id "ninja")
(concat "ninja -C " (shell-quote-argument dir)))
((string= id "scons")
(concat "scons -C " (shell-quote-argument dir)))
(t
(error "Unhandled type (internal error)")))))
(call-interactively 'compile)))
(message "No makefile found in %S" mk-reference-dir))))
```
---
Tags: compilation-mode, compile
---
|
thread-37904
|
https://emacs.stackexchange.com/questions/37904
|
How do I work out what the problem is with the emacs package system?
|
2018-01-05T10:30:52.637
|
# Question
Title: How do I work out what the problem is with the emacs package system?
I am trying to set up emacs (on cygwin / Win10) to handle JSON.
I started with joshwnj/json-mode and was stoked to discover that emacs will now install its own dependencies from online repos. Fab stuff.
I can run `M-x package-install` but I notice it logs the message:
```
Contacting host: elpa.gnu.org:80
Failed to download ‘gnu’ archive.
```
And when I type in `json-mode`, emacs says there's no match. Is this a connection problem? Should I see an HTTP error somewhere?
joshwnj/json-mode says I need the MELPA repository set up.
According to this documentation for MELPA I need to identify if I'm using package.el (which looks good) and work out if the given lisp code is in place.
Is there a command I can run in emacs to tell me if this code is in place?
Trying to following on and ignoring that issue, I tried `M-x package-list-packages` and got the following error:
```
You can run the command ‘package-list-packages’ with M-x pa-l- RET
Waiting for refresh to finish...
Package refresh done
No packages to upgrade.
error in process sentinel: Error retrieving: http://elpa.gnu.org/packages/archive-contents (error connection-failed "failed with code 10060
" :host "elpa.gnu.org" :service 80)
error in process sentinel: Error retrieving: http://elpa.gnu.org/packages/archive-contents (error connection-failed "failed with code 10060
" :host "elpa.gnu.org" :service 80)
```
Is the `sentinel` process critical? Did the package refresh work?
What should I try next?
# Answer
> 7 votes
It appears that
```
(custom-set-variables
'(gnutls-algorithm-priority "normal:-vers-tls1.3"))
```
fixes the problem.
Cf. https://stackoverflow.com/a/60638601/850781
# Answer
> 2 votes
Have you tried to set the `package-archives` variable in your configuration file?
I have added the following lines to my configuration to get packages from elpa, marmalade, and melpa:
```
(package-initialize)
(add-to-list 'package-archives '("gnu" . "https://elpa.gnu.org/packages/") t)
(add-to-list 'package-archives '("marmalade" . "https://marmalade-repo.org/packages/") t)
(add-to-list 'package-archives '("melpa" . "https://melpa.org/packages/") t)
```
---
Tags: package, package-repositories
---
|
thread-56053
|
https://emacs.stackexchange.com/questions/56053
|
orgmode: underscore automatically generates math-mode
|
2020-03-10T15:57:48.593
|
# Question
Title: orgmode: underscore automatically generates math-mode
When I type an underscore `_` in `org-mode`, it automatically generates math mode, i.e. `$_{}$` and it puts the cursor between the braces. Is there a way to disable this when in edit mode but not in math mode?
# Answer
> 2 votes
At the end my question is not very smart. I am using `cdlatex` to type equations and math easily in `orgmode`. Then the answer is in the documentation under "PAIR INSERTION of (), \[\], {}, and $$":
> Also, the keys _ and ^ will insert "\_{}" and "^{}", respectively, and, if necessary, also a pair of dollar signs to switch to math mode.
I didn't assume that this layer operates outside of equations, so I did not know this is the issue.
I am not sure if this is the desired behavior of `cdlatex` or not. Personally, I would prefer to be able to write underscores without the automatic addition of `_${}$`.
**UPDATE**
I got the behavior I wanted by setting up properly `smartparens` and by using `org-cdlatex-mode` (note that it is not `cdlatex-mode`). In this way the `cdlatex` behavior regarding underscores described above is only implemented inside equations (namely, inside `$ $`, `\( \)`, latex equations etc). When typing text, it does not generate any extra characters when typing `_`.
See the proper configuration in the answer of my other question here.
---
Tags: org-mode, text-editing
---
|
thread-56068
|
https://emacs.stackexchange.com/questions/56068
|
Copy images in buffer
|
2020-03-11T17:35:09.477
|
# Question
Title: Copy images in buffer
I'd like to copy part of a buffer *including all images*. The code below copies the text but not the image. How do I copy images and how do I search for images in a buffer?
```
(insert
(with-current-buffer (get-buffer-create "buf")
(insert "-->")
(put-image (find-image '((:type jpeg :file "~/foo.jpg")))
(point))
(insert "<--")
(buffer-substring (point-min) (point-max))))
```
# Answer
> 1 votes
I think I found a solution. You need `copy-overlay` and `move-overlay` to copy an overlay to another buffer:
```
(defun my-copy-buf (buf)
(let* ((beg (with-current-buffer buf (point-min)))
(end (with-current-buffer buf (point-max)))
(ovs (with-current-buffer buf (overlays-in beg end))))
(save-excursion
(insert-buffer-substring buf beg end))
(dolist (ov ovs)
(move-overlay (copy-overlay ov)
(1- (+ (point) (overlay-start ov)))
(1- (+ (point) (overlay-end ov)))
(current-buffer))
)))
(progn
(with-current-buffer (get-buffer-create "tmp-buffer")
(insert "-->")
(put-image (find-image '((:type jpeg :file "~/foo.jpg")))
(point))
(insert "<--"))
(my-copy-buf "tmp-buffer")
)
```
---
Tags: images
---
|
thread-56078
|
https://emacs.stackexchange.com/questions/56078
|
Experience with WSL as underlying shell (esp. with Texlive) for native win-x64 Emacs
|
2020-03-12T08:54:19.667
|
# Question
Title: Experience with WSL as underlying shell (esp. with Texlive) for native win-x64 Emacs
I've been using MinGW compiled native windows 64-bit Emacs for a while, and I paired it with Cygwin to use especially Texlive, as well as other common linux and shell programs and commands.
I am considering switching to Windows Subsystem for Linux (WSL) as I am using Windows 10, and WSL allows me to install genuine linux distributions (esp. the case of WSL2).
I notice two important differences between Cygwin and WSL, which may make pairing up with them for my native windows Emacs different or potentially problematic:
1. WSL uses linux native binary files for their executables. It can run downloaded linux binary executable files. I believe it is only their executables and they can edit and make changes to other files as usual.
2. WSL sets the root directories and home directories in a hidden folder.
Does anyone have experience of making the switch to WSL and using Emacs with it?
# Answer
I am (almost exclusively) using Emacs on WSL**1**.
* I've got X11 support by VcXsrv. It is very stable.
* You can mount Windows paths as `drvfs`. No problem there! My `$HOME` is my `%USERPROFILE%`. You can even mount windows network paths and usb drives.
* File access is much faster under WSL1. It is even possible to use `magit` under WSL. (Under Cygwin `magit` is deadly slow for the projects I am working on.)
On Linux-native drives (EXT2) file system access in WSL2 is even faster than that of WSL1. **But** (at least for Windows10), accessing files of the Windows host (mounted with `mount -t drvfs ...` is much slower in WSL2 than in WSL1. So, if you need interoperability on file-system-level you should stick to WSL1.
* You can call windows apps directly from Linux.
* You can convert paths from/to windows with `/bin/wslpath`. (That is almost like `cygpath.exe`.)
* I am using the Powershell to copy paste images from Windows to Emacs and direct HTML contents from Emacs to Web-applications working in the Windows browser. Export of Orgmode stuff (regions, subtrees, files) without immediate HTML files directly over the Windows-Clipboard.
I do not know much about WSL2, but some yt-video, I don't remember right now, showed that starting windows applications from WSL2 works too.
Having said all the good stuff I have also to mention that I keep my Cygwin environment alive because one never knows when M$ decides to start with compatibility breaking changes or with discontinuing support for WSL.
> 2 votes
---
Tags: latex, microsoft-windows, cygwin, wsl
---
|
thread-55939
|
https://emacs.stackexchange.com/questions/55939
|
How to mark a directory as "not a project" in projectile?
|
2020-03-05T17:46:51.717
|
# Question
Title: How to mark a directory as "not a project" in projectile?
I have a big version-controlled directory hosting a lot of half-independent bodies of work. I want to consider them all as projects for projectile.
So I added an empty `.projectile` file in each of them, with the idea that projectile would pick that up instead of the `.git` above.
So the situation is like this
```
~/main-directory/
-> .git
-> project1/
-> .projectile
-> file1
-> file2
-> project2/
-> .projectile
-> file1
-> file2
```
But if I open `~/main-directory/project2/file1` and call `projectile-add-known-project`, it considers the whole `main-directory` as one project. In particular, completion matches files with the same name in all subdirectories...
I have tried `(setq projectile-project-root-files-bottom-up (delete ".projectile" projectile-project-root-files-bottom-up))`, but it did not help.
Is there a simple way of telling projectile that the `main-directory` is not to be considered a project?
# Answer
> 3 votes
The name is not explanatory, but the function `projectile-remove-current-project-from-known-projects` works fine: simply navigate to the `main-directory` and call the command. Visited subprojects will still appear in the project list.
More information: https://github.com/bbatsov/projectile/issues/315
One can also customize or set the variable `projectile-globally-ignored-directories` or `projectile-ignored-projects` to make the directory durably ignored. There must be a difference between the two, but I don't know it.
---
Tags: projectile
---
|
thread-56083
|
https://emacs.stackexchange.com/questions/56083
|
How to make backspace respect tab-stops when there is only preceeding white-space?
|
2020-03-12T11:50:26.420
|
# Question
Title: How to make backspace respect tab-stops when there is only preceeding white-space?
When pressing backspace, it deletes a single character, however, I would like it to go back the the previous tab-stop level in the case there is only preceding white-space.
# Answer
This can be done using this function, based on this answer on the Emacs wiki.
```
(defun my-backspace-whitespace-to-tab-stop ()
"Delete whitespace backwards to the next tab-stop, otherwise delete one character."
(interactive)
(if (or indent-tabs-mode (use-region-p)
(> (point)
(save-excursion
(back-to-indentation)
(point))))
(call-interactively 'backward-delete-char)
(let ((step (% (current-column) tab-width))
(pt (point)))
(when (zerop step)
(setq step tab-width))
;; Account for edge case near beginning of buffer.
(setq step (min (- pt 1) step))
(save-match-data
(if (string-match "[^\t ]*\\([\t ]+\\)$"
(buffer-substring-no-properties
(- pt step) pt))
(backward-delete-char (- (match-end 1)
(match-beginning 1)))
(call-interactively 'backward-delete-char))))))
```
> 2 votes
---
Tags: indentation, backspace
---
|
thread-56076
|
https://emacs.stackexchange.com/questions/56076
|
Invoke a agenda-view integrated with a calendar
|
2020-03-12T00:53:38.737
|
# Question
Title: Invoke a agenda-view integrated with a calendar
Usually, I check the agenda-view with a calendar as:
1. M-x org-agenda
2. invoke calendar by strike "c"
at this moment, the focus stay on the calendar
How could combine the two process? If C-c a a to invoke a agenda-view, a Day-agenda integrated with a calendar will be invoked and keep the cursor on the agenda's time-grid.
# Answer
> 1 votes
You can advice `org-agenda` to open the calendar and move the cursor back to the agenda. The second advice closes the calendar when you press q in the agenda.
```
(advice-add 'org-agenda :after
(lambda ()
(when (equal (buffer-name)
"*Org Agenda(a)*")
(calendar)
(other-window 1))))
(advice-add 'org-agenda-quit :before
(lambda ()
(let ((window (get-buffer-window calendar-buffer)))
(when (and window (not (one-window-p window)))
(delete-window window)))))
```
---
Tags: org-agenda, calendar
---
|
thread-49108
|
https://emacs.stackexchange.com/questions/49108
|
How connect to remote machine by private key on Tramp mode?
|
2019-04-23T15:35:17.647
|
# Question
Title: How connect to remote machine by private key on Tramp mode?
From my machine Windows 10, I connect to remote Linux machine by private like this (in console)
```
ssh -i d:\Remote\key\privatekey myLogin@some_remote_host
```
success connect:
```
Welcome to Ubuntu 16.04.4 LTS (GNU/Linux 4.15.0-1026-gcp
x86_64)
```
Nice. Now I want by Tramp mode to connect:
```
C-x C-f
/pscp:mylogin@ip_address:
```
But I get error:
# Answer
If you connect via ssh in the shell, you shall use ssh/scp also as Tramp connection method. Access the file as `/scp:mylogin@ip_address:`
The keyfile must be configured in `~/.ssh/config` (don't know what's the Windows equivalent) like
```
IdentityFile d:\Remote\QS\exchange\key\path_to_primary_key@ip_address
```
> 4 votes
# Answer
At least in my case I had to aad this to my `~/.ssh/config`:
```
Host yourserverid2232323.amazonaws.com
IdentityFile /home/justin/.ssh/aws-instance-1.pem
```
Now I can use Tramp like I would with my default ssh key.
> 3 votes
---
Tags: tramp
---
|
thread-56071
|
https://emacs.stackexchange.com/questions/56071
|
smartparens does not work well in orgmode
|
2020-03-11T19:08:57.180
|
# Question
Title: smartparens does not work well in orgmode
First, let me say I am new to orgmode and emacs. I am sure I am not providing all the relevant information for the problem, so please let me know what can I add here.
I am using emacs 26.3, and I use `spacemacs`.
**The problem is:**
`smartparens` is not working well in orgmode. This is what I see when I type the left parenthesis `(`
```
When I add a parenthesis after a whitespace) (
When I add a parenthesis with no whitespace()
```
when I type `\(` it works well:
```
When I add \ and parenthesis after a whitespace \(\)
```
In both cases the `tab` key does not work to get me out of the parenthesis.
My `user-config` has this to load `smartparens`
```
;; smartparens
(with-eval-after-load 'smartparens
(sp-with-modes 'org-mode
(sp-local-pair "$" "$")
(sp-local-pair "" "" :actions '(rem))
(sp-local-pair "=" "=" :actions '(rem))
(sp-local-pair "" "" :actions '(rem))
(sp-local-pair "\\left(" "\\right)" :trigger "\\l(" :post-handlers '(sp-latex-insert-spaces-inside-pair))
(sp-local-pair "\\left[" "\\right]" :trigger "\\l[" :post-handlers '(sp-latex-insert-spaces-inside-pair))
(sp-local-pair "\\left\\{" "\\right\\}" :trigger "\\l{" :post-handlers '(sp-latex-insert-spaces-inside-pair))
(sp-local-pair "\\left|" "\\right|" :trigger "\\l|" :post-handlers '(sp-latex-insert-spaces-inside-pair))
(sp-local-pair "(" ")")
(sp-local-pair "\\(" "\\)")
(sp-local-pair "\\[" "\\]")))
(add-hook 'org-mode-hook 'smartparens-mode)
```
# Answer
The following settings in the `user-config` in my `.spacemacs` file makes everything work properly.
```
;; smartparens
(require 'smartparens-config)
(sp-local-pair 'org-mode "\\[" "\\]")
(sp-local-pair 'org-mode "$" "$")
(sp-local-pair 'org-mode "'" "'" :actions '(rem))
(sp-local-pair 'org-mode "=" "=" :actions '(rem))
(sp-local-pair 'org-mode "\\left(" "\\right)" :trigger "\\l(" :post-handlers '(sp-latex-insert-spaces-inside-pair))
(sp-local-pair 'org-mode "\\left[" "\\right]" :trigger "\\l[" :post-handlers '(sp-latex-insert-spaces-inside-pair))
(sp-local-pair 'org-mode "\\left\\{" "\\right\\}" :trigger "\\l{" :post-handlers '(sp-latex-insert-spaces-inside-pair))
(sp-local-pair 'org-mode "\\left|" "\\right|" :trigger "\\l|" :post-handlers '(sp-latex-insert-spaces-inside-pair))
```
This works well with `org-cdlatex-mode` and finally my parenthesis are matched correctly!
> 2 votes
---
Tags: org-mode, smartparens
---
|
thread-56093
|
https://emacs.stackexchange.com/questions/56093
|
Why is appropos (C-h a) not finding all terms, e.g. backup doesnt find make-backup-file-name-function
|
2020-03-12T14:34:32.523
|
# Question
Title: Why is appropos (C-h a) not finding all terms, e.g. backup doesnt find make-backup-file-name-function
When running `C-h a` then entering `backup`, it lists the following matches, but not all of them (e.g. does not find the `make-backup-file-name-function`)?
```
Buffer-menu-backup-unmark M-x ... RET
Move up and cancel all requested operations on buffer on line
above.
diff-backup M-x ... RET
Diff this file with its backup file or vice versa.
dired-backup-diff M-x ... RET
Diff this file with its backup file or vice versa.
dired-flag-backup-files M-x ... RET
Flag all backup files (names ending with `~') for deletion.
ediff-backup M-x ... RET
Run Ediff on FILE and its backup file.
magit-wip-initial-backup-mode M-x ... RET
Before saving a buffer for the first time, commit to a wip ref.
package-menu-backup-unmark M-x ... RET
Back up one line and clear any marks on that package.
```
# Answer
`C-h a` runs `apropos-command`, and so will only show you interactive commands, not variables like `make-backup-file-name-function`. You could use `apropos-user-option` in combination with a non-`nil` value of `apropos-do-all` to search more extensively.
Interactively you can use a prefix argument `C-u` to tell most 'apropos' commands to use their `apropos-do-all` behaviour.
Note that `M-x` `apropos` will show matching functions, variables, and faces.
> 2 votes
---
Tags: help, apropos
---
|
thread-56077
|
https://emacs.stackexchange.com/questions/56077
|
Unable to install Eclim for Eclipse in emacs
|
2020-03-12T05:30:15.347
|
# Question
Title: Unable to install Eclim for Eclipse in emacs
```
$ sudo apt install eclipse eclipse-jdt
```
Then, tried to install **eclim** using use-package in Emacs:
```
(use-package eclim
:ensure t
:config
(require 'eclim)
(setq eclimd-autostart t)
(defun my-java-mode-hook ()
(eclim-mode t))
(add-hook 'java-mode-hook 'my-java-mode-hook))
```
It seems, it did not install it. Then, I used terminal:
downloaded:
```
eclim_2.8.0.bin
debian# cd Downloads
debian# ./eclim_2.8.0.bin
```
Welcome to the installer for eclim 2.8.0. Please specify the root directory of your eclipse install. Ex: /opt/eclipse /usr/local/eclipse
```
> /home/tom/.eclipse/
```
**The eclipse launcher/executable could not be found in that directory**
eclipse is installed in `~/.eclipse`
**Also, how to configure executable directory path, using *use-package* in Emacs?**
# Answer
Thank you Ian.
1. I manually downloaded the **eclipse** file directly from the site, eclipse.org. Then, installed it using GUI.
2. Then, manually downloaded the **eclim** file from the site, eclim.org. Then, I could give the path
> `/home/tom/eclipse/jee-2019-12/eclipse/`
3. Also, installed **emacs-eclim** by cloning the git.
Now, the **eclimd** is not starting. I will post the question separately,
> 0 votes
---
Tags: use-package, install
---
|
thread-56098
|
https://emacs.stackexchange.com/questions/56098
|
How do I build a regexp that enables Emacs to set all words to the left of an equal sign a specific font-lock-*-face?
|
2020-03-12T16:49:53.653
|
# Question
Title: How do I build a regexp that enables Emacs to set all words to the left of an equal sign a specific font-lock-*-face?
Following some help provided by Tobias, I am trying to assign a font-lock-keyword-face to all text (:alpha:) to the left of an equal sign (=) in a new Tecplot major mode. I read through the regexp section of elisp.pdf and came up with `[^# ][[:alpha:]] ="`, but this only matches the first two letters to the left of the equal sign and the equal sign. In my code:
```
# To ensure all the data needed is displayed, activate the surfaces of
# each zone, and extract from the auxilary data, the number of zones
# in the data set. This number is used throughout this macro to control
# various operations.
$!System "echo \" \" "
$!If "|AuxDataSet:SolverName|" == "OVERFLOW"
$!FieldMap [1-|NumZones|] Surfaces{SurfacesToPlot = BoundaryFaces}
$!FieldMap [1-|NumZones|] Surfaces{IRange{Max = 0}}
$!FieldMap [1-|NumZones|] Surfaces{JRange{Max = 0}}
$!FieldMap [1-|NumZones|] Surfaces{KRange{Max = 0}}
$!Else
$!FieldMap [1-|NumZones|] Surfaces{SurfacesToPlot = BoundaryFaces}
$!EndIf
```
the "ax =" and "ot =" are getting the font. However, I do not want to include the equal sign but I do want to include the entire word, such as "Max" and "SurfaceToPlot". How do I get just the word to the left of the equal sign.
# Answer
In trying to answer your problem, I ran into `M-x regex-builder`, which may help you as you try to build these regular expressions.
Anyways, you've only defined 4 characters to match:
1. something that's not a # or space
2. something that's an :alpha:
3. a space
4. an equals sign
This regex will get you most of the way there: `[[:alpha:]]* =` as it will highlight zero or more alpha characters before a 'space' and 'equals sign'.
You may need to use precedence to make this 'match' not appear for comment lines (which is what I assume you trying to do with the `[^# ]` command). Unfortunately, a single regex cannot fill the need to highlight a portion of a full-line match (I don't think).
> 1 votes
---
Tags: regular-expressions, font-lock
---
|
thread-56090
|
https://emacs.stackexchange.com/questions/56090
|
Display buffer from commandline
|
2020-03-12T13:43:07.800
|
# Question
Title: Display buffer from commandline
I'm trying to do the same thing as described in (Export an org-mode file as a PDF via command line?) generate a pdf from a org file but want to do it inside a docker container also. And now I get an error and no pdf. How do I display the content of the "*Org PDF LaTeX Output*"
The command I'm currently using is as follows:
```
docker run \
-it \
--rm \
-v `pwd`:/docs \
--entrypoint emacs \
hgjt/emacs-texlive:latest \
-l /root/emacs.el \
--visit plot_var.org \
--batch \
--eval "(org-latex-export-to-pdf)"
```
# Answer
As a sanity check, are you sure you have a tex distribution installed correctly? Maybe you can interactively load into your docker to test it out.
Here is a command which will dump the error log to a file named `Org-PDF-LaTeX-Output.err`:
```
emacs --visit plot_var.org --batch --eval "(progn (ignore-errors (org-latex-export-to-pdf))(set-buffer \"*Org PDF LaTeX Output*\")(write-file \"Org-PDF-LaTeX-Output.err\"))"
```
> 0 votes
---
Tags: org-mode, latex
---
|
thread-56063
|
https://emacs.stackexchange.com/questions/56063
|
Filter plain org file by property (file not in agenda)
|
2020-03-11T11:27:06.870
|
# Question
Title: Filter plain org file by property (file not in agenda)
Let's say I have an org file with this structure:
```
* Books
** READING Some book title :@nonfiction:@psychology:
:PROPERTIES:
:AUTHOR: Cialdin
:PURCHASE_DATE: 25/02/2020
:END:
```
How would I filter by `author=cildin`? Basically something like `org-match-sparse-tree` but for property key value pairs?
# Answer
Use `M-x` `org-sparse-tree` `RET`.
First you are asked how you want to filter and one of the options is `[p]roperty`.
If you type `p` you can give `AUTHOR` as property name and `Cialdin` as value.
Tab-completion works for that input.
> 4 votes
---
Tags: org-mode
---
|
thread-56095
|
https://emacs.stackexchange.com/questions/56095
|
Would (cycle-list <ls>) be a bad idea?
|
2020-03-12T15:20:05.010
|
# Question
Title: Would (cycle-list <ls>) be a bad idea?
Would you consider something like this a bad practice?
```
(defun cycle-list (ls &optional backward?)
"Given any list, returns the next element each time it is called."
(let* ((last-pos (- (length ls) 1))
(maybe-counter (gethash ls cycle-list-counter))
(cal-counter (if maybe-counter
(if backward?
(- maybe-counter 1)
(+ maybe-counter 1))
0))
(counter (cond ((> cal-counter last-pos) 0)
((< cal-counter 0) last-pos)
(t cal-counter))))
(puthash ls counter cycle-list-counter)
(nth counter ls)))
```
I wrote it because it is pretty handy, e.g. I used it to write another function which cycle between themes.
Surely, it shouldn't be used with simple lists, such as `'(1 2 3)`, or in place of `(do-list ...)`. But also, say we add one more theme to (custom-available-themes), now the previous hash-key is left unused.
I suppose in this particular case of theme cycling, there is probably a way to deal with this but: I want to know if the function `(cycle-list ...)` itself to you seems bizarre.
# Answer
> 1 votes
There are problems with `cycle-list` as you have defined it.
* It seams that you want to apply `cycle-list` on list variables that you actually do not have control of. What happens if someone uses `push`, `delq`, `nconc`, `cl-nset-difference`, or similar functions on such a list? Your counter would be invalidated by that.
* If, because of the previous item, you define your own list, you can choose the type of the list yourself. You actually have a ring-type of list. Depending on the use-case there are built-in types for that. See. e.g., `M-:` `(info "(elisp)Rings")` or see how the `kill-ring` is implemented (`M-:` `(info "(elisp)The Kill Ring")` ).
* The byte-compiler would moan about your code because you use a variable `cycle-list-counter` that is not declared as special with `defvar` or `defvar-local`. (`defvar` declares the lookup for the `symbol-value` as always dynamically scoped.)
* Currently you do not differentiate between global list variables, buffer-local list variables, and list variables that just have buffer-local values in some buffers. Maybe, that aspect could be fixed by declaring `cycle-list-counter` buffer locally and using either its value or its `default-value`.
---
Tags: list
---
|
thread-663
|
https://emacs.stackexchange.com/questions/663
|
What is the best way to reload git stashed changes you've popped while file is open in buffer?
|
2014-10-03T15:11:38.473
|
# Question
Title: What is the best way to reload git stashed changes you've popped while file is open in buffer?
When I'm viewing a file and then pop a stash which modifies that file in the working tree using `git stash pop` in either bash or eshell, what is the best way to immediately see those changes in the buffer visiting that file?
Usually I end up using `C-x C-f` or `M-x revert-buffer` but that's a bit slow. It would be nice to find a mode that automatically updates buffers when the files they visit change on disk.
I've heard of git-modes for viewing diffs or conflicts, but haven't found much for stashing/popping or cherry-picking.
# Answer
> 13 votes
If you use `magit` you can create a stash with the `z z` command from the `magit-status` buffer. You can also pop a stash using the `A` command.
If you use these commands, affected files will be automatically reverted (changes are loaded).
Check out the `magit documentation` for more info on how to use `magit` effectively.
# Answer
> 0 votes
As mentioned by @elemakil running a Magit command causes buffers that visit files inside the same repository to be reverted when they change on disk.
This mode only does something after you have used a Magit command. If you run a Git command in bash or eshell then `magit-auto-revert-mode` does not kick in.
However that mode is just a specialized variant of `global-auto-revert-mode`. The latter works regardless of what causes a file to change on disk.
# Answer
> 0 votes
Since I don't want to accidentally loose any edits in buffers I have open, I have a key bound to revert all buffers, I just run this command when making large changes to the repository which Emacs's wont be tracking.
---
Tags: git, magit, revert-buffer
---
|
thread-2410
|
https://emacs.stackexchange.com/questions/2410
|
How can I use Emacs to edit questions, answers, and comments here?
|
2014-10-21T16:15:25.403
|
# Question
Title: How can I use Emacs to edit questions, answers, and comments here?
# Emacs as a StackExchange client?
How can I use Emacs to edit questions, answers, and comments here on the Emacs Stack Exchange site?
Broadly, what possible methods exist?
## Kill and yank
This works, but the method is so cumbersome that it's not worth it for short posts or even medium-length posts.
## Browser plugin
There is a relatively well know browser plugin for Firefox that lets your push the text content of any `<textarea>` back and forth between the editor of your choice. I presume it works via temp files and I haven't evaluated it. Using the plugin with emacs has been discussed on StackOverflow. I don't use Chrome any more.
## Stack Exchange API
Something called Stack Exchange Mode for Emacs exists. I have not evaluated it. The source isn't too stale, but the project is obviously not completed.
## Other options?
I seek suggestions!
# Motivations
Regardless of what method is used to edit questions, answers, and comments in emacs, I am sure that doing so will enable us to do some common tasks with ease:
* Adhere to conventions. Something like `M-x record-keystrokes-and-write-them-out-as-markdown RET C-x C-s C-g RET` ...might yield:
`C-x C-s C-g`
* Ask what an error message means: `M-x post-region-on-emacs-se-as-question RET` ...
# Answer
See the Stack Exchange for Emacs project. From their page:
> SX will be a full featured Stack Exchange mode for GNU Emacs 24+. Using the official API, we aim to create a more versatile experience for the Stack Exchange network within Emacs itself.
> 36 votes
# Answer
`edit-server` might be of some help. It lets you edit any text field inside Chrome with Emacs and then send the text back to the browser with minimum effort. Not exactly what you wanted, but its an improvement.
> 11 votes
# Answer
I'm using `w3m` to submit this answer from within Emacs. The StackExchange sites don't look very nice in w3m, but submitting forms works just fine. (I've not been able to submit an answer with the new `eww` browser.)
I don't recommend actually doing this, because it seems rather painful compared to using a regular browser with a Emacs-like bindings (e.g. keysnail for Firefox).
**EDIT**: I had to solve a captcha to submit my answer. Unfortunately, no captcha was shown in the w3m buffer, so I had to visit the captcha URL in a traditional browser.
> 8 votes
# Answer
I have always found kill and yank to be sufficient, but I do have a stackoverflow specific copy function I use.
```
(defun copy-el-for-so (beg end)
"copy region and format for SO."
(interactive "r")
(let ((text (buffer-substring-no-properties beg end)))
(with-temp-buffer
(insert "<!--Language: lang-lisp -->\n")
(replace-string "\n" "\n " nil (point)
(progn
(insert "\n" text)
(point)))
(copy-region-as-kill (point-min) (point-max))
(message "copied"))))
```
Which takes things like:
```
(defun process-exit-code-and-output (program &rest args)
"Run PROGRAM with ARGS and return the exit code and output in a list."
(with-temp-buffer
(list (apply 'call-process program nil (current-buffer) nil args)
(buffer-string))))
```
and turn them into:
```
<!--Language: lang-lisp -->
(defun process-exit-code-and-output (program &rest args)
"Run PROGRAM with ARGS and return the exit code and output in a list."
(with-temp-buffer
(list (apply 'call-process program nil (current-buffer) nil args)
(buffer-string))))
```
---
Alternatively, I find the Edit With Emacs chrome extensions to be very nice.
> 5 votes
# Answer
Keysnail implements Emacs keybindings for Firefox. It also serves as a platform for plug-ins, extending the architecture of Firefox in a distinctively Emacsesque fashion.
> 5 votes
# Answer
I have been using Firemacs and have been very happy with it. It is a firefox extension which gives you emacs keybinding. It supports many keybindings including kill and yank.
It can be installed from here.
> 1 votes
# Answer
You can use the **Firefox** add-on It's All Text. This will add a tiny "edit" button to the bottom of any text area. Clicking it (or using a hot-key, default `C-S-v`) fires up Emacs with the content in a temporary buffer. Write the buffer (repeatedly) and the text area updates.
My config for it is simply setting *Editor* to `/usr/bin/emacsclient`.
> 1 votes
# Answer
For Firefox 57+ Textern works well (writing on Firefox 74).
> 0 votes
---
Tags: major-mode, integration
---
|
thread-56126
|
https://emacs.stackexchange.com/questions/56126
|
Attempting to use org-babel to write “literate” Rust
|
2020-03-13T13:30:19.467
|
# Question
Title: Attempting to use org-babel to write “literate” Rust
I'm playing around with writing Rust snippets in my editor. I can get org mode to format my things nicely and play nicely with `rust-mode`. But I can't evaluate my code snippets. I think that may be because Rust isn't strictly a scripting language, as the suggestive error, "error: no such subcommand: `script`" provides, when I try to expand my rust source blocks. I could be just misunderstanding though.
Edit: I figured out how to solve my problem but minutes later, see answer below. I've moved onto a new question though: how I might run a linter or flycheck in org-mode.
# Answer
Hot diggity darn, but minutes later I discovered a crate for that. For future people landing on this question, all I had to do was run
`cargo install cargo-script`
and bam you'll be off and org-babel-ing. If you've got Cargo.el installed in your profile, you can evaluate pretty quick using Cargo-run. This may become how I write Rust going forward, if I can get flycheck to work too.
> 5 votes
---
Tags: org-mode, org-babel, rust
---
|
thread-56114
|
https://emacs.stackexchange.com/questions/56114
|
Set org-table tab-key behavior to insert row when above a footer/hline
|
2020-03-13T00:11:15.700
|
# Question
Title: Set org-table tab-key behavior to insert row when above a footer/hline
I've been experimenting with/learning org-mode's table features and spreadsheet-like formulae.
If I include a totals-type footer row in a table and precede it with a border (hline), then I can simply press enter when the cursor is in the last row of the main section to insert a new row, but it keeps the cursor in the same column. If I press the tab key from the last cell, it changes focus to the next non-hline cell. Neither actions are quite conducive to rapid data entry.
Is there a setting to enable the tab key to insert a new row in this case (like it does at the end of the table)?
# Answer
Set or customize the variable `org-table-tab-jumps-over-hlines` to `nil`:
```
(setq org-table-tab-jumps-over-hlines nil)
```
The doc string of the variable says:
> Non-nil means tab in the last column of a table with jump over a hline. If a horizontal separator line is following the current line, ‘org-table-next-field’ can either create a new row before that line, or jump over the line. When this option is nil, a new line will be created before this line.
The code is in the function `org-table-next-field` in `org-table.el` if you are interested.
> 1 votes
---
Tags: org-mode, org-table
---
|
thread-56115
|
https://emacs.stackexchange.com/questions/56115
|
Prompt for user input flexibly with interactive
|
2020-03-13T00:31:01.840
|
# Question
Title: Prompt for user input flexibly with interactive
I have a function that uses `smartparens` to replace specified pairs of parentheses.
```
(defun replace-paren-at-point (paren)
(interactive "sReplace with: ")
(if (looking-at "[「『《〈(〔【]")
(progn
(set-mark-command nil)
(forward-sexp)
(sp-wrap-with-pair paren)
(sp-unwrap-sexp))
(if (save-excursion
(backward-char)
(looking-at "[」』》〉)〕】]"))
(progn
(set-mark-command nil)
(backward-sexp)
(sp-wrap-with-pair paren)
(sp-unwrap-sexp)))
(message "No parenthesis at point.")))
```
One issue with the function above is that the user would be prompted to enter the replace string before he/she is reminded that there is `"No parenthesis at point."` (in cases which the cursor is at the wrong position.)
How do I change this so that an error message appears before the user is prompted for the input?
```
(defun replace-paren-at-point (paren)
(interactive)
(if (looking-at "[「『《〈(〔【]")
(progn
(read-string (format "Replace %s with: " (string (char-after))))
(set-mark-command nil)
(forward-sexp)
(sp-wrap-with-pair paren)
(sp-unwrap-sexp))
(if (save-excursion
(backward-char)
(looking-at "[」』》〉)〕】]"))
(progn
(read-string (format "Replace %s with: " (string (char-before))))
(set-mark-command nil)
(backward-sexp)
(sp-wrap-with-pair paren)
(sp-unwrap-sexp)))
(message "No parenthesis at point.")))
```
I try to use `read-string` for the input prompt but it doesn't work this way.
Seems like `read-string` has to be defined *without* the `paren` argument, but I need the `paren` variable set to store the value for the replace string. So I am kind of stuck.
---
# Settings:
In case some of you might like to test the code above, here are the settings that should be evaluated in `init.el` before running the tests.
```
(package-initialize)
(smartparens-global-mode t)
(sp-pair "「" "」")
(sp-pair "『" "』")
(sp-pair "【" "】")
(sp-pair "《" "》")
(sp-pair "〈" "〉")
(sp-pair "(" ")")
(sp-pair "〔" "〕")
```
# Answer
> 1 votes
Put a test for paren at point inside the `interactive` spec. If no paren at point, raise an error.
```
(defun replace-paren-at-point (paren)
(interactive
(if (not (or (looking-at "[「『《〈(〔【]")
(save-excursion (backward-char) (looking-at "[」』》〉)〕】]"))))
(error "No parenthesis at point")
(list (read-string "Replace paren with: "))))
(cond ((looking-at "[「『《〈(〔【]")
(set-mark-command nil)
(forward-sexp)
(sp-wrap-with-pair paren)
(sp-unwrap-sexp))
((save-excursion (backward-char) (looking-at "[」』》〉)〕】]"))
(set-mark-command nil)
(backward-sexp)
(sp-wrap-with-pair paren)
(sp-unwrap-sexp))))
```
(I didn't test the parts of your code. I just rearranged them. Assuming that your tests etc. do what you want, they should do that in this code too.)
# Answer
> 1 votes
You can do the same using sp functions. No need to hardcode the matching pairs.
```
(defun replace-paren-at-point ()
(interactive)
(cond ((sp--looking-at (sp--get-opening-regexp))
(sp-down-sexp)
(call-interactively 'sp-rewrap-sexp))
((sp--looking-back (sp--get-closing-regexp))
(sp-backward-sexp)
(sp-down-sexp)
(call-interactively 'sp-rewrap-sexp))
(t
(user-error "No matching pair at point"))))
```
---
Tags: interactive
---
|
thread-56146
|
https://emacs.stackexchange.com/questions/56146
|
How do I add a time-stamped note to the LOGBOOK drawer
|
2020-03-14T11:05:57.007
|
# Question
Title: How do I add a time-stamped note to the LOGBOOK drawer
According to the documentation of Drawers, I should be able to add a time-stamped note to the LOGBOOK drawer using the command `C-c C-z`.
However, when I try to do this with my cursor on a TODO task, a note with timestamp is added *above* the task and without a LOGBOOK drawer:
```
- Note taken on [2020-03-14 Sat 11:50] \\
Started working on nice task
* TODO Nice task
```
When I do the same thing *under* a task, I get the following result, still without a LOGBOOK drawer:
```
* TODO Hard task
- Note taken on [2020-03-14 Sat 11:51] \\
Man, this task is very hard. I don't know if I can do it...
```
Finally, when I manually add a LOGBOOK drawer myself and navigate the cursor *into* the LOGBOOK drawer area, the note gets added *above* the drawer:
```
* TODO Clock hours
- Note taken on [2020-03-14 Sat 11:52] \\
Add a note to the logbook of this task to see if it works...
:LOGBOOK:
:END:
```
Am I doing something wrong or is the aforementioned documentation wrong? The only thing I want to do is add notes with a timestamp to a task to be able to log my progress and thoughts.
# Answer
Set or customize the variable `org-log-into-drawer` to `t`.<sup>*</sup> The doc string of the variable (`C-h v org-log-into-drawer RET`) states:
> Non-nil means insert state change notes and time stamps into a drawer. When nil, state changes notes will be inserted after the headline and any scheduling and clock lines, but not inside a drawer.
If you want to make this file specific, you can add a line like this to the top of your file (and then either do `C-c C-c` on that line or save the buffer and revert it from the file on disk, so that Org mode will get reinitialized):
```
#+STARTUP: logdrawer
```
<sup>*<sub>You can do this by adding `(setq org-log-into-drawer t)` to your emacs configuration file.</sub></sup>
> 2 votes
---
Tags: org-mode, logging
---
|
thread-10284
|
https://emacs.stackexchange.com/questions/10284
|
How to do remote compile on Windows from Linux
|
2015-03-25T08:33:32.643
|
# Question
Title: How to do remote compile on Windows from Linux
How can I configure Emacs, such that I am able to compile files remotely on a Windows machine, while Emacs is running under Linux? I am using tramp via the smb method to edit files on the Windows machine, but I could not get remote compilation to work until now.
# Answer
> 1 votes
Disclaimer: I don't use MS Windows
Tramp's smb method is able to start processes on a remote MS Windows machine via winexe. Install it locally on your Linux machine, and adapt `tramp-smb-winexe-program` if necessary. See also the Tramp manual `(info "(tramp) Remote processes")`.
# Answer
> 0 votes
You can give my package (ppcompile) a try, if there is a way to run a ssh service on Windows, so that files can be rsync'ed, and remotely compiled.
---
Tags: compilation, remote
---
|
thread-56151
|
https://emacs.stackexchange.com/questions/56151
|
Overlay special properties
|
2020-03-14T17:04:55.183
|
# Question
Title: Overlay special properties
How can I configure overlay text to be read-only? I know there is a text property `read-only`, but that's not exactly what I want to use.
# Answer
There is no predefined overlay property `read-only`.
You can probably get the behavior you want by using property `keymap` or `local-keymap`.
You can use a keymap value that binds all normally self-inserting keys to do nothing or raise an error.
If you do that only for what you know at overlay-creation time to be self-inserting keys then that might not be sufficient. You can instead bind *all* keys in that keymap to a command that does nothing (e.g. `ignore`) or that raises an error.
Someone else might have a better answer. But that's what I'd try first: use property `keymap` or `local-keymap`.
---
I also wonder what your actual use case is. Maybe this is an X-Y problem?
> 1 votes
---
Tags: overlays
---
|
thread-56155
|
https://emacs.stackexchange.com/questions/56155
|
How to promote or demote multiple marked headings in Org Mode
|
2020-03-14T21:43:36.553
|
# Question
Title: How to promote or demote multiple marked headings in Org Mode
# The Problem
**Jump down to Update 1 below for my thoughts as to the chosen answer to this question.**
I'm using Emacs version 26.3 with Org Mode version 9.3.6 installed from Melpa.
In the Org manual for Structure Editing, I read this:
```
When there is an active region - i.e., when Transient Mark mode is
active - promotion and demotion work on all headlines in the region. To
select a region of headlines, it is best to place both point and mark at
the beginning of a line, mark at the beginning of the first headline,
and point at the line just after the last headline to change. Note that
when point is inside a table (see *note Tables::), the Meta-Cursor keys
have different functionality.
```
But when I make the transient Mark active and set both mark and point around more than one heading, type (`org-shiftmetaleft`), it only promotes the first or last heading, depending upon which one mark and point are on at the time. I want it to do what I think the above implies, and promote all headings in the region. Ditto for demoting headings.
Either this is a defect, or user error. Which is it? See MCVE below for details.
# MCVE
Store the following setup.el file into an experiment directory, say, /tmp/org.mode.promote.demote.multiple.headings
```
(defun my-use-package-setup ()
;; Derived from
;; https://github.com/chrispoole643/etc/blob/master/emacs/.emacs.d/init.el
;; referenced by
;; https://www.reddit.com/r/emacs/comments/5sx7j0/how_do_i_get_usepackage_to_ignore_the_bundled/
;;
;; Define org and melpa as package sources, and install `use-package' if it's not
;; already there. Always ensure packages being loaded are there (or else it'll
;; automatically download from melpa)
;;
;; I don't want to do it this way, as it is org-mode specific. This ordering and
;; prioritization has to happen before all use of use-package. Without this,
;; we run the risk of some other package we require pulling in the stock
;; version of Org mode shipped with Emacs, when we only want the latest
;; version.
;;
(require 'package)
;; For this MCVE, I _have_ to set package-user-dir below in order to keep my
;; installation separate from the normal one, so as to prove that I am only
;; installing the minimum set of packages to reproduce the issue for the MCVE:
(setq package-user-dir (expand-file-name "/tmp/.emacs.d.tmp.99712ad4-61f4-4464-b003-d6d4eea9b98f"))
(add-to-list 'package-archives '("melpa" . "https://melpa.org/packages/") t)
(add-to-list 'package-archives '("org" . "https://orgmode.org/elpa/") t)
;; Ensure that "org" and "melpa" are found first in this order (higher numbers are higher priority):
(setq package-archive-priorities '(("org" . 3)
("melpa" . 2)
("gnu" . 1)))
;; This is the key!! --> " The symbol ‘all’ says to load the latest installed
;; versions of all packages not specified by other elements." and for org-mode, this means always get that latest version.
(setq package-load-list '(all))
(package-initialize)
;; Not sure why we need this:
(setq package-enable-at-startup nil)
;;
;; Install use-package unconditionally. For some reason the existing
;; use-package version failed so we have to waste initialization time doing it
;; every time, and cannot use this:
;;
;; ;; Install use-package:
;; (unless (package-installed-p 'use-package)
;; (message "Installing use-package")
;; (package-refresh-contents)
;; (package-install 'use-package))
;;
;; Reason is unknown.
;;
(package-refresh-contents)
(package-install 'use-package)
;; Require use-package:
(require 'use-package)
;; Load org mode early to ensure that the latest org mode version gets picked up, not the
;; shipped version.
;;
;; Reference https://github.com/jwiegley/use-package#package-installation
;;
(require 'use-package-ensure)
(setq use-package-always-ensure t))
;;
;; Get the package ordering and priority for using use-package:
;;
;; Unfortunately, order does matter here: We have to do this setup _before_
;; any and all use of use-package.
;;
(my-use-package-setup)
;;
;; Get the org package:
;;
(use-package org
;; Install both org and "contrib"-uted org-related packages:
;;
;; See https://tinyurl.com/y2gt69kj that indicates that org-plus-contrib
;; seems to be some sort of "mashup" package, that includes both org itself
;; and the so-called "contrib" packages. I'm not sure which ones of those
;; contrib packages I actually use so just grab them all.
;;
:ensure org-plus-contrib
:pin org)
```
Launch emacs and load the above Elisp file under `-Q` conditions like this:
```
#!/bin/bash
exec 2>&1
set -x
experiment_dir='/tmp/org.mode.promote.demote.multiple.headings'
emacs -Q \
--debug-init \
--load $experiment_dir/setup.el \
$experiment_dir/test.org
```
This will download the minimal amount of packages to retrieve the latest version of Org mode into a scratch directory at /tmp/.emacs.d.tmp.99712ad4-61f4-4464-b003-d6d4eea9b98f so you may choose remove that directory later.
Add the following lines into a small Org mode file:
```
* Level 1 heading
** Level 2 heading1
** Level 2 heading2
** Level 2 heading3
```
Move point in front of the first asterisk in the "Level 2 heading" line. Then use M-h (`org-mark-element`) three times to mark the next three headings. Then type (`org-shiftmetaleft`) and then only the first one, "Level 2 heading1", is promoted:
```
* Level 1 heading
* Level 2 heading1
** Level 2 heading2
** Level 2 heading3
```
I tried moving point right after the last "g" in "level 4 heading" and it promoted only the last one, ignoring the region completely:
```
* Level 1 heading
** Level 2 heading1
** Level 2 heading2
* Level 2 heading3
```
I've tried all sorts of things and never achieved the goal in this case which is to promote all three Level 2 headings into level 1:
```
* Level 1 heading
* Level 2 heading1
* Level 2 heading2
* Level 2 heading3
```
https://emacs.stackexchange.com/a/54301/15483 seems to imply that it should work and I have something broken in my org mode or something.
# Update 1
If you look inside Structure Editing only see this:
```
‘M-<LEFT>’ (‘org-do-promote’)
Promote current heading by one level.
‘M-<RIGHT>’ (‘org-do-demote’)
Demote current heading by one level.
‘M-S-<LEFT>’ (‘org-promote-subtree’)
Promote the current subtree by one level.
‘M-S-<RIGHT>’ (‘org-demote-subtree’)
Demote the current subtree by one level.
```
The last paragraph I quoted at the top of this question does not indicate the scope of commands that respect the marked region. That led me to conclude the region applies to them all, which is not the case. Thus, the answer at https://emacs.stackexchange.com/a/56157/15483 is the correct answer.
I consider this to be a defect in the Org Manual, not in the behavior: This question will be out of date with new manuals if/when this defect is fixed.
# Answer
> 3 votes
Try `M-right` and `M-left` instead of `M-S-right` and `M-S-left`. The commands they run are as follows:
* `M-right`: `org-do-demote` (deals with active region).
* `M-left`: `org-do-promote` (deals with active region).
* `M-S-left`: `org-promote-subtree` (just the subtree of the current heading - does not extend it to the active region).
* `M-S-right`: `org-demote-subtree` (just the subtree of the current heading - does not extend it to the active region).
I think I got it wrong in the linked answer.
---
Tags: org-mode
---
|
thread-36266
|
https://emacs.stackexchange.com/questions/36266
|
Move to goal-column inserting spaces if necessary
|
2017-10-19T01:32:07.120
|
# Question
Title: Move to goal-column inserting spaces if necessary
I have a bunch of lines of text and I'm trying to insert text starting at a certain column on each line. For example:
```
'Some text' This is ok
'Another longer text' ask Ram
'weird stuff' see other file
'more lines'
'even more lines'
```
I'd like to continue typing text on the further lines, at the same column as the previous lines. The part that's cumbersome is moving to the right place on each line.
Emacs has a way of moving to the same place on each line: `set-goal-column`. This would work if that column already existed on each line, but that's not the case here.
One way I can work around this (which I'm actually using) is to insert a lot of spaces on each line (replace-regexp $ with a few dozen spaces), then `C-x C-n` (`set-goal-column`), and use regular `C-n` to move between lines. But I'd like to know whether there's a clean way of achieving something better: of setting things up so that after `set-goal-column`, I can just use `C-n` to move to the next line, and Emacs will automatically insert the appropriate number of spaces if there weren't enough columns to start with.
# Answer
> 1 votes
Here is advice that should do what you want:
```
(defun goal-column-advice (&rest _args)
"Advice inserting spaces when needed to obey `goal-column'.
This advice is intended as :after advice for commands
`previous-line' and `next-line'. Normally, these commands will
attempt to obey any `goal-column' setting, but only on lines that
are long enough that the `goal-column' is not past the end of the
line. This advice changes the advised command to instead pad the
line with spaces in this circumstance. If `goal-column' is nil,
the command behaves as if it were not advised."
(when goal-column (move-to-column goal-column t)))
(advice-add 'previous-line :after #'goal-column-advice)
(advice-add 'next-line :after #'goal-column-advice)
```
Thanks to @phils for the comment pointing out the role of `move-to-column`.
As @phils also notes, this method does leave trailing whitespace in your buffer, which some people may not want. The OP doesn't seem to mind, but others may need to find a different solution.
# Answer
> 1 votes
```
;; Here we create the concept of a 'tab-column.'
;; Set the tab column where you want by positioning the cursor and typeing M-+
;; Then move to another line and type M-=, and EMACS will insert enough spaces
;; to get you to the column. This is useful for alinging columns of text without tabs.
;; tab-column is a silly name; I need a better one.
(defun set-tab-column (&rest _args)
"Sets tab column to current column"
(interactive "P")
(setq tab-column (current-column))
(message "tab column set to %s" tab-column))
(global-set-key (kbd "M-+") 'set-tab-column)
(setq tab-column 0))
(defun space-to-tab-column (&rest _args)
"Insert spaces to tab-column"
(interactive "P")
(let ((count 0))
(while (> tab-column (current-column))
(setq count (+ 1 count))
(insert " ")
)
(message "%s spaces inserted" count)
)
)
(global-set-key (kbd "M-=") 'space-to-tab-column)
```
---
Tags: whitespace, motion, insert, column
---
|
thread-30044
|
https://emacs.stackexchange.com/questions/30044
|
How do I patch an Emacs package?
|
2017-01-17T00:04:09.097
|
# Question
Title: How do I patch an Emacs package?
I wish to alter a package, test it and hopefully submit a pull request afterwards. How do I do it in a safe and efficient way? The question might feel too broad, I will accept the answer that covers the following issues:
1. I'd expect to install a separate branch of a package and be able to switch between it and stable branch on a whim, with recompilation performed automatically when it's necessary, but `package.el` doesn't seem to offer a straightforward way to do that. This answer on emacs-SE informs us that “If multiple copies of a package are installed, then the first one will be loaded” so I guess one could manually mess with `load-path` but this doesn't feel robust. What is the standard way to select a specific version of package among those installed?
2. Even if I manage to expose several branches to Emacs, for significant tweaks I need to make sure the unpatched branch is “unloaded” and its side-effects isolated. Does `unload-feature` handle this properly or maybe it has idiosyncrasies that every tester of multi-versioned packages should know about?
3. How do I install and test the local version? The answer appears to be dependent on whether the package is simple (= one file) or multifile. EmacsWiki says about multifile packages: “MELPA builds packages for you”. I doubt that I have to (or should) talk to MELPA every time I change a `defun` form in a multifile package but the question remains. At least I need to tell package manager about local version, and if so, how do I do it?
4. What names should I assign to local versions of packages? Suppose I want to work on multiple features or bugs simultaneously, which means having several branches. Emacs won't allow to name versions in a descriptive manner (along the lines of `20170117.666-somebugorfeature`). I guess I could rename the package itself, a suffix per branch, but again, like manually messing with `load-path` in Q1, this is an ugly hack, so I won't try it with something I intend to send upstream unless it's a widely accepted practice.
The questions probably are naive, since I never wrote a patch neither applied one with git or a similar vcs. However, for plenty of Emacs users, patching an Emacs package might be their first ever (or maybe the only one) social programming endeavour, which is why, I believe, answers to this question would still be valuable.
# Answer
With bitterness, I have to accept my own answer that amounts to “you can't do it in a civilised way.”
There are package manager issues with `package.el` that could be fixed with enough manpower, and there is code reload issue which, on the contrary, looks like a research problem. Because of the latter, we can conclude that the original question cannot be satisfactorily answered. You will have to restart your Emacs while developing Emacs packages, at least each time you want to make sure it compiles and loads correctly.
To work around `package.el` issues, I ended up writing and patching Gentoo packages for Emacs instead of patching (or writing) Emacs packages. This comes with its own set of problems but those are at least tractable on individual user level. In particular, Gentoo's package manager “portage” automatically restarts Emacs for compilation tasks. It does some other things that `package.el` does not: user patch, configure (particularly relevant for Emacs packages that ship dynamic modules), install from git branch, install from org-based sources. Most of this functionality is built-in as of 2020-03.
> 0 votes
# Answer
To chime in with a slightly different work flow for loading different versions of packages, here's a couple of variations of what I do, both of which use the `load-path` to control which version I'm using (changing the name of the package is a bad idea if there are dependencies). I have the current version of "nice-package" installed in `~/.emacs.d/elpa` using `M-x package-install`, and the package repo clone in `~/src/nice-package` with `git clone ...`.
## With use-package
In init.el, I have
```
(use-package nice-package
:load-path "~/src/nice-package"
...)
```
With the `:load-path` line uncommented, this will use the git version of the package. Commenting this line out, and reloading emacs uses the elpa version.
## Similar without use-package
In init.el,
```
(add-to-list 'load-path "~/src/nice-package")
(require 'nice-package)
...
```
Now do the same commenting trick with the first line.
## Using `emacs -L`
This is the same idea, but manipulating the `load-path` from the command line. You can load an instance of emacs with the git version of the package with
```
emacs -L ~/src/nice-package
```
which just prepends this path to the front of the load-path. That way, you can launch `emacs` from a different terminal and get the old and the new versions of the package running side-by-side.
## Misc comments
1. Use `M-x eval-buffer` after editing a package file to load the new definitions you've created.
2. Checking what the compiler says with `M-x emacs-lisp-byte-compile` is handy too
> 11 votes
# Answer
Good question! The answer is that until now, there was no good answer, since none of the existing package managers were designed for this use case *(except for Borg, but Borg does not attempt to handle other common package management operations like dependency handling)*.
But now, there is `straight.el`, a next-generation package manager for Emacs that addresses this problem as comprehensively as possible. **Disclaimer: I wrote `straight.el`!**
After inserting the bootstrap snippet, installing a package is as simple as
```
(straight-use-package 'magit)
```
This will clone the Git repository for Magit, build the package by symlinking its files into a separate directory, byte-compile, generate and evaluate autoloads, and configure the `load-path` correctly. Of course, if the package is already cloned and built, nothing happens, and your init time does not suffer.
How do you make changes to Magit? It's trivial! Just use `M-x find-function` or `M-x find-library` to jump to the source code, and hack away! You can evaluate your changes to test them live, as is general practice for Emacs Lisp development, and when you restart Emacs, the package will automatically be rebuilt, re-compiled, and so on. It's completely automatic and foolproof.
When you are satisfied with your changes, just commit, push, and make a pull request. You have total control over your local packages. But your configuration can still be 100% reproducible because you can ask `straight.el` to make a lockfile that saves the Git revisions of all of your packages, including `straight.el` itself, MELPA, and so on.
`straight.el` can install any package from MELPA, GNU ELPA, or EmacsMirror. But it also has a highly flexible recipe DSL that allows you to install from anywhere, as well as to customize how the package is built. Here's an example that shows some of the options:
```
(straight-use-package
'(magit :type git
:files ("lisp/magit*.el" "lisp/git-rebase.el"
"Documentation/magit.texi" "Documentation/AUTHORS.md"
"COPYING" (:exclude "lisp/magit-popup.el"))
:host github :repo "raxod502/magit"
:upstream (:host github :repo "magit/magit")))
```
`straight.el` has ridiculously comprehensive documentation. Read all about it on GitHub.
> 5 votes
# Answer
These are all good questions!
Emacs works on a memory-image model, where loading new code alters the memory image of the running instance. Defining new functions and variables is easily undone, if you keep a list of them, but there are a lot of side effects a module might have that you would want to undo. It looks like `unload-feature` does make a pretty good go of it though.
I think what you're going to want to do is a combination of live coding and occasionally relaunching Emacs, loading the module you're working on from your branch rather than from where it's installed. If you do end up with a lot of these branches you might want a shell script that launches emacs with the correct `load-path` for the one you're working on at the moment. In any case I wouldn't rename the package; I think that would be even more confusing since emacs could then load them both.
As you develop your patches you can start by simply redefining the functions that you are changing right in your live Emacs session. This lets you test the new definitions immediately, without leaving Emacs. Specifically, as you edit an elisp file you can use `C-M-x` (`eval-defun`) to evaluate the current function in your current Emacs session. You can then call it to make sure it works. If you're changing something that happens at Emacs startup then you'll likely have to start and stop Emacs to test it; you might do that by starting and stopping a separate Emacs process so that your editing session isn't interrupted.
> 2 votes
# Answer
I don't think there's a good answer to that yet (I expect you can get a partial solution with Cask, tho I'm not sufficient familiar with it to give you a good answer using it; hopefully someone else will), but here's what I do (I rarely use a Elisp package without making local changes to it, so it's really my "normal" way):
* `cd ~/src; git clone ..../elpa.git`
* for each package `cd ~/src/elisp; git clone ....thepackage.git`
* `cd ~/src/elpa/packages; ln -s ~/src/elisp/* .`
* `cd ~/src/elpa; make`
* in your `~/.emacs` add
```
(eval-after-load 'package
'(add-to-list 'package-directory-list
"~/src/elpa/packages"))
```
This way, all packages are installed "straight from the Git", a simple `cd ~/src/elpa; make` will recompile those that need it, and `C-h o thepackage-function` will jump to a source file that's under Git.
To "switch between it and stable branch on a whim", you'll need to `git checkout <branch>; cd ~/src/elpa; make`; and if you want it to affect running Emacs sessions it'll take more work. I generally recommend not to use `unload-feature` except in exceptional situations (it's a good feature, but it's not currently reliable enough).
It also doesn't satisfy many of your requirements. And it has some extra downsides, mostly the fact that many packages's Git clone doesn't quite match the layout and contents expected by elpa.git's makefile, so you'll need to begin by tweaking those packages (typically things that have to do with `<pkg>-pkg.el`, since elpa.git's makefile expects to build this file from `<pkg>.el` rather than have it be provided, but more problematically, the compilation is performed differently, so sometimes you need to play with the `require`s).
Oh and of course, this basically means you're installing those packages by hand, so you have to pay attention to dependencies. This setup does properly interact with other packages installed by `package-install`, tho, so it's not that terrible.
> 2 votes
# Answer
The other answers to this question, including my other answer, talk about patching an Emacs package by making changes to its code. But people finding this question via Google might be thinking of something else when they say "patch an Emacs package" -- namely, overriding its behavior without having to modify its source code.
Mechanisms for doing this include, in increasing order of aggressiveness:
* adding functions to hooks, or binding dynamic variables using `let`
* the powerful advice system
* just plain overriding the function you want to modify
Despite the power of the first two options, I found myself taking the third route pretty often, since there is sometimes no other way. But then the question is, what if the original function definition changes? You would have no way of knowing that you needed to update the version of that definition that you had copied and pasted into your init-file!
Because I'm obsessed with patching things, I wrote the package `el-patch`, which solves this problem as comprehensively as possible. The idea is that you define s-expression based diffs in your init-file, which describe both the original function definition and your changes to it. This makes your patches much more readable, and also allows `el-patch` to later validate whether the original function definition has been updated since you made your patch. (If so, it will show you the changes via Ediff!) Quoting from the documentation:
> Consider the following function defined in the `company-statistics` package:
>
> ```
> (defun company-statistics--load ()
> "Restore statistics."
> (load company-statistics-file 'noerror nil 'nosuffix))
>
> ```
>
> Suppose we want to change the third argument from `nil` to `'nomessage`, to suppress the message that is logged when `company-statistics` loads its statistics file. We can do that by placing the following code in our `init.el`:
>
> ```
> (el-patch-defun company-statistics--load ()
> "Restore statistics."
> (load company-statistics-file 'noerror
> (el-patch-swap nil 'nomessage)
> 'nosuffix))
>
> ```
>
> Simply calling `el-patch-defun` instead of `defun` defines a no-op patch: that is, it has no effect (well, not quite—see later). However, by including *patch directives*, you can make the modified version of the function different from the original.
>
> In this case, we use the `el-patch-swap` directive. The `el-patch-swap` form is replaced with `nil` in the original definition (that is, the version that is compared against the "official" definition in `company-statistics.el`), and with `'nomessage` in the modified definition (that is, the version that is actually evaluated in your init-file).
> 2 votes
# Answer
When you make a lot of changes, I think you should use `straight.el`, see the answer by Radon Rosborough.
If you just want to make a one off change, let's assume to a project called `fork-mode`, do the following steps:
* Make a directory to store the git `mkdir ~/.emacs.d/lisp-gits`
* Make a fork of the project you wish to change, say at `https://github.com/user/fork-mode`
* Clone your fork `cd ~/.emacs.d/lisp-gits && git clone git@github.com:user/fork-mode.git`
Write the following code in your `.emacs`
```
(if (file-exists-p "~/.emacs.d/lisp-gits/fork-mode")
(use-package fork-mode :load-path "~/.emacs.d/lisp-gits/fork-mode")
(use-package fork-mode :ensure t))
(use-package fork-mode
:config
(setq fork-mode-setting t)
:hook
((fork-mode . (lambda () (message "Inside hook"))))
```
Now you can use the emacs mode, using `C-h f` to find the functions you want to change. You will notice that when the package is installed in lisp-gits, you will jump to there. Use magit or other git commands to commit/push changes and then use github to send your pull requests.
Once your pull requests are accepted you can just remove the project in `~/.emacs.d/lisp-gits` and let the package manager do its work.
> 0 votes
---
Tags: package-development
---
|
thread-55498
|
https://emacs.stackexchange.com/questions/55498
|
Registering a custom link protocol as an image
|
2020-02-13T10:39:59.723
|
# Question
Title: Registering a custom link protocol as an image
In org mode, is there a way to define how `#+CAPTION: ...` would work for custom link types? i.e, make org refer to them as images.
I created a custom link type called `tex-fig` (using `org-link-set-parameters`, as described here) that has custom behaviors when exporting to LaTeX and HTML, and I'd like to have figure captions for these tex-fig links. Currently, just doing
```
#+CAPTION: caption caption
[[tex-fig:path/to/file.tex]]
```
doesn't work when exporting to either backend. How can I define caption/float behavior for custom link types?
I've searched for hours, and it seems that the caption is handled through element properties, which are inaccessible through the `:export` callback when defining links by `org-link-set-parameters` (as the callback is given only literal strings, not elements or positions in the document). What are the alternative ways?
# Answer
> 1 votes
You posted already the solution for the HTML backend. So I will address only the LaTeX backend here.
Pittingly, you did not describe how you want to export `tex-fig` links to LaTeX. I assume here you want to use `\import{...}` for such figures as the org LaTeX export does for `pgf` figures.
For that case we can just re-use the `.pgf` branch of `org-latex--inline-image` for our purpose. We just have to take care that we
1. provide the right arguments
2. fake a `.pgf` file name which we correct in the resulting exported string
At first glance the code seems a bit bulky. But, the bits of the code are quite general. So, the gv setter for `org-element-property` can be used in general and I am surprised that the Org API didn't provide it already. Furthermore, `my-org-let-info` can be useful for other exporters as well.
```
(require 'org-element)
(defun my-org-export-tex-fig (path description backend)
"Call the BACKEND specific tex-fig exporter.
The name of the exporter is `my-org-export-tex-fig:BACKEND'.
It is called with PATH and DESCRIPTION as arguments."
(let ((sym (intern-soft (format "my-org-export-tex-fig:%s" backend))))
(if sym
(funcall sym path description)
(user-error "Backend %s not implemented" backend))))
(defvar my-org-let-info nil
"Save `info' arg of `org-latex-link'.")
(defun my-org-let-info (fun link desc info)
"Save INFO locally in `my-org-latex-info'.
Just pass all args LINK, DESC, and INFO to FUN."
(let ((my-org-let-info (list link info)))
(funcall fun link desc info)))
(advice-add 'org-latex-link :around #'my-org-let-info)
(gv-define-simple-setter
org-element-property
(lambda (property element value)
(org-element-put-property element property value))
'fix-return)
(defun my-org-export-tex-fig:latex (path description)
"LaTeX specific tex-fig exporter.
Export org links of form [[tex-fig:PATH][DESCRIPTION]] to LaTeX."
(cl-letf* ((link (nth 0 my-org-let-info))
((org-element-property :path link)
(concat path ".pgf"))
(info (nth 1 my-org-let-info))
(ret (org-latex--inline-image link info)))
(replace-regexp-in-string "\\\\input{.*?\\(\\.pgf\\)}" "" ret t t 1)))
(org-link-set-parameters
"tex-fig" :export #'my-org-export-tex-fig)
```
The code is tested with Emacs 26.3 called as `emacs -Q`.
# Answer
> 0 votes
Well, I've succeeded in HTML exporting by simply telling it that `tex-fig` should be treated as an image:
```
(add-to-list 'org-html-inline-image-rules
(cons "tex-fig" "\\.tex"))
```
But there seem to be no way to do it in LaTeX. I've read the source code, and while exporting a link through LaTeX it first checks if the link can be exported through a custom protocol, and only if not it tries as an image - so there is no way to export a custom link AS an image. This might not be the intended behavior...
---
Tags: org-mode, org-export
---
|
thread-55944
|
https://emacs.stackexchange.com/questions/55944
|
disable minor mode inside source blocks
|
2020-03-05T21:38:08.903
|
# Question
Title: disable minor mode inside source blocks
i have org mode set up with typo minor mode and pretty entities enabled by default.
but when i work on programming, these two are totally useless inside the source code blocks i insert into org files. is it possible to disable them for src blocks only?
i don’t understand if there’s a hook or header or something similar for such things? i actually don’t know what kind of object the blocks are.
my only solution so far has been to use local variables to disable the in the whole file individually. but it would make sense to me to disable them universally, but only in the blocks, as no one will need typographic inverted commas in src blocks.
EDIT: here's an image as per comment request.
steps: * install typo mode, and enable typo mode in org buffers with something like (typo-global-mode 1) / (add-hook 'org-mode-hook 'typo-mode) in your init file.
* in an org buffer, insert a source block with #+begin\_src
* quotes inserted inside the block are prettified by typo mode, and your code parser throws an error.
* to disable typo (and also pretty entities) i added this to the bottom of my file:
```
# Local Variables: #
# eval: (typo-mode -1) #
# eval: (org-toggle-pretty-entities) #
# End: #
```
this disables both for the whole file though, not just for the src block. i thought something similar might be possible for blocks and other such structures. and i would be interested in learning how that works.beg
# Answer
> 2 votes
To self-insert the key in the source block:
```
(defun my-org-mode-hook ()
"Custom `org-mode' behaviours."
(typo-mode 1)
(add-hook 'typo-disable-electricity-functions 'org-in-src-block-p nil :local))
(add-hook 'org-mode-hook 'my-org-mode-hook)
```
> Documentation: \*A list of functions to call before an electric key binding is used. If one of the functions returns non-nil, the key self-inserts.
---
Tags: org-mode, minor-mode, typography
---
|
thread-56168
|
https://emacs.stackexchange.com/questions/56168
|
kill-ring-save rectangle and paste transposed?
|
2020-03-16T03:24:57.917
|
# Question
Title: kill-ring-save rectangle and paste transposed?
Suppose I have some code written like:
```
a_to_b = self.tversky(a, b)
b_to_c = self.tversky(b, c)
d_to_e = self.tversky(d, e)
e_to_f = self.tversky(e, f)
g_to_h = self.tversky(g, h)
```
I would like to select as a rectangle the variable names `x_to_y` and then paste it into array as so:
```
return [a_to_b, b_to_c, d_to_e, e_to_f, g_to_h]
```
I don't necessarily need the commas in one command, but basically selecting a few columns and then applying `M-S ^` to each line. So I can get them all next to each other.
# Answer
1. Select the rectangle (e.g. use `C-x SPC`).
2. Use this command (`M-x foo`) to copy the variables to the `kill-ring`, as the string `"a_to_b, b_to_c, d_to_e, e_to_f, g_to_h"`:
```
(defun foo (beg end)
(interactive "r")
(let ((vars (mapconcat #'identity
(extract-rectangle (region-beginning) (region-end))
", ")))
(kill-new vars)))
```
3. Move to where you want the result.
4. Use this command (`M-x bar`) to insert the result at point.
```
(defun bar ()
(interactive)
(insert "return [")
(yank)
(insert "]\n"))
```
> 1 votes
---
Tags: copy-paste, yank, rectangle
---
|
thread-13797
|
https://emacs.stackexchange.com/questions/13797
|
Tramp/Dired transfers files inline over ssh instead of using scp externaly
|
2015-07-08T11:29:01.393
|
# Question
Title: Tramp/Dired transfers files inline over ssh instead of using scp externaly
I am using tramp via ssh to access remote files. For text files, this is working really well, but whenever I want to copy larger remote files to my local machine, tramp uses its slow inline method (encoding the file with gzip). This is much slower than using an external method like for example scp. How do I make emacs use scp when transfering large files?
Relevant information:
* I use an ~/.ssh/config file to access the remote machine. The alias for that machine is hehi09 in the following. The access is password-less
* Messages in *message* buffer when transferring:
```
Copying /ssh:hehi09:/home/christian/big_file.dat to /home/christian/big_file.dat'...
Tramp: Inserting `/ssh:hehi09:/home/christian/big_file.dat'...
Tramp: Encoding remote file `/ssh:hehi09:/home/christian/big_file.dat' with `(gzip <%s | base64)'...
```
* Values of:
+ tramp-copy-size-limit's value is 10240 (much smaller than tested file size)
+ tramp-default-method's value is "scp"
* `$ scp hehi09:/home/christian/big_file.dat ~/` works as expected from the command line and is much faster than the transfer in emacs
Any ideas why emacs is not using scp to copy large files? Any help is greatly appreciated!
# Answer
When you are saying "I am using tramp via ssh" I suppose you open a file like `/ssh:host:/path/to/file`. This is supposed to use always the ssh method. If you want to use the scp method, you shall use `/scp:host:/path/to/file`. This uses automatically ssh for short files, and scp for large files. If you trust the default method set in `tramp-default-method`, you could use the shorter `/host:/path/to/file`.
> 24 votes
# Answer
Because you got to set it in `~/.emacs` file. Despite that, Emacs is a text editor, not a SFTP or FTP client, it uses this `base64` encoding while in `ssh` method that turns it too slow for file transfer.
> 0 votes
---
Tags: dired, tramp, ssh, performance
---
|
thread-56171
|
https://emacs.stackexchange.com/questions/56171
|
Indentation of one-line zsh for loops
|
2020-03-16T11:44:46.597
|
# Question
Title: Indentation of one-line zsh for loops
My EMACS (26.3) thinks the line after
```
for i (`seq 1 10`) echo $i
```
should be indented. Is this a bug?
# Answer
> 1 votes
If `sh-use-smie` is set to t the Simple Minded Indentation Engine (SMIE) is used for indentation. As you experience, the `sh-mode` setup for SMIE does not cover all the alternate complex commands of zsh yet.
Note that those forms should not be used in new programs. I cite the zsh doc:
> These are non-standard and are likely not to be obvious even to seasoned shell programmers; they should not be used anywhere that portability of shell code is a concern.
Nevertheless, it may be that you have to fight with such forms in legacy software.
If you set `sh-use-smie` to nil the line after the short form of the alternate form of `for` is not indented.
Disclaimer: I do not know the negative consequences of setting `sh-use-smie` to nil.
This bug already has a long-standing bug report on bug-gnu-emacs. It is also registered in the bug tracker. But it looks like nobody cares.
---
Tags: indentation, zsh
---
|
thread-56179
|
https://emacs.stackexchange.com/questions/56179
|
Is it possible to DISABLE auto-reverting remote file?
|
2020-03-16T22:20:24.257
|
# Question
Title: Is it possible to DISABLE auto-reverting remote file?
Emacs 26.3 Linux Mint 19.3
I work with my Google drive. I want to disable auto reverting mode for remote files. Is it possible?
# Answer
> 7 votes
Set `auto-revert-remote-files` to `nil`. This disables auto reverting for all files with Tramp syntax.
If you want to disable auto reverting of remote files in a mounted directory, or in a sync directory, add that directory name to `auto-revert-notify-exclude-dir-regexp`.
# Answer
> 3 votes
You could use `C-h``v` `global-auto-revert-ignore-buffer` with `C-h``v` `find-file-hook`
```
(defun my-inhibit-remote-auto-revert ()
"Used in `find-file-hook'."
(when (file-remote-p buffer-file-name)
(setq global-auto-revert-ignore-buffer t)))
(add-hook 'find-file-hook #'my-inhibit-remote-auto-revert)
```
---
Tags: revert-buffer, global-auto-revert-mode
---
|
thread-56180
|
https://emacs.stackexchange.com/questions/56180
|
Automate delete content of remote org mode file!
|
2020-03-16T22:42:50.633
|
# Question
Title: Automate delete content of remote org mode file!
Linux Mint 19.3
Emacs 26.3
Dired+
I use Google drive. To connect I use rclone. As result I success connect to my google drive.
In dired mode I open to.do.org file in Google's drive
Edit file and save by C-x-s
The press C-x d. And as you can see the size of to.do.org is 0 bytes!!!
Press enter and as result open to.do.org file.
After file was open the AUTOMATE start REVERT BUFFER!!!
and as result the content of to.do.org file IS EMPTY!!!
How I can fix this?
P.S. If I work with any LOCAL org file then no problem. But with remote Google's drive file (org files) then has problems.
# Answer
Tramp supports Google drive out of the box. Try to open `C-x C-f /gdrive:your.name@gmail.com:/path/to/file`.
Starting with Tramp 2.4, it supports also rclone. If you have configured Google drive in rclone as, say, `my-google`, try `C-x C-f /rclone:my-google:/path/to/file`. Tramp 2.4 will be part of the upcoming Emacs 27.1. It is available already via GNU ELPA.
In both cases, your Google drive files might be integrated better into Emacs.
> 1 votes
---
Tags: org-mode, remote
---
|
thread-56194
|
https://emacs.stackexchange.com/questions/56194
|
How to restore a window configuration after reboot?
|
2020-03-17T13:58:31.297
|
# Question
Title: How to restore a window configuration after reboot?
I have foo.txt on the left and a terminal on the right:
```
|-------|----------|
|foo.txt|ansi@term>|
|-------|----------|
```
How can I restore the layout of the windows with the same buffers displayed after reboot?
I'v installed https://github.com/ffevotte/desktop-plus and tried `desktop+-load` after `desktop+-create` which doesn't restore nor inform what's happening.
System Info :computer: * OS: gnu/linux
* Emacs: 26.3
* Spacemacs: 0.300.0
* Spacemacs branch: develop
* Graphic display: t
* Distribution: spacemacs
* Editing style: vim
* Completion: helm
# Answer
You could try psession package. I find it fills exactly my needs.
In your init file :
```
(psession-mode 1)
;; For saving minibuffer history, as a replacement of savehist-mode.
(psession-savehist-mode 1)
;; to save periodically (autosave) your emacs session,
(psession-autosave-mode 1)
```
Best, Samusz
> 1 votes
---
Tags: window, window-configuration
---
|
thread-56201
|
https://emacs.stackexchange.com/questions/56201
|
Is there an emacs package which can mirror a region?
|
2020-03-17T17:21:01.960
|
# Question
Title: Is there an emacs package which can mirror a region?
Say, I have a buffer A in which there is a region of text from some position pos1 to an other position pos2.
I switch to buffer B, call a function with buffer A, pos1 and pos2 as parameters and it copies the referred region to buffer B at point and lets me edit it at either place with all the edits made in buffer B's relevant region mirrored to buffer A's relevant region and vica versa.
# Answer
The documentation string for the command `text-clone-create`:
> (text-clone-create START END &optional SPREADP SYNTAX)
>
> Create a text clone of START...END at point. Text clones are chunks of text that are automatically kept identical: changes done to one of the clones will be immediately propagated to the other.
>
> The buffer’s content at point is assumed to be already identical to the one between START and END. If SYNTAX is provided it’s a regexp that describes the possible text of the clones; the clone will be shrunk or killed if necessary to ensure that its text matches the regexp. If SPREADP is non-nil it indicates that text inserted before/after the clone should be incorporated in the clone.
Note, that you must copy the text as the first action yourself.
Pityingly, the original version only works for one buffer. But it is easy to fix it for the case that original and clone do not have the same buffer. In the following Elisp code I marked the changed lines with `;;< Tobias`.
There is also an interactive helper command `my-clone` in the code.
1. Mark the region you want to clone.
2. Call `M-x` `my-clone` `RET`. Emacs goes into `recursive-edit` state.
3. Navigate to the buffer and to the position where you want to clone the previously marked region.
4. Finish `recursive-edit` with `C-M-c`.
5. Now edit either the original region or the clone. The modifications are replicated in the other region.
```
(defvar text-clone--maintaining nil)
(defun my-text-clone--maintain (ol1 after beg end &optional _len)
"Propagate the changes made under the overlay OL1 to the other clones.
This is used on the `modification-hooks' property of text clones."
(when (and after (not undo-in-progress)
(not text-clone--maintaining)
(overlay-start ol1))
(let ((margin (if (overlay-get ol1 'text-clone-spreadp) 1 0)))
(setq beg (max beg (+ (overlay-start ol1) margin)))
(setq end (min end (- (overlay-end ol1) margin)))
(when (<= beg end)
(save-excursion
(when (overlay-get ol1 'text-clone-syntax)
;; Check content of the clone's text.
(let ((cbeg (+ (overlay-start ol1) margin))
(cend (- (overlay-end ol1) margin)))
(goto-char cbeg)
(save-match-data
(if (not (re-search-forward
(overlay-get ol1 'text-clone-syntax) cend t))
;; Mark the overlay for deletion.
(setq end cbeg)
(when (< (match-end 0) cend)
;; Shrink the clone at its end.
(setq end (min end (match-end 0)))
(move-overlay ol1 (overlay-start ol1)
(+ (match-end 0) margin)))
(when (> (match-beginning 0) cbeg)
;; Shrink the clone at its beginning.
(setq beg (max (match-beginning 0) beg))
(move-overlay ol1 (- (match-beginning 0) margin)
(overlay-end ol1)))))))
;; Now go ahead and update the clones.
(let ((head (- beg (overlay-start ol1)))
(tail (- (overlay-end ol1) end))
(str (buffer-substring beg end))
(nothing-left t)
(text-clone--maintaining t))
(dolist (ol2 (overlay-get ol1 'text-clones))
(with-current-buffer (overlay-buffer ol2) ;;< Tobias
(let ((oe (overlay-end ol2)))
(unless (or (eq ol1 ol2) (null oe))
(setq nothing-left nil)
(let ((mod-beg (+ (overlay-start ol2) head)))
;;(overlay-put ol2 'modification-hooks nil)
(goto-char (- (overlay-end ol2) tail))
(unless (> mod-beg (point))
(save-excursion (insert str))
(delete-region mod-beg (point)))
;;(overlay-put ol2 'modification-hooks '(text-clone--maintain))
)))))
(if nothing-left (delete-overlay ol1))))))))
(defun my-text-clone-create (start end &optional spreadp syntax)
"Create a text clone of START...END at point.
Text clones are chunks of text that are automatically kept identical:
changes done to one of the clones will be immediately propagated to the other.
The buffer's content at point is assumed to be already identical to
the one between START and END.
If SYNTAX is provided it's a regexp that describes the possible text of
the clones; the clone will be shrunk or killed if necessary to ensure that
its text matches the regexp.
If SPREADP is non-nil it indicates that text inserted before/after the
clone should be incorporated in the clone."
;; To deal with SPREADP we can either use an overlay with `nil t' along
;; with insert-(behind|in-front-of)-hooks or use a slightly larger overlay
;; (with a one-char margin at each end) with `t nil'.
;; We opted for a larger overlay because it behaves better in the case
;; where the clone is reduced to the empty string (we want the overlay to
;; stay when the clone's content is the empty string and we want to use
;; `evaporate' to make sure those overlays get deleted when needed).
;;
(let* ((clone-buf (or (and (markerp start) (marker-buffer start))
(current-buffer)))
(pt-end (+ (point) (- end start)))
(start-margin (if (or (not spreadp) (bobp) (with-current-buffer clone-buf (<= start (point-min))))
0 1))
(end-margin (if (or (not spreadp)
(>= pt-end (point-max))
(with-current-buffer clone-buf (>= start (point-max))))
0 1))
;; FIXME: Reuse overlays at point to extend dups!
(ol1 (make-overlay (- start start-margin) (+ end end-margin) clone-buf t)) ;;< Tobias
(ol2 (make-overlay (- (point) start-margin) (+ pt-end end-margin) nil t))
(dups (list ol1 ol2)))
(overlay-put ol1 'modification-hooks '(my-text-clone--maintain)) ;;< Tobias
(when spreadp (overlay-put ol1 'text-clone-spreadp t))
(when syntax (overlay-put ol1 'text-clone-syntax syntax))
;;(overlay-put ol1 'face 'underline)
(overlay-put ol1 'evaporate t)
(overlay-put ol1 'text-clones dups)
;;
(overlay-put ol2 'modification-hooks '(my-text-clone--maintain)) ;;< Tobias
(when spreadp (overlay-put ol2 'text-clone-spreadp t))
(when syntax (overlay-put ol2 'text-clone-syntax syntax))
;;(overlay-put ol2 'face 'underline)
(overlay-put ol2 'evaporate t)
(overlay-put ol2 'text-clones dups)))
(defun my-clone (b e pt)
"Clone region from B to E at PT.
B, E, and PT can be markers."
(interactive (list
(region-beginning)
(region-end)
(save-excursion
(message "Choose clone position and finish with C-M-c.")
(recursive-edit)
(set-marker (make-marker) (point))
)))
(let ((b-mark (set-marker (make-marker) b))
(e-mark (set-marker (make-marker) e))
(txt (buffer-substring b e)))
(with-current-buffer (or (and (markerp pt) (marker-buffer pt))
(current-buffer))
(goto-char pt)
(insert txt)
(goto-char pt)
(my-text-clone-create b-mark e-mark))))
```
> 6 votes
---
Tags: region
---
|
thread-56192
|
https://emacs.stackexchange.com/questions/56192
|
Searching for org-mode property values including whitespace
|
2020-03-17T12:54:17.283
|
# Question
Title: Searching for org-mode property values including whitespace
I made this simple example to help explain my problem:
```
* entry
:PROPERTIES:
:author1: me
:author2: my self
:END:
```
Now when I do a property search with `C-c a m` searching `author1="me"` I find `entry` as expected.
When I try to search `author2="my self"` as soon as I hit space to type in the whitespace character between my and self it just says `[No match]` in the minibuffer and the whitespace character is not inserted. I can find `entry` by searching `author2={self}` for example or type the whitespace outside the minibuffer and copy-paste it in, but that can't be the solution... I can type in whitespace normally in other minibuffers, e.g. in the keyword search under `C-c a s`.
I tried typing in a search like that launching `emacs -q`, so without any emacs customization but got the same result. I have emacs 26.3.
What am I missing here?
# Answer
> 2 votes
I finally figured out (thanks to `C-h k`) that space is bound to some autocomplete function in that instance of the minibuffer by default.
So the easy solution was to add
`(define-key minibuffer-local-completion-map (kbd "SPC") 'self-insert-command)`
to the init file to have space act as space in the tag search.
@NickD: thanks for the comment, it helped me understand that space must just be bound to some weird function in the minibuffer and remember that I know how to figure out which function it is ;)
---
Tags: org-mode
---
|
thread-56197
|
https://emacs.stackexchange.com/questions/56197
|
Org mode export dispatcher nil and key binding
|
2020-03-17T14:27:55.033
|
# Question
Title: Org mode export dispatcher nil and key binding
I have two questions for exporting org file to PDF:
1. I would like not to open *Org Export Dispatcher* when my org file export to pdf through LaTeX. I checked the manual, then I found the following:
> When the variable org-export-dispatch-use-expert-ui is set to a non-nil value, Org prompts in the minibuffer.
So, I set the following at my init.el. But it does not work. Are there any wrong for this setting?
```
(setq org-export-dispatch-use-expert-ui t)
```
2. To export a org file to a PDF file, I have to type `C-c C-e C-l C-O`. I don't like this key binding because of too much typing. Could you help me to set a concise keybinding?
# Answer
> 1 votes
For part 2), you can go directly to the export function of interest and bind it to any key you want, e.g a function key, say F8:
```
(define-key org-mode-map [f8] (lambda () (interactive) (org-open-file (org-latex-export-to-pdf))))
```
Here we have to combine a couple of functions to do the export and then the open of the resulting PDF file. Note also that we have to label the function as `interactive` i.e. make it a command. And finally, note that you lose the ability to select options (line `async`, `subtree` etc.) which the dispatcher allows you to use with an export: those are passed as optional arguments to `org-latex-export-to-pdf` by the dispatcher, but the above passes no arguments at all.
---
Tags: org-mode, key-bindings, org-export
---
|
thread-52668
|
https://emacs.stackexchange.com/questions/52668
|
set `all-the-icons-dired` to use consistent directory icon?
|
2019-09-15T19:01:20.043
|
# Question
Title: set `all-the-icons-dired` to use consistent directory icon?
I installed all-the-icons-dired package from melpa, however, it does not use consistent icons for directories. Some directories have their own special icon. Example, these are two directories:
The `.dartServer` icon above is a standard directory icon, however, `Desktop` uses a special icon.
I prefer the standard directory icon for *all* directories. How can I do that?
# Answer
> 0 votes
I haven't tested this, but perhaps you can edit the variable `all-the-icons-dir-icon-alist`.
For example, for Dropbox, you can see an entry like:
```
("dropbox" all-the-icons-faicon "dropbox" :height 1.0 :v-adjust -0.1)
```
and replace the 2nd "dropbox" with "folder" or "folder-o" (the latter is a kind of transparent looking folder icon.
---
Tags: dired, images
---
|
thread-56212
|
https://emacs.stackexchange.com/questions/56212
|
what does the vertical bar "|" mean in sentence-end?
|
2020-03-18T11:15:52.480
|
# Question
Title: what does the vertical bar "|" mean in sentence-end?
Reference to 12.1 The Regular Expression for sentence-end of Elisp introduction
It illustrate alternatives of sentence-end as
```
\\($\\| \\| \\)
^ ^^
TAB SPC
```
and explains:
> Two backslashes, ‘\\’, are required before the parentheses and vertical bars: the first backslash quotes the following backslash in Emacs; and the second indicates that the following character, the parenthesis or the vertical bar, is special.
But what does the vertical bar "|" mean?
# Answer
> 3 votes
The vertical bar lets you form an alternation, a regular expression which matches any one of several alternatives. Combined with the parentheses, this one matches either the end of the line, or a tab character, or two space characters. See https://www.gnu.org/software/emacs/manual/html\_mono/emacs.html#Regexps for details.
---
Tags: regular-expressions
---
|
thread-28056
|
https://emacs.stackexchange.com/questions/28056
|
Spacemacs Latex: how to make view command tile vertically with emacs window?
|
2016-10-23T22:53:28.627
|
# Question
Title: Spacemacs Latex: how to make view command tile vertically with emacs window?
I'm using Spacemacs Latex layer, which uses Auctex. If press space m v for the first time, the document viewer opens up in full screen over my emacs window. After, it only updates the window and keeps it under my emacs window. So to have the workflow that I want, I have to manually resize the emacs window to take up the left half of my screen and the Document Viewer window take up the right half.
There are two possible solutions that I can think of, I don't know how to do either or which is easier:
Get a pdf viewer for emacs and make the view command open the pdf in emacs in a new split window.
Make the view command somehow resize the Document Viewer window and my emacs window.
But presumably there is a standard solution to this problem? It's a pretty standard workflow so I expect someone to have figured it out.
# Answer
This answer is a little bit delayed, but I stumbled over a similar problem. One solution could be to use the package pdf-tools. Installing this on macOS (if you are using this OS) can be quite challenging. I went this path and following this answer was fruitful. Additionally, the following lines in the `.emacs` or `init.el` file are potentially needed to convince emacs to open the pdf with pdf-tools
```
;; Use pdf-tools to open PDF files
(setq TeX-view-program-selection '((output-pdf "PDF Tools"))
TeX-source-correlate-start-server t)
;; Update PDF buffers after successful LaTeX runs
(add-hook 'TeX-after-compilation-finished-functions
#'TeX-revert-document-buffer)
```
I just didn't figure out how to convince emacs to split the window vertically (instead of horizontally), when I run `C-c C-a` to compile and view the pdf.
> 1 votes
---
Tags: latex, auctex, spacemacs
---
|
thread-56218
|
https://emacs.stackexchange.com/questions/56218
|
Default face doesn't specify all attributes?
|
2020-03-18T17:14:06.617
|
# Question
Title: Default face doesn't specify all attributes?
In the elisp manual, it says the default face must specify all face attributes. However, running
```
#+BEGIN_SRC emacs-lisp :results pp
(face-all-attributes 'default)
#+END_SRC
#+RESULTS:
#+begin_example
((:family . unspecified)
(:foundry . unspecified)
(:width . unspecified)
(:height . unspecified)
(:weight . unspecified)
(:slant . unspecified)
(:underline . unspecified)
(:overline . unspecified)
(:strike-through . unspecified)
(:box . unspecified)
(:inverse-video . unspecified)
(:foreground . unspecified)
(:background . unspecified)
(:stipple . unspecified)
(:inherit . unspecified))
#+end_example
```
If we using the `face-attribute` function, however, we get
```
#+BEGIN_SRC emacs-lisp
(face-attribute 'default :family)
#+END_SRC
#+RESULTS:
: Ubuntu Mono
```
Is this a bug?
# Answer
> 1 votes
Ah, this one is a little confusing. `face-all-attributes` takes an optional second argument specifying the frame to query. If the frame is nil then it gives you the default attributes for the face. From \`C-h f face-all-attributes:
```
Signature
(face-all-attributes FACE &optional FRAME)
Documentation
Return an alist stating the attributes of FACE.
Each element of the result has the form (ATTR-NAME . ATTR-VALUE).
If FRAME is omitted or nil the value describes the default attributes,
but if you specify FRAME, the value describes the attributes
of FACE on FRAME.
```
A demo:
```
(face-all-attributes 'default (selected-frame))
((:family . "DejaVu Sans Mono") (:foundry . "PfEd") (:width . normal) (:height . 120) (:weight . normal) (:slant . normal) (:underline) (:overline) (:strike-through) (:box) (:inverse-video) (:foreground . "black") ...)
```
`face-attribute` also takes an optional argument to specify the frame, but it treats nil differently:
```
Signature
(face-attribute FACE ATTRIBUTE &optional FRAME INHERIT)
Documentation
Return the value of FACE's ATTRIBUTE on FRAME.
If the optional argument FRAME is given, report on face FACE in that frame.
If FRAME is t, report on the defaults for face FACE (for new frames).
If FRAME is omitted or nil, use the selected frame.
```
---
Tags: faces
---
|
thread-56221
|
https://emacs.stackexchange.com/questions/56221
|
Why does `insert` not insert colorized text?
|
2020-03-18T18:56:40.943
|
# Question
Title: Why does `insert` not insert colorized text?
For instance, why does `(insert #("abc" 0 3 (face (:foreground "red"))))` not insert red text?
# Answer
You probably try that in the `*scratch*` buffer or any other buffer with active `font-lock-mode`.
In such a buffer the faces are immediately adapted to the rules prescribed by the variable `font-lock-keywords`.
Use the property `font-lock-face` instead of `face` in those buffers.
The modified version of your example would be:
```
(insert #("abc" 0 3 (font-lock-face (:foreground "red"))))
```
`font-lock-face` properties are directly translated into `face` properties by `font-lock-mode`. No fontification rules are applied to those stretches of text.
Side-note: `lisp-interaction-mode` is derived from `emacs-lisp-mode` that activates `font-lock-mode`.
> 7 votes
---
Tags: text-properties
---
|
thread-7933
|
https://emacs.stackexchange.com/questions/7933
|
How do you select under emacs the key you sign/encrypt with when using mml?
|
2015-02-03T18:21:57.783
|
# Question
Title: How do you select under emacs the key you sign/encrypt with when using mml?
Long time `mutt` user, I am currently trying to learn how to deal with my mail from within emacs with the help of `mu4e`.
When it comes to signing mail, I use the following
```
(add-hook 'message-send-hook 'mml-secure-message-sign-pgpmime)
```
which automatically gets the job done.
As I have to manage several different keys / accounts, I am looking for the way to select the key I'll use for signing the message (`epa-list-keys` gives me three answers).
How do you select under emacs the key you sign/encrypt with when using `mml` ?
# Answer
We can set
```
(setq mm-sign-option 'guided)
```
and now we will be prompted with key selection menu before sending a message.
As described:
> mm-sign-option - Option of creating signed parts. nil, use default signing keys; **guided**, ask user to select signing keys from the menu.
We should be able to automate key selection based on e.g. *From:* field with help of
* Default Encryption
> DefaultEncrypt aims for automatic insertion of an MML secure encryption tags into messages if public keys (either GnuPG public keys or S/MIME certificates) for all recipients are available. In addition, before a message is sent, the user is asked whether plaintext should really be sent unencryptedly when public keys for all recipients are available.
* *Keyfile* field text auto-insertion
> ‘keyfile’ - File containing key and certificate for signer.
but I have never been annoyed enough to do so.
> 4 votes
# Answer
See: `mml-secure-openpgp-sign-with-sender`
> If `t`, use message sender to find an OpenPGP key to sign with.
This set the key to match the `From:` for me. You can customize that variable too (and turn off the guided mode).
> 0 votes
---
Tags: mu4e, security, encryption
---
|
thread-56232
|
https://emacs.stackexchange.com/questions/56232
|
Running Emacs through X2Go, the bidirectional clipboard does not work, even though it works for other programs
|
2020-03-19T08:13:48.950
|
# Question
Title: Running Emacs through X2Go, the bidirectional clipboard does not work, even though it works for other programs
Being in home-office due to the Corona outbreak, I am using Emacs and other programs through X2Go.
I am also running a terminal through GNU Screen in a MinTTY window, because scrolling the terminal for analyzing the output is very slow over X2Go.
I was running into the problem, that I couldn't copy/paste between the remote Emacs and other applications, native or remote.
# Answer
> 1 votes
In my case, the cause was having started Emacs as a tab of GNU Screen and connecting to it by `emacsclient`. After restarting Emacs from within the X2Go session, the bidirectional clipboard started working again.
---
Tags: ssh, x11, remote, clipboard
---
|
thread-56172
|
https://emacs.stackexchange.com/questions/56172
|
latex-export image using fancyhdr
|
2020-03-16T13:35:35.650
|
# Question
Title: latex-export image using fancyhdr
I use following preamble in org file to export my regular documents. I want to add logo to right header, but for some reason, the \includegraphics command is not getting exported.
Here is the code
```
#+OPTIONS: num:nil; p:t
#+OPTIONS: toc:nil
#+LATEX_HEADER:\usepackage{geometry} % See geometry.pdf to learn the layout options. There are lots.
#+LATEX_HEADER:\geometry{a4paper} % or letterpaper (US) or a5paper or....
#+LATEX_HEADER:\usepackage{graphicx} % support the \includegraphics command and options
#+LATEX_HEADER:\usepackage{fancyhdr, lastpage}
#+LATEX_HEADER:\usepackage{fontspec,xltxtra}
#+LATEX_HEADER:\usepackage{polyglossia}
#+LATEX_HEADER:\usepackage[Latin,Devanagari]{ucharclasses}
#+LATEX_HEADER:\setlength{\parindent}{0pt}
#+LATEX_HEADER:\fancyhead{}
#+LATEX_HEADER:\headsep= .51 cm
#+LATEX_HEADER:\headheight= 1.5 cm
#+LATEX_HEADER:\fancyhead[L] {{\huge \bfseries My hospital,} \\ 4th floor, My Building \\ My City square, City }
#+LATEX_HEADER:\fancyfoot [L]{{\Large \bfseries Dr My Name} \\{\small MD (Med), DNB(Med), DM (Specialty)}\\ Reg No 123 }
#+LATEX_HEADER:\fancyfoot [R]{{\Large \bfseries Dr Other Name}\\{ \small MBBS DOMS} \\ Reg No 0001}
#+LATEX_HEADER:\renewcommand{\headrulewidth}{0pt}
#+LATEX_HEADER:\fancyhead[R]{\includegraphics[scale=0.15]{c:/gl.jpg}}
#+LATEX_HEADER:\pagestyle{fancy}
#+LATEX_HEADER: \setmainfont{Halant}
```
Kindly help
In short, how can I use **\rhead{\includegraphics\[width=1cm\]{example-image-a}}** in org mode
# Answer
> 1 votes
I think you read this .tex question - and your question is really how to transfer it to org-mode. Try/modify your headers according to the below code:
```
#+LaTeX_HEADER: \usepackage{fancyhdr}
#+LATEX_HEADER: \pagestyle{fancy}
#+ATTR_LATEX: \setlength\headheight{26pt}
#+LATEX_HEADER: \fancyhead[R]{\includegraphics[width=1cm]{fig1.png}}
```
And the result is this:
# Answer
> 0 votes
When I replace `[scale=0.15]` with `[width = 2cm]`, everything work fine .
---
Tags: latex-header, graphics, exporting
---
|
thread-56238
|
https://emacs.stackexchange.com/questions/56238
|
I would like to add a shortcut to sp-wrap-square in spacemacs
|
2020-03-19T12:54:52.753
|
# Question
Title: I would like to add a shortcut to sp-wrap-square in spacemacs
I would like to extend the lisp editing shortcuts so `SPC k [` and `SPC k {` would wrap the current form in `[]` and `{}` respectively.
I don't know what I need to write in my spacemacs config to enable this only for the lisp editing buffers.
What I did so far:
```
(spacemacs/set-leader-keys-for-major-mode 'clojure-mode "k [" 'sp-wrap-square)
(spacemacs/set-leader-keys-for-major-mode 'clojure-mode "k {" 'sp-wrap-curly)
```
But these add only in clojure mode and the shortcuts will be `, k [` and `, k {` instead of the desired `SPC k [` and `SPC k {`
# Answer
I ended up with this:
```
(spacemacs/set-leader-keys (kbd "k [") 'sp-wrap-square)
(spacemacs/set-leader-keys (kbd "k {") 'sp-wrap-curly)
```
> 0 votes
---
Tags: spacemacs, smartparens
---
|
thread-56230
|
https://emacs.stackexchange.com/questions/56230
|
When use setq or set '
|
2020-03-19T06:19:47.337
|
# Question
Title: When use setq or set '
I tried to find an answer to this seemingly simple question, but the swamp (internet) is a big place.
In the emacs init file in one case I use: `(show-paren-mode t)`
In another case I use: `(set 'inhibit-startup-message t)` or `(setq inhibit-startup-message t)`
Why do I need to use `setq` in one case to set a Boolean?
# Answer
> 8 votes
> *In the emacs init file in one case I use: (show-paren-mode t)*
`show-paren-mode` is a function. It accepts `t` as an argument. Using `C-h f show-paren-mode`, the description says,
> With a prefix argument ARG, enable Show Paren mode if ARG is positive, and disable it otherwise.
Behind the scenes, `t` is used as a toggle for a mode (some set of behaviors). This call is not setting a variable (explicitly, anyway).
> *In another case I use: `(set 'inhibit-startup-message t)` or `(setq inhibit-startup-message t)`*
`setq` is a convenience function for `set`.
In Lisp, broadly speaking, there is code and there is data. However, code may be interpreted as data using quoting. The interpreter does not work directly with the source code but with Lisp objects. At a high level, the programmer writes the source code using symbols and lists as well as other data structures like vectors. At a low level, Emacs Lisp subroutines (a.k.a. built-in functions) generate and manage objects: data types and instructions.
To understand this, let's walk through how the statement `(set 'inhibit-startup-message t)` is interpreted. Note this is not *exactly* how it works; some details are omitted to avoid getting too far into the weeds.
Okay, let's go into the weeds a little bit. Lisp works with *symbols*. A symbol is kind of like a container for a variable part and a function part. A symbol has a name and when that name is referenced, depending on the context, the Lisp interpreter knows whether to use the variable part or the function part. To be clear, the symbol is the "word on the page" (the source code) whereas the *meaning* of the "word on the page" is the variable part (any Lisp object) or the function part (a Lisp function object).
```
+----------------+---------------+
symbol (word on page) ---> | variable part | function part |
+----------------+---------------+
+----------------+---------------+
foo ---> | "bar" | do some thing |
+----------------+---------------+
```
For example, we might have a symbol `foo`. The symbol is the "word on the page" `f-o-o`. As a variable, it contains the string `"bar"`. As a function, it does some action like, printing a message or turning on the coffee maker.
Okay, that's enough of getting into the weeds. How does the Lisp interpreter understand `(set 'inhibit-startup-message t)`?
Say you put your cursor to the right of the right paren and press `C-x C-e` (`eval-last-sexp`). This evaluates the previous expression. The Lisp interpreter goes to the start of the expression, the left parens. It says, "Okay, I've got a list here. That's the beginning of a lisp statement." The interpreter will continue reading until the right paren, at which point it will try evaluating.
The interpreter then sees the `set` symbol. It says, "I see a symbol here, but what does it mean?" Since there is no quote preceding the `set` word, the interpreter understands it to be a function. Indeed, the first symbol in a list is interpreted as a function name. Looking at `C-h f set`, the set function accepts a SYMBOL and a NEWVAL.
The next item is `'inhibit-startup-message`. Since this is preceded by a quote, the interpreter uses the same symbol `inhibit-startup-message`.
Therefore, the program can act on the symbol itself (the program can modify this object). The symbol can thus define its function (maybe *void*?) or its value in the code, e.g. *a counter* indicates a change in value. The *quoted symbol* can be passed *as an argument* to a function to create code at runtime (evaluated as a variable or a function). Otherwise, without the quote, the symbol is evaluated as a variable *so the real argument is the variable's value*. Keep in mind that a symbol is a kind of placeholder.
The `t` is then read. Since this is not quoted, `t` is understood to be a variable. In this case, `t` is a specific symbol that evaluates to itself (the evaluation returns the same object).
Finally, the right paren is met, and the whole statement is evaluated. Remember, the `set` function takes two arguments, SYMBOL and NEWVAL. The SYMBOL argument is `inhibit-startup-message` and the NEWVAL argument is `t`, which evaluates to `t`. The `set` function does its black-box behavior and the symbol `inhibit-startup-message` gets `t` for its variable part.
In the case of `(setq inhibit-startup-message t)`, the interpreter knows that because `setq` is being used, the next symbol it encounters refers to the same "symbol object". No need to quote it! Now that's convenience!
# Answer
> 7 votes
As I understand it, Daniel's question was not only about the difference between `set` and `setq`, but also about why to use `set/setq` in some (and not all) cases. The fundamental difference between the two examples you provide is the following:
1. To inhibit the startup message, you need to set the *variable* `inhibit-startup-message` to `t`. You can do this by using one of two equivalent instructions, as explained by Tobias:
```
(setq inhibit-startup-message t)
;; or:
(set 'inhibit-startup-message t)
```
2. To activate the *minor mode* `show-paren-mode`, you need to activate the corresponding *function* `show-paren-mode`:
```
(show-paren-mode t)
```
In the latter case, you must *not* use an expression such as `(setq show-paren-mode t)`, because `show-paren-mode` is not a variable you can set to a given value: it is a function.
In order to know whether you are dealing with a function or a variable, you have to read the corresponding help page.
# Answer
> 6 votes
Emacs comes with the Elisp manual. Try `C-h i` `m` `Elisp` `RET`. Type `i` `setq` `RET` to go to the place where the index topic `setq` is explained.
There you find the following info:
> Special Form: `(setq [symbol form]...)` This special form is the most common method of changing a variable’s value. Each SYMBOL is given a new value, which is the result of evaluating the corresponding FORM. The current binding of the symbol is changed.
>
> **‘setq’ does not evaluate SYMBOL;** it sets the symbol that you write. We say that this argument is “automatically quoted”. The ‘q’ in ‘setq’ stands for “quoted”.
There is mentioned that SYMBOL is not evaluated. Therefore, you do not need to quote it.
> -- Function: `(set symbol value)` This function puts VALUE in the value cell of SYMBOL. Since it is a function rather than a special form, **the expression written for SYMBOL is evaluated to obtain the symbol to set**. The return value is VALUE.
>
> When dynamic variable binding is in effect (the default), ‘set’ has the same effect as ‘setq’, apart from the fact that ‘set’ evaluates its SYMBOL argument whereas ‘setq’ does not. But when a variable is lexically bound, ‘set’ affects its *dynamic* value, whereas ‘setq’ affects its current (lexical) value. \*Note Variable Scoping::.
`set` evaluates SYMBOL. This is useful if you have stored the actual symbol to be set, say `SYM`, in a variable, say `VAR`. Then you use
`(set VAR VAL)`
to store `VAL` in the value cell of `SYM`.
---
Tags: init-file, setq
---
|
thread-48111
|
https://emacs.stackexchange.com/questions/48111
|
Use magit to display the difference between two branches
|
2019-02-28T19:37:23.887
|
# Question
Title: Use magit to display the difference between two branches
Is there a way to bring up a big list of the differences between specific commits across two branches?
I tried the method described in this answer but it came back empty, I assume because the revisions are on different branches.
I'll happily use another method if magit isn't right.
As clarification, this is the result I get from running `d r` from `magit-status` on the range `368513582b027bfde77cb2e9e43eace1b6f5336c..53ebfb70079bb5bc411fd0f8853673c2c5eb0589` which are across two branches (master and WW-pilot) and the branches are very different.
# Answer
> 16 votes
I think that the command you're looking for is `magit-diff-range`. Being on some branch, hit `M-x` and `magit-diff-range`. Then, when prompted, enter the name of the other branch and you will get a buffer with diffs.
# Answer
> 2 votes
> `Git diff` doesn't work for me as it can't find kdiff.
I don't know why `git diff` would need `kdiff` (whatever that is), but if `git diff` does not work on the command line, the various `magit-diff-*` commands also won't work because they get the diff by running `git diff` too.
It appears to me that you have misconfigured Git. You can probably fix that by running `git config --unset diff.external` and/or `git config --global --unset diff.external`.
---
Tags: magit, diff
---
|
thread-56220
|
https://emacs.stackexchange.com/questions/56220
|
How to match first character in line after asteriks and space using regex?
|
2020-03-18T18:26:13.593
|
# Question
Title: How to match first character in line after asteriks and space using regex?
For example i have lines:
```
* test1
** another tests
* some other line
```
I would like to match `t` in first line, `a` in second, `s` in third.
# Answer
```
(re-search-forward "[^*[:space:]]")
```
Then use `match-data` or similar functions, if you want the match.
And put that code inside `save-excursion` if you don't want to end up moving the cursor.
If you want to include newline chars as whitespace chars then use something like
```
"[^*[:space:]\n]"
```
> 2 votes
# Answer
Emacs regexps don't have arbitrary zero-width look-around assertions, so if you're hoping for a pattern which in its entirety would only ever match those characters (no matter where it started from, or how many times you searched) then you're out of luck. In Emacs such behaviours are achieved using elisp rather than solely with the regexp engine.
You can, of course, search for:
```
^\*+ \(.\)
```
aka
```
"^\\*+ \\(.\\)"
```
And then you'll have the character you wanted in the matched sub-group.
It all depends on what you're doing, though.
> 1 votes
---
Tags: regular-expressions, search
---
|
thread-56224
|
https://emacs.stackexchange.com/questions/56224
|
Icomplete and Ido: Why are both in the codebase?
|
2020-03-18T22:32:16.580
|
# Question
Title: Icomplete and Ido: Why are both in the codebase?
My question is pretty simple, and that is why Ido and Icomplete are both available in emacs.
I find it very strange that the two modes exist together, seeing that they both do what is essentially the same thing, incremental completion for different minibuffer queries. What I find annoying about the two is that Ido is much cleaner and nice to use, but doesn't add completion for M-x. In order for that to be implemented, you have to download an external package, smex. On the other hand, Icomplete seems like an early version of Ido, but **with** completion for M-x.
Really, what I'm asking, is why Ido can't replace Icomplete entirely by fully replacing all of Icomplete's features instead of replacing most of them.
# Answer
> 9 votes
Ido is implemented in a way that would require a big rewrite for it to support completion in different context, not just the handful of the pre-defined ones.
But it was born at the time when it was "fashionable" to get things into Emacs, and since it's still popular, it can't be removed outright either.
As for replacing, though, the developers are going in the opposite way, hoping to replace Ido with Icomplete someday. Since the former has some peculiar (but handy) things in its UI, Emacs 27 will contain `fido-mode`. It's a minor mode based on Icomplete that provides a behavior that should be more familiar to Ido users.
Give it a try sometime.
---
Tags: completion, ido, icomplete
---
|
thread-53733
|
https://emacs.stackexchange.com/questions/53733
|
Auctex previews, change foreground color of text
|
2019-11-14T15:11:29.397
|
# Question
Title: Auctex previews, change foreground color of text
I am using a dark theme and the latex previews from auctex are created with black text color. How can I change it? What I can do is change the background color to white (in Preview Reference Face customization), then I can at least read the text but it is irritating. Setting the foreground there did not work for me.
I also already tried to inject \color{white} into the latex commands somehow but without luck. Where would be the right place?
# Answer
Checkout the `preview-pdf-color-adjust-method` option.
Apparently it should use automatically the same foreground color as the buffer text, but at least in my case the problem was that I have only Ghostscript 9.26 installed. As a workaround I downloaded the latest Ghostscript binary and modified `preview-gs-command` to point to it.
> 1 votes
---
Tags: latex, customize, preview-latex
---
|
thread-56158
|
https://emacs.stackexchange.com/questions/56158
|
Is it possible to have expand abbreviations when calling a skeleton-read?
|
2020-03-14T23:43:42.697
|
# Question
Title: Is it possible to have expand abbreviations when calling a skeleton-read?
I have a large set of abbreviations I defined inside an abbrev-table. Take one of them:
```
(define-abbrev-table 'latex-mode-abbrev-table
'(("ff" "my abbreviation!" 0 nil)))
```
If I run a predefined function that calls things through `skeleton-read` is there a way to expand abbreviations within that query? In other words if I define a function,
```
(define-skeleton myfunc "" "" (setq v1 (skeleton-read "put something ")))
```
and call it with `M-x` then within the bottom bar where I type in the value can I use my abbreviation (by typing `ff` and then hitting the space bar) while typing there (nothing happens by default)?
# Answer
> 2 votes
`skeleton-read` will read from the minibuffer, which is a separate buffer that's not using `latex-mode`, which is why your abbrev isn't working there.
You could put your abbrev in `global-abbrev-table` so it's also available in the minibuffers, you could do:
```
(define-skeleton myfunc
"" ""
(setq v1 (minibuffer-with-setup-hook
(lambda () (setq local-abbrev-table latex-mode-abbrev-table))
(skeleton-read "put something "))))
```
to make latex-mode abbrevs available in this specific minibuffer.
---
Tags: abbrev, skeleton
---
|
thread-56229
|
https://emacs.stackexchange.com/questions/56229
|
Sort tags in a headline
|
2020-03-19T05:43:34.320
|
# Question
Title: Sort tags in a headline
When we add tags to a headline, they just get appended. For instance,
```
* Head 1 :A:C:B:
* Head 2 :B:A:C:
```
Is there a way I can sort these tags so we get:
```
* Head 1 :A:B:C:
* Head 2 :A:B:C:
```
# Answer
> 3 votes
You can sort tags alphabetically using:
```
(setq org-tags-sort-function 'org-string-collate-lessp)
```
> Documentation: When set, tags are sorted using this function as a comparator.
# Answer
> 1 votes
I don't think it's already in Org.
What about
```
(defun my-org-sort-tags ()
"On a heading sort the tags."
(interactive)
(when (org-at-heading-p)
(org-set-tags (sort (org-get-tags) #'string<))))
```
for a start?
Activate with
```
M-x my-org-sort-tags
```
---
Tags: org-mode, org-tags
---
|
thread-56254
|
https://emacs.stackexchange.com/questions/56254
|
find files containing "Emacs"
|
2020-03-20T01:00:58.750
|
# Question
Title: find files containing "Emacs"
I employed `find` within the current directory to find files containing "emacs"
```
$ find . -type f -iname "*emacs*" | nl | tail -3
34 ./sources/tech/20190916 The Emacs Series Exploring ts.el.md
35 ./sources/tech/20200311 What you need to know about variables in Emacs.md
36 ./sources/tech/20191009 The Emacs Series ht.el- The Hash Table Library for Emacs.md
```
Get a result of 36 files,
When come to Emacs "find-name-dired", but find only one file
```
2637215 8 -rw-rw-r-- 1 me me 7708 Dec 19 20:48 sources/tech/20191218\ Emacs\ for\ Vim\ users-\ Getting\ started\ with\ the\ Spacemacs\ text\ editor.md
```
What's the problem?
# Answer
# tl;dr
Do you get the expected behavior under `emacs -Q`? It's possible you've disabled case-insensitivity.
# Long answer
Without knowing your arguments to `find-name-dired` (you should add them to your question) it's hard to say. If you included the double quotes, Emacs will escape them and `find` will look for files that include them. Based on your output that doesn't seem to be the case. It's possible you've run into a case-sensitivity issue and you triggered on the "emacs" in "Spacemacs", not the "emacs" in "...Emacs for Vim...".
(The following is based on Emacs 26.2)
By default (ie under `emacs -Q`) `find-name-dired` is case insensitive, but that's configurable. From the documentation of `find-name-dired` (via `Ctrl-H f find-name-dired RET`):
```
find-name-dired is an interactive autoloaded Lisp function in
‘find-dired.el’.
(find-name-dired DIR PATTERN)
Search DIR recursively for files matching the globbing pattern PATTERN,
and run Dired on those files.
PATTERN is a shell wildcard (not an Emacs regexp) and need not be quoted.
The default command run (after changing into DIR) is
find . -name 'PATTERN' -ls
See ‘find-name-arg’ to customize the arguments.
```
If we follow the docs to `find-name-arg`, we find:
```
find-name-arg is a variable defined in ‘find-dired.el’.
Its value is "-iname"
Documentation:
Argument used to specify file name pattern.
If ‘read-file-name-completion-ignore-case’ is non-nil, -iname is used so that
find also ignores case. Otherwise, -name is used.
You can customize this variable.
This variable was introduced, or its default value was changed, in
version 22.2 of Emacs.
```
And again to `read-file-name-completion-ignore-case`:
```
read-file-name-completion-ignore-case is a variable defined in ‘minibuffer.el’.
Its value is t
Documentation:
Non-nil means when reading a file name completion ignores case.
You can customize this variable.
This variable was introduced, or its default value was changed, in
version 22.1 of Emacs.
```
So, if your `find-name-arg` is not "-iname" and/or your `read-file-name-completion-ignore-case` is `nil`, `find-name-dired` will be case sensitive. Check your init files (and `custom.el`), to find when these variables have been changed. Also, you can use `find-dired` to set the arguments to `find` yourself.
> 3 votes
---
Tags: dired, find-dired, find
---
|
thread-56252
|
https://emacs.stackexchange.com/questions/56252
|
perl-mode indentation continuation
|
2020-03-19T22:56:24.407
|
# Question
Title: perl-mode indentation continuation
```
$defs = {
"key1" => 1, # indented correct with tab
"key2" => 2, # indented too much, should align with key1
"key3" => 3, # keeps indentation from here on
};
```
With regular perl-mode in Emacs 26.5 the indentation is "staggered" like above, where key2 and key3 are not aligned with key1 when tab is pressed, but should be. How to make perl-mode do that? (not cperl-mode).
# Answer
Try setting `perl-continued-statement-offset`.
```
(setq perl-continued-statement-offset 0)
```
See it's documentation (via `Ctrl-H v`):
```
perl-continued-statement-offset is a variable defined in ‘perl-mode.el’.
Its value is 4
This variable is safe as a file local variable if its value
satisfies the predicate ‘integerp’.
Documentation:
Extra indent for lines not starting new statements.
You can customize this variable.
```
You'll notice its (default) value is "4"; the number of spaces your `"key2"` is indented. If you change this while a `perl-mode` buffer is active you'll have to manually re-indent the code in that buffer. Setting his may negatively change other indentation, so keep an eye out.
> 1 votes
---
Tags: perl
---
|
thread-38610
|
https://emacs.stackexchange.com/questions/38610
|
TRAMP on Windows connects to Linux but not to OSX (macOS)
|
2018-02-04T23:23:35.373
|
# Question
Title: TRAMP on Windows connects to Linux but not to OSX (macOS)
Using Emacs-25.2.1 on Windows XP (and on 7, too) I can connect to my Raspberry Pi (Rasppian OS) using TRAMP and the plink method and it works flawlessly. But when I try to connect to my Mac mini (OSX 10.7.4), after I input the password it hangs on with the **"Found remote shell prompt..."** message. The shell on OSX is plain old bash with no fancy configuration in **~/.bash\_profile** and the sshd is the default one at **/usr/sbin**
If I try to connect directly from the **CMD** or **MSYS** shell to the OSX e.g.
> $ plink macmini@lionserver.home
It connects flawlessly. Any help is appreciated. Thanks.
Parts of `debug tramp/ssh` related to `locale` from the *Linux* connection:
> 12:40:09.589843 tramp-send-command (6) # locale -a
>
> 12:40:09.655846 tramp-wait-for-regexp (6) #
>
> C
>
> C.UTF-8
>
> en\_GB.utf8
>
> en\_US.utf8
>
> POSIX
>
> tr\_TR
>
> tr\_TR.iso88599
>
> tr\_TR.utf8
>
> turkish
>
> 12:40:09.709849 tramp-open-connection-setup-interactive-shell (5) # Setting coding system to ‘utf-8’ and ‘utf-8-unix’
Parts of `debug tramp/ssh` related to `locale` from the *OSX* connection:
> 12:33:56.549506 tramp-send-command (6) # locale -a
>
> 12:33:56.655512 tramp-wait-for-regexp (6) #
>
> af\_ZA
>
> af\_ZA.ISO8859-1
>
> af\_ZA.ISO8859-15
>
> af\_ZA.UTF-8
>
> tr\_TR
>
> tr\_TR.ISO8859-9
>
> tr\_TR.UTF-8
>
> ....
>
> C
>
> POSIX
>
> 12:33:56.709515 tramp-open-connection-setup-interactive-shell (5) # Setting coding system to utf-8-hfs and utf-8-hfs
# Answer
> 1 votes
Usually, this kind of problem is related to your remote shell prompt. Set `tramp-verbose` to 6 (or to 10, if it doesn't help), and rerun your test. If the Tramp traces don't tell you what's up, contact the Tramp tower via email, `tramp-devel@gnu.org`.
**Edit:** After investigation on the Tramp ML it has been shown, that this was a bug in Tramp. Will be fixed with the next Tramp 2.3.4 release.
# Answer
> 1 votes
Since Apple deprecated bash in favour of zsh, a message appears on login about ‘default interactive shell is now zsh’. This seems to mess with Tramp.
To disable it, add `export BASH_SILENCE_DEPRECATION_WARNING=1` to your .bash\_profile
# Answer
> 0 votes
I had the exact same problem (connecting to Mac OS from Windows using plink hanged on `Found remote shell prompt`). After turning logging verbosity of tramp to 10 I was able to see that tramp was waiting to receive the response of a remote shell command. The response was in the log, but it was terminated by two repetitions of `tramp-end-of-output` variable which contains an MD5 session identifier. The regular expression in `tramp-wait-for-output` function was expecting only one session identifier to indicate the end of response, so it kept waiting.
I fixed it by changing the regexp
```
format "[^#$\n]*%s\r?$" (regexp-quote tramp-end-of-output)
```
in `tramp-sh.el` file to
```
format "[^#$\n]*\\(%s\\)+\r?$" (regexp-quote tramp-end-of-output)
```
to allow for multiple occurrences of `tramp-end-of-output` string.
After making the change, I needed to recompile the file by executing
```
emacs -Q --batch -f batch-byte-compile "<path_to_file>/tramp-sh.el"
```
Afterward, I was able to connect without problems.
---
Tags: osx, microsoft-windows, tramp
---
|
thread-52142
|
https://emacs.stackexchange.com/questions/52142
|
Debugging "Package lacks a file header"
|
2019-08-14T11:45:23.867
|
# Question
Title: Debugging "Package lacks a file header"
I'm playing around with developing and publishing an Emacs package, very simple stuff, just trying things out before I commit to a bigger project. The problem that I'm having is that after I've made a MELPA package (as per this tutorial) and try the `package-install-file` command I'm greeted with the *"Package lacks a file header"* error message, even though as far as I can see my package contains all of the required header information (as you can see here). My source file looks like this:
```
;;; header-tracker.el --- Easy switching between header and source files.
;; Copyright (C) 2019 Nathan Campos
;; Author: Nathan Campos <nathan@innoveworkshop.com>
;; Homepage: http://github.com/nathanpc/header-tracker.el
;; Version: 1.0.0
;; Keywords: convenience, usability
;; Package-Requires: ((emacs "24.1"))
;; This file is NOT part of GNU Emacs.
;;; License:
;; This program is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with this program. If not, see <http://www.gnu.org/licenses/>.
;;; Commentary:
;; Quickly and easily keep track and switch between header and source files
;; using this handy package.
;; This package exports a interactive function `header-tracker-toggle-header`
;; which can be binded to a key to seamlessly switch between source and header
;; files. This can be accomplished by adding the following lines to your
;; configuration file:
;; (add-hook 'c-mode-common-hook
;; (lambda ()
;; (local-set-key (kbd "C-c h") 'header-tracker-toggle-header)))
;; For more information about this package please consult the README file.
;;; Code:
;; Some code here...
(provide 'header-tracker)
;;; header-tracker.el ends here
```
Also, when I run `(package-buffer-info)` in the source buffer this is what I get in return, so apparently the header is valid:
```
(package-desc header-tracker (1 0 0) "Easy switching between header and source files." ((emacs (24 1))) single nil nil ((:authors ("Nathan Campos" . "nathan@innoveworkshop.com")) (:maintainer "Nathan Campos" . "nathan@innoveworkshop.com") (:url . "http://github.com/nathanpc/header-tracker.el")) nil)
```
Running `checkdoc` yields:
```
Buffer comments and tags: Ok
Documentation style: Ok
Message/Query text style: Ok
Unwanted Spaces: Ok
```
Another interesting thing that is happening is that if I run `package-install-from-buffer` in my package (not in the MELPA fork) it installs without any issues.
How can I debug this error since apparently it doesn't give any indication of what made it happen in the first place.
# Answer
> 0 votes
Are you running on windows? I have seen a package work fine on Linux, but generate similar errors on windows. Could be due to GIT changing the CR to CRLF when checking out on Windows.
`git config --global core.autocrlf false` being set before cloning will prevent the change.
Information from here spacemacs issue
---
Tags: package, package-repositories, package-development
---
|
thread-56255
|
https://emacs.stackexchange.com/questions/56255
|
How to use ivy to navigate named locations of a buffer?
|
2020-03-20T01:30:04.560
|
# Question
Title: How to use ivy to navigate named locations of a buffer?
Given a list of `(point-number . title-text)`, how can ivy be used to show this in a list in `ivy`?
I have code which uses `completing-read` to do this (see link). This can use `ivy` since it extends `completing-read` however it doesn't seem to support all of `ivy`'s features.
For example `ivy-next-line-and-call` and `ivy-previous-line-and-call` don't work.
How can ivy be used directly to navigate sections in a document?
# Answer
> I have code which uses `completing-read` to do this
Ivy's analogue to `completing-read` is the function `ivy-read`, whose operation is described in its docstring and the Ivy User Manual under `(info "(ivy) API")`.
> Given a list of `(point-number . title-text)`, how can ivy be used to show this in a list in `ivy`?
Here's an example of how to achieve this:
```
(defun my-ivy-location (locations)
"Goto one of LOCATIONS, using Ivy for completion.
LOCATIONS is a list of (POS . LABEL), where POS is a candidate
buffer position and LABEL is a string describing POS for the
purpose of completion."
(ivy-read "Goto location: " (mapcar #'cdr locations)
:require-match t
:action (lambda (label)
(let ((pos (car (rassoc label locations))))
(when pos (goto-char pos))))
:caller #'my-ivy-location))
```
Note that Ivy:
* prefers using the `:action` callback rather than the return value of `ivy-read` to operate on the selected candidate(s); and
* identifies the current completion command using the `:caller` property.
Depending on how you populate the `LOCATIONS` alist, it may be preferable to flip the order of its car and cdr, so that both built-in and Ivy completion functions can operate on it more naturally as a "completion table" (see `(info "(elisp) Basic Completion")`):
```
(defun my-ivy-location-r (locations)
"Goto one of LOCATIONS, using Ivy for completion.
LOCATIONS is a list of (LABEL . POS), where POS is a candidate
buffer position and LABEL is a string describing POS for the
purpose of completion."
(ivy-read "Goto location: " locations
:require-match t
:action (lambda (location)
(let ((pos (cdr-safe location)))
(when pos (goto-char pos))))
:caller #'my-ivy-location-r))
```
> How can ivy be used directly to navigate sections in a document?
Counsel is a library of handy utilities provided alongside and implemented using the Ivy API. Perhaps some of the following may also be of interest to you:
* `counsel-imenu` (jumping to buffer sections detected by imenu)
* `counsel-mark-ring` (jumping to buffer locations stored in the mark ring)
* `counsel-register` (jumping to buffer locations stored in registers)
> 2 votes
---
Tags: ivy, completing-read
---
|
thread-56225
|
https://emacs.stackexchange.com/questions/56225
|
translating kp-NUM keys
|
2020-03-18T23:54:36.533
|
# Question
Title: translating kp-NUM keys
I am migrating from GNU/Linux to Mac. I am using an MS Windows numeric keyboard (Logitech K200), and I cannot seem to map the keypad keys (`kp-N`) into anything (I had been doing that using `global-set-key` in my `.emacs`).
When I run `describe-key` and press a key I see it gets translated to the related number key, e.g. `describe-key` then press `kp-5` yields: `5 (translated from <kp-5>) runs the command Custom-no-edit...`.
Similarly for Ctrl-/Meta-/Shift-. Adding e.g. `(global-set-key <C-kp-5> 'goto-line)` to my `.emacs` does not change anything that I can see, so I assume the translation is happening before the key mapping.
How can I disable the translation of all the `kp-`*N*s so I can redfine them using `global-set-key`?
# Answer
> 1 votes
Ok, I was led astray by the `C-h k` output (e.g. `...(translated from <kp-5>)...`) which I took to mean that the syntax `<kp-5>` was OK for `KEY` in `global-set-key`. When I did `(global-set-key [kp-5] 'goto-line)` instead it works as I expect. Both forms had worked on the system I came from. I found this by going though my `.emacs` and testing the various `global-set-key` forms I had there. I still have the issue that `Num Lock` is not working, but since I use the keypad for mostly navigation I can live with that.
---
Tags: key-bindings, keymap
---
|
thread-26226
|
https://emacs.stackexchange.com/questions/26226
|
Looking For Simple Bookmark Package
|
2016-08-12T17:40:02.817
|
# Question
Title: Looking For Simple Bookmark Package
Can you recommend, a good bookmark package?
* Yes, emacs standard has bookmarks. Although, hate naming them.
* Just want something small, not uber sophisticated (like bookmark+). (It crashes my setup, at the moment, had to remove it.)
* All I want is a hotkey to mark one location, per file.
* Don't care about saving, between sessions. (Great if just during session.)
* Although, I do have "save last edited place" working now. (Don't know, name of package off top of head.)
Really after, just a remember position (in key), then other hotkey to recall. Yes, plain Emacs bookmark could do this? With a name in macro.
* But, is that the best way?
* Or easiest way?
# Answer
> 2 votes
I use this function to quickly create meaningful bookmarks with a single keypress, without having to think about it:
```
(defun my/quick-save-bookmark ()
"Save bookmark with name as 'buffer:row:col'"
(interactive)
(bookmark-set (format "%s:%s:line %s:column %s"
(thing-at-point 'symbol)
(buffer-name)
(line-number-at-pos)
(current-column)))
(message "Bookmarked saved at current position"))
(global-set-key (kbd "C-S-b") 'my/quick-save-bookmark)
```
Not sure if this is what you are looking for, but it seems to basically meet your description. I have found it to be very useful and lightweight. I also use `helm` and this to quickly see my bookmarks:
```
(bind-key "<menu>" 'helm-bookmarks)
```
# Answer
> 0 votes
If you wonder how to use the current line's contents as bookmark description, here it is:
```
(defun my/quick-save-bookmark ()
"Save bookmark with name as 'buffer:row:line-contents'"
(interactive)
(bookmark-set (format "%s:%s:%s"
;; (thing-at-point 'symbol)
(buffer-name)
(line-number-at-pos)
(string-trim (buffer-substring-no-properties (line-beginning-position) (line-end-position)))
;; (current-column)
))
(message "Bookmarked saved at current position"))
(define-key global-map [remap bookmark-set] 'my/quick-save-bookmark)
```
Replaces the usual bookmark-set shortcut `C-x r m`. Works nicely with helm. Also, helm displays bookmarks in chronological order, which automatically assigns sort of a context to them. BTW: you can mark bookmarks in helm using C-SPC and then use C-d to delete them.
---
Tags: bookmarks
---
|
thread-56269
|
https://emacs.stackexchange.com/questions/56269
|
How to change Org-mode babel tangle write to file way as prepend instead of override by default?
|
2020-03-21T02:16:49.307
|
# Question
Title: How to change Org-mode babel tangle write to file way as prepend instead of override by default?
There's an answer here for appending the current code block to an existing file.
I want to do the opposite, which is to prepend the current code block to an existing file. Could you please help?
# Answer
I don't see a clever way to do what you want: you would have to change the `org-babel-tangle` function itself, or rather write your own function which would be almost the same as the `org-babel-tangle` function, but not quite. @Tobias's answer in the linked question locally redefines the `delete-file` function to `ignore`, so when `org-babel-tangle` is called, the file is not deleted and the block is just written to the existing file (it just so happens that it is written at the *end* of the file, so everything works out).
In your case you would, in addition, have to rewrite a portion of the `org-babel-tangle` function itself. So you would have to write a new function `org-babel-tangle-prepend` which is an almost exact copy of the `org-babel-tangle` function with two changes:
* Delete the code that deletes the file. This is effectively what @Tobias does in a clever way in the linked answer, so he can reuse the existing `org-babel-tangle` function without changing it, but since you have to change the function anyway, you might as well physically delete the relevant lines. So the following code (around line 258 in the file `ob-tangle.el` in the current upstream version \- you may have to look around that line to find the code in your version) should be deleted in the new function:
```
;; delete any old versions of file
(and (file-exists-p file-name)
(not (member file-name (mapcar #'car path-collector)))
(delete-file file-name))
```
* The code in lines 269-280 of `ob-tangle.el` (again that is in the current upstream version and you may have to look around to find it in your version) has to be changed.
The latter code looks like this in the original:
```
;; We avoid append-to-file as it does not work with tramp.
(let ((content (buffer-string)))
(with-temp-buffer
(when (file-exists-p file-name)
(insert-file-contents file-name))
(goto-char (point-max))
;; Handle :padlines unless first line in file
(unless (or (string= "no" (cdr (assq :padline (nth 4 spec))))
(= (point) (point-min)))
(insert "\n"))
(insert content)
(write-region nil nil file-name))))
```
It needs to be changed to look like this in the new `org-babel-tangle-prepend` function:
```
;; We avoid append-to-file as it does not work with tramp.
(let ((content (buffer-string)))
(with-temp-buffer
(insert content)
;; Handle :padlines unless first line in file
(unless (or (string= "no" (cdr (assq :padline (nth 4 spec))))
(= (point) (point-min)))
(insert "\n"))
(when (file-exists-p file-name)
(insert-file-contents file-name))
(write-region nil nil file-name))))
```
This is just a slightly reordered version of the original code:
* We first write the new code.
* Add padlines if necessary.
* Add the contents of the old file.
* Write the whole thing back into the file.
Minimally tested.
> 1 votes
---
Tags: org-mode, org-babel, tangle
---
|
thread-53269
|
https://emacs.stackexchange.com/questions/53269
|
TRAMP mode hangs while copy large file from remote to local via Ssh
|
2019-10-21T23:01:26.427
|
# Question
Title: TRAMP mode hangs while copy large file from remote to local via Ssh
Trying here to download (`scp` file from remote to local) that was considered large file, then Emacs tried to compact it, then got stuck.
Even used `scp` command to do it because copying via `ssh` got stuck too.
Now there are two goals here: one is repair file copy from remote to local via `ssh` or set it to do not compact large files for copy via `scp` on TRAMP mode, but copy it at normal size.
Any ideas?
# Answer
> 4 votes
TRAMP uses itself Base64 encoding, it doesn't hangs, just takes a really long time for larger files.
Maybe `rsync` or `rcp` methods speeds up the process, but this is its basis.
What may be done is run a shell command in minibuffer, via `M-!`, then enter `scp` as outside of Emacs, and without using TRAMP mode, it would accelerate it significantly, with regular `scp` speed.
# Answer
> 3 votes
Try stablishing connection using `scp` itself instead of `ssh`, as of `/scp:user@host#port:/directory`, and then using `scp` again, as managed here to don't use `base64` conversion, which seems to be slowing the transfer.
---
Tags: tramp, ssh
---
|
thread-56279
|
https://emacs.stackexchange.com/questions/56279
|
Quotations / examples in org-mode
|
2020-03-21T19:18:44.223
|
# Question
Title: Quotations / examples in org-mode
I was wondering if there is any way to write something like a quotation or a motto in org mode, in a way that is differentiated from the rest of the text. For instance, it could be indented with a specific number of spaces, and has some sort of "padding" from the rest of the text. Thank you.
# Answer
The standard Orgmode way to write quotations are quotation blocks:
```
#+begin_quote
This is quoted stuff. Org /formatting/ does work here.
#+end_quote
```
In HTML export uses the `<blockquote>` tag for such blocks. You can define the style in `org-html-head` if you like.
> 3 votes
---
Tags: org-mode
---
|
thread-56198
|
https://emacs.stackexchange.com/questions/56198
|
How to use xref-find-references on Elisp files without "No references found for" errors
|
2020-03-17T14:58:57.520
|
# Question
Title: How to use xref-find-references on Elisp files without "No references found for" errors
I am using GNU Emacs 26.3 on Ubuntu 19.10.
I have a directory full of Emacs Lisp files with the `.el` file extension. All of them are loaded into the currently running Emacs. I can open up one of those files, put point on a function that is being called, and then use `M-.` to go to that definition. That works. But when I use `M-?` (which is bound to `xref-find-references`) I get an error of the form:
```
user-error: No references found for: xxx
```
where `xxx` was the symbol at point.
I thought this was due to not using a TAGS file, so I generated one using:
```
cd ~/my_emacs_lisp_dir1
etags -l lisp ../my_emacs_lisp_dir1/*.el ../my_emacs_lisp_dir2/*.el
```
And that did work as it produced a `TAGS` file where I expected it to be which is in `~/my_emacs_lisp_dir1/TAGS`.
In Emacs, I visited that TAGS file using `visit-tags-table`. And then tried `M-?` on the symbol again, and it still failed with the above error.
I then executed `xref-etags-mode` from within that same `.el` buffer and tried again. Still I got the same error.
Opening up the TAGS file and searching for the symbol only turns up what I believe to be an indication of which file a symbol is defined in, but I don't see how it could record references to where that symbol is referenced from. So that may be the problem, and if so, how do I make it tell me which functions and files refer to the symbol at point?
# Update 1: It works for standalone files, but not in my Git-controlled HOME directory
I noticed that it does work if I do something silly like this:
```
rm -rf /tmp/xref-test-dir
mkdir -p /tmp/xref-test-dir
cd /tmp/xref-test-dir
cat > func-1.el <<'EOF'
(defun xxx-func-1 ()
(xxx-func-2))
EOF
cat > func-2.el <<'EOF'
(defun xxx-func-2 ()
(message "xxx-func-2 called"))
EOF
etags -l lisp *.el
```
Then go to each of the two .el files, and run `eval-buffer` on them and then point point on the call to `xxx-func-2` and it at least did something that I think is correct: It showed a buffer with this info:
```
/tmp/xref-test-dir/func-1.el
2: (xxx-func-2))
/tmp/xref-test-dir/func-2.el
1: (defun xxx-func-2 ()
2: (message "xxx-func-2 called"))
```
I noticed that somewhere along the way I was prompted for a project directory and I supplied it `/tmp/xref-test-dir`.
But I got no such prompting from when I did it inside my `~/my_emacs_lisp_dir1` directory.
I dug even deeper into the `xref-backend-references` function, and found some code dealing with projects. So I went back to the .el file inside `~/my_emacs_lisp_dir1` directory, and ran this via `eval-expression`:
```
(project--find-in-directory ".")
```
and it returned this:
```
(vc . "~/")
```
that sort of makes sense because both `~/my_emacs_lisp_dir1` and `~/my_emacs_lisp_dir2` are within a Git repo.
But I'm still stuck because I don't know how to tell "it" to just look into those two directories, or even look into the files in that same directory.
# Answer
xref provides UI for code navigation. The actual functionalities are provided by the backend. In you case, the backend is etags.
If you open TAGS file, its format is very simple. It has only the information of tag definition. So you can not find reference of tag.
So you got two solutions,
**Solution 1,** Install lsp-mode and some language server, hope they will have implementation for finding references.
**Solution 2,** grep project with other packages. You can try `counsel-git-grep` or `counsel-rg`.
You can read Emacs Lisp code by yourself to confirm my point.
By default, `xref--find-xrefs` is called. Its definition,
```
(funcall (intern (format "xref-backend-%s" kind))
(xref-find-backend)
arg)
```
kind is `references`, so `xref-backend-references` is called. Here's its definition,
```
(cl-defgeneric xref-backend-references (_backend identifier)
"Find references of IDENTIFIER.
The result must be a list of xref objects. If no references can
be found, return nil.
The default implementation uses `semantic-symref-tool-alist' to
find a search tool; by default, this uses \"find | grep\" in the
`project-current' roots."
(cl-mapcan
(lambda (dir)
(xref-collect-references identifier dir))
(let ((pr (project-current t)))
(append
(project-roots pr)
(project-external-roots pr)))))
```
Notice the parameter `_backend` is ignored. I'm not sure what's the value of `semantic-symref-tool-alist`, maybe it's set up by you or the 3rd party packages you installed.
Definition of `semantic-symref-tool-alist`,
```
(defvar semantic-symref-tool-alist
'( ( (lambda (rootdir) (file-exists-p (expand-file-name "GPATH" rootdir))) .
global)
( (lambda (rootdir) (file-exists-p (expand-file-name "ID" rootdir))) .
idutils)
( (lambda (rootdir) (file-exists-p (expand-file-name "cscope.out" rootdir))) .
cscope )
)
"Alist of tools usable by `semantic-symref'.
Each entry is of the form:
( PREDICATE . KEY )
Where PREDICATE is a function that takes a directory name for the
root of a project, and returns non-nil if the tool represented by KEY
is supported.
If no tools are supported, then 'grep is assumed.")
```
So you could find real references if and only if you install GNU Global or GNU ID Utils or Cscope.
The documentation does mention the grep will be used as fallback. But I tested with a real project. The grep didn't happen.
> 1 votes
# Answer
**Note:** This is a very complicated solution. See How to use xref-find-references on Elisp files without "No references found for" errors for when I came to my senses and simplified things.
# Problems and fixes
I found multiple things that I did that tripped me up:
1. I had an ~/ID file that is generated using ID Utils. xref, or something beneath it, was trying to use ID as its backend, because it is much, much faster than grep, of course. However, the way I have to generate these ID files is by disabling all language specific parsing in the lang-map file I use with gid (see the mkid lang-map below). But mkid for text treats dashes as punctuation, and thus, not a part of a symbol name. And, most if not all of the Emacs Lisp symbols I define have dashes. Thus, when I was searching using M-?, it used `lid` to find them and got nothing. Even when I called mkid with a lang-map that marked `*.el` files as `lisp`, something still wanted to search all of ~/ which is not what I need (see next item).
2. Removing the ID files caused it to work, but it took quite a bit longer time than I know it should if it was only to search my small bit of Elisp code. It turns out that the slowness was caused by the elisp definitions that include everything in the `load-path` which is a ton of directories. So that had to be changed to limit the search to only one directory (containing subdirectories). It is probably correct to do this by default (if you intend to search for everything that Emacs knows about, which is useful in some contexts), however, not in this special case where I have only two directories.
# My ~/elisp/.dir-locals.el file
```
;; -*- fill-column: 100 -*-
;;
;; This is needed so that M-? (runs the command xref-find-references) can not trip over ID files
;; (created by my use of mkid from the idutils package). When I create these ID files, I cannot
;; specify things for Elisp that uses "-"s in the symbol names, because I use gid to find things
;; everywhere, even text files. When searching for an Elisp symbol that contains dashes, it cannot
;; find it inside the .el files referenced by that ID file. So the ID backend has to be deactiviated
;; for searching purposes for M-?.
;;
((emacs-lisp-mode . ((eval . (let ((my-elisp-dir "~/elisp"))
;;
;; By default, the "vc" part of the xref code finds ~/.git and thus
;; assumes the entire Git-controlled directory, ~/, is to be
;; searched. But that results is a HUGE amount of search time
;; (because grep is used, and not something like ID or Global etc.)
;; because ~/ also has ~/emacs.d/ which houses all of the packages I
;; use. Instead, we have to force that "off" by forcing it to only
;; look inside my-elisp-dir.
;;
(eval `(defun my-elisp-project-find (dir)
(cons 'vc
;; Use file-name-as-directory to avoid the assert inside
;; xref-collect-references:
,(file-name-as-directory my-elisp-dir))))
;;
;; Make project-find-functions buffer-local as this should not apply
;; anywhere else but here:
;;
(make-variable-buffer-local 'project-find-functions)
(add-hook 'project-find-functions #'my-elisp-project-find)
;;
;; Do not let the xref code search all of the other directories in
;; the elisp "load-path", which tends to be huge, as it includes both
;; the site-lisp area in the installed Emacs *and* all of the stuff
;; inside ~/emacs.d from Elpa etc. I intend to be searching for my
;; personally-defined Elisp functions when I'm doing my own personal
;; development.
;;
(setq-local project-vc-external-roots-function
`(lambda ()
(mapcar
;; Something is buggy in some lower level emacs lisp
;; code that does not accept "~" in the paths. So
;; hack around that bug with expand-file-name:
#'expand-file-name
(list ,my-elisp-dir)))))))))
```
# My mkid lang-map
```
# Welcome to the mkid language mapper.
#
# The format of each line is:
#
# <pattern> <language> [options]
#
# Filenames are matched top-to-bottom against the patterns, and the
# first match is chosen. The special language `IGNORE' means that
# this file should be ignored by mkid. The options are
# language-specific command-line options to mkid.
#
# If a file name doesn't match any pattern, it is assigned the default
# language. The default language may be specified here with the
# special pattern `**', or overridden from the mkid command-line with
# the `--default-lang=LANG' option.
#
# The special pattern `***' means to include the named file that
# immediately follows. If no file is named, then the default system
# language mapper file (i.e., this file) is included.
# Default language
** text
# Ignore PDF files as they are binary and don't provide much value in
# the output, and cause mkid to chew up CPU:
*.pdf IGNORE
```
> 1 votes
---
Tags: symbols, project, xref, etags
---
|
thread-34999
|
https://emacs.stackexchange.com/questions/34999
|
How to toggle multi-line comment blocks?
|
2017-08-19T02:32:24.677
|
# Question
Title: How to toggle multi-line comment blocks?
Is it possible to configure multi-line comments to comment/uncomment selected text?
For example C/C++'s preprocessor could be toggled like this.
eg:
Before:
```
// a comment
Some(code); /* some comment */
```
After:
```
#if 0
// a comment
Some(code); /* some comment */
#endif
```
Since C/C++ don't support nested comments, I find this preferable behavior to quickly disable chunks of code.
# Answer
This can be done by matching the beginning & end of the region, removing when found, adding when not found.
The following example is a generic function which takes arguments which can be set for each major-mode.
```
(defun my-comment-multi-line-toggle--impl (head tail head-regex tail-regex)
"Utility for toggling multi-line comments.
Argument HEAD Start of multi-line comment.
Argument TAIL End of multi-line comment.
Argument HEAD-REGEX Match the start of a multi-line comment.
Argument TAIL-REGEX Match the end of a multi-line comment."
(unless (use-region-p)
(user-error "No active region"))
(let ((beg (region-beginning))
(end (region-end))
(match-head nil)
(match-tail nil)
;; Prevent local language settings
;; impacting basic space stepping.
(syntax-table (make-syntax-table)))
(save-excursion
(with-syntax-table syntax-table
;; True when we have multi-line comments.
(if (and (setq match-head
(save-match-data
(goto-char beg)
(skip-chars-forward "[:blank:]")
(when (looking-at head-regex)
(match-data))))
(setq match-tail
(save-match-data
(goto-char end)
(skip-chars-backward "[:blank:]")
(when (looking-back tail-regex)
(match-data))))
;; Double check there is no overlap.
(<= (save-match-data
(set-match-data match-head)
(match-end 0))
(save-match-data
(set-match-data match-tail)
(match-beginning 0))))
;; Remove multi-line comment.
(dolist (match (list match-tail match-head))
(save-match-data
(set-match-data match)
(goto-char (match-beginning 0))
(replace-match "" t nil nil))
(beginning-of-line)
(when (looking-at-p "[[:blank:]]*$")
(kill-whole-line)))
;; Add multi-line comment.
(goto-char end)
(insert tail)
(indent-according-to-mode)
(insert "\n")
(goto-char beg)
(insert head)
(indent-according-to-mode)
(insert "\n"))))))
(defun my-comment-multi-line-toggle (&optional head tail head-regex tail-regex)
"Toggle multi-line comments for various languages."
(interactive)
(cond
;; Support optionally passing in arguments.
((and head tail head-regex tail-regex)
(my-comment-multi-line-toggle--impl
head tail head-regex tail-regex))
((member major-mode '(c-mode c++-mode glsl-mode))
(my-comment-multi-line-toggle--impl
"#if 0"
"#endif"
"^[[:blank:]]*#[[:blank:]]*if[[:blank:]]+0[[:blank:]]*$"
"^[[:blank:]]*#[[:blank:]]*endif[[:blank:]]*$"))
((member major-mode '(lua-mode))
(my-comment-multi-line-toggle--impl
"--[["
"]]"
"^[[:blank:]]*\\-\\-\\[\\[[[:blank:]]*$"
"^[[:blank:]]*\\]\\][[:blank:]]*$"))
((member major-mode '(cmake-mode))
(my-comment-multi-line-toggle--impl
"#[["
"]]"
"^[[:blank:]]*#\\[\\[[[:blank:]]*$"
"^[[:blank:]]*\\]\\][[:blank:]]*$"))
((member major-mode '(python-mode))
(my-comment-multi-line-toggle--impl
"'''"
"'''"
"^[[:blank:]]*\\('''\\|\"\"\"\\)[[:blank:]]*$"
"^[[:blank:]]*\\('''\\|\"\"\"\\)[[:blank:]]*$"))
(t
(user-error "Multi-line comment unsupported major mode '%s'" major-mode))))
```
> 0 votes
---
Tags: c, comment
---
|
thread-52187
|
https://emacs.stackexchange.com/questions/52187
|
Is there a way (a package?) to "redirect" pop-up menus to the minibuffer, ido, or completion buffer; either generic or flyspell-specific
|
2019-08-17T03:42:38.380
|
# Question
Title: Is there a way (a package?) to "redirect" pop-up menus to the minibuffer, ido, or completion buffer; either generic or flyspell-specific
Sometimes I must use Emacs (in X mode) over a network connection (for example, working on a cloud VM). I am pretty comfortable with the interface responsiveness inside a frame, although X is notoriously sensitive to network delays. But when it comes to any type of creating a new X window, be it a menu, a tooltip or a new frame, I'm looking at a few seconds wait. Tolerably painful if I want a new frame--this is not something I do often--but entirely unusable for a menu.
Unfortunately, flyspell, that I often use, is hard-coded to invoke `x-popup-menu`¹. Fixing a typo manually is certainly faster than popping up the menu, but there is not a function in it to add the word to dictionary, and this is where the menu gets me.
But nothing in principle prevents one from fbinding their own override version of `x-popup-menu` to intercept calls to it. So my question is, essentially, two-part:
1. Is there a more or less generic way (a package, presumably) that converts pop-up menus into (ideally) ido prompts, or other in-frame interface, e. g., the usual completion buffer? This would be a win for me!
2. If such a thing does not exist, is there a flyspell-specific modification: a package that hooks into flyspell, or a fork that does not use menus, or just anything but the popups?
---
I am aware of certain alternatives. For example, I use tramp mode over SSH when feasible and edit remote files in a local, responsive Emacs. But it often happens that all I have on me is a Windows laptop, so a remote X client is the only practical option.
---
¹ Tangentially, and curiously, for the (late) XEmacs flyspell has a separate code path that invokes the more general, window-system-agnostic `popup-menu` function, which exists, and is *supposedly* compatible, in GNU Emacs. Even though the XEmacs project has been thoroughly dead for a decade, being one of its major developers, I can't stop wondering what was the reason for this...
# Answer
> 1 votes
Not quite sure what you're asking, but this might be a partial answer, although I don't think it applies to `(x-)popup-menu`.
If some code explicitly invokes `(x-)popup-menu` then it has chosen to use a popup menu. As far as I know, you have no choice in that case; it's hard-coded.
You could of course copy the source code, change it to use keyboard input, and use your own, modified commands instead of those provided by the library. You could also request that the library maintainer offer users a choice in this.
---
Here's what I was going to mention, which is not about popup menus:
If you customize option `use-dialog-box` to non-`nil` then mouse-initiated commands use dialog boxes instead of the keyboard to query you.
If you also customize `use-file-dialog` to non-`nil` then the same happens for file selection: a file-selection dialog box is used. In this case the dialog box is used even if the command is initiated from the keyboard.
On MS Windows, if you customize option `w32-use-w32-font-dialog` to non-`nil` then font selection uses the standard Windows font-selection dialog.
# Answer
> 0 votes
I forgot that I asked this question before, got frustrated by the slow link again, started googling, and this was the first page that came up in search. Not a good sign... So I did it. Hope someone would use it one day.
This relies on string keys in `plist` be `eq` to strings in `choices`: this is how `plist-get` works; the strings must not be copied. Not that I can think of a scenario where that would make sense; a reminder just in case.
If someone would want to make that into a package, please do. This can be generalized by attaching a concrete function (like this one which parses the menu and returns something that `flyspell-correct-word-before-point` expects to get from its `x-popup-menu` call) as a property of a command symbol (`'flyspell-correct-word-before-point` in this case).
```
(require 'ido)
;; This can be generalized by attaching a property to command symbol.
(defun x-popup-menu--advice-around (f &rest args)
(if (or (not (eq 'flyspell-correct-word-before-point this-command))
(ignore-errors (mouse-event-p (car args))))
(apply f args) ; Not our guy, or called via a mouse event, run normally.
;; Called via keyboard, do ido-completing-read.
(let* ((mdesc (cadadr args))
(prompt (concat (car mdesc) ": ")) ; Menu title.
(mbody (cdr mdesc)) ; Menu body: (("foo" "foo") ... "" ... ) ; Menu body.
(plist (mapcan (lambda (p) (and p (listp p)
(list (car p) (cdr p))))
mbody)) ; (display_name (value) ... )
(choices (mapcan (lambda (p) (and p (listp p)
(list (car p))))
mbody))) ; (display_name ...)
;; Every value in the plist is a 1-element list.
(plist-get plist
(ido-completing-read prompt choices nil t)))))
(add-hook 'flyspell-mode-hook
(lambda ()
(if (not flyspell-mode)
(advice-remove 'x-popup-menu #'x-popup-menu--advice-around)
(advice-add 'x-popup-menu :around #'x-popup-menu--advice-around)
(define-key flyspell-mode-map [(control ?\.)]
#'flyspell-correct-word-before-point))))
```
---
Tags: package, ido, menus
---
|
thread-56275
|
https://emacs.stackexchange.com/questions/56275
|
Spacemacs Unable to use dap mode for Spring Boot web app
|
2020-03-21T14:28:23.170
|
# Question
Title: Spacemacs Unable to use dap mode for Spring Boot web app
I am trying to set up a break point in my controller so that I can debug my spring boot web application within spacemacs. Can someone walk me through the steps on doing this.
The steps I have done so far are
1. start up the spring boot application in debug mode with the 8000 port as the debug port. I did this by adding to my pom the following.
```
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<jvmArguments>-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=8000</jvmArguments>
</configuration>
</plugin>
</plugins>
</build>
```
2. execute the `mvn spring-boot:run` command. I have added the entire command run below with the logs. It does show 8000 port listening
3. `M-x dap-debug`
4. I select Java-Attach
5. I enter `8000` as the debug port
I have added an image of my controller that has breakpoints. One thing I notice is that in the bottom bar it shows `localhost(8000) - pending`. So it seems that dap does not attach to the debug port.
I am not sure if this is relevant to this issue, but I am currently spacemacs develop branch.
```
~/P/b/backup02-after-hello-world-path-param λ mvn spring-boot:run
[INFO] Scanning for projects...
[INFO]
[INFO] -------< com.in28minutes.rest.webservices:restful-web-services >--------
[INFO] Building restful-web-services 0.0.1-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] >>> spring-boot-maven-plugin:2.0.0.RELEASE:run (default-cli) > test-compile @ restful-web-services >>>
[INFO]
[INFO] --- maven-resources-plugin:3.0.1:resources (default-resources) @ restful-web-services ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 1 resource
[INFO] Copying 0 resource
[INFO]
[INFO] --- maven-compiler-plugin:3.7.0:compile (default-compile) @ restful-web-services ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-resources-plugin:3.0.1:testResources (default-testResources) @ restful-web-services ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory c:\Users\dmsil\Projects\backup02-after-hello-world-path-param\backup02-after-hello-world-path-param\src\test\resources
[INFO]
[INFO] --- maven-compiler-plugin:3.7.0:testCompile (default-testCompile) @ restful-web-services ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] <<< spring-boot-maven-plugin:2.0.0.RELEASE:run (default-cli) < test-compile @ restful-web-services <<<
[INFO]
[INFO]
[INFO] --- spring-boot-maven-plugin:2.0.0.RELEASE:run (default-cli) @ restful-web-services ---
[INFO] Attaching agents: []
Listening for transport dt_socket at address: 8000
10:19:35.252 [main] DEBUG org.springframework.boot.devtools.settings.DevToolsSettings - Included patterns for restart : []
10:19:35.254 [main] DEBUG org.springframework.boot.devtools.settings.DevToolsSettings - Excluded patterns for restart : [/spring-boot-starter/target/classes/, /spring-boot-autoconfigure/target/classes/, /spring-boot-starter-[\w-]+/, /spring-boot/target/classes/, /spring-boot-actuator/target/classes/, /spring-boot-devtools/target/classes/]
10:19:35.256 [main] DEBUG org.springframework.boot.devtools.restart.ChangeableUrls - Matching URLs for reloading : [file:/C:/Users/dmsil/Projects/backup02-after-hello-world-path-param/backup02-after-hello-world-path-param/target/classes/]
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v2.0.0.RELEASE)
2020-03-21 10:19:35.590 INFO 10852 --- [ restartedMain] c.i.r.w.r.RestfulWebServicesApplication : Starting RestfulWebServicesApplication on DESKTOP-CQC5H52 with PID 10852 (C:\Users\dmsil\Projects\backup02-after-hello-world-path-param\backup02-after-hello-world-path-param\target\classes started by dmsil in c:\Users\dmsil\Projects\backup02-after-hello-world-path-param\backup02-after-hello-world-path-param)
2020-03-21 10:19:35.591 INFO 10852 --- [ restartedMain] c.i.r.w.r.RestfulWebServicesApplication : No active profile set, falling back to default profiles: default
2020-03-21 10:19:35.642 INFO 10852 --- [ restartedMain] ConfigServletWebServerApplicationContext : Refreshing org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext@2e66ae0c: startup date [Sat Mar 21 10:19:35 EDT 2020]; root of context hierarchy
2020-03-21 10:19:37.086 INFO 10852 --- [ restartedMain] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration' of type [org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration$$EnhancerBySpringCGLIB$$f29ac588] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2020-03-21 10:19:38.020 INFO 10852 --- [ restartedMain] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8080 (http)
2020-03-21 10:19:38.045 INFO 10852 --- [ restartedMain] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2020-03-21 10:19:38.045 INFO 10852 --- [ restartedMain] org.apache.catalina.core.StandardEngine : Starting Servlet Engine: Apache Tomcat/8.5.28
2020-03-21 10:19:38.054 INFO 10852 --- [ost-startStop-1] o.a.catalina.core.AprLifecycleListener : The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: [C:\Program Files\Java\jdk1.8.0_241\jre\bin;C:\Windows\Sun\Java\bin;C:\Windows\system32;C:\Windows;c:\Windows\system32;c:\Windows;c:\Windows\System32\Wbem;c:\Windows\System32\WindowsPowerShell\v1.0;c:\Windows\System32\OpenSSH;c:\apache-maven-3.6.3\bin;c:\Program Files\Git\cmd;c:\Program Files\Java\jdk1.8.0_241\bin;c:\Program Files (x86)\Common Files\Oracle\Java\javapath;c:\Users\dmsil\AppData\Local\Microsoft\WindowsApps;.;c:\emacs-26.3-x86_64\libexec\emacs\26.3\x86_64-w64-mingw32;;.]
2020-03-21 10:19:38.158 INFO 10852 --- [ost-startStop-1] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2020-03-21 10:19:38.158 INFO 10852 --- [ost-startStop-1] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 2518 ms
2020-03-21 10:19:38.339 INFO 10852 --- [ost-startStop-1] o.s.b.w.servlet.ServletRegistrationBean : Servlet dispatcherServlet mapped to [/]
2020-03-21 10:19:38.340 INFO 10852 --- [ost-startStop-1] o.s.b.w.servlet.ServletRegistrationBean : Servlet webServlet mapped to [/h2-console/*]
2020-03-21 10:19:38.340 INFO 10852 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'characterEncodingFilter' to: [/*]
2020-03-21 10:19:38.344 INFO 10852 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'hiddenHttpMethodFilter' to: [/*]
2020-03-21 10:19:38.344 INFO 10852 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'httpPutFormContentFilter' to: [/*]
2020-03-21 10:19:38.344 INFO 10852 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'requestContextFilter' to: [/*]
2020-03-21 10:19:38.506 INFO 10852 --- [ restartedMain] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Starting...
2020-03-21 10:19:38.687 INFO 10852 --- [ restartedMain] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Start completed.
2020-03-21 10:19:38.738 INFO 10852 --- [ restartedMain] j.LocalContainerEntityManagerFactoryBean : Building JPA container EntityManagerFactory for persistence unit 'default'
2020-03-21 10:19:38.760 INFO 10852 --- [ restartedMain] o.hibernate.jpa.internal.util.LogHelper : HHH000204: Processing PersistenceUnitInfo [
name: default
...]
2020-03-21 10:19:38.832 INFO 10852 --- [ restartedMain] org.hibernate.Version : HHH000412: Hibernate Core {5.2.14.Final}
2020-03-21 10:19:38.836 INFO 10852 --- [ restartedMain] org.hibernate.cfg.Environment : HHH000206: hibernate.properties not found
2020-03-21 10:19:38.881 INFO 10852 --- [ restartedMain] o.hibernate.annotations.common.Version : HCANN000001: Hibernate Commons Annotations {5.0.1.Final}
2020-03-21 10:19:39.005 INFO 10852 --- [ restartedMain] org.hibernate.dialect.Dialect : HHH000400: Using dialect: org.hibernate.dialect.H2Dialect
2020-03-21 10:19:39.265 INFO 10852 --- [ restartedMain] o.h.t.schema.internal.SchemaCreatorImpl : HHH000476: Executing import script 'org.hibernate.tool.schema.internal.exec.ScriptSourceInputNonExistentImpl@27ee34'
2020-03-21 10:19:39.269 INFO 10852 --- [ restartedMain] j.LocalContainerEntityManagerFactoryBean : Initialized JPA EntityManagerFactory for persistence unit 'default'
2020-03-21 10:19:39.737 INFO 10852 --- [ restartedMain] s.w.s.m.m.a.RequestMappingHandlerAdapter : Looking for @ControllerAdvice: org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext@2e66ae0c: startup date [Sat Mar 21 10:19:35 EDT 2020]; root of context hierarchy
2020-03-21 10:19:39.813 WARN 10852 --- [ restartedMain] aWebConfiguration$JpaWebMvcConfiguration : spring.jpa.open-in-view is enabled by default. Therefore, database queries may be performed during view rendering. Explicitly configure spring.jpa.open-in-view to disable this warning
2020-03-21 10:19:39.867 INFO 10852 --- [ restartedMain] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/hello-world/path-variable/{name}],methods=[GET]}" onto public com.in28minutes.rest.webservices.restfulwebservices.HelloWorldBean com.in28minutes.rest.webservices.restfulwebservices.HelloWorldController.helloWorldPathVariable(java.lang.String)
2020-03-21 10:19:39.868 INFO 10852 --- [ restartedMain] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/hello-world],methods=[GET]}" onto public java.lang.String com.in28minutes.rest.webservices.restfulwebservices.HelloWorldController.helloWorld()
2020-03-21 10:19:39.868 INFO 10852 --- [ restartedMain] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/hello-world-bean],methods=[GET]}" onto public com.in28minutes.rest.webservices.restfulwebservices.HelloWorldBean com.in28minutes.rest.webservices.restfulwebservices.HelloWorldController.helloWorldBean()
2020-03-21 10:19:39.874 INFO 10852 --- [ restartedMain] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/error]}" onto public org.springframework.http.ResponseEntity<java.util.Map<java.lang.String, java.lang.Object>> org.springframework.boot.autoconfigure.web.servlet.error.BasicErrorController.error(javax.servlet.http.HttpServletRequest)
2020-03-21 10:19:39.875 INFO 10852 --- [ restartedMain] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/error],produces=[text/html]}" onto public org.springframework.web.servlet.ModelAndView org.springframework.boot.autoconfigure.web.servlet.error.BasicErrorController.errorHtml(javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse)
2020-03-21 10:19:39.945 INFO 10852 --- [ restartedMain] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped URL path [/webjars/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2020-03-21 10:19:39.945 INFO 10852 --- [ restartedMain] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped URL path [/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2020-03-21 10:19:40.006 INFO 10852 --- [ restartedMain] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped URL path [/**/favicon.ico] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2020-03-21 10:19:40.305 INFO 10852 --- [ restartedMain] o.s.b.d.a.OptionalLiveReloadServer : LiveReload server is running on port 35729
2020-03-21 10:19:40.508 INFO 10852 --- [ restartedMain] o.s.j.e.a.AnnotationMBeanExporter : Registering beans for JMX exposure on startup
2020-03-21 10:19:40.508 INFO 10852 --- [ restartedMain] o.s.j.e.a.AnnotationMBeanExporter : Bean with name 'dataSource' has been autodetected for JMX exposure
2020-03-21 10:19:40.513 INFO 10852 --- [ restartedMain] o.s.j.e.a.AnnotationMBeanExporter : Located MBean 'dataSource': registering with JMX server as MBean [com.zaxxer.hikari:name=dataSource,type=HikariDataSource]
2020-03-21 10:19:40.544 INFO 10852 --- [ restartedMain] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 8080 (http) with context path ''
2020-03-21 10:19:40.548 INFO 10852 --- [ restartedMain] c.i.r.w.r.RestfulWebServicesApplication : Started RestfulWebServicesApplication in 5.279 seconds (JVM running for 5.795)
```
# Answer
> 1 votes
There is currently a bug in the dap java package that is preventing dap from running on Windows operating system.
I was able to run it successfully in mac os. I also assume it should work on Linux too.
I found a git ticket on this issue https://github.com/emacs-lsp/dap-mode/issues/214
Hopefully someone will fix this bug in the future.
---
Tags: spacemacs, java
---
|
thread-56295
|
https://emacs.stackexchange.com/questions/56295
|
SPC key shortcut is not working in spacemacs
|
2020-03-22T20:01:28.697
|
# Question
Title: SPC key shortcut is not working in spacemacs
I've spacemacs installed in my ubuntu/opensuse OS
emacs version 26.3.
SPC shortcut is not working for my spacemacs.
I'm getting message `Buffer is read-only: #<buffer *spacemacs*>`
Below is the screenshot -
How can I make SPC key work for my spacemacs?
# Answer
> 0 votes
Spacemacs by default has the SPC key as leader.
Double check this in the .spacemacs file (which is by default in home directory).
Check that the following line exists in the configuration.
```
dotspacemacs-leader-key "SPC"
```
If this does not work check for boot up errors.
Check \*Messages\* buffer to see if there are any errors while booting up.
One other thing I notice is that the powerline has a blue color in it. This blue color means you are in emacs mode. When you were setting it up for the first time you might have selected emacs keybinding. In this case just delete the .spacemacs file then reopen.
When it first opens it will ask you.
What is your perfered editing style?
Select the below option
Among the stars aboard the Evil flagship (vim)
---
Tags: spacemacs
---
|
thread-56291
|
https://emacs.stackexchange.com/questions/56291
|
Exclude org_archive files from agenda
|
2020-03-22T15:38:53.317
|
# Question
Title: Exclude org_archive files from agenda
In `~/.emacs/init.el` i have:
```
(setq org-agenda-files (list "~/org"))
```
Most of the .org files in that directory have associated .org\_archive files with a long history of archived TODO tasks.
When I run org-agenda, it collects any TODO item in the .org\_archive files.
Is there a regex type solution to exclude files ending in `.org_archive`? I've previously identified individual files to include in the agenda view but that's getting a little cumbersome.
The value of `org-agenda-file-regexp` is:
```
"\\`[^.].*\\.org\\'"
```
# Answer
> 2 votes
Check the value of `org-agenda-archive-mode`. In my case it was set to true in my init.el.
```
(setq org-agenda-archives-mode t)
```
Setting it to `nil` (the default) makes it so that archived items are not included in the agenda.
The docstring of the variable says:
> Non-nil means the agenda will include archived items. If this is the symbol ‘trees’, trees in the selected agenda scope that are marked with the ARCHIVE tag will be included anyway. When this is t, also all archive files associated with the current selection of agenda files will be included.
---
Tags: org-mode, org-agenda
---
|
thread-54886
|
https://emacs.stackexchange.com/questions/54886
|
Spacemacs config on OSX is not detected?
|
2020-01-13T12:19:52.507
|
# Question
Title: Spacemacs config on OSX is not detected?
I have installed spacemacs following this tutorial: https://github.com/syl20bnr/spacemacs#prerequisites
The spacemacs config is not detected.
The `$HOME` dir is set to `/home/<username>` and is correct.
Upon running `emacs --insecure` errors with "Unknown command insecure" So I tried running emacs and manually setting the path to emacs.d dir like so:
`emacs --load ~/.emacs.d/init.el` and I got the following error: `no such file or directory core-spacemacs`
I am pretty sure that I am missing something, since I am following the official tutorial, but I can't figure out what to do.
I think the config isn't loaded properly but since these are my first steps I am having a hard time debugging further.
Help appreciated!
PS: OSX Catalina
```
emacs --version
GNU Emacs 28.0.50
```
# Answer
> -1 votes
I believe I may have an idea why this is occurring. I had a similar problem earlier today where the command line in spacemacs was not finding my environment variables.
The reason this happened to me was that spacemacs uses zsh by default (not bash). I had environment variable for bash setup, but not for zsh.
To resolve this issue I created a .zshrc file in my home directory that held all my environment variables.
To see if this is the reason go to the command line within spacemacs. Type in a command line `echo $HOME`. If nothing is printed then you can conclude that it was caused by the environment variables not being found. Just create a .zshrc file (within your profile directory) with all of your environment variables.
---
Tags: spacemacs
---
|
thread-56297
|
https://emacs.stackexchange.com/questions/56297
|
Hide org-table rows outside certain date ranges?
|
2020-03-22T20:50:26.167
|
# Question
Title: Hide org-table rows outside certain date ranges?
Excel tables lets us show just the rows that have "July 2018" in a specific column, and hide the rest. Or to show "21st August 2017-30th August 2017, and also July 2018, and also all of 2019", and filter away the rest
How can we most easily do this with org-tables?
# Answer
> 2 votes
You can create an overlay that hides lines with `(make-overlay (line-beginning-position) (1+ (line-end-position)))` and `(overlay-put ol 'invisible t)`.
The following Elisp Org formula hides the line with the element `21` in its first column. It just shows the principle and has much room for improvement. E.g., multiple evaluation of the org formula results in multiple overlapping overlays.
The lisp form is called for side-effect only therefore it just returns `$1`.
```
| 11 | 12 | 13 |
| 21 | 22 | 23 |
| 31 | 32 | 33 |
#+TBLFM: $1='(progn (when (equal $1 "21") (let ((ol (make-overlay (line-beginning-position) (1+ (line-end-position))))) (overlay-put ol 'invisible t))) $1)
```
I just use `remove-overlays` to remove the overlays when I want to.
For convenience I gave `remove-overlays` an interactive form:
```
(defun remove-overlays-interactive-form (&rest _args)
"Make `remove-overlays' interactive.
Forward _ARGS to `remove-overlays'."
(interactive (when (region-active-p)
(list (region-beginning) (region-end)))))
(advice-add 'remove-overlays :before #'remove-overlays-interactive-form)
```
That way I only need to select a region - in our example the table - and run `M-x` `remove-overlays` `RET`.
---
Tags: org-mode, org-table, time-date, filtering
---
|
thread-56261
|
https://emacs.stackexchange.com/questions/56261
|
Emacs acting strangely with indentation
|
2020-03-20T09:54:57.357
|
# Question
Title: Emacs acting strangely with indentation
So I've recently come back to working with emacs again I mostly write JavaScript in particular React these days and I'm noticing some strange behaviour when trying to indent my code.
it seems the indentation will only work for the first couple of times and then everything after a certain point has to be on the same indent. For example:
```
import React from 'react';
const About = () => {
return (
<div className="about">
<div className="header">
</div>
</div>
);
}
export default About;
```
You will notice that the react component above that the header div is indented to the same level as the about container. but all other indentation is fine. If I try to add any further elements in the header or anywhere else in the container the indentation remains the same too.
Here is my .emacs (apologies for the mess):
```
;; Include MELPA packages
(when (>= emacs-major-version 24)
(require 'package)
(package-initialize)
(add-to-list 'package-archives '("melpa" . "http://melpa.milkbox.net/packages/") t)
)
;; KEY MODIFIERS
(global-set-key (kbd "M-3") '(lambda () (interactive) (insert "#")))
(defalias 'yes-or-no-p 'y-or-n-p)
;; YASNIPPET
(require 'yasnippet)
(yas-global-mode 1)
;; IDO MODE
(ido-mode 1)
(setq ido-file-extensions-order '(".js" ".json" ".scss" ".html" ".css" ".yml" ".rb"))
(setq ido-create-new-buffer 'always)
(setq ido-enable-flex-matching t)
(setq ido-everywhere t)
;; THEME
;; (load-theme 'tsdh-dark)
;; WEB MODE
(setq-default indent-tabs-mode nil)
(defun my-web-mode-hook ()
"Hooks for Web mode."
(setq web-mode-markup-indent-offset 2)
(setq web-mode-css-indent-offset 2)
(setq web-mode-code-indent-offset 2)
)
(add-hook 'web-mode-hook 'my-web-mode-hook)
(add-to-list 'auto-mode-alist '("\\.js\\'" . web-mode))
(add-to-list 'auto-mode-alist '("\\.scss\\'" . web-mode))
(add-to-list 'auto-mode-alist '("\\.html\\'" . web-mode))
(add-to-list 'auto-mode-alist '("\\.css\\'" . web-mode))
(add-to-list 'auto-mode-alist '("\\.jsx\\'" . web-mode))
(add-to-list 'auto-mode-alist '("\\.json\\'" . json-mode))
;; No more backup files
(setq make-backup-files nil)
;; FLYCHECK
(require 'flycheck)
;; turn on flychecking globally
(add-hook 'after-init-hook #'global-flycheck-mode)
;; disable jshint since we prefer eslint checking
(setq-default flycheck-disabled-checkers
(append flycheck-disabled-checkers
'(javascript-jshint)))
;; use eslint with web-mode for jsx files
(flycheck-add-mode 'javascript-eslint 'web-mode)
;; customize flycheck temp file prefix
(setq-default flycheck-temp-prefix ".flycheck")
;; disable json-jsonlist checking for json files
(setq-default flycheck-disabled-checkers
(append flycheck-disabled-checkers
'(json-jsonlist)))
;; https://github.com/purcell/exec-path-from-shell
;; only need exec-path-from-shell on OSX
;; this hopefully sets up path and other vars better
(when (memq window-system '(mac ns))
(exec-path-from-shell-initialize))
(custom-set-variables
;; custom-set-variables 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.
'(package-selected-packages
'(yasnippet exec-path-from-shell web-mode flycheck darkmine-theme json-mode js3-mode)))
(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.
)
```
I've been banging my head agasint this problem for most of the morning, so I thought it was time to ask on here. Any help towards getting my indentation working correctly would be a huge help!
TIA
# Answer
With `web-mode`, make sure your treating your code as React, not JavaScript.
Using your init file, and saving your example code to a file with a `.js` extension, I get the behavior you describe. Saving your example code to a `.jsx` file, the html is syntax highlighted and indented properly.
To specify ReactJS vs JavaScript you could mess with `web-mode-content-type` and/or `web-mode-set-content-type` a la this emacs.SE answer no html/jsx indentation in jsx-mode or expand what files get what content type a la this emacs.SE answer Formatting jsx in js files with web-mode. You can also settings on a per-project basis with directory local variables.
> 3 votes
# Answer
Solved: After some digging it turns out the solution is actually really simple you just need to tell web mode to act the same for.js and .jsx files by adding this line into your emacs config:
```
(setq web-mode-content-types-alist '(("jsx" . "\\.js[x]?\\'")))
```
> 2 votes
---
Tags: indentation, html, javascript
---
|
thread-56289
|
https://emacs.stackexchange.com/questions/56289
|
Why adding the display property does not work on some part of a file, while it works on other parts?
|
2020-03-22T14:04:49.373
|
# Question
Title: Why adding the display property does not work on some part of a file, while it works on other parts?
Let's say I have an org file with this content (this is the Org Manual):
```
*** System-wide header arguments
#+vindex: org-babel-default-header-args
```
The file is opened normally, highlighted and everything.
Now, as a test I try to add a display property to the S character of System:
```
(put-text-property (point) (1+ (point)) 'display "aaa")
```
It works. The S is replaced with aaa.
But if I try the same on a character on the vindex line then nothing happens.
Why is that?
# Answer
> 3 votes
The text property is removed by `font-lock` in `org-mode` buffers.
The list `org-font-lock-extra-keywords` contains the function `org-fontify-meta-lines-and-blocks` as a matcher of a font lock keyword for meta lines, i.e., lines starting with `#+` followed by a keyword.
That function calls `org-fontify-meta-lines-and-blocks-1` which has the following lines for lines matching `#+` at the beginning:
```
(t ;; just any other in-buffer setting, but not indented
(org-remove-flyspell-overlays-in (match-beginning 0) (match-end 0))
(remove-text-properties (match-beginning 0) (match-end 0)
'(display t invisible t intangible t))
(add-text-properties beg (match-end 0)
'(font-lock-fontified t face org-meta-line))
t)
```
One of the text properties removed there is the `display` property.
# Answer
> 2 votes
This complements the answer given by @Tobias, where it is explained how org-mode removes the `display` property.
One way to get around this is to use the variable `char-property-alias-alist`. It is used by Emacs to make one property to behave like another property. If you add `(display my-display)` to this list, you can set the property `my-display` on text and it would not be removed by org-mode.
The following is from the built-in documentation:
> Alist of alternative properties for properties without a value. Each element should look like (PROPERTY ALTERNATIVE1 ALTERNATIVE2...). If a piece of text has no direct value for a particular property, then this alist is consulted. If that property appears in the alist, then the first non-nil value from the associated alternative properties is returned.
---
Tags: org-mode, text-properties
---
|
thread-56309
|
https://emacs.stackexchange.com/questions/56309
|
Auto-refresh magit status only when magit is running
|
2020-03-23T19:04:33.403
|
# Question
Title: Auto-refresh magit status only when magit is running
I've seen the post Magit: Auto-refresh “magit-status”, and tarsius recommends the same method from the Magit manual to set `magit-after-save-refresh-status` to non-nil to the `after-save-hook`:
`(add-hook 'after-save-hook 'magit-after-save-refresh-status t)`
This is a great solution when a Magit buffer is available. However, if this setting causes some noisy warnings when saving a file when a Magit buffer is not available:
`run-hooks: Symbol’s function definition is void: magit-after-save-refresh-status`
How can I get around this such that this setting is active only when there is a Magit buffer available?
# Answer
The problem isn't that no Magit buffer exists but rather that Magit has not even been loaded. The result is that `Symbol’s function definition is void: magit-after-save-refresh-status`.
So you have to delay adding this function to the hook until it actually exists, like so:
```
(with-eval-after-load 'magit-mode
(add-hook 'after-save-hook 'magit-after-save-refresh-status t))
```
> 5 votes
---
Tags: init-file, magit, hooks
---
|
thread-56307
|
https://emacs.stackexchange.com/questions/56307
|
Set LaTex export fallback font
|
2020-03-23T17:03:08.853
|
# Question
Title: Set LaTex export fallback font
How do I set a fallback font for LaTex export to pdf?
I have the following setting in my `init.el`.
```
(setq org-latex-classes
'(("article"
"
\\documentclass[12pt,a4paper]{article}
\\usepackage{xeCJK}
%\\usepackage[heading]{CJK}
\\usepackage{zhnumber} % package for Chinese formatting of date time (use /zhtoday)
%\\usepackage[yyyymmdd]{datetime} % set date time to numeric
% Set default indentation
\\setlength\\parindent{12pt}
% Set Paper Size, Page Layout (another variable is 'bindingoffset')
\\usepackage[margin = 1.5in, paper = a4paper, inner = 2.5cm,
outer = 2.5cm, top = 3cm, bottom = 2.5cm]{geometry}
% Keep paragraph indentation while having a line break in between paragraphs.
\\edef\\restoreparindent{\\parindent=\\the\\parindent\\relax}
\\usepackage{parskip}
\\restoreparindent
% Indent first paragraph.
\\usepackage{indentfirst}
\\usepackage{titlesec}
\\usepackage{titling}
\\usepackage{fontspec} % packages for title and section-heading font setting.
% Set Font.
\\setsansfont{Arial Unicode MS}
\\setmainfont{Calibri} % Set serifed font to Calibri. Originally set to 'Times New Roman', but it cannot display certain characters such as ①②③.
\\setCJKmainfont{MingLiU}
\\setCJKsansfont{Kaiti TC} % Set Chinese font. NOTE: Remember to append CJK before of the font class. CJK HAS to be there for the font to show.
\\titleformat*{\\section}{\\fontsize{16}{18}\\bfseries\\sffamily}
\\titleformat*{\\subsection}{\\fontsize{14}{16}\\bfseries\\sffamily}
\\titleformat*{\\subsubsection}{\\fontsize{12}{14}\\bfseries\\sffamily} % Set formats for each heading level. 'sffamily' will point to the sans-serif font. In this case, 「楷體」.
\\renewcommand{\\maketitlehooka}{\\sffamily} % Set title font.
% Set quotation font.
\\usepackage{etoolbox}
\\newCJKfontfamily\\quotefont{Kaiti TC}
\\AtBeginEnvironment{quote}{\\quotefont\\normalsize}
% Tweak default settings.
\\renewcommand{\\baselinestretch}{1.2} % Set line width.
\\renewcommand{\\contentsname}{目次} % Translate content page title to Chinese. (Could possibly be done automatically with '\\usepackage[heading]{CJK}'. TODO experiment. )
% For text-boxes
\\usepackage{mdframed}
\\BeforeBeginEnvironment{minted}{\\begin{mdframed}}
\\AfterEndEnvironment{minted}{\\end{mdframed}}
% [FIXME] ox-latex 的設計不良導致 hypersetup 必須在這裡插入
\\usepackage{hyperref}
\\hypersetup{
colorlinks=true, %把紅框框移掉改用字體顏色不同來顯示連結
linkcolor=[rgb]{0,0.37,0.53},
citecolor=[rgb]{0,0.47,0.68},
filecolor=[rgb]{0,0.37,0.53},
urlcolor=[rgb]{0,0.37,0.53},
pagebackref=true,
linktoc=all,}
"
("\\section{%s}" . "\\section*{%s}")
("\\subsection{%s}" . "\\subsection*{%s}")
("\\subsubsection{%s}" . "\\subsubsection*{%s}")
("\\paragraph{%s}" . "\\paragraph*{%s}")
("\\subparagraph{%s}" . "\\subparagraph*{%s}"))
))
```
# Sample Org Document:
```
#+OPTIONS: toc:nil
#+BEGIN_QUOTE
㊀㊁㊂ ①②③
#+END_QUOTE
㊀㊁㊂ ①②③
```
# PDF generated:
---
As apparent from the above example, `Kaiti TC` contains the characters ㊀ etc. but `MingLiU` does not.
How can we define a fallback font for `CJKmainfont` so that ㊀㊁㊂ without the quote can be displayed properly?
# Answer
> 0 votes
I've found a working solution with the code below:
```
\\newCJKfontfamily\\fallbackfont{PingFang TC}
\\newunicodechar{㊀}{{\\fallbackfont ㊀}}
\\newunicodechar{㊁}{{\\fallbackfont ㊁}}
\\newunicodechar{㊂}{{\\fallbackfont ㊂}}
\\newunicodechar{㊃}{{\\fallbackfont ㊃}}
\\newunicodechar{㊄}{{\\fallbackfont ㊄}}
\\newunicodechar{㊅}{{\\fallbackfont ㊅}}
\\newunicodechar{㊆}{{\\fallbackfont ㊆}}
\\newunicodechar{㊇}{{\\fallbackfont ㊇}}
\\newunicodechar{㊈}{{\\fallbackfont ㊈}}
```
I would appreciate other suggestions to the problem, especially with shorter code.
---
Tags: latex, fonts
---
|
thread-56311
|
https://emacs.stackexchange.com/questions/56311
|
How to postpone loading a file until it's function is called?
|
2020-03-24T01:23:26.077
|
# Question
Title: How to postpone loading a file until it's function is called?
Say I have `foobar_utility.el` that defines an interactive function `foobar_utility`.
How can I postpone loading `foobar_utility.el` until `foobar_utility` is called?
Example usage:
```
(load (concat user-emacs-directory "foobar_utility.el") :nomessage t)
(global-set-key (kbd "<f1>") 'foobar_utility)
```
Is there a better way to do this besides moving the load into the key binding? e.g:
```
(global-set-key
(kbd "<f1>")
(lambda ()
(interactive)
(load (concat user-emacs-directory "foobar_utility.el") :nomessage t)
(call-interactively 'foobar_utility)))
```
# Answer
Put `(autoload 'foobar_utility "foobar_utility" nil t)` in your init file, and put `foobar_utility.el` in a directory in your `load-path`. Don't load the file explicitly.
See the Elisp manual, node Autoload.
---
In response to a comment:
This is an explicit sexp that invokes function `autoload`. You can use it *instead* of using `;;;###autoload` cookies and generating an autoloads file from them (which you then load from your init file). All an `;;;###autoload` cookie does is let you generate a file with autoload sexps like the one I showed.
Cookies can be convenient when you write a library that has many function definitions. Individual calls to function `autoload` can be convenient when you just want to autoload, from your init file, some functions that are defined in other files.
> 1 votes
---
Tags: autoload
---
|
thread-56315
|
https://emacs.stackexchange.com/questions/56315
|
\subsubsubsection instead of \paragraph in LaTeX export with header levels and section numbering > 3
|
2020-03-24T02:22:58.033
|
# Question
Title: \subsubsubsection instead of \paragraph in LaTeX export with header levels and section numbering > 3
How should I get a proper numbered header `\subsubsubsection{The Header}` instead of a numbered paragraph `\paragraph{The Header}` when exporting to LaTeX with header levels of more than 3?
Having this in my preamble:
```
% Set default Counter Depth
\\setcounter{tocdepth}{5}
\\setcounter{secnumdepth}{4}
```
And this in my Org file:
```
#+OPTIONS: H:5 num:t
```
Produces numbered paragraphs instead of proper headings at the fourth level and above.
The answer given over here did not solve the problem.
---
# Sample Data:
```
#+OPTIONS: H:5
* Section
some text
** Subsection
some text
*** Subsubsection
some text
**** Subsubsubsection
some text
```
# Answer
After some research, here is my solution to the problem.
Below is part of the `org-latex-classes` code:
```
\\usepackage{titlesec}
\\usepackage{titling}
\\usepackage{fontspec} % packages for title and section-heading font setting.
% Set Header and Numbering Depth
\\setcounter{tocdepth}{5}
\\setcounter{secnumdepth}{5}
% Set formats for each heading level. 'sffamily' will point to the sans-serif font. In this case, 「楷體」.
\\titleformat*{\\section}{\\fontsize{20}{22}\\bfseries\\sffamily}
\\titleformat*{\\subsection}{\\fontsize{18}{20}\\bfseries\\sffamily}
\\titleformat*{\\subsubsection}{\\fontsize{16}{18}\\bfseries\\sffamily}
% The `titlesec` package is used over here to make use of `\\paragraph` and `\\subparagraph` as headings. Up to five levels of headings can be implemented this way.
\\titleformat{\\paragraph}
{\\fontsize{14}{16}\\bfseries\\sffamily}{\\theparagraph}{1em}{}
% New line after heading. (`\\paragraph` and `\\subparagraph` would not automatically generate a new line after the heading text. )
\\titlespacing*{\\paragraph}{\\parindent}{3.25ex plus 1ex minus .2ex}{.75ex plus .1ex}
\\titleformat{\\subparagraph}
{\\fontsize{12}{14}\\bfseries\\sffamily}{\\thesubparagraph}{1em}{}
\\titlespacing*{\\subparagraph}{\\parindent}{3.25ex plus 1ex minus .2ex}{.75ex plus .1ex}
```
This lies right at the end of `org-latex-classes` to implement all 5 levels of subheadings:
```
("\\section{%s}" . "\\section*{%s}")
("\\subsection{%s}" . "\\subsection*{%s}")
("\\subsubsection{%s}" . "\\subsubsection*{%s}")
("\\paragraph{%s}" . "\\paragraph*{%s}")
("\\subparagraph{%s}" . "\\subparagraph*{%s}")
```
> 0 votes
---
Tags: org-export, latex-header
---
|
thread-56322
|
https://emacs.stackexchange.com/questions/56322
|
Set Consistent line spacing, irrespective of bold or underlines etc
|
2020-03-24T11:18:11.143
|
# Question
Title: Set Consistent line spacing, irrespective of bold or underlines etc
I current have set the current line number face to be bold:
```
`(line-number-current-line ((,class (:foreground "#4F4F4F" :background "#00CC00" :bold t))))
```
When I move the cursor between lines, there is a very unpleasant movement of all the text, as the line with the bold text takes up a little more height, so that line gets taller, and then contracts when the cursor moves past it.
This is just a single example of where this issue is popping up. Another example is if any highlighting makes the word bold (e.g. matching parenthesis).
If I change the line spacing, there is just extra space between the lines, and bold text still expands even though there is adequate space.
# Answer
> 0 votes
@Drew was right. Instead of using the default font, I downloaded a nice mono space font from Google (Roboto Mono), and that is working fine.
---
Tags: fonts, display
---
|
thread-56303
|
https://emacs.stackexchange.com/questions/56303
|
Emacs wsl grep fails on special characters
|
2020-03-23T11:33:42.140
|
# Question
Title: Emacs wsl grep fails on special characters
I'm using GNU Emacs 26.3 on a Windows 10 system (Virtualbox guest on Mac).
The following grep command inside emacs fails:
```
grep -i -n -d skip -e temp_ *
```
with this error:
```
grep -i -n -d skip -e temp_ * NUL
agrep: NUL: No such file or directory
Grep exited abnormally with code 2 at Mon Mar 23 12:27:03
```
If I run the command in the `wsl` shell it works.
The following grep command inside emacs also works fine:
```
grep -i -n -d skip -e temp *
```
*Note:* the missing _ at the end.
I tried escaping the underscore with `\` and `\\`, nothing helped.
Any ideas? Thanks a lot.
**Edit:** FYI: I'm using the following shell command, which works fine for other grep, make, etc. commands:
```
(setq explicit-shell-file-name "C:/Windows/System32/bash.exe")
(setq shell-file-name explicit-shell-file-name)
```
**as for Tobias request:** I run the 'grep command via my shortcut F5:
```
(global-set-key [f5] 'grep)
```
then:
```
Run grep (like this): grep -i -n -d skip -e temp_ *
```
# Answer
> 0 votes
Based on @Tobias valuable feedback it is now working. See the comments above for details. Here is the **summary**:
I was using the mingw-version of Emacs (means the windows version of emacs). Now I installed an X-Server and emacs in my wsl Ubuntu shell and now use this emacs instead. And the problem no longer occurs.
---
Tags: grep, wsl
---
|
thread-56274
|
https://emacs.stackexchange.com/questions/56274
|
Different indentation in files with same modes
|
2020-03-21T14:12:06.870
|
# Question
Title: Different indentation in files with same modes
My `.cxx` files have 8-character indentation, while `.cpp` files have 4-character one. They have exact same modes enabled:
My `auto-mode-alist` has the following c++ lines:
`("\\.ii\\'" . c++-mode)
("\\.h\\'" . c-or-c++-mode)
("\\.c\\'" . c-mode)
("\\.\\(CC?\\|HH?\\)\\'" . c++-mode)
("\\.[ch]\\(pp\\|xx\\|\\+\\+\\)\\'" . c++-mode)
("\\.\\(cc\\|hh\\)\\'" . c++-mode)`
How can I fix the `.cxx` files?
# Answer
As was pointed out by nega in the comments, I should have re-indented the file after fixing offset in my `init.el` file:
```
(setq c-default-style "linux"
c-basic-offset 4); <-- this changes the default value 8 to 4.
```
> 1 votes
---
Tags: c++
---
|
thread-21930
|
https://emacs.stackexchange.com/questions/21930
|
org-mode macro not evaluated inside link?
|
2016-04-28T18:02:02.400
|
# Question
Title: org-mode macro not evaluated inside link?
If I create a file with `{{{input-file}}}` as contents and export to HTML, the default macro is correctly evaluated to the filename. However, if I write `[[file:{{{input-file}}}.alternative][Alternative version]]` the macro is *not* evaluated. However, if I place the macro on the other part of the link: `[[file:manual.html.alternative][{{{input-file}}}.alternative]]` then it works! If I use it in a `#+BEGIN_HTML #+END_HTML` session instead of in a link the macro isn't evaluated either.
How can I fix this?
# Answer
> 1 votes
You can try a `emacs-lisp` `src` block with raw results.
For example:
```
#+begin_src emacs-lisp :exports results :results raw
(concat "[[file:./" (buffer-file-name) ".alternative]]" )
#+end_src
```
To get rid of confirmation messages, you can use the `org-confirm-babel-evaluate`variable. This is my setting:
```
(defun my-org-confirm-babel-evaluate (lang body)
(not (member lang '("dot" "emacs-lisp" "shell" "plantuml"))))
(setq org-confirm-babel-evaluate 'my-org-confirm-babel-evaluate)
```
---
Tags: org-mode, org-export
---
|
thread-56320
|
https://emacs.stackexchange.com/questions/56320
|
Delete from point to beginning of the line
|
2020-03-24T09:39:26.020
|
# Question
Title: Delete from point to beginning of the line
Have read the GNU manuals on erasing, killing, and deleting.
In bash `C-u` deletes from the cursor to the beginning. I have searched and in much disbelief can't find out what the equivalent is in emacs? Very often in a buffer and in the minibuffer I wish to delete from the cursor to the beginning of the line.
# Answer
There is `C-0 C-k` or `C-u 0 C-k`.
See section (info "(emacs) Killing by Lines").
> 10 votes
# Answer
`M-0 C-k` should do what you want.
> 1 votes
# Answer
I have `C-<backspace>` bound to the following function:
```
(defun phg/kill-to-bol ()
"Kill from point to beginning of line."
(interactive)
(kill-line 0))
```
Basically just the `C-u 0 C-k` from the other answer, see `kill-line`.
> 1 votes
---
Tags: deletion, kill-text
---
|
thread-56327
|
https://emacs.stackexchange.com/questions/56327
|
Appearance of Menubar titles in gui
|
2020-03-24T15:53:05.397
|
# Question
Title: Appearance of Menubar titles in gui
I have tried to get new version of Emacs using guix package manager. Which done successfully. Now I also have Emacs 26.1 alongside Emacs 24.
But I am facing a problem that the gui menu-bar titles appear as condensed. Little or no space in between. Please see the image.
I want it to look like properly legible and clear. I googled for the same but could not found the solution. Please guide me for that.
# Answer
It appears that several fonts are missing - the default font for the editor should be monospaced. Consider installing a font package, like `font-liberation`, for example.
GUIX will only use its own fonts by default, and won't employ your system fonts.
> 1 votes
---
Tags: menu-bar
---
|
thread-56339
|
https://emacs.stackexchange.com/questions/56339
|
Designate a speficied day of 20 days later
|
2020-03-25T02:01:05.167
|
# Question
Title: Designate a speficied day of 20 days later
Strike "C-u C-c ." to insert the current datetime,
```
<2020-03-25 Wed 09:56>
```
How could I designate a accurate day of 20 days later,
Currently, I invoke "Shift+ right-arrow" step-move the the day of 20 days later.
Is it possible to insert a future day with a method of "+20d"?
# Answer
The function `org-time-stamp` from the library `org.el` supports the increment/decrement day feature out of the box. In an `org-mode` buffer, type `C-c .` or `C-u C-c .` and then just type `+20` and press the enter/return key. The function `org-time-stamp` uses the function `org-read-date` -- to read the various options for `org-read-date`, type `M-x describe-function` aka `C-h f`.
---
Here is an alternative method that lets the user control the format of the time/date that gets inserted -- the format is hard-coded. The function `org-read-date` from the library `org.el` supports the increment/decrement day feature out of the box. The doc-strings for `org-read-date` and `format-time-string` are lengthy, so go ahead and type `M-x describe-function` aka `C-h f` to read about the various options. To try out this example using `my-org-insert-date` below, type `M-x my-org-insert-date` and then just type `+20` and press the enter key. This will work in any mode; i.e., there is no requirement that the buffer be in `org-mode` in order to use this example.
```
(require 'org)
(defun my-org-insert-date ()
"Insert a date at point using `org-read-date' with its optional argument
of TO-TIME so that the user can customize the date format more easily."
(interactive)
(let ((time (org-read-date nil 'to-time nil "Date: ")))
(insert (format-time-string "<%F %a %I:%M>" time))))
```
> 1 votes
---
Tags: org-mode, calendar
---
|
thread-56332
|
https://emacs.stackexchange.com/questions/56332
|
tramp runs on odt export --
|
2020-03-24T20:23:20.483
|
# Question
Title: tramp runs on odt export --
this is slightly embarrassing, but i'm confused about it so:
i run emacs 26.1, org 9.3.
when i use the org exporter to export a file to odt format, tramp fires up and runs on the newly created file. after the .odt is created, in *messages* i get a message like, `"Tramp: Opening connection for file /path/to/new/file.odt"` and i have a buffer (and tramp process?) named `*tramp/archive file /path/to/new/file.odt*`. the new odt file is 'mounted'. when i exit emacs, it first has to 'unmount' the file. it also shows up as a mounted 'drive' in my file manager. i find this very bizarre.
the only things in my init file about tramp are:
* tramp-backup-directory-alist (set to a file path)
* tramp-default-method (set to "ssh")
* tramp-mode-hook auto-sudoedit
my only org-export conf in my init it:
* require 'ox
* require 'ox extra
* ox-extras-activate '(ignore-headlines)
*
if this is too weird to help me troubleshoot: is there a way to just block/disable tramp? i very rarely use it, and use the odt exporter much more often.
# Answer
You are hit by the new tramp-archive.el package, which regards \*.odt files as an archive (like \*.tar files). In order to disable this, you might add the following to your ~/.emacs:
```
(with-eval-after-load 'tramp-archive
(setq tramp-archive-enabled nil))
```
However, there might be an error in the org exporter, because tramp-archive is activated only for a file name xxx.odt/ (note the trailing slash). Maybe you report this to the org people.
> 2 votes
---
Tags: org-export, tramp, odt
---
|
thread-56344
|
https://emacs.stackexchange.com/questions/56344
|
Using `dired-do-compress-to` with `tramp`
|
2020-03-25T07:42:49.137
|
# Question
Title: Using `dired-do-compress-to` with `tramp`
Within a `eamcs -q` session and in a `tramp` `dired` buffer and call `dired-do-compress-to` on a file, I got this eror
```
zip I/O error: No such file or directory
zip error: Could not create output file (/ssh:user@192.168.0.99:/home/user/Downloads/a.zip)
```
However, calling `dired-do-compress` on the same file is just OK.
How can I fix this?
# Answer
I can reproduce it with Emacs 28.0.50. Looks like an error; pls report it as Emacs bug via `M-x report-emacs-bug`.
> 1 votes
---
Tags: dired, tramp
---
|
thread-56319
|
https://emacs.stackexchange.com/questions/56319
|
Why needs syntax highlighting often a `revert-buffer`?
|
2020-03-24T08:57:14.937
|
# Question
Title: Why needs syntax highlighting often a `revert-buffer`?
Quite frequently, syntax highlighting in a given buffer is broken (i.e., a big fraction of the code is not highlighted). This is definitely not due to syntax errors, and the point at which highlighting stops quite often is in the middle of an identifier. Then, a `revert-buffer` regularly restores the highlighting. Of course, it is annoying to be forced to do so over and over again. What is the root cause of this, and how can one make the syntax highlighting more robust?
I observe this on python-mode buffers since I program almost exclusively in that language, but I have observed this in other modes, too.
# Answer
When there is an error in the syntax highlighting code, it is silently ignored by the font-lock package. When this happens, the buffer can be left in an unhighlighted state.
You can use the package font-lock-studio to investigate what happens, and catch errors in the font-lock code. It is a debugger that lets you step each part of the font-lock rules and if any rule triggers an error, the normal elisp debugger is invoked.
> 2 votes
---
Tags: python, font-lock, syntax, revert-buffer
---
|
thread-56323
|
https://emacs.stackexchange.com/questions/56323
|
Custom theme only loads changes every second start-up
|
2020-03-24T11:43:49.637
|
# Question
Title: Custom theme only loads changes every second start-up
Using Emacs 26.3. I made a theme file. If I change the theme, then restart Emacs the change is not applied. I have to close Emacs a second time, and then only on the second start up does the change take effect.
`init.el`:
```
(load-theme 'foo t)
(package-install-file (expand-file-name "foo-theme.el" user-emacs-directory))
```
Within the theme:
```
... other stuff ...
(custom-theme-set-faces
'foo
;; DEFAULT
`(default ((,class (:foreground "#FFFFFF" :background "#000000" :distant-foreground "#000000"))))
```
If I perform the following:
1. Comment out the `default` face in `foo-theme.el`
2. Save `foo-theme.el`
3. Close Emacs.
4. Open Emacs, open `foo-theme.el`, I see the change is still there but the face change was not applied to the default face (Emacs looks the same).
5. Close Emacs.
6. Open Emacs, and now I see that `foo-theme` has been applied correctly (default face looks as it should), and the `my-theme.el` file remains the same.
Why does it not apply correctly on the next start up of Emacs? How to fix it to load the theme correctly (maybe it is caching it somewhere)?
# Answer
My crystal ball says:
* `load-theme` loads the theme from `~/.emacs.d/elpa/foo-theme-<version>`
* then `package-install-file` takes your `~/.emacs.d/foo-theme.el` and installs it (aka copies it and compiles it) into `~/.emacs.d/elpa/foo-theme-<version>`.
So the first time you run Emacs after changing `~/.emacs.d/foo-theme` you load the "old" file (and copy the new file to the elpa location, so you'll get to see the change on the second invocation).
> 4 votes
---
Tags: themes
---
|
thread-22516
|
https://emacs.stackexchange.com/questions/22516
|
Bind control left click
|
2016-05-25T10:32:43.193
|
# Question
Title: Bind control left click
I want to be able to jump to definition with control left click when editing c++ code. I tried
```
(define-key c++-mode-map [C-mouse-1] 'rtags-find-symbol-at-point)
```
This does not seem to work because emacs (24.5.1) already define a global behavior for C-mouse-1 (buffer navigation in graphical mode). The contextual window opens, but rtags-find-symbol-at-point is not called. Any way to make this work ?
# Answer
Try:
```
(define-key c++-mode-map [C-down-mouse-1] 'rtags-find-symbol-at-point)
```
> 2 votes
# Answer
For me the `C-down-mouse-1` solution worked, but still used the point from before the click. Thus I use now:
```
(define-key c-mode-base-map [C-down-mouse-1] 'mouse-drag-region)
(define-key c-mode-base-map [C-mouse-1] 'rtags-find-symbol-at-point)
```
so now, first the point gets set, then we find the correct symbol.
> 2 votes
---
Tags: key-bindings
---
|
thread-12613
|
https://emacs.stackexchange.com/questions/12613
|
Convert the first character to uppercase/capital letter using yasnippet
|
2015-05-22T11:39:08.343
|
# Question
Title: Convert the first character to uppercase/capital letter using yasnippet
**Q:** I have the following Yasnippet, which looks like this:
```
MYNAME - $1 (`(insert-mode-description)`).
$2
```
When I insert the snippet, the cursor starts on `$1`. Then I begin with typing. I would like to convert the first character of the sentence that I'm typing to uppercase.
When I look in the documentation of Yasnippet, there is a transformer that converts your text to uppercase. I need only to capitalize the first character.
Then I figured out another option:
```
MYNAME - $1 $2 (`(insert-mode-description)`).
$3
```
So Everything in `$1`-place gets converted to uppercase. Then press `tab`, to jump to `$2` and typing further in lowercase letters. But I'm not looking for that. Then I need to press `tab` every time after I insert the first character. I would just convert the first character of $1 to be uppercase. Any suggestion?
# Answer
## Function to capitalize only the first char
Make sure that the below function is evaluated in your emacs config before the `yasnippet` snippets are loaded.
```
(defun my/capitalize-first-char (&optional string)
"Capitalize only the first character of the input STRING."
(when (and string (> (length string) 0))
(let ((first-char (substring string nil 1))
(rest-str (substring string 1)))
(concat (capitalize first-char) rest-str))))
```
---
## Snippet
Here is a snippet that makes use of the above function
```
# -*- mode: snippet -*-
# name: intro
# key: zname
# --
Hi, my name is ${1:$$(my/capitalize-first-char yas-text)}.
$0
```
---
## Demo
Reference
> 8 votes
# Answer
You may find a working solution here.
**Function**
```
(defun capitalizeFirst (s)
(if (> (length s) 0)
(concat (upcase (substring s 0 1)) (downcase (substring s 1)))
nil))
```
Again put this function to your .emacs file before yasnippet initialization.
**Snippet**
```
# -*- mode: snippet -*-
# name: name
# key: name
# --
Hi, my name is ${1:$$(capitalizeFirst yas-text)}
```
Also some countries use different locales. According to Turkish locale if you convert *ırak* word which means far, distant to uppercase it should be converted like this *Irak*.
Here is a function which converts the first character of a string uppercase correctly according to Turkish locale.
**Function which converts first character according to Turkish locale**
```
(defun buyukHarfYap (metin)
(let (ilkHarf sesliMi)
(if (> (length metin) 0)
(progn
(setq ilkHarf (aref metin 0))
(if (eq ilkHarf 105) ; i harfi
(aset metin 0 ?İ))
(if (eq ilkHarf 305) ; ı harfi
(aset metin 0 ?I))
(if (eq ilkHarf 97) ; a harfi
(aset metin 0 ?A))
(if (eq ilkHarf 101) ; e harfi
(aset metin 0 ?E))
(if (eq ilkHarf 252) ; ü harfi
(aset metin 0 ?Ü))
(if (eq ilkHarf 111) ; o harfi
(aset metin 0 ?O))
(if (eq ilkHarf 246)
(aset metin 0 ?Ö)); ö harfi
(if (eq ilkHarf 117)
(aset metin 0 ?U)); u harfi
(setq ilkHarf (substring metin 0 1))
(setq sesliMi (string-match ilkHarf "AEIİOÖUÜ"))
(if (eq sesliMi nil)
(concat (upcase(substring metin 0 1)) (downcase (substring metin 1)))
(concat (substring metin 0 1) (downcase (substring metin 1)))))nil)))
```
> 2 votes
# Answer
Regarding the capitalization part, you can also use `s-capitalized-words` of the s.el library, which is a handy string library.
> 0 votes
---
Tags: yasnippet, capitalization
---
|
thread-16735
|
https://emacs.stackexchange.com/questions/16735
|
how to add date and time into spacemacs' mode line
|
2015-09-18T19:05:48.827
|
# Question
Title: how to add date and time into spacemacs' mode line
I usually use Spacemacs in maximized window, thus the date and time presented in mode line is a must.
I understand that spacemacs uses powerline mode to mimic vim, the manuals of both spacemacs and powerline does not tell how to add new section to display additional info (in this case it is date and time).
I have attempted to comprehend the nyan cat code in color layer, but my elisp skill did not satisfy.
# Answer
To get the time mode, just add `(display-time-mode 1)` to your `~/.spacemacs` configuration.
To get date and time, do this instead
```
;;display time in powerline
(spacemacs|define-mode-line-segment date-time-segment
(shell-command-to-string "echo -n $(date +%k:%M--%m-%d)")
)
(add-to-list 'spacemacs-mode-line-right 'date-time-segment)
```
Source: https://www.reddit.com/r/emacs/comments/3lu414/how\_to\_add\_date\_and\_time\_into\_spacemacs\_powerline/
I customized mine with this...
```
;; display time in powerline
(spacemacs|define-mode-line-segment date-time-segment
(shell-command-to-string "echo -n \"⏰ $(date '+%a %d %b %I:%M%p')\""))
(add-to-list 'spacemacs-mode-line-right 'date-time-segment)
)
```
so now my powerline looks like this
> 9 votes
# Answer
What worked for me was the following.
```
(spaceline-define-segment datetime
(shell-command-to-string "echo -n $(date '+%a %d %b %I:%M%p')"))
(spaceline-spacemacs-theme 'datetime)
```
I had to put that code in `user-config` section of `.spacemacs`.
> 3 votes
# Answer
Mine's working great just with:
```
(setq display-time-format "%H:%M:%S %a,%d %b %Y")
(display-time)
```
> 2 votes
# Answer
Emacs has native time functions: `current-time-string` and `format-time-string`. You should just have to eval one of those - i.e. `(current-time-string)`. This works fine for telephone line, so I would assume it's the same for powerline/spaceline/etc.
E.g.
```
(spaceline-define-segment datetime
(current-time-string))
(spaceline-spacemacs-theme 'datetime)
```
Here's the doc for `format-time-string` if you want something other than the default:
https://www.gnu.org/software/emacs/manual/html\_node/elisp/Time-Parsing.html
> 0 votes
---
Tags: spacemacs, powerline
---
|
thread-56353
|
https://emacs.stackexchange.com/questions/56353
|
What EWW Emacs Web Brower Would Be Used For
|
2020-03-25T14:18:16.483
|
# Question
Title: What EWW Emacs Web Brower Would Be Used For
Managed here to run `eww`, despite its requirements of `libxml2-dev` package BEFORE compiling and installing Emacs itself.
Have already browsed some websites, including some simple ones, only with basic Html an Css styling but coudn't find great utility in, once it renders quite strange browsing, finding `w3m` package much better for web browsing via command-line interface.
Anyway, what would `eww` be good for?
# Answer
I don't have any experience with `w3m`, so I don't know how it compares, but I've found EWW to work OK for Wikipedia, so I occasionally use it for that.
As for what it's *good* for: I use it to read/browse the OCaml and Coq documentation for which I find it works about as well as my browser with the advantage that it's actually faster and that I can navigate it in the usual way.
> 2 votes
---
Tags: eww, web-browser
---
|
thread-56358
|
https://emacs.stackexchange.com/questions/56358
|
Emacs shell not picking aliases from bashrc
|
2020-03-25T16:01:19.503
|
# Question
Title: Emacs shell not picking aliases from bashrc
NOT Working: `/bin/bash: Psu: command not found`
```
M-! cmd Psu
```
Working
```
M-! cmd ls
```
#### .bashrc
```
cat ~/.bashrc | grep Psu
cat ~/.bashrc | grep aliases
alias Psu='sudo pacman -Syyu'
if [ -f ~/.bash_aliases ]; then
. ~/.bash_aliases
```
#### .bash\_profile
```
cat ~/.bash_profile | grep -A 2 bashrc
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi
```
#### .bash\_aliases
```
cat ~/.bash_aliases
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi
```
I've read and followed: https://emacs.stackexchange.com/a/28999/21118
What am I missing?
# Answer
From the documentation:
> To specify the shell file name used by M-x shell, customize the variable `explicit-shell-file-name`. If this is nil (the default), Emacs uses the environment variable ESHELL if it exists. Otherwise, it usually uses the variable `shell-file-name`
You obviously want to use `bash` shell; may I suggest a piece of my Emacs configuration:
```
;; make emacs recognize my bash aliases and functions & use bash as default shell
(setq explicit-shell-file-name "/bin/bash")
(setq shell-file-name "bash")
(setq explicit-bash.exe-args '("--noediting" "--login" "-ic"))
(setq shell-command-switch "-ic")
(setenv "SHELL" shell-file-name)
```
> 1 votes
---
Tags: shell-command
---
|
thread-56340
|
https://emacs.stackexchange.com/questions/56340
|
Read first N lines of file into list
|
2020-03-25T02:47:09.657
|
# Question
Title: Read first N lines of file into list
The general way this seems to be done using Elisp is to first read the entire file using something like `insert-file-contents-literally` or `find-file-no-select`, using `split-string` on a newline, and then removing the unwanted elements:
```
(defun first-n (list &optional n)
"Return list containing the first N elements of LIST.
If N is nil, return the entire list."
(let ((n (or n (length list))))
(butlast list (- (length list) n))))
(defun read-lines (file &optional n delimiter)
"Return the first N lines of FILE as separate elements of a list.
If N is nil, return the entire file."
(let ((delimiter (or delimiter "\n")))
(first-n
(split-string
(with-temp-buffer
(insert-file-contents file)
(buffer-substring-no-properties
(point-min)
(point-max)))
delimiter
t)
n)))
```
This works but with the obvious drawback of reading the entire file.
What is a more efficient way to handle this?
Many of the file functions for Elisp are geared towards buffers than raw file processing. Looking at Common Lisp, it seems reading files is handled through streams. I couldn't find `with-open-file` in the `cl-lib` library. It doesn't seem like Elisp has any stream capabilities either.
Other than using the *BEG* and *END* arguments for `insert-file-contents-literally`, I can't think of a way to perform this task more efficiently.
# Answer
You're still going need to read the entire file, but you don't have to process every line, since you need just first N lines.
```
(defun your-read-lines (file n)
"Return first N lines of FILE."
(with-temp-buffer
(insert-file-contents-literally file)
(cl-loop repeat n
unless (eobp)
collect (prog1 (buffer-substring-no-properties
(line-beginning-position)
(line-end-position))
(forward-line 1)))))
```
It should be problematic if the file you're reading is larger than your available RAM, I guess it should be fine to tell Emacs to read a 1 GB file on a 4 GB RAM computer, that is, memory consumption is the concern, it should not be slow.
> 3 votes
---
Tags: files, read
---
|
thread-56304
|
https://emacs.stackexchange.com/questions/56304
|
Aquamacs: Display *Occur* in current frame
|
2020-03-23T12:37:21.180
|
# Question
Title: Aquamacs: Display *Occur* in current frame
I find that if I run `*Occur*` on different virtual displays, Aquamacs will reuse whichever frame `*Occur*` ran in the previous time, often giving me the results I want to see on a display which I am not currently looking at.
I could find nothing in https://www.emacswiki.org/emacs/AquamacsEmacsCompatibilitySettings about changing this back to the normal sane behavior, and I don't really understand how the "dedicated window" logic works, or whether that's what at play here. I have already implemented most of the other tweaks to get a "normal" Emacs, including setting `one-buffer-one-frame-mode` to `nil`.
In simple terms, how can I make sure the `*Occur*` buffer is displayed in the frame which is currently active, where I just ran `M-x occur`?
There are other functions which behave the same in Aquamacs, too; a general solution which turns off this buffer window reuse would be much preferred. For example, I often (but not always) see this with `*vc-log*` for getting diffs for a version-controlled file.
# Answer
> 1 votes
Aquamacs is a version of GNU Emacs configured to behave in a more OSX way like TextEdit. This means that each thing is in a separate OS Window. Later versions of Aquamacs and macOS have added tabs so things can open in a new tab.
Thus Aquamacs is behaving as designed.
You can limit the number of new OS Windows/Emacs frames that are opened by customising the One Buffer One Frame Mode to nil (note just setting it won't work). Aquamacs will open new things in the current frame.
However if you have already opened `*Occurs*` in one frame and then call it from another then Aquamacs will open the `*Occurs*` buffer in the frame it was already in and not your current frame.
I get annoyed with this as you are and now run Aquamacs as one Emacs Frame/OS Window, a sort of halfway house. That is I very rarely use the new frame command e.g. `⌘N` or `⌘T`
---
Tags: frames, aquamacs, occur, dedicated-windows
---
|
thread-56347
|
https://emacs.stackexchange.com/questions/56347
|
abbreviations do not expand
|
2020-03-25T10:54:41.487
|
# Question
Title: abbreviations do not expand
My abbreviations are not expanding when I type the abbreviations
I have the following in my `~/.emacs` for initiating the abbrev mode
```
(setq-default abbrev-mode t)
(setq save-abbrevs t)
(setq abbrev-file-name "~/abbrev.el")
(if (file-readable-p abbrev-file-name)
(read-abbrev-file abbrev-file-name))
(dolist (hook '(erc-mode-hook
emacs-lisp-mode-hook
text-mode-hook))
(add-hook hook #'abbrev-mode))
```
I get the following message saying that the abbreviation file is loaded
```
Loading /Users/baburaj/abbrev.el (source)...done
For information about GNU Emacs and the GNU system, type C-h C-a.
Mark set
Automatic display of crossref information was turned on
Applying style hooks...
Loading /Users/baburaj/auto/junk.el (source)...done
Loading /Users/baburaj/.emacs.d/elpa/auctex-12.2.0/style/article.elc...do
Applying style hooks...done
Sorting environment...done
Removing duplicates...done
Mark set
```
I also get the following when I type `M-x list-abbrev`
```
(text-mode-abbrev-table)
";af" 1 "aerofoil"
```
However when I type `;af` it does not expand to `aerofoil`
What is the error that I am making? How can I fix this?
# Answer
> 1 votes
From the documentation:
`M-x abbrev-mode` toggles Abbrev mode.
*Either*, you want Abbrev mode always on, everytime/everywhere, then you put the following in your ~/.emacs file: `(setq-default abbrev-mode t)`
*Either* you want Abbrev mode on, **but only for the some modes**, for example: `erc-mode`, `emacs-lisp-mode`, `text-mode`, in this case, you can put in your ~/.emacs file:
```
;; enable Abbrev mode only for erc, emacs-lisp, and text modes
(dolist (hook '(erc-mode-hook
emacs-lisp-mode-hook
text-mode-hook))
(add-hook hook #'abbrev-mode))
```
Now, it is also written in another part of the documentation that:
> and any word-constituent character can be part of an abbrev.
A `;` is not word constituent, unless you want it to be. So `a semicolon can't be part of an abbrev`.
Maybe it's time to write some Fortran :)
---
Tags: abbrev
---
|
thread-16444
|
https://emacs.stackexchange.com/questions/16444
|
How do you configure emacs for julia?
|
2015-09-08T11:01:24.083
|
# Question
Title: How do you configure emacs for julia?
What is a recomended way for making emacs as julia code editor? The things which I would like to have are:
* autocomplete
* julia shell in emacs with abbility to send the code from buffer
* debugging
# Answer
> 6 votes
The ESS development environment seems to support julia out of the box.
According to the documentation, it supports most of the features you mentioned:
* completion
* code evaluation
* error navigation (there doesn't seem to be a full debugger yet, though)
# Answer
> 4 votes
I am currently using these 2 Emacs packages:
everything is detailed in the julia-repl author's blog post.
It is the best I have found so far. I am quite happy with it and I prefer it to the previously cited ESS-Julia solution.
I still miss an auto-complete solution for Julia, though.
# Answer
> 1 votes
The latest project in this field (as of 2020) is Julia snail, which aims at providing development environment and REPL interaction package for Julia in the spirit of Common Lisp’s SLIME and Clojure’s CIDER.
It currently supports:
* REPL display and interaction
* cross-referencing
* auto-completion
---
Tags: shell, debugging, auto-complete-mode
---
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.