Last active
October 25, 2024 00:17
-
-
Save jamescherti/15168bb060d79a5c57215e62dd9bfa55 to your computer and use it in GitHub Desktop.
Emacs Evil Org-mode: Delete everything before the cursor except the first '*' and space.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;;; delete-before-cursor-except-asterisks.el --- Emacs Evil Org-mode: Delete everything before the cursor except the first '*' and space. -*- lexical-binding: t; -*- | |
;; Gits URL: https://gist.github.com/jamescherti/15168bb060d79a5c57215e62dd9bfa55 | |
;; License: MIT | |
;; Author: James Cherti | |
(with-eval-after-load "org" | |
(with-eval-after-load "evil" | |
(defun my-evil-delete-to-heading-star () | |
"Delete everything before the cursor except the first '*' and space. | |
In Org mode with Evil insert state, this function deletes everything before the | |
cursor except the first Org heading star (`*`), the space following it, and any | |
word after the space that contains at least two uppercase characters." | |
(interactive) | |
(let ((cur-point (point))) | |
(save-excursion | |
(if (re-search-backward | |
"^\\(*+\\)\\( +\\)\\([A-Z]\\{2,\\}\\)?\\( +\\)?" | |
(line-beginning-position) t) | |
(let ((delete-start (match-end 0))) | |
(delete-region delete-start cur-point)) | |
(evil-delete-back-to-indentation))))) | |
(evil-define-key 'insert org-mode-map (kbd "C-u") | |
'my-evil-delete-to-heading-star))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment