u/yikesx10000

▲ 133 r/emacs

A great underappreciated book/tutorial: Keith Waclena's "Use Gnu Emacs"

This is a book I found when I was just starting to use Emacs a couple of years ago, and I got a huge amount from it. But every time I see a list of suggested resources for beginners (and others), I never see it mentioned, and it baffles me. I've been meaning to give it a plug for a long time and noticed it was updated fairly recently, so thought this would be a good time.

Don't be put off by the fact that it's a "work in progress" -- the pdf is 641 pages and it's more than enough to get you proficient; the areas the book doesn't yet cover are generally pretty advanced or specialized. As a tutorial it's exemplary: clear, detailed, accurate, well-written. The pdf (which I read in Emacs, conveniently) is beautifully laid out.

I highly, highly recommend it.

www2.lib.uchicago.edu
u/yikesx10000 — 9 days ago
▲ 62 r/emacs

TIL `remove-hook` is interactive!

Apologies if everybody already knows this, but discovering this has been super useful for me and will save me lots of very specific headaches, so I wanted to highlight it.

If you've ever written a hook that turned out to be ill-advised, or had typos, or even just needed to be updated, you've probably realized that fixing the issue without restarting Emacs can be tricky: you can't just delete it from your init file and have it be gone if you've already evaluated it, and if you change it, then sometimes you have both versions active in your session (especially if you've been careless and implemented it as a lambda).

You can evaluate a remove-hook statement to clear out the hook, but then you have to reproduce the original hook's text in that statement, which isn't always easy (especially, as I said, if you've been careless and implemented it as a lambda, which I've definitely never, ever done).

But it turns out that (since 28.1, according to the Help text) remove-hook can be used as an interactive function -- all you have to do is M-x it and you can select the hook variable in the minibuffer (with whatever completion framework you use) and get a list of hooks which you can remove just by hitting Enter. (Of course, you will also need to manually remove the hook from your init file or it will just recur the next time Emacs starts up.)

A lot of times, my instinct with Emacs is to do things using Elisp rather than take advantage of the various menus it provides, but this is an instance where not exploring those friendlier interfaces has caused me a lot of hassle when a clean, simple, effective method already existed to solve my problem.

Hope this helps someone!

reddit.com
u/yikesx10000 — 3 months ago
▲ 0 r/emacs

Yesterday I asked an LLM for help writing a minor mode that would cater to my very particular workflow when reading large amounts of PDF documents and taking notes on them. I intended it to be largely an educational experience in Elisp, and it was, but what I ended up with was so useful (and fancy!) that I wanted to share it in case anyone else could use some of the functions or ideas in their own setup.

Basically, the mode builds the split-screen setup and provides functions that allow me to navigate within the PDF file and between files without moving point from the Org buffer containing my notes. Opening a PDF file using these commands automatically moves point to the Org headline for that document or, if a headline doesn't exist for that document, appends one to the bottom of the Org file and moves point there. I can also open a document in the viewer from its corresponding Org headline.

I don't think it's suitable for distribution as a package -- vibe-coded, too me-specific, any number of other reasons -- but I made a Github repo; the README has all the details, and the prompt I used.

I was careful during the session with the LLM to slow down and make sure I understood everything it was doing, asking questions and making suggestions. But while it was really educational, I don't know what I don't know, so it's likely there are places where there are other, better ways of achieving the same result. I'd love to hear about these; if anyone's interested enough to take the time to read the code (and the copious comments!), any feedback would be very welcome.

u/yikesx10000 — 5 months ago
▲ 16 r/emacs

I posted this at the quick-sdcv Github page, but, on the off chance it might help someone else achieve this dream scenario for a very particular kind of nerd (who might not be aware of the package), wanted to cross-post here. So this is how I set up quick-sdcv to get instant offline access to the Oxford English Dictionary from any buffer in Emacs (but especially epub buffers).

(The OED, if you don't know, is a legendary, massive "historical dictionary" which focuses on providing information about the shifting usage of English words over time, with extensive quotations. It's a fascinating monster; read more here.)

First I installed sdcv itself, through apt; very easy. Then I downloaded the two files containing the OED from here -- it's a chunky boi, but so worthwhile. Unzipped them and copied them to ~/.stardict/dic/ (/usr/share/stardict/dict also works). This is all you have to do to make the OED available from the command line.

To wire it up to Emacs, I put the following block in my init.el:

(use-package quick-sdcv
  :bind  
  ("s-d" . my-quick-sdcv-dwim)
  (:map quick-sdcv-mode-map
        ("q" . quit-window)        
        ("<tab>" . outline-toggle-children))    
  :hook    
  (quick-sdcv-mode . goto-address-mode)    
  :config    
  (add-to-list 'display-buffer-alist    
               '("\\*sdcv"    
                 (display-buffer-reuse-window display-buffer-at-bottom)    
                 (window-height . 0.3)))    
  :custom    
  (quick-sdcv-dictionary-prefix-symbol "▶")    
  (quick-sdcv-ellipsis " ▼")    
  (quick-sdcv-unique-buffers t))

There are some modifications here: I wanted the quick-sdcv buffer to behave essentially like a help buffer: open a window (or reuse one), move my cursor there, and restore my previous window layout when I hit q. And quick-sdcv displays its results in outline-minor-mode with each dictionary's results under its own heading, so I wanted <tab> to quickly close and open results from different dictionaries (I did grab some others, it's pretty irresistible).

my-quick-sdcv-dwim is a very simple function which makes the keybind either search for the word at point or, with C-u, prompt me for a search term:

(defun my-quick-sdcv-dwim (&optional arg)
  "Look up a word using quick-sdcv.
By default, looks up the word at point.
With a prefix argument (\\[universal-argument]), prompts for a word."
  (interactive "P")
  (if arg
      (call-interactively #'quick-sdcv-search-input)
    (quick-sdcv-search-at-point)))

This is already very long! But let me just mention three more small things I tweaked to make the experience complete:

I use nov to read epub books inside Emacs, so to the nov-mode-map I added (with use-package):

:bind
(:map nov-mode-map
...
("K" . quick-sdcv-search-at-point))

...for a slightly more ergonomic experience when I'm deep in some book.

As you might have guessed from the K binding, I use evil, but I want the quick-sdcv window to just be in regular Emacs mode so my q and <TAB> work as expected, so I added this line to my evil config:

(evil-set-initial-state 'quick-sdcv-mode 'emacs)

Finally, the sdcv formatting of output is minimalistic, and the OED in particular is very dense (the printed edition comes with a literal magnifying glass), so I set a hook to display the results in olivetti-mode, just to make things a little bit prettier:

(use-package olivetti
  :hook
  (quick-sdcv-mode . olivetti-mode))

This is way more than I intended to write, but I hope that doesn't give the impression that this package (and its dependency) is in any way complicated or difficult to get up and running; I probably spent less time setting all this up than I did writing this post. And now I have instantaneous access to the freaking OED at the push of a button.

This is why Emacs is so magical for me: those moments when the program and its community come together to help me scratch some very particular itch that would be impossible (for me) to do in quite the same way in any other context. I'm so grateful to the package author, James Cherti, and I hope this helps some other word nerds out there!

u/yikesx10000 — 6 months ago