Skip to content

Instantly share code, notes, and snippets.

@jdtsmith
jdtsmith / org_emphasis_cursor_inside.el
Last active April 4, 2026 14:24
org hidden emphasis: change cursor when "inside" emphasized org text
;; `org-hide-emphasis-markers' is great, but when point is at the ends
;; of an emphasized piece of text, it's often not clear if you're in
;; position [A] or [B] (or, [X] or [Y]):
;;
;; [A]_[B]italicized[X]_[Y]
;;
;; This is frustrating, because sometimes you want to add text inside,
;; and sometimes you want to add adjacent text outside. The code below
;; tweaks `org' to help with with that problem, in two ways:
;;
@jdtsmith
jdtsmith / move_space.lua
Last active February 24, 2026 21:26
Move Space of Current Window with Hammerspoon by simulated click+Ctrl-arrow
local hotkey = require "hs.hotkey"
local window = require "hs.window"
local hse, hsee, hst = hs.eventtap,hs.eventtap.event,hs.timer
local spaces = require "hs.spaces"
function flashScreen(screen)
local flash=hs.canvas.new(screen:fullFrame()):appendElements({
action = "fill",
fillColor = { alpha = 0.35, red=1},
type = "rectangle"})
@jdtsmith
jdtsmith / consult-ripgrep-fd.el
Last active January 4, 2026 04:57
Roll your own emacs consult ripgrep + fd tool
;; An example building your own consult command. Here we take
;; advantage of fd's -X argument to find files with fd (e.g. recent
;; files, etc.) and search them with rg. Consult make this easy.
(defun consult--ripgrep-fd-make-builder (paths)
(let* ((opt-pat (rx (+ space) (group "--") (or (+ space) eos)))
(fd-builder (consult--fd-make-builder paths))
(rg-builder (consult--ripgrep-make-builder nil))
(rg-builder-with-paths (consult--ripgrep-make-builder paths)))
(lambda (input)
@jdtsmith
jdtsmith / repeat-change-cursor-color.el
Last active December 6, 2025 23:54
Emacs: change cursor color during active repeat-mode commands
(let ((orig (default-value 'repeat-echo-function))
rcol ccol in-repeat)
(setq
repeat-echo-function
(lambda (map)
(if orig (funcall orig map))
(unless rcol (setq rcol (face-foreground 'error)))
(if map
(unless in-repeat ; new repeat sequence
(setq in-repeat t
@jdtsmith
jdtsmith / toggle-debug-on-hidden-error.el
Last active November 16, 2025 03:20
Elisp: get stack trace for functions with suppressed errors (filter functions, post command hooks, etc.)
;;;; Power debugging
(defun my/reraise-error (func &rest args)
"Call function FUNC with ARGS and re-raise any error which occurs.
Useful for debugging post-command hooks and filter functions, which
normally have their errors suppressed."
(condition-case err
(apply func args)
((debug error) (signal (car err) (cdr err)))))
(defun toggle-debug-on-hidden-errors (func)
@jdtsmith
jdtsmith / highlight-indentation-current-column-timer.el
Created May 2, 2023 15:49
Custom code with a timer delay for current-column marking in highlight indentation mode
(use-package highlight-indentation
:ensure highlight-indentation
:init
;; Add a timer delay to the current column highlight for efficiency,
;; and to avoid flashing when scrolling or moving by line
(defvar my/highlight-indentation-current-column-timer nil)
(defun my/highlight-indentation-current-column ()
(highlight-indentation-redraw-window (selected-window)
'highlight-indentation-current-column-overlay
'highlight-indentation-current-column-put-overlays-region))
@jdtsmith
jdtsmith / eglot-next-highlight.el
Last active October 17, 2025 20:27
eglot-next-highlight
(defun my/eglot-next-highlight (&optional prev)
"Move to the next symbol highlighted by eglot.
Relative position within the symbol is preserved. Moves to the previous
symbol if PREV is non-nil or called with a prefix argument. Wraps at
beginning and end of the symbol set."
(interactive "P")
(let* ((p (point)) (b (current-buffer))
(overlays (sort (seq-filter
(lambda (o)
(eq (overlay-buffer o) b))
@jdtsmith
jdtsmith / elisp-xref-find-def-in-source.el
Last active July 15, 2025 21:21
Redirect xref on elisp to the source-directory
(defun my/elisp-xref-find-def-in-source (sym)
"Find elisp files in the source directory."
(let* ((elisp-xref-find-def-functions nil) ; recurses otherwise
(records (elisp--xref-find-definitions sym)))
(dolist (rec records)
(when-let* ((file (xref-elisp-location-file (xref-item-location rec)))
( (and (stringp file)
(string-match (rx ".el" (? ".gz") eos) file)
(file-in-directory-p file lisp-directory)))
(relname (file-relative-name file lisp-directory))
@jdtsmith
jdtsmith / consult-org-heading-store-link.el
Last active June 16, 2025 06:24
Insert link from consult-org-headings with embark
@jdtsmith
jdtsmith / event-buffer.txt
Created April 8, 2025 23:18
eglot version mismatch in publishDiagnostics
This file has been truncated, but you can view the full file.
(:jsonrpc "2.0" :id 63 :method "completionItem/resolve" :params
(:label #("acorr" 0 1 ...) :kind 3 :data
(:uri
"file:///Users/jdsmith/code/python/test/test_axes.py"
:position ... :funcParensDisabled t :symbolLabel
"acorr")
:sortText "09.9999.acorr"))
[jsonrpc] e[19:11:33.283] --> textDocument/didChange
(:jsonrpc "2.0" :method "textDocument/didChange" :params