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.
might be this package - https://github.com/daimrod/highlight-sexp
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.
this is to make it easier for the audience watching on an overhead project to follow what’s happening.
wrt highlight-sexp, chatgpt thinks it’s loadable from package-install.
maybe https://github.com/magnars/expand-region.el could help, though it would be a manual pain
but it seems the daimrod package is not in melpa
for a manual approach I could simply always type cnt-meta-space
what function name does that correspond to?
mark-sexp
IMHO expand-region is strictly superior
i’ve never used expand-region. what is it?
when I try to find the doc for expand-region, it gives me the doc for expand-region-abbrevs. dammit
> 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.
that's from https://github.com/jackrusher/dotemacs
watching video.
looks like backward-up-list
except that backward-up-list just moves to the beginning of the surrounding sexp, without highlighting it.
I use backward-up-list all the time.
expand-region is about selection, not moving
@delaguardo you mentioned hightlight-sexp, have you used it or were you just mentioning that you found it and it sounds similar?
I used it for a week or so but quickly ditched it. expand-region is far superior imho
@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
@delaguardo yes I would imagine highlight-sexp would be unusable for day-to-day editing. my though is just for demoing.
I’ll take a look into expand-region.
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
basically I'm in control when and what I try to focus audience attention on
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"))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
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?)
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.
I also have expand-region installed but I just don't use it. Regular commands work mostly.
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
f b u d SPC etc
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.
(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)))))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)
There is a built-in way to highlight an expression before/after point:
(setopt show-paren-style 'expression)
(show-paren-mode)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
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?
(setopt show-paren-style 'expression) this does the trick beautifully. Thanks @rrudakov
The color looks good too. I hope this works well for the video projector.
I have not tested it on a projector, but the modus themes have really good contrast, both the light and dark variants.
Example (modus-operandi emacs 30+, only customized to have subtle line numbers/fringe)