From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Daniel Boerner Newsgroups: gmane.emacs.devel Subject: Collecting chunks of text. Just an idea Date: Thu, 29 Jan 2015 09:07:36 +0100 Message-ID: <54C9EA48.60609@fundaciobit.org> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit X-Trace: ger.gmane.org 1422544981 25358 80.91.229.3 (29 Jan 2015 15:23:01 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Thu, 29 Jan 2015 15:23:01 +0000 (UTC) To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Thu Jan 29 16:22:56 2015 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1YGqvk-0005UO-5w for ged-emacs-devel@m.gmane.org; Thu, 29 Jan 2015 16:22:52 +0100 Original-Received: from localhost ([::1]:60306 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YGqvj-0001SJ-JC for ged-emacs-devel@m.gmane.org; Thu, 29 Jan 2015 10:22:51 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:57028) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YGk8f-00043w-99 for emacs-devel@gnu.org; Thu, 29 Jan 2015 03:07:46 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YGk8b-0002zT-TT for emacs-devel@gnu.org; Thu, 29 Jan 2015 03:07:45 -0500 Original-Received: from smtp.bitel.es ([194.179.36.18]:54004 helo=dinky.bitel.es) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YGk8b-0002wZ-Hp for emacs-devel@gnu.org; Thu, 29 Jan 2015 03:07:41 -0500 Original-Received: from caragol.fundaciobit.org ([194.179.36.25]) by dinky.bitel.es (Post.Office MTA v3.5.3 release 223 ID# 548-67071U4500L450S0V35) with ESMTP id es for ; Thu, 29 Jan 2015 09:08:00 +0100 X-MDAV-Result: clean X-MDAV-Processed: caragol.fundaciobit.org, Thu, 29 Jan 2015 09:07:37 +0100 Original-Received: from [x.x.x.x] by fundaciobit.org (Cipher TLSv1:RC4-MD5:128) (MDaemon PRO v14.5.2) with ESMTPS id md50003724094.msg for ; Thu, 29 Jan 2015 09:07:35 +0100 X-MDArrival-Date: Thu, 29 Jan 2015 09:07:35 +0100 X-Return-Path: prvs=14714a0339=dboerner@fundaciobit.org X-Envelope-From: dboerner@fundaciobit.org X-MDaemon-Deliver-To: emacs-devel@gnu.org User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.4.0 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x (barebone) [generic] [fuzzy] X-Received-From: 194.179.36.18 X-Mailman-Approved-At: Thu, 29 Jan 2015 10:22:29 -0500 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:181985 Archived-At: 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.