Skip to content

Instantly share code, notes, and snippets.

@kobapan
Last active October 17, 2022 09:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kobapan/329eb42f3709928c18eabe0143080fe2 to your computer and use it in GitHub Desktop.
Save kobapan/329eb42f3709928c18eabe0143080fe2 to your computer and use it in GitHub Desktop.
リージョン選択範囲、もしくは現在行のLisp 式を(1つ)読み込み、評価した結果を、次行に挿入する
(defun eval-print-region ()
(interactive)
(let ((f (lambda (s e)
(print (eval (read (replace-regexp-in-string "," "" (buffer-substring s e)))) (current-buffer)))))
(if (region-active-p)
;; リージョン全体
(funcall f (region-beginning) (region-end))
;; カーソルのある行全体
(progn (end-of-line)
(funcall f (point-at-bol) (point-at-eol))))))
(define-key global-map (kbd "C-=") 'eval-print-region)
@kobapan
Copy link
Author

kobapan commented Jun 21, 2019

テキストモードでふと「この計算式を評価したい」というときがある。

M-:としてミニバッファで評価しても、結果は見れるだけで、コピーされない。

そこで

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment