Skip to content

Instantly share code, notes, and snippets.

@jdtsmith
jdtsmith / org-refile-attach.el
Last active April 13, 2024 18:58
org-refile-attach.el: Move attachments when refiling org nodes
;;; org-refile-attach.el --- Move attachments on org refile -*- lexical-binding: t; -*-
;; Copyright (C) 2024 J.D. Smith
;;; Commentary:
;; org-refile-attach enables moving attachments associated with a
;; given heading and sub-headings upon refiling it.
;; XXX: This a proof of concept, and does not handle moving arbitrary
;; sub-trees or regions correctly
;;; Code:
(require 'org-attach)
(require 'org-element)
@jdtsmith
jdtsmith / org-toggle-emphasis.el
Last active February 15, 2024 11:27
org-toggle-emphasis: easily toggle emphasis markers: =~*/_+
(defun my/org-toggle-emphasis (type)
"Toggle org emphasis TYPE (a character) at point."
(cl-labels ((in-emph (re)
"See if in org emphasis given by RE."
(and (org-in-regexp re 2)
(>= (point) (match-beginning 3))
(<= (point) (match-end 4))))
(de-emphasize ()
"Remove most recently matched org emphasis markers."
(save-excursion
@jdtsmith
jdtsmith / eglot-booster.el
Last active February 16, 2024 18:17
eglot-booster: boost eglot with emacs-lsp-booster. ****NOTE: USE THIS PACKAGE INSTEAD: https://github.com/jdtsmith/eglot-booster
;;; eglot-booster.el --- boost eglot using emacs-lsp-booster -*- lexical-binding: t; -*-
;; Copyright (C) 2024 J.D. Smith
;;; Commentary:
;; **UPDATE** This has been superseded by the following package:
;; https://github.com/jdtsmith/eglot-booster
;;
;; Boost eglot with emacs-lsp-booster.
;; 1. Download a recent emacs-lsp-booster from
;; Simple test exhibiting motion errors with inline images.
;; See Bug#67604
;; 1. Eval this buffer (M-x eval-buffer).
;; 2. A buffer with 3 colored SVG blocks will appear.
;; 3. Adjust your frame's width until the green image just wraps to
;; the 2nd screen line, then reduce width by one more char.
;; 4. In the buffer with the images, M-x my/find-skip-bug. If it
;; succeeds, it will report the pixel offset where the bug
;; occurred. NOTE: The Green image must appear at the start of a
;; line, or a "false positive" bug ID has occurred. Increase your
@jdtsmith
jdtsmith / bug67533_test_svg_file.el
Last active December 3, 2023 15:24
Testing Emacs SVG layout positioning
;;; test-svg-wrapped --- test pixel position for SVG images -*- lexical-binding: t; -*-
;; This small code creates a buffer with a couple long lines with
;; several SVG images of varying height interspersed. It also
;; includes a tool to check if the pixel height information one pixel
;; above each character agrees with expectations. To use:
;; M-x my/test-svg-positions
;; (use a C-u prefix to create SVG overlays instead of text properties)
;;
@jdtsmith
jdtsmith / test_org_latex_preview.org
Last active November 30, 2023 20:54
LaTeX Preview with SVG

This is normal text. $ω(t) = \sqrt[16]{t}$ Nam a sapien. $ρ(y) = exp\left(\sqrt{log(y)}\right)$ Lorem ipsum dolor sit amet, consectetuer adipiscing elit. $υ(x) = exp\left(\sqrt{exp(x)}\right)$ Aliquam posuere.

@jdtsmith
jdtsmith / maximize-window.el
Created November 14, 2023 02:44
maximize-window-vertically in emacs
(defun maximize-window-in-direction (&optional horizontally)
"Maximize window.
Default vertically, unless HORIZONTALLY is non-nil."
(interactive)
(unless (seq-every-p
(apply-partially #'window-at-side-p nil)
(if horizontally '(left right) '(top bottom)))
(let* ((buf (window-buffer))
(top-size (window-size (frame-root-window) (not horizontally)))
(size (min (/ top-size 2) (window-size nil (not horizontally))))
@jdtsmith
jdtsmith / repeat-change-cursor-color.el
Last active March 16, 2024 15:20
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 / box-stipple.el
Last active September 9, 2023 18:06
Using Emacs `:stipple` face attribute for drawing bars and other pixel-level features
(let ((buf (get-buffer-create "*stipple-box*")))
(switch-to-buffer-other-window buf)
(cl-flet ((srot (s r) (concat (substring s (- r)) (substring s 0 (- r)))))
(let* ((bar-width 0.3)
(w (window-font-width))
(h (window-font-height))
(rot (indent-bars--stipple-rot w))
(bsz (round (* bar-width w)))
(vrot (mod (cadr (window-edges nil t nil t)) h))
(pad (make-string (- h bsz) ?\s))
@jdtsmith
jdtsmith / test_treesitter.el
Last active August 20, 2023 12:30
tree-sitter navigation speed test
(let (cnt tm node res)
(goto-char (point-min))
(while (< (point) (point-max))
(setq tm
(benchmark-run 100
(setq node (treesit-node-at (point)))
(while node
(setq node (treesit-node-parent node))))
node (treesit-node-at (point)))
(setq cnt 0)