all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Daniel Boerner <dboerner@fundaciobit.org>
To: emacs-devel@gnu.org
Subject: Collecting chunks of text. Just an idea
Date: Thu, 29 Jan 2015 09:07:36 +0100	[thread overview]
Message-ID: <54C9EA48.60609@fundaciobit.org> (raw)

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.





                 reply	other threads:[~2015-01-29  8:07 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=54C9EA48.60609@fundaciobit.org \
    --to=dboerner@fundaciobit.org \
    --cc=emacs-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.