Skip to content

Instantly share code, notes, and snippets.

@mmarshall540
mmarshall540 / cua-fixes.el
Last active May 17, 2025 19:30
Making CUA-mode play nice
;; Emacs's CUA-mode is great for minimizing context-switching if
;; you're forced to also use "normal" programs.
;;
;; These are some settings that help CUA-mode play more nicely with
;; the rest of Emacs.
;;; Org-mode conflict-resolution
;; Avoid keybinding conflict between Org-mode and CUA-rectangle by
;; using "C-M-RET" instead of "C-RET" for the latter. This must be
@mmarshall540
mmarshall540 / which-key-prefix-descriptions.el
Last active May 10, 2025 23:37
Missing Which-key Prefix descriptions
;; By default, Which-key doesn't give much help for prefix-keys. It
;; either shows the generic description, "+prefix", or the name of a
;; prefix-command, which usually isn't as descriptive as we'd like.
;;
;; Here are some descriptions for the default bindings in `global-map'
;; and `org-mode-map'.
(which-key-add-key-based-replacements
"<f1> 4" "help-other-win"
"<f1>" "help"
@mmarshall540
mmarshall540 / mbol-advice.el
Last active April 6, 2025 14:24
Beginning-of-line or indentation on one key
(defun my/mbol-advice (arg)
"With prefix ARG other than 1, return t.
Else, go `back-to-indentation', and if point hasn't moved, return t."
(if (eq arg 1)
(let ((start (point)))
(back-to-indentation)
(eq start (point)))
t))
(advice-add 'move-beginning-of-line :before-while 'my/mbol-advice)
@mmarshall540
mmarshall540 / my-mode-line.el
Last active March 28, 2025 00:15
A clean and minimal mode-line configuration (requires Emacs 30.1)
(setopt mode-line-format
'("%e"
mode-line-front-space
;; removed mode-line-mule-info
mode-line-client
mode-line-modified
mode-line-remote
mode-line-window-dedicated
;; removed `display' property from the above constructs
"\t" ; added
@mmarshall540
mmarshall540 / my-org-id-insert-link-with-completion.el
Created March 15, 2025 02:48
Org-mode: Select a heading for link with completion, but use ID property for link heading text as default description
@mmarshall540
mmarshall540 / my-wk-abbrev.el
Created February 27, 2025 23:30
A macro for shortening which-key descriptions
(defmacro my/wk-abbrev (prefixstr &optional prefixabbrev mode)
"Remove PREFIXSTR from which-key descriptions.
Or, with PREFIXABBREV, replace it. Optionally, condition
replacement on the value of MODE. This should typically be used
in the `:config' block of the package that uses the prefix. An
`eval-after-load' is included, to ensure that which-key will have
loaded before adding to `which-key-replacement-alist'."
(let ((wkabbfuncsym (intern
(concat "my-wk-" prefixstr "-abbreviator")))
(rx (concat "^\\(\\[[ X]\\] \\|\\)" prefixstr "-")))
@mmarshall540
mmarshall540 / down-list-with-marking-strings-and-succession.el
Last active November 21, 2023 17:40
Alternatives to 'down-list' and 'backward-up-list' with string-movement, marking, and traversal
(defun my-down-sexp-with-mark (arg)
"Like `down-list', but with some differences.
- Enter strings in addition to lists.
- Mark inner of the list or string reached.
- Traverse beyond the lowest level in a list or string and descend
into the next top-level list or string when necessary.
- Move up and select contents of the string or list reached when
prefix is negative.
@mmarshall540
mmarshall540 / simple-modal.el
Last active December 17, 2023 11:00
A simplistic modal editing system.
;; This is based on a Dvorak keyboard layout and isn't
;; very comprehensive. The purpose is just to demonstrate
;; that you can create your own modal editing system in Emacs
;; using only a little bit of code.
;;
;; After loading this file, you can use "M-\" to enter command
;; mode (aka "normal-state").
;;
;; To exit back to "insert-state", press "i".
@mmarshall540
mmarshall540 / translate-modifiers.el
Last active November 23, 2022 01:50
Translating modifier keys in Emacs
;; There seems to be no built-in mechanism to swap modifier keys in
;; Emacs, but it can be accomplished (for the most part) by
;; translating a near-exhaustive list of modifiable keys. In the case
;; of 'control and 'meta, some keys must be omitted to avoid errors or
;; other undesired effects.
(defun my/make-key-string (modsymbol basic-event)
"Convert the combination of MODSYMBOL and BASIC-EVENT.
BASIC-EVENT can be a character or a function-key symbol. The
return value can be used with `define-key'."
(vector (event-convert-list `(,modsymbol ,basic-event))))