Irreal: 🥩 Red Meat Friday: Minimal Configs

This Irreal post on dependencies and this one on Emacs bloat discussed the idea that many Emacs users have too many packages and other capabilities enabled in their Emacs configuration files. I’ve never worried about that because, really, there’s no reason to do so. Indeed, those who do worry about it mostly fall back on aesthetics as the reason for their worry.

Over at the Emacs subreddit, ptrtoj is complaining that he’s eliminated a lot of packages but his configuration is still over 500 lines long. He’s wondering what else he can do in his quest for a minimal configuration. His post got me thinking explicitly about the value of small configurations and the quest for them.

Here’s a heretical thought: why are minimal configurations a good thing and why should we pursue them? To be sure, every Emacs user eventually accumulates cruft in their configuration: packages they no longer use, workarounds for a bug in Emacs 22 that’s long since been fixed, customizations no longer serving a purpose, and other things they don’t need anymore. No one is arguing that we shouldn’t get rid of the cruft but that’s a bit different from seeking a “minimal configuration” as if it were a good thing per se.

I would argue that on the contrary a large configuration is a sign of users who have—probably over time—made the effort to optimize Emacs for their particular workflow. That a large configuration is, in fact, a sign of a serious—and possibly master—Emacs user.

On reflection, I don’t understand what those desiring a minimal conjuration are seeking or why they’re seeking it. In these days of virtually infinite memory and unlimited CPU power, a minimalism enforced for no clear reason doesn’t make sense.

-1:-- 🥩 Red Meat Friday: Minimal Configs (Post jcs)--L0--C0--July 26, 2024 03:39 PM

J.e.r.e.m.y B.r.y.a.n.t: On the Origin of Emacs in 1976

Summary: EMACS was developed at the MIT AI Lab in 1976. The specifics of the origin have been documented by different people in various places. There is an interesting thread which was discussed on the blog of the late Dan Weinreb, and preserved by archive.org. Ultimately, Guy Steele pulled up his records (in the form of printed emails). The below is an extract which is of historical interest and includes emails from the first couple months of Emacs in 1976. I quote some sections and include the verbatim text at the bottom, which starts with an ITS email from RMS to GLS.
-1:-- On the Origin of Emacs in 1976 (Post)--L0--C0--July 25, 2024 11:02 PM

Alvaro Ramirez: Emacs macOS native emoji picker (revisited)

25 July 2024 Emacs macOS native emoji picker (revisited)

Update: Doh! I was wrong. There's a better way.

So, I totally missed the macOS native emoji picker is actually supported out of the box 😭. Thanks to redditor u/hrabannixlisp who pointed me in the right direction.

ns-do-show-character-palette is bound to C-s-SPC by default, which didn't work for me as I use (setq mac-command-modifier 'meta), that is, ⌘ as meta modifier.

While I won't be giving up (setq mac-command-modifier 'meta), I can certainly use ns-do-show-character-palette via M-x or a different binding. Thank you u/hrabannixlisp!

Read on for how I went about it the long convoluted way 🤷‍♂️

A couple of years ago, I was delighted to discover a macOS freebie for us Emacs users. Newer Macbook models started shipping with a globe/🌐 key, which summons the macOS native emoji picker. Pressing this key in Emacs works as you'd expect (no config required 🎉).

While I seldom use emojis, the globe key worked great for me until I started using an external keyboard, which didn't have this magical key. The potential solutions I came across suggest either reprogramming the keyboard or using the likes of Karabiner-Elements to map other keys to an alternate shortcut: Ctrl-⌘-SPC. As far as I can tell, this is the only other available shortcut (please reach out if otherwise). Not a great option (it conflicts with Emacs's mark-sexp). Not that I'd be super keen to lose this mark command, but even unbinding doesn't seem of much help.

While we have Emacs packages available for different emoji-picking experiences, I was keen on maintaining that native experience I enjoyed before. I nearly gave up on the matter until I remembered we have at least one more tool in the Emacs toolbox: dynamic modules. Thanks to Valeriy Savchenko's emacs-swift-module, we can leverage Swift to integrate native macOS experiences.

With that in mind, I set out to find the relevant macOS API, which turned out to be a lovely one-liner:

NSApp. orderFrontCharacterPalette(nil)

Let's bring it into Emacs via emacs-swift-module's infrastructure:

 try env. defun(
   "macos-module--show-emoji-picker",
  with:  "Show emoji picker (macOS module implementation)."
) { (env: Environment)  in
  NSApp. orderFrontCharacterPalette(nil)
}

In theory, this is all we need. We can M-x eval-expression (macos-module--show-emoji-picker) and the picker simply pops up. I haven't worked out how define an interactive command from emacs-swift-module just yet, so for now I'll just wrap with a little elisp:

(defun  macos-show-emoji-picker ()
   "Show macOS emoji picker."
  (interactive)
  (macos-module--show-emoji-picker))

And with that, we got our native macoOS emoji picker back at our fingertips:

hearts3.webp

While the dedicated globe key just worked without configuration, it required newer hardware. This new approach works on older Macbooks too. Since it's an interactive command, you can optionally bind to your preferred keys.

Having said all that, you may have noticed a brief lag during insertion. I haven't worked out the source, but since I rarely use emojis, this will have to do for now. If you have a better macOS alternative working on external keyboards, I'd love to hear about it!

I've added macos-show-emoji-picker to EmacsMacOSModule, a tiny repo I've used to experiment with emacs-swift-module. You can find EmacsMacOSModule on GitHub.

Unrelated - Want your own blog?

Like this blog? Want to start a blog? Run your blog off a single file. Write from the comfort of your favourite text editor and drag and drop to the web. I'm launching a blogging service at lmno.lol. Looking for early adopters. Get in touch.

-1:-- Emacs macOS native emoji picker (revisited) (Post)--L0--C0--July 25, 2024 08:27 PM

James Cherti: outline-indent.el – Indentation based Folding and Outlining in Emacs

5/5

The outline-indent.el Emacs package provides a minor mode that enables code folding and outlining based on indentation levels for various indentation-based text files, such as YAML, Python, and other indented text files.

In addition to code folding, outline-indent.el allows moving indented sub-trees up and down, promoting and demoting sections to adjust indentation levels, customizing the ellipsis, and inserting a new line with the same indentation level as the current line, among other features.

The outline-indent.el package leverages the built-in outline-minor-mode, which is maintained by the Emacs developers and has less chance of being abandoned like origami.el.

The outline-indent.el Emacs package offers a similar functionality to Vim’s set foldmethod=indent setting. Just as in Vim, it allows to fold and unfold code sections based on their indentation levels.

Installation

To install the outline-indent using straight.el:

  1. If you haven’t already done so, add the straight.el bootstrap code to your init file.
  2. Add the following code to your Emacs init file:
(use-package outline-indent
  :ensure t
  :straight (outline-indent
             :type git
             :host github
             :repo "jamescherti/outline-indent.el")
  :custom
  (outline-indent-ellipsis " ▼ "))

Usage

Once installed, the minor mode can be activated using:

(outline-indent-minor-mode)

The minor mode can also be automatically activated for a certain mode. For example for Python and YAML:

(add-hook 'python-mode-hook #'outline-indent-minor-mode)
(add-hook 'python-ts-mode-hook #'outline-indent-minor-mode)

(add-hook 'yaml-mode-hook #'outline-indent-minor-mode)
(add-hook 'yaml-ts-mode-hook #'outline-indent-minor-mode)

(You can also adjust the indentation offset by modifying the variable outline-indent-default-offset)

Once outline-indent-minor-mode is activated, you can use the built-in outline-minor-mode functions to fold or unfold indented sections:

  • outline-hide-body: Hide all body lines in buffer, leaving all headings visible.
  • outline-hide-other: Hide everything except current body and parent and top-level headings.
  • outline-hide-entry: Hide the body directly following this heading.
  • outline-hide-leaves: Hide the body after this heading and at deeper levels.
  • outline-hide-subtree: Hide everything after this heading at deeper levels.
  • outline-show-children: Show all direct subheadings of this heading.
  • outline-hide-sublevels: Hide everything but the top LEVELS levels of headers, in whole buffer.
  • outline-show-all: Show all of the text in the buffer.
  • outline-show-entry: Show the body directly following this heading.
  • outline-show-subtree: Show everything after this heading at deeper levels.
  • outline-show-branches: Show all subheadings of this heading, but not their bodies.
  • outline-show-children: Show all direct subheadings of this heading.

You can also indent/unindent and move subtree up and down:

  • (outline-indent-demote) and (outline-indent-promote): Indent or unindent the entire subtree.
  • (outline-indent-move-subtree-down) and (outline-indent-move-subtree-up) to move the current subtree up or down.
  • (outline-insert-heading) to insert a new line with the same indentation level/depth as the current line just before the next heading that shares the same or less indentation level.

In Evil mode, outline-indent-minor-mode works out of the box, and you can use the Evil keyboard mappings: zo, zc, zO, zC, za, zr, and zm to manage folds.

Related links

-1:-- outline-indent.el – Indentation based Folding and Outlining in Emacs (Post James Cherti)--L0--C0--July 25, 2024 04:05 PM

Irreal: Dedicated Windows

Marcin Borkowski (mbork) has a very interesting post on something I didn’t know about: dedicated windows. The TL;DR is that dedicated windows are restricted—more or less—to the single buffer that they were displaying when they were set to dedicated.

