## § Emacs Cheat Sheet

• M-q: fill-paragraph: make stuff 80 column, at least in text. so this is not that bad.
• C-u C-space: go back to where you were in the file.
• C-x r t: string-rectangle. insert new text in a rectangle ergoemacs ascii art . I bind this to C-x r i for insert.
• C-x r k: delete column of text. For kill.
• C-x space: rectangle-mark-mode to select rectangles. C-space to lay down mark. I bind it to C-x r r.

#### § Org

• C-c C-c: org-capture into code snippet.
• C-c C-d: open org-capture list.
• C-c C-o: follow a link.

#### § Auctex

• C-c C-a: compile file.
• C-c backtick: go to error.
• C-c C-v: view file.
• M-x TeX-error-overview: see all errors
• C-c C-s: enter section
• C-c C-e: enter environment (stuff in between \begin{}...\end{})
• M-g n: goto next error. M-g p: goto previous error.

### § Magit

• C-x g: pop up magit

### § LSP mode

(define-key lsp-mode-map (kbd "C-c l") lsp-command-map)

• C-c l g r: goto ref
• C-c l g g: goto definition

### § Eshell

• C-c C-r: go to output.
• C-u C-c C-r: narrow to output.
• cd =  gives a list to go do.
• Using C-c = gives a completion list.

### § Dired

• dired-jump: open current file in dired.

### § Gripes

#### § markdown-mode lags when I open a paren [for a link.

I suppose this is because it's attempting to match it, and is unable to figure out what to match to. I now edit markdown in text-mode.

#### § ctrl-backspace/ backward-kill-word kills far too much.

The answer seems to be: yes, it kills a word. You can redefine what a word is, and break lots of other stuff in the process, or redefine what ctrl-backspace does. However, as a non-expert, it's hard to say what redefining this will mean. Will it still interact with history the same way?

#### § there is no centralized notion of C-o (go back to where I came from).

Instead, it differentiates between "go back in buffer" versus "go back across buffers". This is extremely confusing when one is attempting to read code and understand control-flow: I want a unified way to say "go forward in my history; OK go back" when I am exploring code. I don't want to keep track of whether I came to this buffer from the same buffer or another buffer. The fact that emacs needs this is moronic. Furthermore, once a mark is popped, it is lost forever. In vim, one can navigate backwards and forwards across movement. This is not possible with emacs.

#### § Scrolling half a page is broken

There is no inbuilt functionality to scroll half a page. The canonical reference points to this:
(autoload 'View-scroll-half-page-forward "view")
(global-set-key (kbd "C-d") 'View-scroll-half-page-forward)
(global-set-key (kbd "C-u") 'View-scroll-half-page-backward)

However, this does not work well. On press C-u to go to the top of the file, it does not move the cursor to the top completely; once the first line is in view (with my cursor still on line 30), emacs obstinately refuses to scroll up with a 'beginning of buffer' message. I'm sure there's more elisp I can write to fix this, but the fact that something like moving-half-a-page is rocket science just rubs me the wrong way. This code that is given in emacswiki also has the exact same issue, I don't understand how the poster says they come from vim and did not notice this inconsistency.
(defun zz-scroll-half-page (direction)
"Scrolls half page up if direction' is non-nil, otherwise will scroll half page down."
(let ((opos (cdr (nth 6 (posn-at-point)))))
;; opos = original position line relative to window
(move-to-window-line nil)  ;; Move cursor to middle line
(if direction
(recenter-top-bottom -1)  ;; Current line becomes last
(recenter-top-bottom 0))  ;; Current line becomes first
(move-to-window-line opos)))  ;; Restore cursor/point position

(defun zz-scroll-half-page-down ()
"Scrolls exactly half page down keeping cursor/point position."
(interactive)
(zz-scroll-half-page nil))

(defun zz-scroll-half-page-up ()
"Scrolls exactly half page up keeping cursor/point position."
(interactive)
(zz-scroll-half-page t))

(global-set-key (kbd "C-d") 'zz-scroll-half-page-down)
(global-set-key (kbd "C-u") 'zz-scroll-half-page-up)


#### § Default encoding is weird: chinese-iso-8bit

Why in the world is this the option that shows up by default? There are so many better options, with utf-8 being the sanest of them all; this is a nice spherical cow of the problems with emacs: too much stuff, too like sanity. The spell is:
(set-language-environment "UTF-8")


#### § linum lags on large files

global-linum-mode lags on very long files.

#### § emacs lags on long lines

emacs lags given very long lines. A comment by eli-zaretskli on reddit says:
That is true, but the "fix" part misses the point. There's nothing wrong with the current algorithms, they just cannot handle these situations better than they already do. The main problem that makes redisplay slow in these cases is that, given a cursor motion command, such as C-n or M-v, the display engine needs first to find where in the buffer that command puts point. And that is non-trivial when variable-size fonts are supported and variable-size characters (or images) can be anywhere on display.
So there's a fundamental problem. He continues:
... we are talking about one of the following two alternatives: Add new members to the data structures used by the display engine, that would allow it to find good approximations for buffer positions corresponding to given screen coordinates, then augment the algorithms to generate and use this additional data. edesign the display code to use a model that is entirely different from the current simple 2D canvas.

#### § emacs crashes on attempting to open an SVG file

My emacs --version says:
╰─\$ emacs --version
GNU Emacs 26.2
Copyright (C) 2019 Free Software Foundation, Inc.
GNU Emacs comes with ABSOLUTELY NO WARRANTY.
You may redistribute copies of GNU Emacs
under the terms of the GNU General Public License.
For more information about these matters, see the file named COPYING.

I ran it with emacs -q. The bactrace points at a segfault in ImageMagick:
Fatal error 11: Segmentation fault
Backtrace:
emacs[0x50fdc9]
emacs[0x4f61f7]
emacs[0x50e77e]
emacs[0x50ea83]
emacs[0x50eac0]
/usr/lib/x86_64-linux-gnu/ImageMagick-6.8.9/modules-Q16/coders/svg.so(+0xb8b8)[0x7f211676e8b8]
emacs[0x5e65fc]
emacs[0x5eed1d]
emacs[0x5ef1a0]
emacs[0x56cf26]
emacs[0x5a5ff8]
emacs[0x56ce93]
emacs[0x5a5ff8]
emacs[0x56ce93]
emacs[0x5a5ff8]
emacs[0x56ce93]
emacs[0x5a5ff8]
emacs[0x56ce93]
emacs[0x5a5ff8]
emacs[0x56ce93]
emacs[0x5a5ff8]
emacs[0x56ce93]
emacs[0x5a5ff8]
emacs[0x56ce93]
emacs[0x5a5ff8]
emacs[0x56ce93]
emacs[0x5a5ff8]
emacs[0x56ce93]
emacs[0x5a5ff8]
emacs[0x56ce93]
emacs[0x5a5ff8]
emacs[0x56ce93]
emacs[0x5a5ff8]
emacs[0x56ce93]
emacs[0x568c9d]
emacs[0x56cf26]
emacs[0x56eb24]
emacs[0x56904e]
...
[3]    7224 segmentation fault (core dumped)  emacs -q ~/work/IIIT-H-Code/softwarefoundations/project
`
This is tagged as "not a bug" --- because "if imagemagick crashes, there is no recourse".