Skip to content

Instantly share code, notes, and snippets.

@jdtsmith
jdtsmith / move_space.lua
Last active October 11, 2024 21:40
Move Space of Current Window with Hammerspoon
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 / custom-buffer-local-keys.el
Last active July 11, 2024 23:23
custom-buffer-local-keys
;; JD Smith 2024, based on https://www.emacswiki.org/emacs/BufferLocalKeys
(defvar-local custom-buffer-local-keys nil
"Key-bindings to be set up local to the current buffer.
A single (KEY . BINDING) cons or list of such conses, of the form
`bind-keys' accepts. Set this as a file-local variable to make
bindings local to that buffer only.")
;; Only include this if you trust the files you open
(put 'custom-buffer-local-keys 'safe-local-variable 'consp)
@jdtsmith
jdtsmith / repeat-change-cursor-color.el
Last active July 4, 2024 23:15
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 May 29, 2024 18:44
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 / maximize-window.el
Last active May 11, 2024 14:18
maximize-window-vertically in emacs
;; Maximize a window vertically or horizontally within its frame
(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)))
@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 / consult-org-heading-store-link.el
Last active February 24, 2024 01:49
Insert link from consult-org-headings with embark
@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
@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
;; 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