diff options
author | Yuchen Pei <id@ypei.org> | 2024-10-11 20:13:06 +1100 |
---|---|---|
committer | Yuchen Pei <id@ypei.org> | 2024-10-11 20:22:34 +1100 |
commit | b1e707d5544da0811f602eed125d8d5e64accd65 (patch) | |
tree | 8ab2a31c3f08ed8096df1c2e86215c677714f0a3 /emacs/.emacs.d/lisp/my/my-editing.el | |
parent | b4068a7ad802f5a3b2bb014412e2f88ccf8384ea (diff) |
[emacs] Some changes from the past months
* emacs/.emacs.d/init/ycp-complete.el: comment why corfu does not work
well with gud
* emacs/.emacs.d/init/ycp-editing.el: bind my-write-file to C-x C-w;
change viper-syntax-preference to 'extended
* emacs/.emacs.d/init/ycp-org.el: comment on tab-width
* emacs/.emacs.d/lisp/my/my-buffer.el: add a function
`my-save-text-and-switch-to-buffer' that Save TEXT to FILE-NAME and
switch to the buffer
* emacs/.emacs.d/lisp/my/my-editing.el: renamed a function; and
override `viper-forward-word-kernel' and
`viper-backward-word-kernel' (why?); add function `my-write-file',
which is the same as `write-file', but keep the old buffer and remain
there.
* emacs/.emacs.d/lisp/my/my-mariadb.el: remove sleep in
`my-gdb-maria-spider'; add a function to fetch source of a mariadb kb
entry
* emacs/.emacs.d/lisp/my/my-net.el: extract out local I/O and buffer
logic from `my-fetch-url-save-and-switch' to
`my-save-text-and-switch-to-buffer'.
* emacs/.emacs.d/lisp/my/my-org-jira.el: fix formatting of
`my-org-jira--render-issue', and add affected-versions, fix-versions
and related-issues for rendering
* emacs/.emacs.d/lisp/my/my-prog.el: ensure indent-tabs-mode is by
default nil in prog-modes, to protect from c-style-alist overriding
* mariadb-server/.dir-locals.el: Moved from sql/.dir-locals.el
Diffstat (limited to 'emacs/.emacs.d/lisp/my/my-editing.el')
-rw-r--r-- | emacs/.emacs.d/lisp/my/my-editing.el | 50 |
1 files changed, 47 insertions, 3 deletions
diff --git a/emacs/.emacs.d/lisp/my/my-editing.el b/emacs/.emacs.d/lisp/my/my-editing.el index aa65ba1..0775063 100644 --- a/emacs/.emacs.d/lisp/my/my-editing.el +++ b/emacs/.emacs.d/lisp/my/my-editing.el @@ -90,7 +90,7 @@ (interactive) (zap-up-to-char -1 ?/)) -(defun my-toggle-forward-word-viper-symbol () +(defun my-toggle-forward-word-symbol () (interactive) (require 'viper) (cond ((eq (lookup-key (current-global-map) "\M-f") 'forward-word) @@ -102,14 +102,47 @@ (progn (define-key global-map "\M-f" 'forward-symbol) (define-key global-map "\M-b" - (lambda () (interactive) - (forward-symbol -1))) + (lambda () (interactive) + (forward-symbol -1))) (message "M-f is forward-symbol"))) (t (progn (define-key global-map "\M-f" 'forward-word) (define-key global-map "\M-b" 'backward-word) (message "M-f is forward-word"))))) +;;; todo: move to my-viper +;;; do not skip underscore +(defun viper-forward-word-kernel (val) + (while (> val 0) + (cond ((viper-looking-at-alpha) + (viper-skip-alpha-forward "") + (viper-skip-separators t)) + ((viper-looking-at-separator) + (viper-skip-separators t)) + ((not (viper-looking-at-alphasep)) + (viper-skip-nonalphasep-forward) + (viper-skip-separators t))) + (setq val (1- val)))) + +(defun viper-backward-word-kernel (val) + (while (> val 0) + (viper-backward-char-carefully) + (cond ((viper-looking-at-alpha) + (viper-skip-alpha-backward "")) + ((viper-looking-at-separator) + (forward-char) + (viper-skip-separators nil) + (viper-backward-char-carefully) + (cond ((viper-looking-at-alpha) + (viper-skip-alpha-backward "_")) + ((not (viper-looking-at-alphasep)) + (viper-skip-nonalphasep-backward)) + ((bobp)) ; could still be at separator, but at beg of buffer + (t (forward-char)))) + ((not (viper-looking-at-alphasep)) + (viper-skip-nonalphasep-backward))) + (setq val (1- val)))) + (defun my--duplicate-buffer-substring (beg end &optional indent) "Duplicate buffer substring between BEG and END positions. With optional INDENT, run `indent-for-tab-command' after @@ -525,5 +558,16 @@ With an prefix-arg, copy the file name relative to project root." (defun my-turn-off-truncate-lines () (setq truncate-lines nil)) +(defun my-write-file () + "Same as `write-file', but keep the old buffer and remain there. + +In other words, create a new buffer with the same content and +execute `write-file', then switch back to the current buffer." + (interactive) + (let ((old-buffer (current-buffer))) + (with-temp-buffer + (insert-buffer-substring old-buffer) + (call-interactively 'write-file)))) + (provide 'my-editing) ;;; my-editing.el ends here |