Last active
November 29, 2020 04:57
-
-
Save nfunato/9b5a2c6d08b80e8bcdee29556a172d84 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| ;;;=================================================================== | |
| ;;; delete-newlines-inside-paragraphs (for DeepL translation, etc) | |
| ;;; | |
| (defvar *dnip-mark* "\C-a") | |
| ;; only for internal use | |
| (defun dnip-replace-str (from-str to-str) | |
| (goto-char (point-min)) | |
| (while (search-forward from-str nil t) (replace-match to-str nil t))) | |
| (defun delete-newlines-inside-paragraphs (begin end) | |
| "Delete newlines inside paragraphs in the current buffer." | |
| (interactive "r") | |
| (save-excursion | |
| (save-restriction | |
| (narrow-to-region begin end) | |
| (dnip-replace-str "\n\n" *dnip-mark*) | |
| (dnip-replace-str "\n" " ") | |
| (dnip-replace-str *dnip-mark* "\n\n")))) | |
| ;; The following code is quick hack for interworking DeepL.com well. | |
| ;; (sorry, I don't know emacs lisp well) | |
| (defun kb-val (val) | |
| (cond ((null val) nil) | |
| ((numberp val) nil) | |
| (t val))) | |
| (defun lookup-kb (str) ; ignoring the case of kbd-macro, etc | |
| (or (lookup-key (current-local-map) str) | |
| (lookup-key (current-global-map) str))) | |
| (defun like-control-E () ; Really I usually use "M-x dnip" under org-mode | |
| (funcall (lookup-kb "\C-e"))) | |
| (defun dnip (begin end) | |
| (interactive "r") | |
| (delete-newlines-inside-paragraphs begin end) | |
| (like-control-E) | |
| (insert "\n")) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment