Last active
August 29, 2015 14:25
-
-
Save tam17aki/edc86c8c5cfbe61ef767 to your computer and use it in GitHub Desktop.
avyで同一ウィンドウ内の2行を選択し、そこに挟まれたテキストに対して動作する関数群
This file contains 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
(defun avy-delete-blank-lines () | |
"Delete blank lines around a selected line." | |
(interactive) | |
(avy-with avy-delete-blank-lines-line | |
(let ((start (avy--line))) | |
(save-excursion (goto-char start) (delete-blank-lines))))) | |
;; 当該行は削除せず、kill-ringに保存する | |
(defun avy-copy-line2 (arg) | |
"Just copy a selected line. ARG lines can be used." | |
(interactive "p") | |
(avy-with avy-copy-line | |
(let ((start (avy--line))) | |
(move-beginning-of-line nil) | |
(kill-new | |
(save-excursion | |
(buffer-substring-no-properties | |
start (save-excursion (goto-char start) (move-end-of-line arg) (point)))))))) | |
;; 当該テキスト部分をコメントアウトする | |
(defun avy-comment-region () | |
"Select two lines and comment out the text between them." | |
(interactive) | |
(avy-with avy-comment-region | |
(let ((beg (avy--line)) | |
(end (avy--line))) | |
(comment-region | |
beg (save-excursion (goto-char end) (forward-line) (point)))))) | |
;; 当該テキスト部分のコメントを外す | |
(defun avy-uncomment-region () | |
"Select two lines and uncomment the text between them." | |
(interactive) | |
(avy-with avy-uncomment-region | |
(let ((beg (avy--line)) | |
(end (avy--line))) | |
(uncomment-region | |
beg (save-excursion (goto-char end) (forward-line) (point)))))) | |
;; 当該テキストを対象にインデント整理を実行 | |
(defun avy-indent-region () | |
"Select two lines and indent the text between them." | |
(interactive) | |
(avy-with avy-indent-region | |
(let ((beg (avy--line)) | |
(end (avy--line))) | |
(indent-region | |
beg (save-excursion (goto-char end) (forward-line) (point)))))) | |
;; 当該テキストを削除。kill-ringに保存せず。 | |
(defun avy-delete-region () | |
"Select two lines and delete the text between them." | |
(interactive) | |
(avy-with avy-copy-region | |
(let ((beg (avy--line)) | |
(end (avy--line))) | |
(goto-char end) | |
(delete-region | |
beg (save-excursion (goto-char end) (forward-line) (point)))))) | |
;; 当該テキストを削除。kill-ringに保存。 | |
(defun avy-kill-region () | |
"Select two lines and then copy & delete the text between them." | |
(interactive) | |
(avy-with avy-copy-region | |
(let ((beg (avy--line)) | |
(end (avy--line))) | |
(kill-region | |
beg (save-excursion (goto-char end) (forward-line) (point)))))) | |
;; 当該テキストを削除せず。kill-ringに保存。 | |
(defun avy-copy-region () | |
"Select two lines and copy the text between them." | |
(interactive) | |
(avy-with avy-copy-region | |
(let* ((beg (avy--line)) | |
(end (avy--line)) | |
(str (buffer-substring-no-properties | |
beg (save-excursion (goto-char end) (line-end-position))))) | |
(kill-new str)))) | |
;; 当該テキストは削除せず。kill-ringに保存せず。カーソル位置にペースト | |
(defun avy-paste-region () | |
"Select two lines and paste the text between them at the current position." | |
(interactive) | |
(avy-with avy-copy-region | |
(let ((beg (avy--line)) | |
(end (avy--line)) | |
(pad (if (bolp) "" "\n"))) | |
(move-beginning-of-line nil) | |
(save-excursion | |
(insert (buffer-substring-no-properties | |
beg (save-excursion (goto-char end) (line-end-position))) pad))))) | |
;; 当該テキストを削除せず。kill-ringに保存。カーソル位置にペースト | |
(defun avy-copy&paste-region () | |
"Select two lines and then copy & paste the text between them at the current position." | |
(interactive) | |
(avy-with avy-copy-region | |
(let* ((beg (avy--line)) | |
(end (avy--line)) | |
(pad (if (bolp) "" "\n")) | |
(str (buffer-substring-no-properties | |
beg (save-excursion (goto-char end) (line-end-position))))) | |
(move-beginning-of-line nil) | |
(kill-new str) | |
(insert str pad)))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment