Emacs
Table of Contents
- 1. How to learn
- 2. Notes
- 3. Tips
- 4. Get image height/width in emacs
- 5. Bad Emacs Defaults
- 6. Debugging Emacs
- 7. Before submitting PRs to packages
- 8. Mouse while using Emacs inside terminal over ssh
- 9. Unfill Paragraph
- 10. Place Marker and jump back to that place
- 11. Clipboard from SSH Terminal to iTerm2
2. Notes
leuven theme is nice for light mode (especially org-mode)
Figure 1: A Theme
ESCis servers as a substitute for Meta key. Try:ESC xinstead ofM-x
3. Tips
3.1. Counsel Ripgrep
counsel-rg by default looks for a directory with .git and starts a search from there.
To limit the scope to current directory and its sub directories, not where .git is, use prefix argument before running counsel-rg then select which directory you want to run rg on.
3.2. Change face for some mode only
See example at org-config.el
;; a more noticable bold face for org mode in dark themes (spacemacs-dark) (face-remap-add-relative 'bold '(:weight bold :foreground "green3"))
4. Get image height/width in emacs
Open the dir of the image in dired. Keep the point on the file and
then run shell command M-! exiftool <file-name>
5. Bad Emacs Defaults
(setf sentence-end-double-space nil require-final-newline t) (add-hook programming-mode-hook (lambda () (setf show-trailing-whitespace t)))
5.1. backup-by-copying
https://news.ycombinator.com/item?id=37845995
Moving files to backup instead of copying is better. First, the file modification dates remain meaningful. When a backup is made, the backup file has a last modified date of when it was last changed and the new copy has the current time. It is also reversible if creating the new file fails for some reason. The backup file can moved back to the original location with a single file system operation and retains the right modification date.
It's also more robust in case of errors. Emacs can write new data to a temp file, confirm it succeeded then rename working to backup and new to working. You never have a situation where the working or backup file ends up half written.
5.2. sentence-end-double-space
This allows the editor to reliably differentiate between those periods (.) that are used in abbreviations and those that end sentences.
6. Debugging Emacs
https://emacsredux.com/blog/2025/02/03/debugging-emacs-commands/
Use Edebug.
Press C-u C-M-x while in the body of the function
7. Before submitting PRs to packages
Install flycheck-package and check the file with flycheck.
MELPA recommends this https://github.com/melpa/melpa/blob/master/CONTRIBUTING.org
8. Mouse while using Emacs inside terminal over ssh
Try M-x xterm-mouse-mode
9. Unfill Paragraph
Hit M-^ repeatedly
10. Place Marker and jump back to that place
Say you are at some place in the file writing stuff and you want to
make a small edit somewhere else in that file. You can first mark the
place you are at with C-SPC C-SPC. Then goto the next place, make the
changes and then C-u C-SPC to come back.
C-SPC C-SPCplaces a marker. ActuallyC-SPCmarks the place and activates the mark so that any movement selects the region. But if you do it twice, mark is first activated and then deactivated.C-u C-SPCpops back to the last mark.
11. Clipboard from SSH Terminal to iTerm2
iTerm2 + SSH + tmux + Emacs clipboard:
- Enable “Applications in terminal may access clipboard” in iTerm2
- in ~/.tmux.conf set
set -g set-clipboard on - in Emacs install and enable
clipetty
Now, copy in Emacs sends the clipboard info to terminal through OSC 52 escape sequence. Then iTerm2 picks that up and updates macOS clipboard.