Last active
January 5, 2023 09:33
-
-
Save jidaikobo-shibata/ee6b2f8ef659ed58605d to your computer and use it in GitHub Desktop.
Emacs(Elisp): Join multi lines to one. 選択範囲を1行にまとめます。
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
;;; ------------------------------------------------------------ | |
;;; 選択範囲を1行にする。最初のインデントは残す。 | |
;; gist-description: Emacs(Elisp): Join multi lines to one. 選択範囲を1行にまとめます。 | |
;; gist-id: ee6b2f8ef659ed58605d | |
;; gist-name: join-multi-lines-to-one.el | |
;; gist-private: nil | |
(defun join-multi-lines-to-one () | |
"Join multi lines." | |
(interactive) | |
(let ((beg (region-beginning)) | |
(end (region-end)) | |
strings) | |
(goto-char beg) | |
(back-to-indentation) | |
(setq beg (point)) | |
(goto-char end) | |
(goto-char (- (point) 1)) | |
(end-of-line) | |
(setq end (point)) | |
(setq strings (buffer-substring-no-properties beg end)) | |
(setq strings (replace-regexp-in-string "\n\\|^>+ *\\|^[\t ]+" "" strings)) | |
(setq strings (replace-regexp-in-string " +" " " strings)) | |
(delete-region beg end) | |
(insert strings) | |
(goto-char beg))) | |
(global-set-key (kbd "<s-kp-divide>") 'join-multi-lines-to-one) | |
(global-set-key (kbd "s-/") 'join-multi-lines-to-one) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment