Skip to content

Commit a8ad41f

Browse files
committed
Implement polymode-kill-ring-save-chunk to copy current chunk
1 parent b082846 commit a8ad41f

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

polymode.el

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ in `polymode-minor-mode-map` keymap:
7070
;; chunk manipulation
7171
(define-key map "\M-k" #'polymode-kill-chunk)
7272
(define-key map "\M-m" #'polymode-mark-or-extend-chunk)
73+
(define-key map "\M-w" #'polymode-kill-ring-save-chunk)
7374
(define-key map "\C-t" #'polymode-toggle-chunk-narrowing)
7475
;; backends
7576
(define-key map "e" #'polymode-export)
@@ -244,10 +245,22 @@ Return the number of chunks of the same type moved over."
244245
(pm-span-to-range span)
245246
(pm-chunk-range (1- (nth 1 span))))))))
246247

247-
(defun polymode-kill-ring-save ()
248-
"Copy current chunk into the kill-ring."
248+
(defun polymode-kill-ring-save-chunk ()
249+
"Copy current chunk into the kill-ring.
250+
When in the head of chunk, copy the chunk including the head and tail,
251+
otherwise only the body span.
252+
When called interactively, highlight the copie region for `copy-region-blink-delay'."
249253
(interactive)
250-
)
254+
(let ((span (pm-innermost-span)))
255+
(let ((range (if (memq (car span) '(nil body))
256+
(pm-span-to-range span)
257+
(pm-chunk-range))))
258+
(copy-region-as-kill (car range) (cdr range))
259+
(when (called-interactively-p 'interactive)
260+
(let ((overlay (make-overlay (car range) (cdr range))))
261+
(overlay-put overlay 'face 'highlight)
262+
(run-with-timer copy-region-blink-delay nil
263+
(lambda () (delete-overlay overlay))))))))
251264

252265
(defun polymode-mark-or-extend-chunk ()
253266
"DWIM command to repeatedly mark chunk or extend region.

0 commit comments

Comments
 (0)