emacs

Jim Newton 2025-05-23T12:01:05.916639Z

has anyone used an emacs package called hl-sexp? chatGPT thinks it exists, but I can’t find it. Am I suggesting that chatGPT sometimes lies? hmmm maybe.

Kirill Chernyshov 2025-05-23T12:01:53.482609Z

might be this package - https://github.com/daimrod/highlight-sexp

Jim Newton 2025-05-23T12:02:32.228699Z

I’m planning on doing a demo which involves quite a bit of evaluating the expressions at the cursor. just for DEMO purposes, i’d like to always pre-highlight expression which I am about to evaluate.

Jim Newton 2025-05-23T12:02:55.309759Z

this is to make it easier for the audience watching on an overhead project to follow what’s happening.

Jim Newton 2025-05-23T12:03:18.758419Z

wrt highlight-sexp, chatgpt thinks it’s loadable from package-install.

daveliepmann 2025-05-23T12:03:33.281479Z

maybe https://github.com/magnars/expand-region.el could help, though it would be a manual pain

👍🏻 1
Jim Newton 2025-05-23T12:03:50.759759Z

but it seems the daimrod package is not in melpa

Jim Newton 2025-05-23T12:04:15.139559Z

for a manual approach I could simply always type cnt-meta-space

daveliepmann 2025-05-23T12:04:39.945169Z

what function name does that correspond to?

Jim Newton 2025-05-23T12:05:05.246379Z

mark-sexp

daveliepmann 2025-05-23T12:05:53.267639Z

IMHO expand-region is strictly superior

Jim Newton 2025-05-23T12:06:43.942519Z

i’ve never used expand-region. what is it?

Jim Newton 2025-05-23T12:07:12.958879Z

when I try to find the doc for expand-region, it gives me the doc for expand-region-abbrevs. dammit

daveliepmann 2025-05-23T12:07:39.670679Z

> Watch this https://www.youtube.com/watch?v=_RvHz3vJ3kA on Expand region. This is a feature every code editor should have. In this configuration, it's bound to s-1 and contract-region is bound to s-2, which allows one to press s-1 repeatedly without concern for overshooting the intended selection because it's easy to contract if we go to far.

daveliepmann 2025-05-23T12:08:11.103749Z

that's from https://github.com/jackrusher/dotemacs

Jim Newton 2025-05-23T12:08:18.995379Z

watching video.

Jim Newton 2025-05-23T12:09:42.549769Z

looks like backward-up-list

Jim Newton 2025-05-23T12:10:02.053619Z

except that backward-up-list just moves to the beginning of the surrounding sexp, without highlighting it.

Jim Newton 2025-05-23T12:10:43.427619Z

I use backward-up-list all the time.

daveliepmann 2025-05-23T12:11:52.406099Z

expand-region is about selection, not moving

Jim Newton 2025-05-23T12:13:56.568239Z

@delaguardo you mentioned hightlight-sexp, have you used it or were you just mentioning that you found it and it sounds similar?

Kirill Chernyshov 2025-05-23T12:16:47.969049Z

I used it for a week or so but quickly ditched it. expand-region is far superior imho

Jim Newton 2025-05-23T12:17:12.071179Z

@daveliepmann what’s the point of highlighting without moving there? I think i’ve been using backward-up-list for 15 years or so, and have trouble thinking otherwise

Jim Newton 2025-05-23T12:18:55.497169Z

@delaguardo yes I would imagine highlight-sexp would be unusable for day-to-day editing. my though is just for demoing.

Jim Newton 2025-05-23T12:19:01.362569Z

I’ll take a look into expand-region.

Kirill Chernyshov 2025-05-23T12:21:26.070929Z

even for demoing. I found it noisy to always highlight s-exp under the cursor. Instead, if I want to emphasize on some particular place, I can move and then use expand region to put an accent there

👍🏻 1
Kirill Chernyshov 2025-05-23T12:22:14.768589Z

basically I'm in control when and what I try to focus audience attention on

Macroz 2025-05-23T12:24:37.742519Z

I tend to use mic-paren for this. It automatically highlights the correct previous sexp when I'm at the end paren (where I would send the sexp to eval anyway) Something like this

;; parenthesis highlight
(use-package mic-paren
  :defer t

  :init
  (paren-activate)

  :config
  (setq paren-sexp-mode t)
  (setq paren-highlight-at-point t)
  (set-face-background 'paren-face-match "#204020"))

daveliepmann 2025-05-23T12:25:03.220489Z

selecting highlighting and moving are such completely separate things in my workflow (I suppose because I've used expand-region since day 1 on emacs) that I don't know how to answer your question, Jim

daveliepmann 2025-05-23T12:26:04.373409Z

I select to copy/cut, to make sure I'm counting parens correctly, to add another set of parens (which is I guess another form of navigation?)

Gent Krasniqi 2025-05-23T12:27:09.646059Z

I recently switched to mostly vanilla emacs commands for structural editing (just adding a custom slurp function on top), and IMO mark-sexp is plenty good. If you're at the beginning of a sexp it's just C-M-SPC. If you want the parent sexp, it's C-M-u C-M-SPC. Not that much of a hassle, every sexp command is basically on C-M and performs somewhat equivalent commands to non-sexp counterparts.

➕ 1
Macroz 2025-05-23T12:28:44.726389Z

I also have expand-region installed but I just don't use it. Regular commands work mostly.

Gent Krasniqi 2025-05-23T12:29:05.532749Z

When I'm doing structural editing my pinky is on natural positions on C (remapped capslock) and M, and the other default keybinings are all natural emacs ones

Gent Krasniqi 2025-05-23T12:29:21.482409Z

f b u d SPC etc

Gent Krasniqi 2025-05-23T12:31:48.954049Z

This custom slurp function has been serving me well, though it probably has some edge cases. Haven't run into them so far. It uses inbuilt sexp commands as well.

Gent Krasniqi 2025-05-23T12:35:52.382429Z

(defun gk-slurp-sexp ()
    "If the point is after a closing paren, slurp the next sexp into the former."
    (interactive)
    (when (member (preceding-char) '(?\) ?\} ?\]))
      (save-excursion 
        (delete-horizontal-space) 
        (kill-sexp) 
        (if (string-match-p "[[:graph:]]+" (current-kill 0))
            (progn
              (backward-char) 
              (unless (member (preceding-char) '(?\( ?\{ ?\[))
                (insert " ")) 
              (yank))
          (yank)))))

Gent Krasniqi 2025-05-23T12:44:13.840279Z

mark-sexp is mo go to, though. I don't use slurp that much anymore. I like the visual feedback of doing a mark-sexp then a paren, which wraps that sexp. (previously I'd start to the left of the sexp with a () and slurp)

Roma 2025-05-23T13:55:05.402039Z

There is a built-in way to highlight an expression before/after point:

(setopt show-paren-style 'expression)
(show-paren-mode)

🙌 1
🙌🏻 1
practicalli-johnny 2025-05-23T14:54:42.702459Z

https://www.gnu.org/software/emacs/manual/html_node/emacs/Narrowing.html is used to focus on a specific piece of code in the current buffer Its not the main use of narrowing, but is one option for helping an audience follow code

Ed 2025-05-23T15:13:30.463229Z

If you have transient-mark-mode enabled then C-M-SPC will highlight move the mark one sexp forwards (and C-M-- C-M-SPC will highlight move the mark one sexp backwards). You could then use cider-eval-region (`C-c C-v C-r` by default) or elisp-eval-region-or-buffer (`C-c C-e` on my machine) to eval the code?

Jim Newton 2025-05-23T21:57:30.363909Z

(setopt show-paren-style 'expression) this does the trick beautifully. Thanks @rrudakov

👍 1
Jim Newton 2025-05-23T21:57:58.830879Z

The color looks good too. I hope this works well for the video projector.

gunnar 2025-05-24T08:36:00.986919Z

I have not tested it on a projector, but the modus themes have really good contrast, both the light and dark variants.

👆 1
👆🏻 1
gunnar 2025-05-24T08:40:25.475679Z

Example (modus-operandi emacs 30+, only customized to have subtle line numbers/fringe)