Skip to content

Instantly share code, notes, and snippets.

@mmarshall540
mmarshall540 / set-window-4-scrolling.el
Created June 28, 2025 20:46
Set the window to use with `scroll-other-window`
(defun my/set-window-4-scrolling (arg)
"Set current window as target window for `scroll-other-window'.
This ensures that `scroll-other-window' scrolls the desired window, even
if Emacs doesn't consider it the \"next-window\" and regardless of which
window is selected when `scroll-other-window' is called.
Compared to setting the `other-window-scroll-buffer' variable, the
method this command uses works even when the window is on another frame
and won't cause a duplicate window to pop up on the current frame.
@mmarshall540
mmarshall540 / cua-problem-keys.org
Last active June 22, 2025 18:12
List of default keybindings under C-x and C-c (org-mode) that can use an active region

List of default keybindings that use region under C-x and C-c

(Note: this is easier to read if you click the “Raw” button, or even better, download and view it in Emacs.)

This is for helping to locate bindings that might be corrected for CUA-mode.

Global-map (only C-x)

  • Editing
    C-x TAB
    indent-rigidly
    C-x C-l
    downcase-region
    • Bind downcase-dwim to M-l.
@mmarshall540
mmarshall540 / save-theme-separately.el
Last active June 22, 2025 18:31
Use customize-themes but not custom-file
;; I generally don't like to use the Customize system. It's great for
;; browsing settings, but for actually maintaining them, things
;; somehow always end up in a mess with little indication of the
;; cause. (In most cases, the root cause is probably the "Options:
;; Save Options" menu item, which tends to save far more than you'd
;; expect, but that's another topic.)
;;
;; However, the `customize-themes' interface is quite nice, and I like
;; using it to select and save a theme. So how to continue doing that
;; without otherwise using the Customize system? Like this...
@mmarshall540
mmarshall540 / cua-fixes.el
Last active June 14, 2025 15:12
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 June 12, 2025 00:45
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 June 1, 2025 20:20
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.