Mbork’s use case is reading a technical book in one window while taking notes and trying code snippets from the book in another. He notes that if there’s an error when executing those code snippets Emacs will open an error window over your book. By marking the window as dedicated, you can avoid that and force Emacs to open a third window so you can see all the pertinent information.

Although dedicated windows have been in Emacs for some time, there’s never been an easy way of invoking them. That changed in Emacs 30. Now’s there a convenient key sequence to mark a window as dedicated (Ctrl+x w d).

To be honest, my workflow doesn’t have much use for this feature but, of course, that can change without warning so it’s nice to know that there’s a way of pinning a window to a particular buffer. If you think that you have a use for such a feature, be sure to take a look at Mbork’s post for the details. The easy UI won’t be available until Emacs 30.1 but you still set a window dedicated by calling the appropriate function. See the documentation for the details.

-1:-- Dedicated Windows (Post jcs)--L0--C0--July 25, 2024 03:48 PM

Alex Popescu: Key Binding and Function to Jump to Emacs Completions Buffer

Updated with a second solution. Both are useful. The new one is simpler. I have recently disabled Ivy/Counsel/Swiper in my Emacs setup1. One of the first things that I experienced, after disabling Ivy & friends, was a new interaction mode with completions. When trying to complete something in the minibuffer, completion candidates are displayed in the *Completions* buffer which is conveniently displayed right above the minibuffer. What confused me about this behavior was the need to use the mouse to move to this buffer.
-1:-- Key Binding and Function to Jump to Emacs Completions Buffer (Post)--L0--C0--July 25, 2024 08:59 AM

Protesilaos Stavrou: Emacs: Denote backlinks buffer can now toggle its details

The level of detail shown in the backlinks buffer can now be toggled on demand. This is done with the new command denote-backlinks-toggle-context. The feature is available as part of the current development target of Denote (version 3.1.0-dev, which I am actively working on).

Below are a couple of pictures, showing a note that (i) has just gotten a backlinks buffer with the denote-backlinks command and (ii) the user interacts with the backlinks buffer to show/hide the context of matching links.

The compact view

This shows the files that link to the current file, one per line. If a file has multiple links, it still counts as one on this list.

Denote backlinks buffer toggled to compact view

The detailed view

In this presentation, each match is displayed in its context, with a reference to the line number it is found at. Multiple links in each file are shown separately and are grouped per file.

Denote backlinks buffer toggled to detailed view

The implementation details may change

Remember that this is part of the current development version. I might make further changes to it and I am happy to get your feedback.

Users have long now had the denote-backlinks-show-context option to set their default preference. With current developments, they can still do what they did, plus toggle the view when the need arises.

When will version 3.1.0 be released?

There are no deadlines. Things are in a good state, but I will not rush to make this happen. To give you a rough idea, expect it some time in mid to late August.

About Denote

Denote is a simple note-taking tool for Emacs. It is based on the idea that notes should follow a predictable and descriptive file-naming scheme. The file name must offer a clear indication of what the note is about, without reference to any other metadata. Denote basically streamlines the creation of such files while providing facilities to link between them.

Denote’s file-naming scheme is not limited to “notes”. It can be used for all types of file, including those that are not editable in Emacs, such as videos. Naming files in a consistent way makes their filtering and retrieval considerably easier. Denote provides relevant facilities to rename files, regardless of file type.

-1:-- Emacs: Denote backlinks buffer can now toggle its details (Post)--L0--C0--July 25, 2024 12:00 AM

Irreal: Mastering Emacs (Emacs 29 Edition)

I just got a notice from Mickey that the latest version of Mastering Emacs is out. It is, when you think about it, a modern miracle. You buy a really great book on Emacs once and keep getting the new editions for free.

This version brings the book up to date as of Emacs version 29. The two megafeatures of version 29 are Tree Sitter for finally rationalizing syntax highlighting and Eglot to provide smart completion and other “modern” IDE-like functionality. But as Mickey says, there are a “million” other, smaller improvements.

Speaking of buying Mastering Emacs, Mickey is having his usual new edition sale on the book. For a little more than the next day, you can get the book for 29% off. If you have any interest at all in Emacs, you really should have this book and now is the perfect time to get it. By the time you read this, the sale will be almost over so act now if you’re interested.

-1:-- Mastering Emacs (Emacs 29 Edition) (Post jcs)--L0--C0--July 23, 2024 04:01 PM

Alex Schroeder: 2024-07-23 Eglot for Go, Perl and Markdown

2024-07-23 Eglot for Go, Perl and Markdown

Apparently there’s a way to have Oddµ and Eglot cooperate in Emacs using Marksman.

Note that LSP integration only works in a “project”: a VCS repository, or in the case of Marksman, a directory containing an (empty) .marksman.toml file. This latter option is important if your notes aren’t under version control.

After installing the Marksman binary, use something like the following. This installs Eglot for Go mode, Perl mode and Markdown mode.

;; There is probably a way to put this inside the use-package form but
;; this is how it works for me.
(add-hook 'go-mode-hook 'eglot-ensure)
(add-hook 'perl-mode-hook 'eglot-ensure)
(add-hook 'markdown-mode-hook 'eglot-ensure)
(autoload 'eglot-ensure "eglot" "Start Eglot session for current buffer if there isn’t one.")

(use-package eglot :ensure t
  :config (add-to-list 'eglot-server-programs '(markdown-mode . ("marksman"))))

(setq-default eglot-workspace-configuration
    '((:gopls .
        ((staticcheck . t)
         (matcher . "CaseSensitive")))))

#Emacs #Oddµ #Markdown #Perl #Golang

-1:-- 2024-07-23 Eglot for Go, Perl and Markdown (Post)--L0--C0--July 23, 2024 03:08 PM

Protesilaos Stavrou: Emacs: use-package essentials

Raw link: https://www.youtube.com/watch?v=RaqtzemHFDU

In this ~35-minute video I demonstrate the main features of the ‘use-package’ configuration macro that is built into Emacs 29. It is the de facto standard for setting up packages and is designed to make Emacs faster to start up and more robust overall.

;;; Install a package, if needed

(use-package denote
  :ensure t)

(use-package dired
  :ensure nil)

;;; Evaluate code after a package is loaded

