codefastdieyoung
  • about
  • links
    • github
    • twitter
  • .config
    • .emacs.d
    • Linux setup
    • Windows setup
    • Emacs usage notes
    • :emacs: posts
    • :configuration: posts
codefastdieyoung
  • about
  • links
    • github
    • twitter
  • .config
    • .emacs.d
    • Linux setup
    • Windows setup
    • Emacs usage notes
    • :emacs: posts
    • :configuration: posts

Emacs usage notes

Home » Knowledge base » Emacs usage notes
Table of Contents

    1. links

    • historical paper on emacs by stallman
      • https://dspace.mit.edu/bitstream/handle/1721.1/5736/AIM-519A.pdf?sequence=2&isAllowed=y
    • some nice examples – http://emacsrocks.com/
    • list of useful packages]]
    • [good] community driven list of useful packages
    • reference configs
      • lots of stuff, documented, ledger – rememberYou
      • lupan.pl, good stuff
      • evil configs – few packages to try
      • example of split config files, some interesting stuff to try
      • sasha’s config with description

    2. cheat sheet

    M-x describe-personal-keybindings

    2.1. bindings convention

    2.2. simple ref-card.pdf

    2.3. core

    system-configuration-options
    system-configuration-features

    2.4. desktop

    M-x desktop-save
    –no-desktop
    M-x desktop-clear

    2.5. file-menu

    with GUI/non-GUI: M-`

    2.6. bindings

    • discover-major – C-h C-m

    2.7. bookmarks

    C-x r m/M/b/l

    2.8. customize

    M-x customize – entry for customizations

    2.9. startup

    start in the console mode
    emacs –no-window-system
    emacs -nw

    2.10. undo-tree

    C-x u – show visually

    2.11. scala

    2.11.1. tags

    ctags support – https://github.com/ceedubs/sbt-ctags
    http://ensime.github.io/editors/emacs/hacks/#tags
    https://gist.github.com/tsdeng/8451067

    2.12. navigate

    back to previous position
    C-x C-spc (global)
    C-u C-spc (buffer)
    <normal> C-i C-o

    2.13. shell

    M-!
    :! (evil)

    2.14. spelling

    s-; M-$

    2.15. eval

    eval C-x C-e
    M-:
    C-j (in scratch)
    C-M-x – evaluate top-level form (most useful)

    2.16. macro

    • see linux-notes/vim
    • C-x ( C-x ) C-x e e
    • C-x C-k n – name macro

    2.17. themes

    M-x disable-theme

    2.18. magit

    git rm -> K (magit-file-untrack)

    2.19. multiple cursors

    extended config – https://github.com/kaushalmodi/.emacs.d/blob/master/setup-files/setup-multiple-cursors.el
    mark on click C-S-click
    evil: evil-mc-mode, g-r-…

    2.20. help

    C-h ?
    info – C-h i
    C-h i d – go to top directory
    C-h i t – go to top
    M-x info-appropos
    motion C-o, C-t – go back in history
    find index – C-h i d, select manual, i
    C-c C-b/C-f – go back/forward (or l/r in emacs mode)
    C-c C-c – follow symbol
    C-h M-k – describe keymap very usesfull

    2.21. info nav

    n, p, ^, [, ] – navigate
    l, r – history
    L – menu of visited
    d – top directory

    2.22. dired

    2.22.1. invoke dired – C-x d (dired)

    2.22.2. select regex recursive (plus) – M-+ % m

    2.22.3. replace regex in filess (plus-recursive) – (M-+) Q

    2.22.4. sort – `o`, sort with ls args – `C-u o`, -X , sort by size -laS

    2.22.5. edit mode – C-x C-q

    2.22.6. work with images and thumbnails: t (toggle select), C-t d (open thumbnail)

    2.22.7. open with – just run ! on the file

    2.23. mark

    C-x h – all, select all
    C-x C-p – page

    2.24. files

    reload file – M-x revert-buffer or C-x C-v (alternative file)

    2.24.1. open new file instead of search for

    C-f in ido to remove fanciness

    2.24.2. rename file and buffer

    (defined global function – C-c e

    2.25. text / editor

    2.25.1. whitesapce – M-x whitespace-mode

    2.25.2. line-numbers – M-x linum-mode

    2.25.3. return to prev position – C-u C-space / C-x C-space

    2.25.4. transpose

    c-t – transpose two characters (transpose-chars).
    m-t – trans ose two words (transpose-words).
    c-m-t – transpose two balanced expressions (transpose-sexps).
    c-x c-t – transpose two lines (transpose-lines).

    2.25.5. case change

    M-l/u/l lower/upper/capital
    C-x C-l/u – region
    <normal> (g) ~ (iw, etc) – uppercase

    2.25.6. C-x tab. – indentation

    2.25.7. replace – M-%, n, <spc> or ! for all

    2.25.8. replace – with newline – C-q to quote and then C-j for newline

    2.25.9. earlier yank (paste previous) – M-y/C-y

    2.26. projectile

    all files – C-c p f
    known projects – C-c p p
    C-c p p ;; switch projects
    C-c p f ;; list project files
    C-c p g ;; grep project

    2.27. C-\ – change language

    2.28. org-mode

    http://doc.norang.ca/org-mode.html
    https://orgmode.org/worg/orgcard.html

    2.28.1. insert code block – <s then TAB

    2.28.2. C-c C-s – schedule

    2.28.3. C-c C-d – deadline

    2.28.4. C-c a – agenda

    2.28.5. C-c \ – search by tag

    2.28.6. C-c q – add tag

    2.28.7. display inline images

    (define-key org-mode-map (kbd “C-c C-c”)
    (lambda () (interactive) (org-ctrl-c-ctrl-c)
    (org-display-inline-image)))

    2.28.8. C-c l – store link, C-c C-l with up/down – insert link

    2.28.9. C-c ‘ – org edit special (edit code in a separate buffer)

    2.28.10. C-c C-j – jump

    2.28.11. C-c [C-n|C-p|C-f|C-b|C-u] – navigate

    2.28.12. C-c C-x C-i / C-o – clock in / out

    2.28.13. in insert – C-d, C-t to move subtree, in normal – M-h, M-l

    2.28.14. C-u C-c C-l – insert link to file

    2.28.15. C-c C-x C-b – toggle checkbox

    2.28.16. C-c C-x C-v – show inline images (e.g. babel plantuml output)

    2.28.17. agenda

    evil-org-mode/evil-org-agenda.el::evil-org-agenda-set-keys – there are a lot of useful keys there

    2.28.18. remove schedule – C-u C-c C-s

    2.28.19. C-u C-c C-x C-s – archive all done in bufferk

    2.28.20. C-c [, C-c ] – add,remove agenda files

    2.28.21. C-u C-c C-q – fix tag indentation in buffer/region

    2.28.22. org (sub)tree – widen/narrow C-x n s, C-x n w

    2.29. suspend – C-z, unsuspend – %emacs

    2.30. windows/buffers

    C-S-left C-S-right / up / down – global keys redefined in init.el

    2.31. speedbar

    https://www.gnu.org/software/emacs/manual/html_mono/speedbar.html

    2.32. evil-mode

    2.32.1. [[see linux-notes/vim

    2.32.2. https://github.com/noctuid/evil-guide

    2.32.3. C-w C-w – other window

    2.32.4. regex groups

    :%s/$latex \w$$latex \w\w$/\1y\2/

    2.32.5. override binding

    e.g. – (define-key evil-normal-state-map (kbd “M-.”) ‘ensime-edit-definition-with-fallback)

    2.32.6. jump forward-backward C-o, C-i

    2.32.7. [[see linux-notes/vim

    2.33. elisp

    cookbook wiki

    2.33.1. common

    • nil and () is the same
    • () – is empty list
    • FALSE value represented as nil
    • TRUE represented as t (though can be represented by any symbol)
    • t and nil – are special symbols you can use them without quotation
    • in Lisp – expression is an object and secondarly a text
    • character escapes – ?\U12312 or hexa – ?\x2342 or octal ?\111
    • keyword symbol – starts with :
    • sequence types – lists and arrays
      • arrays – strings, vectors, char-tables, bool-vectors
    • s-expr
      • car – cdr = head – tail : but they are more general (trees as well)
    • dotted pair notation – (1 . (2 . (3 . nil)))
    • vectors – [1 2 3]
    • (make-bool-vector 3 t)
    • hash-table
    • defun
      (defun foo () 5)
    • let
    • lambda
    • primitive function
    • special form
    • macros

    2.33.2. functions

    • lambda
      (lambda (ARG-VARIABLES…)
      [DOCUMENTATION-STRING] [INTERACTIVE-DECLARATION] BODY-FORMS…)

    2.33.3. buffers

    • point-min
    • eobp

    2.34. yasnippet

    • yas-describe-tables

    2.35. ivy

    stop autocomplete and choose as is – M-C-j
    occur – C-c C-o
    hydra – C-c C-c
    can toggle case through hydra
    space in swiper – double space

    2.36. debug

    1. debug-on-entry
    2. c / d
    3. cancel-debug-on-entry

    2.37. whitespace/indentation/blank lines fixup

    http://ergoemacs.org/emacs/emacs_shrink_whitespace.html

    3. guidelines

    3.1. how to recompile elpa

    3.2. org and plantuml

    ##+BEGIN_SRC plantuml :file test.png
    Alice -> Bob: synchronous call
    Alice ->> Bob: asynchronous call
    #+END_SRC

    test.png

    3.2.1. plantuml for er modeling (database)

    https://gist.github.com/QuantumGhost/0955a45383a0b6c0bc24f9654b3cb561

    3.3. convert markdown to org

    pandoc -f markdown -t org -o newfile.org original-file.markdown
    

    3.4. how to bulk rename with ivy

    https://sam217pa.github.io/2016/09/11/nuclear-power-editing-via-ivy-and-ag/
    in search result - occur C-c C-o
    then change to wgrep mode - C-x C-q
    and then C-c C-c to apply
    

    3.5. when org-gcal fetches timezone 00, at :404

    (append
    `(("access_token" . ,(org-gcal--get-access-token))
    ("timeZone" . "Europe/Kiev")
    ("singleEvents" . "True"))
    

    3.6. how to quit daemon emacs

    save-buffers-kill-emacs

    3.7. how to profile

    http://stardiviner.github.io/Blog/Emacs-slow-and-heavy-Profile,-Benchmark-your-Emacs,-and-speed-it-up.html

    3.8. how to set fallback font

    https://idiocy.org/emacs-fonts-and-fontsets.html

    3.9. plotting

    3.9.1. orgtbl+gnuplot test

    Format Fine-grained-control Initial Effort Syntax simplicity Editor Support Integrations Ease-of-referencing Versatility
    Word 2 4 4 2 3 2 2
    LaTeX 4 1 1 3 2 4 3
    Org Mode 4 2 3.5 1 4 4 4
    Markdown 1 3 3 4 3 3 1
    Markdown + Pandoc 2.5 2.5 2.5 3 3 3 2

    3.9.2. test matplotlib

    import matplotlib.pyplot as plt
    
    x, y, z = zip((1,9,3),(2,3,4),(4,5,6))
    
    fig = plt.figure()
    axes = fig.add_subplot(1,1,1)
    axes.plot(y, z, marker='o')
    fig.savefig(fname)
    
    return fname
    

    3.10. diff between #’ and ‘

    https://emacs.stackexchange.com/a/35989/29202

    3.11. how to wrap region into src block

    C-c C-, s
    https://orgmode.org/manual/Structure-of-Code-Blocks.html

    • Twitter
    • Telegram
    • Email
    • RSS
    © 2023 - made in ukraine