[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Collecting chunks of text. Just an idea
From: |
Daniel Boerner |
Subject: |
Collecting chunks of text. Just an idea |
Date: |
Thu, 29 Jan 2015 09:07:36 +0100 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.4.0 |
Problem: Given a text file and want to pick up regions of text (words,
half or whole sentences,
paragraphs, URL's, etc...).
I think that the most practical way would be selecting the region with
the mouse and done.
One of this inspiring days a came up with a solution for GNU Emacs
24.4.1: apply the following patch to mouse.el,
reload mouse.el, find the text file, split the window and change one
window into another buffer (e.g. *scratch*).
Now drag the mouse holding down Mouse-1 (left button) over the desired
text, release Mouse-1 and ditto.
A copy of the selected region appears in the other buffer. Keep
collecting chunks of text in this way.
Try also double-click on a text unit.
--- emacs-24.4/lisp/mouse.el 2014-09-12 06:50:30.000000000 +0200
+++ mouse-new-A.el 2015-01-29 08:35:28.035302072 +0100
@@ -853,7 +853,12 @@
(and mouse-drag-copy-region
do-mouse-drag-region-post-process
(let (deactivate-mark)
- (copy-region-as-kill (mark) (point)))))
+ (copy-region-as-kill (mark) (point))))
+ (copy-region-as-kill (mark) (point))
+ (select-window (next-window))
+ (yank)
+ (newline)
+ (select-window (next-window)))
;; Otherwise, run binding of terminating up-event.
(deactivate-mark)
Now, getting line numbers of picked text:
--- emacs-24.4/lisp/mouse.el 2014-09-12 06:50:30.000000000 +0200
+++ mouse-new-B.el 2015-01-29 08:36:46.895302527 +0100
@@ -853,7 +853,16 @@
(and mouse-drag-copy-region
do-mouse-drag-region-post-process
(let (deactivate-mark)
- (copy-region-as-kill (mark) (point)))))
+ (copy-region-as-kill (mark) (point))))
+ (copy-region-as-kill (mark) (point))
+ (let ((num-line (count-lines (point-min) (if mark-active
+ (max (point) (mark))
+ (point-max)))))
+ (select-window (next-window))
+ (yank)
+ (insert (concat ", " (number-to-string num-line)))
+ (newline)
+ (select-window (next-window))))
;; Otherwise, run binding of terminating up-event.
(deactivate-mark)
And finally, execute something fed with picked text as argument:
--- emacs-24.4/lisp/mouse.el 2014-09-12 06:50:30.000000000 +0200
+++ mouse-new-C.el 2015-01-29 08:38:03.183302967 +0100
@@ -853,7 +853,22 @@
(and mouse-drag-copy-region
do-mouse-drag-region-post-process
(let (deactivate-mark)
- (copy-region-as-kill (mark) (point)))))
+ (copy-region-as-kill (mark) (point))))
+ (copy-region-as-kill (mark) (point))
+ (select-window (next-window))
+ (erase-buffer)
+ (yank)
+ (exchange-point-and-mark) ;; activate mark
+ (let ((fill-column (- (max (mark) (point)) (min (mark)
(point)))))
+ ;; do some preprocessing (what is expected by shell command?)
+ ;; get rid of newlines because of -n perl switch
+ (fill-region (mark) (point))
+ (shell-command-on-region (mark) (point)
+ (concat (if (executable-find "env") "env " "")
+ (concat "perl" " -ne 'use strict; print uc $_
;'"))
+ (current-buffer) t)
+ (deactivate-mark))
+ (select-window (next-window)))
;; Otherwise, run binding of terminating up-event.
(deactivate-mark)
Even if I'm already served with these hacks and because of my humble
knowledge of elisp, I'd be glad if someone
could develop them further.
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- Collecting chunks of text. Just an idea,
Daniel Boerner <=