(use-package ef-themes
  :ensure t
  :config
  (ef-themes-select 'ef-cyprus)) ; the theme for this video

;;; Evaluate code before a package is loaded

(use-package corfu
  :init
  (setq tab-always-indent 'complete)
  :config
  ...)

;;; Conditional loading

(use-package spacious-padding
  :ensure t
  :if (display-graphic-p)
  :config
  ...)

;; This is for the sxhkd program, which is used with minimalist tiling
;; window managers.
(use-package sxhkdrc-mode
  :ensure t
  :if (eq system-type 'gnu/linux)
  ...)

(when (eq system-type 'gnu/linux)
  (use-package sxhkdrc-mode
    :ensure t
    ...))

;;; Defer loading by defining keys

(use-package denote
  :ensure t
  :bind
  ("C-c n n" . denote)
  :config
  (setq denote-known-keywords '("emacs" "philosophy" "politics")))

(use-package denote
  :ensure t
  :bind
  ( :map global-map ; same as above
    ("C-c n n" . denote))
  :config
  (setq denote-known-keywords '("emacs" "philosophy" "politics")))

(use-package denote
  :ensure t
  :bind
  ;; For more key bindings, you need a list of such pairs
  (("C-c n n" . denote)
   ("C-c n r" . denote-rename-file))
  :config
  (setq denote-known-keywords '("emacs" "philosophy" "politics")))

;;; Defer loading with a hook

(use-package nerd-icons-dired
  :ensure t
  :hook
  (dired-mode . nerd-icons-dired-mode)
  :config
  ;; Evaluated only after I am in Dired.
  ...)

;;; Defer loading until some command is called (usually not needed)

(use-package bookmark
  :ensure nil
  :commands (bookmark-set bookmark-jump bookmark-bmenu-list))

;;; Defer loading until a file is opened (for major modes)

(use-package sxhkdrc-mode
  :ensure t
  ;; We generally do not need :mode because major modes set this up
  ;; already.
  :mode "sxhkdrc_.*")

;;; Defer loading indefinitely or for N seconds of idleness

(use-package server
  :ensure nil
  :defer 1
  :config
  (setq server-client-instructions nil)
  (unless (server-running-p)
    (server-start)))

(use-package markdown-mode
  :ensure t
  :defer t
  :config
  (setq markdown-fontify-code-blocks-natively t))

;;; Force loading when deferring is not desired

(use-package modus-themes
  :ensure t
  :demand t
  :bind
  (("<f5>" . modus-themes-toggle)
   ("C-<f5>" . modus-themes-select))
  :config
  (modus-themes-load-theme 'modus-vivendi-tinted))

;;; Define many keys in many key maps

(use-package denote
  :ensure t
  :bind
  ( :map global-map

    ("C-c n n" . denote)
    ("C-c n r" . denote-rename-file)

    :map text-mode-map

    ("C-c n i" . denote-link) ; "insert" mnemonic
    ("C-c n I" . denote-add-links)

    :map dired-mode-map

    ("C-c C-d C-i" . denote-link-dired-marked-notes)
    ("C-c C-d C-r" . denote-dired-rename-marked-files)))

;;; Add the same function to many hooks

(use-package abbrev
  :ensure nil
  :hook ((text-mode prog-mode git-commit-mode) . abbrev-mode))

;; This is the same as above, which has the advantage of being easier
;; to make sense of and modify, but is repetitive.
(use-package abbrev
  :ensure nil
  :hook ((text-mode . abbrev-mode)
         (prog-mode . abbrev-mode)
         (git-commit-mode . abbrev-mode)))

;;; Specify a custom `load-path'

(use-package notmuch
  :ensure nil ; do not install, because I get it from my Linux distro packages
  :load-path "/usr/share/emacs/site-lisp/"
  :defer t
  :commands (notmuch notmuch-mua-new-mail))

;;; Load a package after another

(use-package notmuch
  :load-path "/usr/share/emacs/site-lisp/"
  :defer t
  :commands (notmuch notmuch-mua-new-mail))

(use-package notmuch-indicator
  :ensure t
  :after notmuch
  :config
  (notmuch-indicator-mode 1))

;;; Do not force dependencies with `:after'

(use-package register
  :ensure nil
  :defer t ; its commands are autoloaded, so this will be loaded then
  :config
  ;; Use `with-eval-after-load', name the symbol of the feature, and
  ;; then write arbitrary code below.
  (with-eval-after-load 'savehist
    (add-to-list 'savehist-additional-variables 'register-alist)))

;;; Avoid never loading the package with `:bind'

(use-package vertico
  :ensure t
  ;; This is WRONG, because it defers the loading of the package until
  ;; `vertico-directory-delete-char' is invoked.  But this command is
  ;; only accessible through the `vertico-map' which, in turn, is only
  ;; available inside the Vertico-powered minibuffer, i.e. after
  ;; `vertico-mode' is enabled.
  :bind
  ( :map vertico-map
    ("DEL" . vertico-directory-delete-char))
  :config
  (vertico-mode 1))

(use-package vertico
  :ensure t
  ;; This is fine now.
  :hook
  (after-init . vertico-mode)
  :bind
  ( :map vertico-map
    ("DEL" . vertico-directory-delete-char)))
-1:-- Emacs: use-package essentials (Post)--L0--C0--July 23, 2024 12:00 AM

Marcin Borkowski: New things in new Emacs

Some time ago I wrote about a few new things in Emacs 29. Well, even though Emacs 30 is not out yet, I use Emacs compiled from source on the master branch, and while I do not compile a new version very often, I still have a version newer than what my distro offers. So, I went through the NEWS.30 in my Emacs Git repo, and – as usual – found a few gems.
-1:-- New things in new Emacs (Post)--L0--C0--July 22, 2024 07:11 PM

Irreal: Ready Player Mode On MELPA

A couple of week ago I wrote about Álvaro Ramírez’s ready player mode. The idea is to be able to take a quick peek at a media file from within Emacs. At the time, the app was still beta quality and not yet on MELPA.

Now, Ramírez has announced that the app is on MELPA and ready for general use. Take a look at Ramírez’s original post to see what it can do and why you might want it. Now that it’s on MELPA, it’s easy to install.

-1:-- Ready Player Mode On MELPA (Post jcs)--L0--C0--July 22, 2024 03:50 PM

Sacha Chua: 2024-07-22 Emacs news

Links from reddit.com/r/emacs, r/orgmode, r/spacemacs, r/planetemacs, Mastodon #emacs, Hacker News, lobste.rs, programming.dev, lemmy, communick.news, planet.emacslife.com, YouTube, the Emacs NEWS file, Emacs Calendar, and emacs-devel. Thanks to Andrés Ramírez for emacs-devel links. Do you have an Emacs-related link or announcement? Please e-mail me at sacha@sachachua.com. Thank you!

-1:-- 2024-07-22 Emacs news (Post Sacha Chua)--L0--C0--July 22, 2024 02:53 PM

Mickey Petersen: The Emacs 29 Edition of Mastering Emacs is out now

It’s taken a little bit longer than I would have liked to get the next edition out the door. I also felt the site needed a lick of paint which, if you’re a regular and astute reader, you may have noticed already.

But as I explain in the book update below, the two headline features are tree-sitter support and Eglot. To say nothing of the million other new Emacs 29.1 features that were added.

A couple of years ago, I wrote about Tree Sitter and the Complications of Parsing Languages. In it, I talk about the immense difficulties around parsing languages in a way that is both useful and consistent for a wide range of programming languages and structured texts. Tree-sitter is one of the few that have managed to cross that chasm; no small feat, in my opinion.

The other major inclusion is Eglot. It’s another smart and sensible addition to Emacs core. Combined with tree-sitter, you now have access to top-notch syntax highlighting and IDE-like features right out of the box.

As always, to celebrate the release of the new edition of the book, I have put it on sale with a 29% discount.

2024 Edition Update

This is 2024 Edition update the excerpt from the book.

Emacs 29 continues the long-running trend of keeping up with advances in technology. That is commendable. Emacs is an old piece of software, and yet it is continuously improving.

One of the hardest things to get right in a text editor is syntax highlighting (font locking in Emacs parlance) and writing a robust indentation engine. You see, when Emacs – and many other editors, old and new – syntax highlight your source code, they do so using regular expressions, a terse method for matching text using pattern matching. Regular expressions are great; they’re a succinct way of matching and extracting important information from text. They are the backbone of syntax highlighters nearly everywhere, but they also have a flaw: they can be imprecise, and can impede performance if they are poorly written.

A regular expression also cannot contextualize what it is matching: just that it did (or did not) match something. For a wide range of granular tasks, it is simply not possible to rely on regular expressions. That is a problem as you want as much precision as you can get. Yet it’s often impossible to tell some things apart with a regular expression, such as whether a series of characters is a variable or a function call. The same series of characters may have one meaning in one context, and an altogether different one in another. Regular expressions are rarely powerful enough to capture that nuance. And so most text editors build their syntax highlighting and indentation engines with a medley of regular expressions and hand-tuned, imperative code to try to work around the limitations of the former.

Good news, then, as Emacs 29 adds optional support for tree-sitter, a parser library with an exacting eye for source code parsing that constructs a Concrete Syntax Tree from any text for which it has a valid grammar. Such a tree is the perfect medium for a computer (or willing user) to query. It makes correct syntax highlighting possible with little more than a few dozen lines of code. It also adds the tantalizing promise of structured editing and movement, a sprawling concept that reuses the tree-like structure tree-sitter yields to offer unparalleled editing and movement in your code base.

Tree-sitter’s not the only game in town. What it does bring to the table, and what has eluded most other attempts (in Emacs and beyond), is that is has the largest repository of parsers for both common and uncommon languages and structured text files. Tree-sitter is thus capable and popular. It helps that it is quite straightforward to write your own parser using tree-sitter’s tooling. The cherry on top is a query language to quickly find and match segments of the parsed tree that it emits. That is perhaps its ace in the hole: being able to ask it to show you (for example) all the functions that contain one or more variables with a given name is a powerful feature indeed. Modeled on LISP’s S-expressions, the query language also feels right at home in an Emacs ecosystem.

Presently, the feature is optional, as you must compile Emacs with tree-sitter support. So it is unlikely to replace, wholesale, the existing major modes and the old way of doing things. But it’s a large step forward for Emacs, as it makes writing syntax highlighting and indentation code downright easy. Its adoption into Emacs core is a positive development, and a repudiation against the entrenched belief that Emacs can never fundamentally change. Font locking in Emacs was first introduced around 35 years ago, and now there is a new way – and often much better way – than the old regular expressions. Its successful integration into Emacs is also reflected in the wider Emacs community where it has proven to be a popular feature, despite the fact that tree-sitter is, being new to Emacs, cumbersome to set up and use.

The other major inclusion is Eglot, a client that understands the language server protocol (LSP). Eglot adds IDE-like features to any buffer for which there is a language server available. It’s designed to work with nothing more than base Emacs and the requisite language server. Provided you’ve got your language server set up, all you need to type is M-x eglot (or select Tools -> Language Server Support) to get started. Eglot’s been around for a long time on ELPA, an Emacs package repository. Now it’s built into Emacs.

Both capabilities are capstones in an otherwise packed release full of exciting improvements and fixes. If you’re not using Emacs 29 already, you should definitely upgrade.

-1:-- The Emacs 29 Edition of Mastering Emacs is out now (Post)--L0--C0--July 22, 2024 02:17 PM

Ryan Rix: For better or worse, the CCE now runs on River WM

For better or worse, the CCE now runs on River WM

tl;dr I am now running RiverWM on my NixOS distribution and have a published configuration for it therein.

I'm not particularly happy to write this. For literally half of my life, from 16 to 32 years, I ran the KDE Plasma desktop but recently I was forced to swap away. I really like using my computer without a mouse and KDE has made it difficult to impossible for me to do so.

For quite a number of years I was able to run KDE Plasma with XMonad as the window manager under X11 by just setting a session variable in my .profile to KDEWM=/usr/bin/awesome and that worked great for many years; I was even able to go full emacs for a long time with EXWM (which allows one to treat Emacs as the "root" environment with X11 windows acting as Emacs buffers, rather than a WM being the root environment and Emacs being a window). At some point the simple solution of setting an environment variable stopped working but all you had to do to get Plasma with another WM on X11 was set up a SystemD user-unit overlay and then basically ask the WM to manage the Plasma windows.

When I got my GPD Pocket 3 , however, I found that despite it being an Intel integrated graphics machine, X11 did not run well on it and I set up my first Wayland-native environment which meant risking and considering throwing away a decade and a half of good experience with stacking tiling window managers. I set up Bismuth which was a KDE Plasma 5 KWin plugin which would auto-tile and lay out windows and manage an ordered stack so that I could Super-j and Super-k up and down the stack of windows and Super RET to push the active window to the top of the stack and re-organize the windows so that that window was the largest. It was basically good enough, Plasma 6 is a really nice desktop and the stacking features of Bismuth meant that my three or four main applications could be driven from my keyboard's home-row.

Bismuth does not work on Plasma 6 and I started to have some really frustrating crashes in Plasma 5 KWin Wayland which was resolved by a fix only applied to Plasma 6 and XWayland would randomly exit with code 0 and no log output. I eventually got Plasmas X11 to work decently on the GPD Pocket 3 but at the cost that touch events and other libinput stuff didn't work well enough to be my daily driver that I've had to look to other shores.

Bismuth doesn't work with Plasma 6, and is no longer under active development so I had to try to go back to a non-stacking tiling WM (think sway/i3) and tried Polonium, which unfortunately did not work with how i want to use my computer. Not having an auto-tile system was driving me mad. The other Wayland tiling window managers were mostly interested in emulating this tiling philosophy that i3 uses rather than an auto-tiling system with layouts built in like XMonad or Awesome.

River WM is the tiling system that gives you that, basically, with caveats. so I spent the last week or two while my personal life un-winds and comes back together, building a desktop configuration with RiverWM and getting really angry with the state of modern linux desktop systems along the way.

Any intuition I have about how a Linux desktop system is composed is thrown out the window with the move toward D-Bus and SystemD managed desktop sessions. I have spent the last week dealing with fiddly fucking environment variable propagation and XDG Desktop Portal configuration files to get things like my Matrix.org local proxy service Pantalaimon to connect to D-Bus and auto-spawn a secret service which contained the OLM keys. After every NixOS rebuild, I would end up with two waybar instances running and spent all day today trying to get it to work within a systemd-run ephemeral user unit, but for some reason despite verifying the environment variables being basically-equivalent by poking at /proc/$PID/eniviron, the user-unit version of waybar would not show icons in the taskbar, despite it working if I spawned waybar in the initialized desktop session. Infuriating shit.

I have a system I am mostly content with but I know that the "long tail" of issues in maintaining and spit-shining this thing will probably end up being about the same amount of work as it would take to just grit my teeth and get used to PaperWM or Polonium running within a desktop that provides all this ugly plumbing.

But it lends a problem, I can no longer recommend the software I use to anyone else, especially "normies." I've spent the last year carefully polishing a Linux distribution and Emacs environment that I could hand to family to plug in to a cloud that is not owned by a tech monopoly and believe they could use built on a desktop I've tried to understand the control surfaces and plumbing of since high school. I thought I was close with the Rebuild of The Complete Computer , but this feels like a set back.

Now I have a fucked up tiling window manager system that no one else can use and a bunch of shell-script- and JSON- configured microservices that aim to provide a desktop that sucks less but mostly end up making me hate the Linux desktop and the isolated islands it's become. And meanwhile the display power management system on my laptop still barely works.

The Hey Smell This factor of going with the "choose your own Wayland Desktop" is nearly unbound, I can't recommend this to anyone in good faith unless they know what they're getting in to.

I hope some day that there is a window manager like River that implements the same Wayland protocols as KWin and I can swap it back in over the Plasma desktop, because I am oh so tired of dealing with desktop Linux plumbing. I probably should put my money where my mouth is one of these days.

The River CCE module is laid out nicely, though I still need to un-tangle some of the more frustrating bits of configuration like the XDG Desktop Portal configuration. If you want to try out River, there is a "batteries included" lightly opinionated home-manager.nix and nixos configuration for you to walk through.

-1:-- For better or worse, the CCE now runs on River WM (Post)--L0--C0--July 22, 2024 12:30 PM

Alvaro Ramirez: Real Player Mode now on MELPA

21 July 2024 Real Player Mode now on MELPA

A few weeks ago, I announced Ready Player Mode's availability on GitHub. As of today, you can find it on MELPA.

Ready Player Mode is a lightweight major mode to open media (audio/video) files in an Emacs buffer.

Install, enable via M-x ready-player-mode and you should be good to go.

Open and preview media files (audio + video) like other files. If in repeat mode, ready-player attempts to play other files in the current directory. Track playback from the corresponding dired buffer.

ready-player.gif

Playback is handled by your favourite command line utility. ready-player-mode will try to use either mpv, vlc, ffplay, or mplayer (in that order), but you can customize that. I'd love to hear of other defaults worth considering.

Bonus rendering includes media thumbnails and metadata, if either ffmpegthumbnailer or ffmpeg are found.

Unrelated - Want your own blog?

Like this blog? Want to start a blog? Run your blog off a single file. Write from the comfort of your favourite text editor and drag and drop to the web. I'm launching a blogging service at lmno.lol. Looking for early adopters. Get in touch.

-1:-- Real Player Mode now on MELPA (Post)--L0--C0--July 21, 2024 06:15 PM

Irreal: Casual RE-Builder Improved

I recently wrote about Casual RE Builder, one of Charles Choi’s Casual Suite apps. As I wrote then, it goes a long ways towards making RE-builder usable for those of us who can’t remember all the commands necessary to export the resulting regex to a useful place.

While he was working on Casual RE-builder, Choi discovered that sometimes—usually in the Dired subsystem—Emacs expects “grep-like” regular expressions rather than the Emacs style. This is undoubtedly because Emacs outsources certain tasks to external grep routines. The fact that the particular regexp subset used depends on what flavor of grep you have installed makes things even more complicated. If you’re like me, all of this is news to you. Somehow, I’ve managed to stumble through using Dired without realizing that it was pulling a bait-and-switch on me.

Regardless, Choi has come to the rescue. He’s changed Casual RE-builder to add an option to export the regexps from RE-builder in grep format. It’s a small thing but it makes Casual RE-builder even more useful.

I’ve already installed Casual RE-builder and presumably I’ll get Choi’s latest changes with my next update. This is, I say again, a really useful package and if you use regexps at all in Emacs, you should take a look at it.

-1:-- Casual RE-Builder Improved (Post jcs)--L0--C0--July 21, 2024 03:52 PM

Unwound Stack: fill-column-indicator

Just removed fill-column-indicator from my Emacs configuration

-1:-- fill-column-indicator (Post Michael (sp1ff@pobox.com))--L0--C0--July 21, 2024 07:00 AM

Magnus: Emacs via Nix with mu4e

I've been running development versions of Emacs ever since I switched to Wayland and needed the PGTK code. The various X-git packages on AUR makes that easy, as long as one doesn't mind building the packages locally, and regularly. Building a large package like Emacs does get a bit tiring after a while though so I started looking at the emacs overlay to see if I could keep up without building quite that much.

The first attempt at this failed as I couldn't get my email setup working; emacs simply refused to find the locally installed mu4e package. I felt I didn't have time to solve it at the time, reverted back to doing the builds myself again. It kept irritating me though, and today I made another attempt. This time I invested a bit more time in reading up on how to install emacs via Nix with packages. Something that paid off.

I'm managing my packages using nix profile and a flake.nix. To install emacs with a working mu4e I started with adding the emacs overlay to the inputs

inputs = {
  nixpkgs.url = "github:nixos/nixpkgs?ref=nixpkgs-unstable";
  ...
  community-emacs.url = "github:nix-community/emacs-overlay";
};

and in my outputs I made sure to use the overlay on nixpkgs

outputs = inputs@{ nixpkgs, community-emacs, ... }:
  let
    system = "x86_64-linux";
    pkgs = import nixpkgs {
      inherit system;
      overlays = [ community-emacs.overlays.emacs ];
    };
    ...

and in the list of packages passed to pkgs.buildEnv I added

...
((emacsPackagesFor emacs-pgtk).emacsWithPackages
  (epkgs: [ epkgs.mu4e ]))
mu
...

That's all there's to it. After running nix profile update 0 I had a build of emacs with Wayland support that's less than a day old, all downloaded from the community cache. Perfect!

-1:-- Emacs via Nix with mu4e (Post)--L0--C0--July 20, 2024 11:04 PM

James Cherti: Emacs: Enhancing up and down subtree movement in outline-mode and outline-minor-mode

4.5/5

When editing outlined files (e.g., using the built-in outline-minor-mode, or packages like outline-indent.el, outline-yaml.el, etc.), handling subtrees efficiently can significantly enhance productivity, especially when working with complex documents. If you’re familiar with outline-mode or outline-minor-mode, you might have noticed that the built-in functions for moving subtrees up and down, outline-move-subtree-up and outline-move-subtree-down:

  • Blank line exclusion: outline-move-subtree-up and outline-move-subtree-down exclude the last blank line of the subtree when the outline-blank-line variable is set to t. Setting outline-blank-line to t is worthwhile because it retains a visible blank line after the subtree and before the next heading, improving the readability of the document.
  • Cursor position reset: After moving a subtree up or down, the cursor position is often reset, which can be disruptive during editing.

Here’s how you can address these issues by using custom functions to enhance subtree movement:

(require 'outline)

(defun my-advice-outline-hide-subtree (orig-fun &rest args)
  "Advice for `outline-hide-subtree'.
This ensures that the outline is folded correctly by
outline-move-subtree-up/down, preventing it from being unable to open the fold."
  (let ((outline-blank-line
         (if (bound-and-true-p my-outline-hide-subtree-blank-line-enabled)
             my-outline-hide-subtree-blank-line
           outline-blank-line)))
    (apply orig-fun args)))

(defun my-advice-outline-move-subtree-up-down (orig-fun &rest args)
  "Move the current subtree up/down past ARGS headlines of the same level.
This function ensures the last blank line is included, even when
`outline-blank-line' is set to t. It also restores the cursor position,
addressing the issue where the cursor might be reset after the operation."
  (interactive "p")
  (let ((column (current-column))
        (outline-blank-line nil)
        (my-outline-hide-subtree-blank-line-enabled t)
        (my-outline-hide-subtree-blank-line outline-blank-line))
    (apply orig-fun (or args 1))
    (move-to-column column)))

(advice-add 'outline-hide-subtree
            :around #'my-advice-outline-hide-subtree)
(advice-add 'outline-move-subtree-up
            :around #'my-advice-outline-move-subtree-up-down)
(advice-add 'outline-move-subtree-down
            :around #'my-advice-outline-move-subtree-up-down)

I also recommend using Ctrl-Up and Ctrl-Down key bindings for moving subtrees up and down.

(define-key outline-mode-map (kbd "C-<up>") 'outline-move-subtree-up)
(define-key outline-mode-map (kbd "C-<down>") 'outline-move-subtree-down)

(defun my-setup-outline-minor-mode-keybindings ()
    "Set up keybindings for moving subtrees in `outline-minor-mode'."
  (define-key outline-minor-mode-map (kbd "C-<up>") 'outline-move-subtree-up)
  (define-key outline-minor-mode-map (kbd "C-<down>") 'outline-move-subtree-down))
(add-hook 'outline-minor-mode-hook 'my-setup-outline-minor-mode-keybindings) 

With this setup, you will ensure that every time you use outline-move-subtree-up or outline-move-subtree-down, the last blank line of the subtree is included and the cursor position is restored.

-1:-- Emacs: Enhancing up and down subtree movement in outline-mode and outline-minor-mode (Post James Cherti)--L0--C0--July 20, 2024 03:56 PM

But She's a Girl: Devilish fun with a modeless modal editing mode

As I write this, I am imagining one of those slightly cheesy voiceovers for a TV show, reminding viewers of the previous episode: “Last time on ‘BSAG Gets Nerdy About Emacs’…”. You may remember that I was on the Emacs from Scratch cycle again, and enjoying the process of learning the default Emacs keybindings, instead of installing evil-mode like I usually do. Well, I am still doing that, but a random meander around the Emacs-y corners of the internet turned up susam’s devil-mode, a sort of modeless modal editing mode. A what now?

-1:-- Devilish fun with a modeless modal editing mode (Post)--L0--C0--July 20, 2024 10:45 AM

James Cherti: Introducing elispcomp: Compiling Elisp code directly from the command line

5/5

The elispcomp command line tool allows compiling Emacs Lisp (Elisp) code directly from the terminal or from a shell script. It facilitates the generation of optimized .elc (byte-compiled) and .eln (native-compiled) files, which can significantly improve the performance of Emacs.

The tool executes a headless instance of Emacs that recursively scans the specified directories, byte compiling and native compiling all the .el files that haven’t been compiled yet. It supports various configuration options, allowing you to adapt the compilation process to suit your needs.

When configured appropriately, Emacs can compile to both .elc and .eln files. However, for those who wish to automate the background compilation of .el files using a script, the elispcomp command-line tool can be beneficial in ensuring that their Emacs setup remains up-to-date without manual intervention and without starting an Emacs instance. I personally use elispcomp compile multiple Elisp files across various machines and Emacs versions.

Installation

To get started with elispcomp, you can install it using pip, Python’s package installer. Here’s how:

pip install --user elispcomp

This command installs elispcomp and places the executable in your ~/.local/bin/ directory, making it easily accessible from your command line.

Usage

The elispcomp command line tool is straightforward to use.

First example: To compile all .el files located in the ~/.emacs.d/lisp:

elispcomp ~/.emacs.d/lisp

Second example: To compile all .el files located in the ~/.emacs.d/lisp directory, and store the native-compiled files in the ~/.emacs.d/eln-cache directory:

elispcomp --eln-cache ~/.emacs.d/.eln-cache ~/.emacs.d/lisp

Command line options

usage: elispcomp [--option] [N]

Recursively byte and native compile .el files.

positional arguments:
  N                     The directories to be scanned recursively by Emacs to 
                        locate the '.el' files for compilation.

options:
  -h, --help            show this help message and exit
  -c ELN_CACHE, --eln-cache ELN_CACHE
                        The eln-cache directory where Emacs stores the
                        compiled native compiled code. Defaults to the
                        default Emacs eln-cache directory.
  -e EMACS_BIN, --emacs-bin EMACS_BIN
                        Path to the Emacs binary. Defaults: emacs
  -j JOBS, --jobs JOBS  Specify the number of parallel jobs for compilation.
                        Default: Half the number of available CPUs
  -b, --disable-byte-comp
                        Disable byte-compile. Default: enabled
  -n, --disable-native-comp
                        Disable native compilation. Default: enabled
  -i LOAD_PATH, --load-path LOAD_PATH
                        Recursively adds the subdirectories of the specified
                        directory to the Emacs `load-path`. This option can
                        be used multiple times to include several directories.

The elispcomp command-line tool offers an alternative approach to managing Emacs Lisp code. Try it out and experience a new way to compile your Elisp codebase from the command line or from a script.

Links

-1:-- Introducing elispcomp: Compiling Elisp code directly from the command line (Post James Cherti)--L0--C0--July 19, 2024 01:08 PM

James Dyer: Selected Window Accent Mode v0.8.0

Whats New

What’s New in Selected Window Accent Mode v0.8.0 - (selected-window-accent-mode) which is my window accent package in MELPA for Emacs, here is a quick summary before I dive into the new features:

The Selected Window Accent Mode is an Emacs package designed to visually distinguish the currently selected window by applying a unique accent color to its fringes, mode line, header line, and margins.

https://github.com/captainflasmr/selected-window-accent-mode

Transient Map for Quick Access

In the latest release of Selected Window Accent Mode, version 0.8.0, users of Emacs 28.1 and above can enjoy the convenience of a transient map. This new feature allows you to access a transient menu by simply pressing `C-c w`:

(global-set-key (kbd "C-c w") 'selected-window-accent-transient)

Upon invoking this key binding, the following transient menu will be displayed:

Release Highlights

v0.8.0 | 2024-07-15

  • Transient Menu: A transient menu has been added for interactive adjustments, simplifying the process of tweaking settings on the fly. Refer to the README for detailed usage instructions.
  • Emacs Dependency: The Emacs dependency has been upgraded to version 28.1.
  • Custom Foreground Accent Color: A new variable, `selected-window-accent-fg-color`, has been introduced for setting a custom foreground accent color.
  • Enhanced Customization Options:
    • `selected-window-accent-foreground-adjust-factor`
    • `selected-window-accent–use-complementary-color`
    • `selected-window-accent–foreground-invert-state`
    • `selected-window-accent–foreground-offset`
  • Foreground Brightness Functions:
    • `selected-window-accent-flip-foreground-color`
    • `selected-window-accent-increment-foreground-color`
    • `selected-window-accent-decrement-foreground-color`
    • `selected-window-accent-toggle-complementary-color`
    • `selected-window-accent-toggle-tab-accent`
    • `selected-window-accent-toggle-smart-borders`
  • Configuration Export: A new function, `selected-window-accent-output-selected-window-accent-settings`, allows you to output the current settings for easy copying and pasting into your Emacs init file.
  • Miscellaneous: Various improvements and refactoring have been made to enhance the overall functionality and maintainability.

v0.7.0 | 2024-07-09

  • Compatibility Fixes: Addressed issues with other packages and restored modeline height when switching between modes.
  • Issue Resolutions:
    • ISSUE #4: Resolved compatibility issues with other packages.
    • ISSUE #3: Fixed problems causing the package to break fringes.

With these updates, Selected Window Accent Mode continues to offer increased customization and improved user experience. Stay tuned for more exciting features in the upcoming versions! 😀

-1:-- Selected Window Accent Mode v0.8.0 (Post James Dyer)--L0--C0--July 19, 2024 10:15 AM

Charles Choi: Emacs Regexps: The Small Print

With my recent work with Casual RE-Builder, I found to my surprise that not all Emacs regexp commands take an Emacs-style regexp. 🤯

Apparently some commands take a grep-style of regex like dired-do-find-regexp and dired-do-find-regexp-and-replace. For such commands, the regexp syntax is dependent on the type of grep that is installed and configured for use by Emacs. If you are using GNU grep, the good news is that the regexp syntax is largely the same as Emacs.

I qualify this as largely because with interactive commands, the escaping rules are different between Emacs and grep-style regexps. I suspect this has only added to the frustration of using plain RE-Builder which only provides export for a Emacs-style regexp to be used in code.

To alleviate this, Casual RE-Builder now has a new command to export specifically to interactive grep-style regex commands. This presumes that the GNU grep is being called.

Also the search & replace menu in Casual Dired has been modified to highlight such grep-style regex commands.

One last note: While I’ve taken effort to verify that this new command is doing all the right escaping, I would not be surprised if it has bugs. Because Elisp does not have support for raw strings like Python and Swift, I’m at a loss to know how to write a unit-test to automate its verification. For now I’m doing it manually, with test regexps that hopefully cover enough escaping behavior. If you find a bug, please report an issue with your regexp and the target text so I can troubleshoot. I’d also qualify that my knowledge of Elisp regexps is not that deep. I’d be happy to get guidance from more enlightened readers.

With all that said, I invite you to try this new feature out in Casual RE-Builder. I think you’ll be delighted that you did.

-1:-- Emacs Regexps: The Small Print (Post Charles Choi)--L0--C0--July 18, 2024 09:00 PM

Irreal: Learn Vim or Emacs

Kris Brandow has a (very) short video—I think it’s part of a podcast—advancing the idea that you should learn Vim or Emacs. Irreal, of course, is not going to argue with that but I wish he’d given more reasons why you should. What he does say is that you’ll discover you can be more productive with Vim or Emacs than you can with an IDE but doesn’t explain why that is. You should, he says, just try them.

One of the other people on the video objected that you don’t “just try” Emacs. It’s a commitment that takes dedication and effort to learn. That is certainly true of Emacs as we all know but it’s true of Vim as well. It’s not as hard to master as Emacs but there’s a surprising amount to know before you can consider yourself to have mastered it. That’s the problem with saying, “Just try it.” You won’t see real benefits from either editor until you’ve put a some time and effort into learning them.

The most depressing thing about the video is that Brandow described his suggestion as an “unpopular opinion”. I suppose that it might be unpopular among a certain segment of our community but there are also those who think that Javascript is a great, well thought out programming language. Ours is nothing if not a vibrant community with a diversity of opinion.

-1:-- Learn Vim or Emacs (Post jcs)--L0--C0--July 18, 2024 03:15 PM

J.e.r.e.m.y B.r.y.a.n.t: preview-auto in LaTeX buffers

AUCTeX includes the @code{preview-mode} facility, which generates embedded images of LaTeX fragments, typically mathematical expressions. This needs to be called manually, with @code{preview-at-point}. Paul Nelson has written the package preview-auto, providing the preview-auto-mode. This runs preview as needed after certain changes. This is a very useful feature which works well alongside AUCTeX, on which it depends. This package is available in GNU ELPA.
-1:-- preview-auto in LaTeX buffers (Post)--L0--C0--July 17, 2024 11:02 PM

Alvaro Ramirez: OCR those buffers

17 July 2024 OCR those buffers

I've written about macosrec before. A tiny macOS command line utility I built to take screenshots or videos of my macOS windows. Sure, there are a gazillion utilities out there, but I wanted my own, so I could bend and integrate with Emacs as needed.

If you've seen me post a screenshot or gif after April 2023, it was likely taken with macosrec.

As of macosrec v0.7.3, OCR was added to the mix. I've also added a couple of dwim-shell-commands ( dwim-shell-commands-macos-ocr-text-from-desktop-region and dwim-shell-commands-macos-ocr-text-from-image), so I can do things like:

OCR region

Use the mouse to select a region to OCR.

ocr-region.gif

*This gif area recording was captured via macOS's built-in screencapture.

OCR dired files

Selecting any file (or files) in dired OCRs the whole lot.

ocr-files.gif

*This gif window recording was captured via macosrec.

Invoking dwim-shell-commands-macos-ocr-text-from-image from the current image buffer does the job also.

What about non-macOS users?

The same approach can be used with any other OCR command line tool. dwim-shell-command includes dwim-shell-commands-tesseract-ocr-text-from-image, which uses tesseract.

While I've had more reliable results via macosrec (using macOS's Vision API), I'm sure there are other great alternatives on linux. If you know of one, I'd love to hear.

Available on github

Both macosrec and dwim-shell-command are on GitHub and installable via brew install xenodium/macosrec/macosrec and MELPA respectively.

Unrelated - Want your own blog?

Like this blog? Want to start a blog? Run your blog off a single file. Write from the comfort of Emacs and drag and drop to the web. I'm launching a blogging service at lmno.lol. Looking for early adopters. Get in touch.

-1:-- OCR those buffers (Post)--L0--C0--July 17, 2024 04:54 PM

Irreal: Gluing Emacs Features Together

Álvaro Ramírez has a very revealing post about the compounding benefits of learning a bit of Elisp. Studying how Emacs works and learning its various features pays huge dividends but, says Ramírez, learning some Elisp can compound those dividends and enable you to mold Emacs to a tool hyperspecialized to your needs.

He starts by postulating two features that you realize would be even more useful if you could somehow combine them. Then he gives a specific example. He considers the two packages symbol-overlay and multiple-cursors. The symbol-overlay package highlights all occurrences of the symbol under point in the current buffer and, of course, multiple-cursors lets you perform the same operation in multiple places at the same time.

He uses them both all the time but realized that it would be very handy if he could invoke multiple-cursors with a cursor on each occurrence of the symbol under point. He needed, in short, to combine the action of symbol-overlay and multiple-cursors.

That turns out to be fairly easy if you know some Elisp. Ramírez walks us through how he figured out how to do it and shows the Elisp that does it. There’s not a lot of code (about 20 lines), it’s easy to understand, and it serves as a great example of how a bit of Elisp can work magic. Finally, he made an animated GIF that shows it in action.

This is a nice post and it provides some code that you may find useful for your own workflow. Take a few minutes to give it a look.

-1:-- Gluing Emacs Features Together (Post jcs)--L0--C0--July 17, 2024 02:58 PM

Irreal: Casual RE Builder

Charles Choi has another great addition to his Casual Suite. This time it’s an interface to the re-builder command. There are two things that everyone agrees about Emacs regular expressions:

  1. They’re very powerful and useful
  2. They have an arcane syntax and are hard to use

Well really, they’re not that much different from other RE syntaxes but there is enough difference to make using them harder than it should be. Indeed, many folks who everyone would agree are master Emacs users constantly bemoan the RE syntax and wish it were replaced with something else such as Perl Compatible REs.

Happily, there’s a tool, re-builder, that can help. I’ve written about it here and here. Unhappily, I find it really hard to use. Finding a good regexp is easy enough but it’s hard to remember how to export that regexp for use in your code or the current command.

That’s where Choi’s Casual RE-builder comes in. Like other members of the Casual Suite, when you need to remember some of the arcane commands, you can simply invoke a handy transient menu to remind you.

As much as I like re-builder, I almost never use it because I can never remember how to export the resulting regexp to where I need it. Choi’s RE-builder solves this problem and, to my mind, increases the utility of re-builder a great deal.

If you have troubles with Emacs regexs or have found re-builder too hard to use, you should take a look at Choi’s RE-builder app.

-1:-- Casual RE Builder (Post jcs)--L0--C0--July 16, 2024 03:45 PM

James Dyer: Emacs Blog 2 Year Anniversary - First Post Revisit - Create Local Offline ELPA MELPA ORG

I’ve noticed that my Emacs blog is now almost 2 years old!

Is there something absurd about writing about a text editor in that very text editor for such a long period? - I think the answer to this is clearly…, no!

My first post was on 2022-07-15 and this will be blog number 97.

And yes before you ask, how do I know this to be true?, well I found out the Emacs way!

I recorded its inception date in org-agenda, so I saw this date creep up this week :

** blog anni :james:web:
<2022-07-15 .+1y>

The date of my first post is in an org drawer in my single Emacs blog org file:

:EXPORT_HUGO_LASTMOD: 2022-07-15

and the blog number?, well, I org-copy-visible’d my org blog file of all the top level org headers, pasted into the scratch buffer, flush-line’d out all the TODO entries, then finally entered (display-line-numbers-mode) to get the number of lines (I suspect there might be an easier way to do this 😀)

I also wrote this post ahead of time and to remind me when to post I created an org schedule entry as follows:

** TODO post 2 yr emacs blog post
SCHEDULED: <2024-07-15 Mon>

and appeared in the agenda as :

Monday     15 July 2024 W29
  aab--calendar:Scheduled:  TODO post 2 yr emacs blog post

and in (cfw:open-org-calendar) as :

+-------------------------+
| 15 (3)                  |
| TODO post 2 yr emacs    |
| blog anni               |
|                         |
|                         |
|                         |
+-------------------------+

Living an Emacs life and especially partially through org means that any and all information can be easily extracted let alone initially logged, the basic text format is so simple and uniform that all the data items above were pretty much extracted using the same mechanism through Emacs.

Anyway enough of all that, in celebration of being able to maintain some level of blogging discipline for 2 years, I decided to revisit my very first post, which was on how to create an offline version of the major Emacs repositories, namely:

  • ELPA
  • MELPA
  • ORG

As it turns out this post is still quite relevant as from time to time, I need an offline version for an Emacs setup without an internet connection.

So lets re-post!, just for fun!, including the bash script that I still use:


Steps to locally download emacs packages for offline installation.

Local ELPA MELPA ORG

#! /bin/bash
cd ~
mkdir -p emacs-pkgs/melpa
mkdir -p emacs-pkgs/elpa

echo
echo "updating MELPA..."
echo
rsync -avz --delete --progress rsync://melpa.org/packages/ ~/emacs-pkgs/melpa/.

echo
echo "updating ELPA..."
echo
rsync -avz --delete --progress elpa.gnu.org::elpa/. ~/emacs-pkgs/elpa

# org (currently no rsync support)
echo
echo "updating ORG..."
echo
cd ~/emacs-pkgs
git clone https://git.savannah.gnu.org/git/emacs/org-mode.git
# wget -r -l1 -nc -np https://orgmode.org/elpa

I then copy the emacs-pkgs directory to the offline target machine and change the default package manager archives to point to these packages.

Modify .emacs in the following manner commenting out the online package communication:

;; (setq package-archives '(("melpa" . "https://melpa.org/packages/")
;;                          ("org" . "https://orgmode.org/elpa/")
;;                          ("elpa" . "https://elpa.gnu.org/packages/")))

(setq package-archives '(("melpa". "~/emacs-pkgs/melpa")
                          ("org" . "~/emacs-pkgs/elpa")
                          ("elpa" . "~/emacs-pkgs/org-mode/lisp")))
-1:-- Emacs Blog 2 Year Anniversary - First Post Revisit - Create Local Offline ELPA MELPA ORG (Post James Dyer)--L0--C0--July 15, 2024 08:00 PM

Charles Choi: Announcing Casual RE-Builder

Knowing how to use regular expressions (regexp) is a superpower. While there are many different variants of regexp syntax, in Emacs the reward is handsome if you put in the effort to learn its flavor of it. Emacs has many interactive commands that take in a regexp argument. Here’s a small sample:

dired-do-copy-regexp, dired-do-find-regexp , dired-do-find-regexp-and-replace , dired-do-hardlink-regexp , dired-do-isearch-regexp , dired-do-query-replace-regexp , dired-do-rename-regexp , dired-do-search , dired-do-symlink-regexp , dired-flag-files-regexp , dired-isearch-filenames-regexp , dired-mark-files-containing-regexp , dired-mark-files-regexp , ibuffer-do-isearch-regexp , ibuffer-do-query-replace-regexp , ibuffer-mark-by-content-regexp , ibuffer-mark-by-file-name-regexp , ibuffer-mark-by-mode-regexp , ibuffer-mark-by-name-regexp , isearch-backward-regexp , isearch-forward-regexp , isearch-highlight-lines-matching-regexp , isearch-highlight-regexp , isearch-query-replace-regexp , query-replace-regexp

Emacs has a built-in tool called RE-Builder that makes it easier to learn and construct regexps. Invoked by the command re-builder, this creates a small editable window where you can interactively enter a regexp and see matches (if any) highlighted in a target buffer, typically the last one you were working on. While it’s nice to have around, recalling its command set can be a chore which makes it an ideal candidate for Casual.

Announcing Casual RE-Builder now on MELPA as part of the Casual Suite of Emacs porcelains. Install this as an individual package or if you already have Casual Suite installed, update your packages and you’ll automatically pick this up.

Notable Features

  • Easy access to regexp syntax documentation.
    • The less friction it takes to figure out the right syntax, the further along you are to having your desired regexp.
  • Export regexp for interactive use.
    • Basic RE-Builder only supports exporting a regexp to use in Elisp code. This regexp unfortunately can not work when entered interactively because of character escaping. Casual addresses this by providing support for exporting a regexp that can be used interactively.

Usage

Basic Usage

When the command re-builder is invoked, a buffer named “✳︎RE-Builder✳︎” is created. Activate Casual RE-Builder with the binding C-o (or one of your preference).

At the top of the menu shows the title “RE-Builder” with the target buffer enclosed in parenthesis. The regexp pattern will be applied to the target buffer. The target buffer can be changed with the (b) Target buffer menu item.

Emacs supports three different regexp syntax: 1) read, 2) string, 3) Rx. Use the (x) Syntax menu item to alter it. The current syntax is shown in parenthesis.

If multiple sub-expressions are in the regexp pattern, then they can be observed via the (s) Subexp mode menu item.

If the regexp pattern entered in the “✳︎RE-Builder✳︎” finds multiple matches, a match can be navigated to via the (p) Previous and (n) Next menu items.

Exporting the Regexp Pattern

Once a desired regexp pattern is defined, there are two menu items that can be used to export (copy) it to the kill-ring for further use.

  • (w) Interactive will copy the regexp to the kill-ring so that it can be yanked in an interactive command that requires a regexp (e.g. query-replace-regexp).
    • This should only be used when the regexp syntax is set to string.
    • ❗️When yanking (typically C-y) a regexp into an interactive prompt, you must have the point/focus in the minibuffer prompt (typically via mouse). Otherwise the desired content can be altered with extra escaping.
  • (c) Code will copy the regexp to the kill-ring so that it can be yanked into a Elisp code that requires a regexp argument.

Regexp Syntax Help

The menu item (i) will invoke the Info page for regexp syntax with respect to the current syntax type.

Quitting RE-Builder

Select (q) Quit to exit the RE-Builder tool.

Closing Thoughts

While I’ve known and used RE-Builder for years, it has never been an “essential” tool to me because it was so clumsy to orchestrate its output with other interactive regexp commands. Add to that the inertia to learn yet another regexp variant and ultimately it would result in me overlooking Emacs commands that used regexp arguments.

Adding interactive export and orchestrating it with the regexp commands in Casual Dired and Casual IBuffer has been an eye-opening and exhilarating experience. With the above I can now do multi-file refactoring in Emacs with confidence. Before Casual RE-Builder, this would of been both a heroic and unthinkable notion.

If you’re like me and are most familiar with Perl Compatible Regular Expressions (PCRE) (for yours truly, the Python library re in particular), it won’t be too much of a stretch to understand Emacs regexps. My recommendation is to jump in! The reward will be a whole universe of Emacs regexp commands that will become available to you to use at your discretion.

References

-1:-- Announcing Casual RE-Builder (Post Charles Choi)--L0--C0--July 15, 2024 04:20 PM

Irreal: Relative Line Numbers

Just a quickie from something that I’ve had in the queue for a while. Chris Maiorana has a short post on relative line numbers. The idea is that the current line—the line you’re on—is considered line 0 and the lines above and below it are labeled as the number of lines away from the current line.

That’s handy if you’re interested in, say, 5 lines above or below the current line because they’re labeled as that. I love the idea but, truth to tell, I have never found a compelling use case for them. Maiorana says it handy for authors who want to know how many lines there are in the current paragraph but offers no other reason to adopt them.

Still, lots of people seem to like them and they’re certainly easy to turn on. Take a look at Maiorana’s post for the details.

-1:-- Relative Line Numbers (Post jcs)--L0--C0--July 15, 2024 03:07 PM

Sacha Chua: 2024-07-15 Emacs news

Links from reddit.com/r/emacs, r/orgmode, r/spacemacs, r/planetemacs, Mastodon #emacs, Hacker News, lobste.rs, programming.dev, lemmy, communick.news, planet.emacslife.com, YouTube, the Emacs NEWS file, Emacs Calendar, and emacs-devel. Thanks to Andrés Ramírez for emacs-devel links. Do you have an Emacs-related link or announcement? Please e-mail me at sacha@sachachua.com. Thank you!

-1:-- 2024-07-15 Emacs news (Post Sacha Chua)--L0--C0--July 15, 2024 01:54 PM

Alvaro Ramirez: Its all up for grabs, compound with glue

14 July 2024 It's all up for grabs, compound with glue

I've written before, once you learn a little elisp, Emacs becomes this hyper malleable editor/platform. A live playground of sorts, where almost everything is up for grabs. You can inspect and tweak behaviour of just about anything to your liking.

While the compounding benefits of using your favourite Emacs utilities are evident over time, learning elisp takes the compounding effect to another level. It empowers you to have those aha moments like "if I could just wire this awesome utility with that other one, it'd be perfect for me" and enable you to act on it.

Take, for example, symbol-overlay and multiple-cursors. Two Emacs packages I've been using for years. The first one is a feature you've likely experienced on your favourite IDE or editor without thinking too much about it. Placing your editor cursor on a variable automatically highlights its usages. It's one of those lovely features with zero learning demands.

overlay-symbol.gif

The second utility, multiple-cursors, does demand some learning but can be so fun to use once you get the hang of it. Below is a little multiple cursor demo I used recently in a reddit comment, but you really should check out Emacs Rocks! Episode 13: multiple-cursors (stick around for the ending).

mc_x2.gif

So where am I going with this? While symbol-overlay offers a mechanism to rename symbols via symbol-overlay-rename, I prefer multiple-cursors for this kind of thing… "if I could just get symbol-overlay to tell multiple-cursors where to place my cursors, it'd be just perfect for me".

I've been wanting this tweak for some time. Today's the day I finally act on it. I had no idea how to go about it, but opening symbol-overlay.el (via M-x find-library symbol-overlay) and browsing through all functions (via imenu) yields the first piece I needed: symbol-overlay-get-list.

imenu.png

(defun  symbol-overlay-get-list (dir  &optional symbol exclude)
   "Get all highlighted overlays in the buffer.
 If SYMBOL is non-nil, get the overlays that belong to it.
 DIR is an integer.
 If EXCLUDE is non-nil, get all overlays excluding those belong to SYMBOL."
  ...)

Let's take symbol-overlay-get-list for a spin, courtesy of M-x eval-expression, and see what we get out of it:

eval.gif

With a list of overlays, we now know where to tell multiple-cursors to do its thing. For the second piece, we needed to peek at any of the multiple-cursors commands I already use. I happen to pick mc/mark-all-like-this to examine what's under the hood.

(defun  mc/mark-all-like-this ()
   "Find and mark all the parts of the buffer matching the currently active region"
  (interactive)
  (unless (region-active-p)
    (error  "Mark a region to match first."))
  (mc/remove-fake-cursors)
  (let ((master (point))
        (case-fold-search nil)
        (point-first (< (point) (mark)))
        (re (regexp-opt (mc/region-strings) mc/enclose-search-term)))
    (mc/save-excursion
     (goto-char 0)
     (while (search-forward-regexp re nil t)
       (push-mark (match-beginning 0))
       (when point-first (exchange-point-and-mark))
       (unless (= master (point))
         (mc/create-fake-cursor-at-point))
       (when point-first (exchange-point-and-mark)))))
  (if (> (mc/num-cursors) 1)
      (multiple-cursors-mode 1)
    (mc/disable-multiple-cursors-mode)))

The star of the mc/mark-all-like-this attraction is mc/create-fake-cursor-at-point, used to create each cursor. If we can just iterate over the overlays, we'd be able to create a fake cursor per overlay. There's some additional logic needed to ensure all fake cursors are placed in the same relative position within symbol (using an offset). Finally, we need to enable multiple-cursors-mode.

We put it all together in ar/mc-mark-all-symbol-overlays:

(defun  ar/mc-mark-all-symbol-overlays ()
   "Mark all symbol overlays using multiple cursors."
  (interactive)
  (mc/remove-fake-cursors)
  (when-let* ((overlays (symbol-overlay-get-list 0))
              (point (point))
              (point-overlay (seq-find
                              (lambda (overlay)
                                (and (<= (overlay-start overlay) point)
                                     (<= point (overlay-end overlay))))
                              overlays))
              (offset (- point (overlay-start point-overlay))))
    (setq deactivate-mark t)
    (mapc (lambda (overlay)
            (unless (eq overlay point-overlay)
              (mc/save-excursion
               (goto-char (+ (overlay-start overlay) offset))
               (mc/create-fake-cursor-at-point))))
          overlays)
    (mc/maybe-multiple-cursors-mode)))

and with that, you finally get to see it all in action…

symbol-overlay-meets-multiple-cursors.gif

Unrelated - Want your own blog?

Like this blog? Want to start a blog? Run your blog off a single file. Write from the comfort of Emacs (or your favourite text editor) and drag and drop to the web. I'm launching a blogging service at lmno.lol. Looking for early adopters. Get in touch.

-1:-- Its all up for grabs, compound with glue (Post)--L0--C0--July 14, 2024 08:30 PM

Irreal: A Spelling Transient

Over at DyerDwelling there’s another nice example of using a transient menu to capture the keystrokes for a set of packages. This time it’s for some spelling related packages. The author couldn’t make up his mind on what keystrokes he wanted for the various commands so he decided to implement a menu instead.

If you’ve been reading Irreal lately, you know that I’m a big fan of this approach, especially as realized by Charles Chou’s Casual Suite. Nonetheless, I’m not sure that a menu is the best solution here. At least not for commands that do things like correct the last misspelling. I use commands like that constantly and want them instantly available without having to wade through a menu.

Still, we can have it both ways. There’s no reason to restrict yourself to one approach. You can have a menu as described in the DyerDwelling post and still specify keybindings for the commands you use all the time. And to be fair, you can also think of the sequence to invoke the menu and the option choice as a single, slightly longer, key sequence.

I’m again impressed at how easy it is to set up a transient menu. Take a look at the code in the DyerDwelling post to see for yourself.

-1:-- A Spelling Transient (Post jcs)--L0--C0--July 14, 2024 03:32 PM

Anand Tamariya: Annotate completion candidates (GNU Emacs)


GNU Emacs supports annotation for completion candidates. An annotation is a small bit of useful information shown next to a completion candidate which a package developer can use to provide additional help to the user while making a selection. e.g. while selecting a command, this is usually the keyboard shortcut.

In the following example, annotation is used to display a sample text with the candidate font-family applied. 

(defun test ()
  (interactive)
  (let* ((completion-extra-properties
          `(:annotation-function
        (lambda (a)
          (propertize " (OIly10)" 'face
              `(:family ,a :background "grey"))))))
    (completing-read "Font family: " (font-family-list))
    ))

 

By default, Emacs uses completions-annotations face for the annotation. Use the following patch to skip changing the face when the annotation already has a face attached.

modified   lisp/minibuffer.el
@@ -1754,8 +1754,10 @@ completion--insert-strings
               (let ((beg (point))
                     (end (progn (insert (cadr str)) (point))))
                 (put-text-property beg end 'mouse-face nil)
-                (font-lock-prepend-text-property beg end 'face
-                                                 'completions-annotations)))
+                (or (get-text-property beg 'face)
+                    (font-lock-append-text-property beg end 'face
+                                                    'completions-annotations))
+                ))
         (cond
          ((eq completions-format 'vertical)
           ;; Vertical format

 

-1:-- Annotate completion candidates (GNU Emacs) (Post Anand Tamariya (noreply@blogger.com))--L0--C0--July 14, 2024 09:24 AM

Irreal: Org Template Fundamentals

Forward

Does anyone know what happened to Emacs Elements? As I was getting ready to publish this post, I notices that the below linked video was gone and that Google said it had been deleted by the author. On further investigation, I see that the entire playlist is gone.

I did find this post on the Emacs subreddit but it doesn’t have any information: just others wondering what happened to the site, and mourning its loss. If you know anything, please leave a comment.

My original post is below but, of course, none of the links lead anywhere interesting.

Original Post

Emacs Elements has a nice video up on Org mode capture templates. This video concentrates on the structure and meaning of the templates.

Org templates are one of the most useful ways of using Org to capture and record various types of data. I use them to capture tax, health, journal, TODO, email, and blogging data. They’re easy to adapt for capturing data in several formats and to annotate the captured information.

Building the templates is a bit fussy and you have to get them just right or they won’t work. That said, they have a reasonable format and aren’t too hard to learn. Even if you don’t want to build them yourself you can still use the Emacs configure subsystem.

The video is relatively short—7 minutes, 37 seconds—so there’s no point in recapitulating it here. Spend a few minutes with it to find out the sorts of things that are possible and use the excellent Org documentation to fill in any blanks.

-1:-- Org Template Fundamentals (Post jcs)--L0--C0--July 13, 2024 03:12 PM

James Cherti: Emacs Evil Mode: Disabling the automatic removal of spaces after leaving Insert mode

5/5

By default, Emacs evil-mode removes newly inserted spaces when exiting insert mode. However, some users may find this disruptive to their workflow. This is particularly true for those who edit file formats where trailing spaces are significant or who simply prefer to manage whitespace manually.

To prevent the automatic removal of trailing spaces when leaving insert mode, add the following Elisp code to the Emacs init file:

(with-eval-after-load 'evil
  (defun my-evil-disable-remove-spaces ()
    "Disable automatic removal of trailing spaces in `evil-mode'."
    (setq-local evil-maybe-remove-spaces nil))

  (add-hook 'evil-insert-state-entry-hook #'my-evil-disable-remove-spaces))

The function above sets the evil-maybe-remove-spaces variable to nil when entering insert mode, preventing the evil-maybe-remove-spaces function from deleting whitespace after leaving insert mode.

The evil-insert-state function, which Evil uses to switch to insert mode, behaves as follows:

  • When entering insert mode: It sets the evil-maybe-remove-spaces variable to t.
  • When exiting insert mode, it calls the evil-maybe-remove-spaces function, which removes trailing spaces if the evil-maybe-remove-spaces variable is set to t. Because the my-evil-disable-remove-spaces function above sets the evil-maybe-remove-spaces variable to nil when entering insert mode, it prevents the evil-maybe-remove-spaces function from deleting whitespace after leaving insert mode.

If you want to compare the behavior before and after the function above, use whitespace-mode. This mode visually highlights different types of whitespace characters, such as spaces, tabs, and newlines, making it easier to see the differences.

Customizing evil-mode with the simple piece of Elisp code above can prevent the automatic removal of trailing spaces when exiting insert mode. This adjustment allows for better control over whitespace in files.

-1:-- Emacs Evil Mode: Disabling the automatic removal of spaces after leaving Insert mode (Post James Cherti)--L0--C0--July 13, 2024 02:12 PM

Magnus: A function for jumping to a project TODO file

I've had org-projectile in my config since the beginning, and while it's worked nicely for me in my main config it gave me some grief when I played around with elpaca the other week.1

I tried to get the install instructions to work, but kept on getting errors when loading my config. Given that I only use it for one thing, to open the file TODO.org in the current project's root, I decided to just write a function for doing that instead.

(defun mep-projectile-open-todo ()
  "Open the project's todo file."
  (interactive)
  (if-let* ((proj-dir (projectile-project-root))
            (proj-todo-file (f-join proj-dir "TODO.org")))
      (org-open-file proj-todo-file)
    (message "Not in a project")))

Footnotes:

1

This was the second time I gave up on using it instead of straight, but that's another story.

-1:-- A function for jumping to a project TODO file (Post)--L0--C0--July 13, 2024 08:24 AM

Marcin Borkowski: Dedicated windows

There are some features of Emacs which you can read about in the manual and go “huh? what is that about? who’d ever need it?”, and then later turn out to need exactly them. Recently I learned that dedicated windows are just like that.
-1:-- Dedicated windows (Post)--L0--C0--July 13, 2024 06:14 AM

Please note that planet.emacslife.com aggregates blogs, and blog authors might mention or link to nonfree things. To add a feed to this page, please e-mail the RSS or ATOM feed URL to sacha@sachachua.com . Thank you!