From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Jari Aalto Newsgroups: gmane.emacs.bugs Subject: bug#7538: [PATCH / wishlist] rect.el: (rectangle-number-lines) New user command C-x r N Date: Fri, 03 Dec 2010 11:49:50 +0200 Message-ID: <874oavxk1t.fsf@picasso.cante.net> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Trace: dough.gmane.org 1291371336 19557 80.91.229.12 (3 Dec 2010 10:15:36 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Fri, 3 Dec 2010 10:15:36 +0000 (UTC) Cc: scott evans To: 7538@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Fri Dec 03 11:15:31 2010 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1POSfr-0007Jr-8S for geb-bug-gnu-emacs@m.gmane.org; Fri, 03 Dec 2010 11:15:31 +0100 Original-Received: from localhost ([127.0.0.1]:59316 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1POSfp-00025b-Vb for geb-bug-gnu-emacs@m.gmane.org; Fri, 03 Dec 2010 05:15:30 -0500 Original-Received: from [140.186.70.92] (port=49187 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1POSfb-00024E-Kv for bug-gnu-emacs@gnu.org; Fri, 03 Dec 2010 05:15:17 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1POSfZ-0002ue-2K for bug-gnu-emacs@gnu.org; Fri, 03 Dec 2010 05:15:15 -0500 Original-Received: from debbugs.gnu.org ([140.186.70.43]:54690) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1POSfY-0002uZ-UH for bug-gnu-emacs@gnu.org; Fri, 03 Dec 2010 05:15:12 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.69) (envelope-from ) id 1POSCN-00075X-Eq; Fri, 03 Dec 2010 04:45:03 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Jari Aalto Original-Sender: debbugs-submit-bounces@debbugs.gnu.org Resent-To: owner@debbugs.gnu.org Resent-CC: gse@antisleep.com, bug-gnu-emacs@gnu.org Resent-Date: Fri, 03 Dec 2010 09:45:03 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 7538 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch X-Debbugs-Original-To: submit@debbugs.gnu.org X-Debbugs-Original-Xcc: scott evans Original-Received: via spool by submit@debbugs.gnu.org id=B.129136947327176 (code B ref -1); Fri, 03 Dec 2010 09:45:03 +0000 Original-Received: (at submit) by debbugs.gnu.org; 3 Dec 2010 09:44:33 +0000 Original-Received: from localhost ([127.0.0.1] helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1POSBp-00074C-6q for submit@debbugs.gnu.org; Fri, 03 Dec 2010 04:44:32 -0500 Original-Received: from emh07.mail.saunalahti.fi ([62.142.5.117]) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1POSBY-00073Q-57 for submit@debbugs.gnu.org; Fri, 03 Dec 2010 04:44:27 -0500 Original-Received: from saunalahti-vams (vs3-10.mail.saunalahti.fi [62.142.5.94]) by emh07-2.mail.saunalahti.fi (Postfix) with SMTP id E181B18D4E3; Fri, 3 Dec 2010 11:49:54 +0200 (EET) Original-Received: from emh02.mail.saunalahti.fi ([62.142.5.108]) by vs3-10.mail.saunalahti.fi ([62.142.5.94]) with SMTP (gateway) id A04DEDDB84C; Fri, 03 Dec 2010 11:49:54 +0200 Original-Received: from picasso.cante.net (a91-155-187-216.elisa-laajakaista.fi [91.155.187.216]) by emh02.mail.saunalahti.fi (Postfix) with ESMTP id 767472BD42; Fri, 3 Dec 2010 11:49:51 +0200 (EET) Mail-Copies-To: poster X-Antivirus: VAMS X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.11 Precedence: list Resent-Date: Fri, 03 Dec 2010 04:45:03 -0500 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 3) X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.bugs:42103 Archived-At: --=-=-= Content-Type: text/plain Package: emacs Version: 23.2+1-5.1 Severity: wishlist X-debbugs-cc: Scott Evans The following patch is based on Scott Evans' work (2006): http://www.antisleep.com/download/elisp/gse-number-rect.el from where the relevant functionatily has been lifted. - Used by permission of Scott (Email exchange, GPL). - If my memory serves right, Scott applied 2009 for disclaimer papers. Please verify the paper archives. 2010-12-03 Jari Aalto * rect.el (number-rectangle): New user function. (rectangle-number-line-callback): New function. (rectangle-number-line-format-history): New variable. (rectangle-number-line-counter): New variable. (define-key ctl-x-r-map "N" 'number-rectangle): New user key binding. The basis of the rectangle numbering code was lifted from gse-number-rect.el, orignally developed by Scott Evans . Used by permission (GPL). --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=0001-etc-NEWS-Changes-in-Specialized-Modes-number-rectang.patch >From 70387b605961ac9ea35750195763738dc9d50d77 Mon Sep 17 00:00:00 2001 From: Jari Aalto Date: Fri, 3 Dec 2010 11:32:15 +0200 Subject: [PATCH] etc/NEWS: (Changes in Specialized Modes): number-rectangle Organization: Private Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit Signed-off-by: Jari Aalto --- etc/NEWS | 5 ++++- 1 files changed, 4 insertions(+), 1 deletions(-) diff --git a/etc/NEWS b/etc/NEWS index 5e16f45..f5afbf2 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -309,8 +309,11 @@ set `x-select-enable-clipboard' to nil. ** shell-mode can track your cwd by reading it from your prompt. Just set shell-dir-cookie-re to an appropriate regexp. -** Modula-2 mode provides auto-indentation. +** New command `rectangle-number-lines' bound globally to `C-x r N' +can number selected lines in region. The optional zero padding, if the +line count is bigger than 9, is controlled by a prefix argument. +** Modula-2 mode provides auto-indentation. ** latex-electric-env-pair-mode keeps \begin..\end matched on the fly. ** FIXME: xdg-open for browse-url and reportbug, 2010/08. -- 1.7.2.3 --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=0001-lisp-rect.el-number-rectangle-New-user-key-binding-C.patch >From 7fe34999c0926bf9a988cdd1a0913de3f41ab18d Mon Sep 17 00:00:00 2001 From: Jari Aalto Date: Fri, 3 Dec 2010 11:20:38 +0200 Subject: [PATCH] lisp/rect.el: (number-rectangle): New user key binding C-x r N Organization: Private Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit Signed-off-by: Jari Aalto --- lisp/rect.el | 40 ++++++++++++++++++++++++++++++++++++++++ 1 files changed, 40 insertions(+), 0 deletions(-) diff --git a/lisp/rect.el b/lisp/rect.el index 6658408..f05af8d 100644 --- a/lisp/rect.el +++ b/lisp/rect.el @@ -40,6 +40,7 @@ ;;;###autoload (define-key ctl-x-r-map "y" 'yank-rectangle) ;;;###autoload (define-key ctl-x-r-map "o" 'open-rectangle) ;;;###autoload (define-key ctl-x-r-map "t" 'string-rectangle) +;;;###autoload (define-key ctl-x-r-map "N" 'rectangle-number-lines) ;;; Code: @@ -396,6 +397,45 @@ rectangle which were empty." (delete-region pt (point)) (indent-to endcol))))) +(defvar rectangle-number-line-counter nil + "Variable holding line numbering information. +Initial value is set in function `rectangle-number-lines' +and incremented for each line in `rectangle-number-line-callback'.") + +(defvar rectangle-number-line-format-history nil + "History variable that records previous format strings.") + +(defun rectangle-number-line-callback (start end format-string) + (move-to-column start t) + (setq rectangle-number-line-counter (+ rectangle-number-line-counter 1)) + (insert (format format-string rectangle-number-line-counter))) + +(defun rectangle-number-lines (beg end start-at format &optional no-zero-padding) + "Insert numbers in front of lines in rectangle BEG END. + +START-AT specifices the first number to start at. +FORMAT is format string where %i denotes inserted number. + +If prefix arg NO-ZERO-PADDING is non-nil, do not padd numbers +with leading zeroes." + (interactive + (list + (region-beginning) + (region-end) + (if (functionp 'read-number) + (read-number "First number [1]: " 1) + (string-to-int (read-string "First number [1]: " nil nil "1"))) + (read-string "Format: " "%i " 'rectangle-number-line-format-history) + current-prefix-arg)) + (setq start-at (- start-at 1)) + (unless no-zero-padding + (let* ((max (+ (count-lines beg end) start-at)) + (longest (length (int-to-string (+ 1 max)))) + (fmt (concat "%0" (int-to-string longest) "i"))) + (setq format (replace-regexp-in-string "%i" fmt format)))) + (setq rectangle-number-line-counter start-at) + (apply-on-rectangle 'rectangle-number-line-callback beg end format)) + (provide 'rect) ;; arch-tag: 178847b3-1f50-4b03-83de-a6e911cc1d16 -- 1.7.2.3 --=-=-= Content-Type: text/plain -- System Information Debian Release: squeeze/sid APT Prefers testing APT policy: (990, testing) (500, unstable) (1, experimental) Architecture: amd64 Kernel: Linux picasso 2.6.32-5-amd64 #1 SMP Fri Sep 17 21:50:19 UTC 2010 x86_64 GNU/Linux Locale: LANG=en_DK.UTF-8 -- Versions of packages `emacs depends on'. Depends: emacs23 23.2+1-5.1 GNU Emacs is the extensible self-documenting emacs23-lucid 23.2+1-5.1 GNU Emacs is the extensible self-documenting emacs23-nox 23.2+1-5.1 GNU Emacs is the extensible self-documenting --=-=-=--