Skip to content

Instantly share code, notes, and snippets.

@yonta
Created August 22, 2019 17:55
Show Gist options
  • Save yonta/a59e92a1a0da1cf1b9a4d59dcc733cf0 to your computer and use it in GitHub Desktop.
Save yonta/a59e92a1a0da1cf1b9a4d59dcc733cf0 to your computer and use it in GitHub Desktop.
;;; 結局採用したやつ
(defun call-with-region-or-line (func-symbol)
"Call FUNC-SYMBOL with marked region or current line.
If the region is active, beggining and end of region is used for the function
arguments, othewise current line is used."
(if (region-active-p)
(funcall func-symbol (region-beginning) (region-end))
(let* ((begin (line-beginning-position))
(end (1+ (line-end-position))))
(funcall func-symbol begin end))))
(use-package sml-mode
:config
(defun sml-prog-proc-send-region-or-line ()
"Call REPL with active region or current line."
(interactive) (call-with-region-or-line #'sml-prog-proc-send-region))
:bind (:map sml-mode-map ("C-c C-r" . sml-prog-proc-send-region-or-line)))
;;;=================================================================
;;; 行頭に右を足すと動く -*- lexical-binding: t; -*-
;;; :bindと相性が悪く、bind-keyべた書きしている
(defun call-with-region-or-line (func-symbol)
""
(lambda () (interactive)
(if (region-active-p)
(funcall func-symbol (region-beginning) (region-end))
(let* ((begin (line-beginning-position))
(end (1+ (line-end-position))))
(funcall func-symbol begin end)))))
(bind-key "C-c C-r" (call-with-region-or-line #'sml-prog-proc-send-region)
sml-mode-map)
;;;=================================================================
;;; dynamic bindingでも動く
;;; けど、毎回(lambda () (interactive) ...を書く必要がある
(defun call-with-region-or-line (func-symbol)
""
(if (region-active-p)
(funcall func-symbol (region-beginning) (region-end))
(let* ((begin (line-beginning-position))
(end (1+ (line-end-position))))
(funcall func-symbol begin end))))
:bind (:map sml-mode-map
("C-c C-r" .
(lambda () (interactive)
(call-with-region-or-line #'sml-prog-proc-send-region))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment