org: add monster org-dwim-char
function, remove bloat
This commit is contained in:
parent
7909a82e2b
commit
4bd20b7930
@ -64,15 +64,6 @@
|
|||||||
;; (add-to-list 'auto-mode-alist `(,org-wiki-regex . org-vw-mode))
|
;; (add-to-list 'auto-mode-alist `(,org-wiki-regex . org-vw-mode))
|
||||||
(add-hook 'org-mode-hook #'org-vw-mode)
|
(add-hook 'org-mode-hook #'org-vw-mode)
|
||||||
|
|
||||||
;; ------------------ ABANDON ALL SANITY, YE WHO ENTER HERE --------------------
|
|
||||||
|
|
||||||
;; Below, I attempt to generalize tangling a whole directory of org files into
|
|
||||||
;; whichever export format, and then apply that.
|
|
||||||
|
|
||||||
;; (require 'ox-hugo)
|
|
||||||
|
|
||||||
;; --------- LET THY BRAIN NO LONGER TREMBLE, FOR I AM BECOME COMPLETE ---------
|
|
||||||
|
|
||||||
(defun mitch-insert-current-datetime ()
|
(defun mitch-insert-current-datetime ()
|
||||||
"Insert the current date and time in my preffered format, with a newline at
|
"Insert the current date and time in my preffered format, with a newline at
|
||||||
the end."
|
the end."
|
||||||
@ -91,5 +82,66 @@ Start insert mode."
|
|||||||
(mitch-insert-current-datetime)
|
(mitch-insert-current-datetime)
|
||||||
(evil-insert 1))
|
(evil-insert 1))
|
||||||
|
|
||||||
|
;; ------------------ ABANDON ALL SANITY, YE WHO ENTER HERE --------------------
|
||||||
|
|
||||||
|
(defun mitch/org-dwim-char (&optional char)
|
||||||
|
"If a region is active (visual mode), surround selection with CHAR.
|
||||||
|
|
||||||
|
If in a word, surround it with CHAR (like `evil-surround') or, if word is
|
||||||
|
already surrounded with CHAR, un-surround it. If on the first character of a
|
||||||
|
word, run the default function that Evil binds the key CHAR to.
|
||||||
|
|
||||||
|
If the next character is the same as CHAR, move cursor past it \(like
|
||||||
|
`electric-pair').
|
||||||
|
|
||||||
|
If the line is a block delimiter or heading, or when in a protected block \(see
|
||||||
|
variable `org-protecting-blocks') or properties drawer, just insert the
|
||||||
|
character CHAR.
|
||||||
|
|
||||||
|
Otherwise, insert two of CHAR and put point between them like `electric-pair'."
|
||||||
|
(interactive) ; TODO: can we make CHAR an arg to `interactive'?
|
||||||
|
(let ((char (or char (string-to-char (this-command-keys))))
|
||||||
|
(word (thing-at-point 'word 'no-properties)))
|
||||||
|
(cond
|
||||||
|
((eq evil-state 'visual)
|
||||||
|
(let* ((beg (region-beginning))
|
||||||
|
(end (region-end)))
|
||||||
|
(evil-surround-region beg end evil-visual-selection char nil)))
|
||||||
|
((eq evil-state 'normal)
|
||||||
|
(if (or (bolp) (eq (char-before (point)) ?\ )) ; at beginning of word
|
||||||
|
;; run original function bound to key
|
||||||
|
(let ((charstr (make-string 1 char)))
|
||||||
|
(pcase charstr
|
||||||
|
;; TODO: can we not hard-code this?
|
||||||
|
("_" (call-interactively 'evil-next-line-1-first-non-blank))
|
||||||
|
("/" (call-interactively 'evil-search-forward))
|
||||||
|
("*" (call-interactively 'evil-search-word-forward))
|
||||||
|
("+" (call-interactively 'evil-next-line-first-non-blank))
|
||||||
|
("~" (call-interactively 'evil-invert-char))
|
||||||
|
("=" (call-interactively 'evil-indent))))
|
||||||
|
(save-excursion
|
||||||
|
(if (and (eq (char-before (beginning-of-thing 'word)) char)
|
||||||
|
(eq (char-after (end-of-thing 'word)) char))
|
||||||
|
(progn
|
||||||
|
(search-backward (char-to-string char)) (delete-char 1)
|
||||||
|
(search-forward (char-to-string char)) (delete-char -1))
|
||||||
|
(evil-with-single-undo
|
||||||
|
(beginning-of-thing 'word)
|
||||||
|
(insert char)
|
||||||
|
(end-of-thing 'word)
|
||||||
|
(insert char))))))
|
||||||
|
((eq char (char-after))
|
||||||
|
(right-char))
|
||||||
|
((or (string-match-p (rx bol (or "#" "*"))
|
||||||
|
(thing-at-point 'line 'no-properties))
|
||||||
|
(org-in-block-p org-protecting-blocks)
|
||||||
|
(org-at-property-p))
|
||||||
|
(insert char))
|
||||||
|
(t (progn
|
||||||
|
(insert (make-string 2 char))
|
||||||
|
(left-char))))))
|
||||||
|
;; (setq debug-on-error t)
|
||||||
|
;; --------- LET THY BRAIN NO LONGER TREMBLE, FOR I AM BECOME COMPLETE ---------
|
||||||
|
|
||||||
(provide 'mitch-orgstuff)
|
(provide 'mitch-orgstuff)
|
||||||
;;; mitch-orgstuff.el ends here
|
;;; mitch-orgstuff.el ends here
|
||||||
|
@ -470,8 +470,8 @@ targets."
|
|||||||
:diminish (org-indent-mode org-vw-mode)
|
:diminish (org-indent-mode org-vw-mode)
|
||||||
:custom
|
:custom
|
||||||
(org-hide-leading-stars t)
|
(org-hide-leading-stars t)
|
||||||
(org-startup-indented t)
|
;; (org-startup-indented t)
|
||||||
(org-hide-emphasis-markers t)
|
;; (org-hide-emphasis-markers t)
|
||||||
:config
|
:config
|
||||||
(add-hook 'after-save-hook
|
(add-hook 'after-save-hook
|
||||||
#'(lambda () (if (equal major-mode 'org-mode)
|
#'(lambda () (if (equal major-mode 'org-mode)
|
||||||
@ -485,10 +485,10 @@ targets."
|
|||||||
"Electric pairs for org-mode.
|
"Electric pairs for org-mode.
|
||||||
|
|
||||||
See https://emacs.stackexchange.com/questions/2538/how-to-define-additional-mode-specific-pairs-for-electric-pair-mode")
|
See https://emacs.stackexchange.com/questions/2538/how-to-define-additional-mode-specific-pairs-for-electric-pair-mode")
|
||||||
(defun org-add-electric-pairs ()
|
;; (defun org-add-electric-pairs ()
|
||||||
(setq-local electric-pair-pairs (append electric-pair-pairs org-electric-pairs))
|
;; (setq-local electric-pair-pairs (append electric-pair-pairs org-electric-pairs))
|
||||||
(setq-local electric-pair-text-pairs electric-pair-pairs))
|
;; (setq-local electric-pair-text-pairs electric-pair-pairs))
|
||||||
(add-hook 'org-mode-hook 'org-add-electric-pairs)
|
;; (add-hook 'org-mode-hook 'org-add-electric-pairs)
|
||||||
(require 'mitch-orgstuff)
|
(require 'mitch-orgstuff)
|
||||||
(defun insert-zws ()
|
(defun insert-zws ()
|
||||||
(interactive)
|
(interactive)
|
||||||
@ -496,16 +496,25 @@ See https://emacs.stackexchange.com/questions/2538/how-to-define-additional-mode
|
|||||||
:hook
|
:hook
|
||||||
(org-mode . turn-off-line-numbers)
|
(org-mode . turn-off-line-numbers)
|
||||||
(org-mode . org-vw-mode)
|
(org-mode . org-vw-mode)
|
||||||
|
(org-mode . yas-minor-mode)
|
||||||
:general (general-define-key
|
:general (general-define-key
|
||||||
:states 'insert
|
:states 'insert
|
||||||
:maps 'org-mode-map
|
:keymaps 'org-mode-map
|
||||||
"`" (general-key-dispatch 'self-insert-command
|
"`" (general-key-dispatch 'self-insert-command
|
||||||
:timeout 0.1
|
|
||||||
"SPC" 'insert-zws)))
|
|
||||||
(use-package darkroom
|
|
||||||
:hook (org-mode . darkroom-tentative-mode))
|
|
||||||
(use-package org-tempo
|
(use-package org-tempo
|
||||||
:straight (:type built-in)
|
:straight (:type built-in)
|
||||||
|
:timeout 0.1
|
||||||
|
"SPC" 'insert-zws))
|
||||||
|
(general-define-key
|
||||||
|
:states '(normal visual insert)
|
||||||
|
:keymaps 'org-mode-map
|
||||||
|
"_" 'mitch/org-dwim-char
|
||||||
|
"/" 'mitch/org-dwim-char
|
||||||
|
"*" 'mitch/org-dwim-char
|
||||||
|
"+" 'mitch/org-dwim-char
|
||||||
|
"~" 'mitch/org-dwim-char
|
||||||
|
"=" 'mitch/org-dwim-char))
|
||||||
|
|
||||||
:after org
|
:after org
|
||||||
:config
|
:config
|
||||||
(add-to-list 'org-structure-template-alist '("sh" . "src shell"))
|
(add-to-list 'org-structure-template-alist '("sh" . "src shell"))
|
||||||
|
Loading…
Reference in New Issue
Block a user