all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Collecting chunks of text. Just an idea
@ 2015-01-29  8:07 Daniel Boerner
  0 siblings, 0 replies; only message in thread
From: Daniel Boerner @ 2015-01-29  8:07 UTC (permalink / raw)
  To: emacs-devel

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.





^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2015-01-29  8:07 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-01-29  8:07 Collecting chunks of text. Just an idea Daniel Boerner

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.