Skip to content

Instantly share code, notes, and snippets.

View rytswd's full-sized avatar
🌄

Ryota rytswd

🌄
View GitHub Profile
@rytswd
rytswd / move-text.el
Created February 29, 2024 21:04
Emacs: Move text, similar to VSCode
(defun rytswd/move-text--internal (arg)
"Moves text down or up based on arg input.
There are 6 patterns in total:
1. (Region) Direction up, with region beginning is where the cursor is at
2. (Region) Direction up, with region end is where the cursor is at
3. (Region) Direction down, with region beginning is where the cursor is at
4. (Region) Direction down, with region end is where the cursor is at
5. Direction up without region
6. Direction down without region
@rytswd
rytswd / multi-vterm-focus.el
Created January 13, 2024 18:02
Emacs: Focus multi-vterm
(defun rytswd/multi-vterm-focus ()
"When vterm is active, focus that window. If no vterm is running, start one."
(interactive)
(unless (get-buffer (multi-vterm-project-get-buffer-name))
(multi-vterm-project))
(switch-to-buffer-other-window (multi-vterm-project-get-buffer-name))
)
@rytswd
rytswd / org-add-log-note-evil-insert.el
Created January 9, 2024 23:48
Emacs: Start with insert mode for org-note
(defun rytswd/org-add-log-note-set-evil-insert (&rest args)
(when (bound-and-true-p evil-mode)
(evil-insert-state)))
;; org-add-log-note called by org-add-note and org-agenda-add-note.
(advice-add 'org-add-log-note :after #'rytswd/org-add-log-note-set-evil-insert)
@rytswd
rytswd / vterm-execute-current-line-or-region.el
Created November 16, 2023 23:55
Emacs: Send text or region to vterm
(defun rytswd/vterm-execute-current-line-or-region ()
"Insert text of current line or region in vterm and execute."
(interactive)
(let* ((current-line (buffer-substring
(save-excursion
(beginning-of-line)
(point))
(save-excursion
(end-of-line)
(point))))
@rytswd
rytswd / elfeed-search-toggle-unread-filter.el
Created November 6, 2023 22:15
Emacs: Toggle Elfeed search filter to use "+unread"
(defun rytswd/elfeed-search-toggle-unread-filter ()
"Update the current Elfeed search filter to toggle \"+unread\"."
(interactive)
(let* ((unread-tag "+unread")
(filter-items (split-string elfeed-search-filter))
(has-unread (member unread-tag filter-items))
(filter-items-no-unread (remove unread-tag filter-items)))
(when (not has-unread)
(nconc filter-items-no-unread (list unread-tag)))
(setq elfeed-search-filter (mapconcat 'identity filter-items-no-unread " "))
@rytswd
rytswd / save-without-save-hook.el
Created November 3, 2023 00:31
Emacs: Save without formatting
(defun rytswd/save-without-save-hook ()
"This function saves the current buffer without invoking save hook.
This uses a bit of a hacky trick of using ~write-region~ to achieve this.
It may cause some unintended behaviours depending on the context."
(interactive)
(let ((filename (if buffer-file-name buffer-file-name
(read-string "File name to save as: "))))
(write-region (point-min) (point-max) filename)
(revert-buffer :ignore-auto :noconfirm)))
@rytswd
rytswd / duplicate-line-or-region.el
Created September 30, 2023 22:55
Emacs: Duplicate line or region like VSCode
(defun rytswd/duplicate-line-or-region-up (arg)
"Duplicate the current line or selected region upward."
(interactive "*p")
(dotimes (_ arg)
(rytswd/duplicate-line-or-region -1)))
(defun rytswd/duplicate-line-or-region-down (arg)
"Duplicate the current line or selected region downward."
(interactive "*p")
(dotimes (_ arg)

Keybase proof

I hereby claim:

  • I am rytswd on github.
  • I am rytswd (https://keybase.io/rytswd) on keybase.
  • I have a public key ASD2o0bbkQu0b43lm4xrvJm9alLLyDtmA40n7t3uk0_rlgo

To claim this, I am signing this object: