branch: externals/polymode commit a8ad41fa00c6d58ad730026785665c074dd7fe16 Author: Vitalie Spinu <spinu...@gmail.com> Commit: Vitalie Spinu <spinu...@gmail.com>
Implement polymode-kill-ring-save-chunk to copy current chunk --- polymode.el | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/polymode.el b/polymode.el index a72db2e03b..e56b21e234 100644 --- a/polymode.el +++ b/polymode.el @@ -70,6 +70,7 @@ in `polymode-minor-mode-map` keymap: ;; chunk manipulation (define-key map "\M-k" #'polymode-kill-chunk) (define-key map "\M-m" #'polymode-mark-or-extend-chunk) + (define-key map "\M-w" #'polymode-kill-ring-save-chunk) (define-key map "\C-t" #'polymode-toggle-chunk-narrowing) ;; backends (define-key map "e" #'polymode-export) @@ -244,10 +245,22 @@ Return the number of chunks of the same type moved over." (pm-span-to-range span) (pm-chunk-range (1- (nth 1 span)))))))) -(defun polymode-kill-ring-save () - "Copy current chunk into the kill-ring." +(defun polymode-kill-ring-save-chunk () + "Copy current chunk into the kill-ring. +When in the head of chunk, copy the chunk including the head and tail, +otherwise only the body span. +When called interactively, highlight the copie region for `copy-region-blink-delay'." (interactive) - ) + (let ((span (pm-innermost-span))) + (let ((range (if (memq (car span) '(nil body)) + (pm-span-to-range span) + (pm-chunk-range)))) + (copy-region-as-kill (car range) (cdr range)) + (when (called-interactively-p 'interactive) + (let ((overlay (make-overlay (car range) (cdr range)))) + (overlay-put overlay 'face 'highlight) + (run-with-timer copy-region-blink-delay nil + (lambda () (delete-overlay overlay)))))))) (defun polymode-mark-or-extend-chunk () "DWIM command to repeatedly mark chunk or extend region.