Live data from Hacker News

Ask HN: What are your best Emacs tips?

news.ycombinator.com

1–5 of 5 posts

Re: Ask HN: What are your best Emacs tips?

#3
Here is a very specific tip for doing literate programming with org-mode:

Usually you put a code block like this in the .org file and generate the actual source file with M-x org-babel-tangle.

    #+begin_src emacs-lisp :tangle "init.el"
    (setq make-backup-files nil)
    #+end_src
The file name doesn't have to be a string constant, you can also call an Elisp function: (the org-prefix is recommended or you will have issues with HTML export)

    #+begin_src emacs-lisp :tangle (org-my-tangle)
    (setq make-backup-files nil)
    #+end_src
The function could look like this: ("no" means don't tangle this block)

    (defun org-my-tangle ()
      (if my-flag
          "init.el"
        "no"))
Or like this: (a more complex example using named, optional parameters)

    (defun org-my-tangle (&rest args)
      (let ((file (or (plist-get args :file) "init.el"))
            (sys (plist-get args :sys)))
        (if (or (null sys)
                (eq sys system-type))
            file
          "no")))
This will tangle to init.el on any system:

    #+begin_src emacs-lisp :tangle (org-my-tangle)
    (setq make-backup-files nil)
    #+end_src
This will tangle to init.el on Linux:

    #+begin_src emacs-lisp :tangle (org-my-tangle :sys 'gnu/linux)
    (setq make-backup-files nil)
    #+end_src
This will tangle to foo.el on Windows:

    #+begin_src emacs-lisp :tangle (org-my-tangle :file "foo.el" :sys 'windows-nt)
    (setq make-backup-files nil)
    #+end_src
I use this approach for example to generate different Emacs configurations for different platforms and use cases (private, work, ...) all from a single org file.

Re: Ask HN: What are your best Emacs tips?

#4
post #3

Here is a very specific tip for doing literate programming with org-mode: Usually you put a code block like this in the .org file and generate the actual source file with M-x org-babel-tangle. #+begin_src emacs-lisp :tangle "init.el" (setq make-backup-files nil) #+end_src The file name doesn't have to be a string constant, you can also call an Elisp function: (the org-prefix is recommended or you will have issues wit…

I would love to integrate my lsp setup into Org babel and get completions when writing code in org babel blocks.

Re: Ask HN: What are your best Emacs tips?

#5
Uncommonly useful: I have a file with two functions that I want to not just see side-by-side, but with a diff.

`C-x 4 c' runs the command clone-indirect-buffer-other-window Now you can narrow both buffers to the two different functions (mark and C-x n n) and do M-x ediff-buffers to get a diff

See also https://karthinks.com/software/batteries-included-with-emacs...

Also, rectangles: https://karthinks.com/software/more-batteries-included-with-...