From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Jonas Bernoulli Newsgroups: gmane.emacs.bugs Subject: bug#13207: lisp-mnt.el improvements Date: Mon, 17 Dec 2012 17:26:33 +0100 Message-ID: <878v8wve4m.fsf@bernoul.li> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Trace: ger.gmane.org 1355761683 579 80.91.229.3 (17 Dec 2012 16:28:03 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Mon, 17 Dec 2012 16:28:03 +0000 (UTC) To: 13207@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Mon Dec 17 17:28:17 2012 Return-path: Envelope-to: geb-bug-gnu-emacs@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 1TkdY5-0000bu-Ic for geb-bug-gnu-emacs@m.gmane.org; Mon, 17 Dec 2012 17:28:13 +0100 Original-Received: from localhost ([::1]:48940 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TkdXs-0002Jc-8I for geb-bug-gnu-emacs@m.gmane.org; Mon, 17 Dec 2012 11:28:00 -0500 Original-Received: from eggs.gnu.org ([208.118.235.92]:53246) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TkdXk-0002Ip-Uf for bug-gnu-emacs@gnu.org; Mon, 17 Dec 2012 11:27:58 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TkdXf-0000SR-8y for bug-gnu-emacs@gnu.org; Mon, 17 Dec 2012 11:27:52 -0500 Original-Received: from debbugs.gnu.org ([140.186.70.43]:37083) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TkdXf-0000SM-5S for bug-gnu-emacs@gnu.org; Mon, 17 Dec 2012 11:27:47 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.72) (envelope-from ) id 1TkdYs-0003hh-Bh for bug-gnu-emacs@gnu.org; Mon, 17 Dec 2012 11:29:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Jonas Bernoulli Original-Sender: debbugs-submit-bounces@debbugs.gnu.org Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Mon, 17 Dec 2012 16:29:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 13207 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: X-Debbugs-Original-To: bug-gnu-emacs@gnu.org Original-Received: via spool by submit@debbugs.gnu.org id=B.135576169314169 (code B ref -1); Mon, 17 Dec 2012 16:29:02 +0000 Original-Received: (at submit) by debbugs.gnu.org; 17 Dec 2012 16:28:13 +0000 Original-Received: from localhost ([127.0.0.1]:47334 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1TkdY4-0003gT-3y for submit@debbugs.gnu.org; Mon, 17 Dec 2012 11:28:13 -0500 Original-Received: from eggs.gnu.org ([208.118.235.92]:41686) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1TkdXx-0003gI-La for submit@debbugs.gnu.org; Mon, 17 Dec 2012 11:28:10 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TkdWf-0000IA-UD for submit@debbugs.gnu.org; Mon, 17 Dec 2012 11:26:49 -0500 Original-Received: from lists.gnu.org ([208.118.235.17]:58280) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TkdWf-0000I5-Qc for submit@debbugs.gnu.org; Mon, 17 Dec 2012 11:26:45 -0500 Original-Received: from eggs.gnu.org ([208.118.235.92]:53040) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TkdWb-00028R-Uh for bug-gnu-emacs@gnu.org; Mon, 17 Dec 2012 11:26:45 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TkdWX-0000Fa-V4 for bug-gnu-emacs@gnu.org; Mon, 17 Dec 2012 11:26:41 -0500 Original-Received: from mail-wi0-f179.google.com ([209.85.212.179]:43863) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TkdWX-0000FS-Fc for bug-gnu-emacs@gnu.org; Mon, 17 Dec 2012 11:26:37 -0500 Original-Received: by mail-wi0-f179.google.com with SMTP id o1so2043982wic.12 for ; Mon, 17 Dec 2012 08:26:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:subject:user-agent:date:message-id:mime-version :content-type; bh=MDYyqpNxZPHNglj0ViDEIT5YFSXg3UCCARuA/GhgCac=; b=YiFKTQs2fiAy/vCdALiIjMPZVytGb6UgpTgJfcPJzdAzmwWO+m6/ovu8oSDx4gTSqo IE6xbqIafqNJGbvn+OVJJ8F3MGY8JMzvCrBg1HJpOvpI5FKU52XZUpfHBR9aoqSogdlm F3dSRcfEelsxVf8Srw6GfOOnnEQwH/Si99eQC8YbbemVQSGpaYCqy4vRARxV/94QB3TJ jM/DRI/MAYFyseug5vzO5MUaL4sW1vmjQl7VxjL18IV7jEu+SqksrgG/cRSwpv0sYsmt 8pbS9APBfip4bXgpVpkJMCCVDV9h0jE/lg1++vVBKTuM2b7QxMT6jUbKpdOKhS7lGhVU T1sA== Original-Received: by 10.180.107.197 with SMTP id he5mr16833532wib.1.1355761596046; Mon, 17 Dec 2012 08:26:36 -0800 (PST) Original-Received: from lem (178-83-148-79.dynamic.hispeed.ch. [178.83.148.79]) by mx.google.com with ESMTPS id i2sm11797204wiw.3.2012.12.17.08.26.34 (version=TLSv1/SSLv3 cipher=OTHER); Mon, 17 Dec 2012 08:26:34 -0800 (PST) User-agent: mu4e 0.9.9.5-dev4; emacs 24.3.50.1 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [fuzzy] X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.13 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x X-Received-From: 140.186.70.43 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: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.bugs:68647 Archived-At: --=-=-= Content-Type: text/plain Hello I extract information from the library headers of all packages mirrored on the Emacsmirror. Since many packages don't follow the header conventions lisp-mnt.el in it's current form isn't always suitable. So I have written elx.el which can handle some departure from the standard; it also includes some additions. Now I would like to merge some of the changes back into lisp-mnt.el: 1. Add function lm-homepage (lm-header "\\(?:x-\\)?\\(?:homepage\\|url\\)") These keywords are used quite often, most often without the X- prefix. 2. lm-section-end: the end is now always before the following non-comment text Many people don't add ;;; Code: after the header. As a result lm-commentary was often way of (like eof!) and lm-commentary returned text that isn't part of the commentary but code. 3. lm-header, lm-header-multiline: wrap with save-match-data 4. lm-header-multiline: continuation lines now need to be intended more than the first line. E.g: ;; Keyword: value ;; more value This is necessary because some built-in libraries contain things like: ;; Author: Kenichi HANDA ;; (according to ack.texi) And some third-party libraries contain things like: ;; Keywords: key words ;; This file is not part of Emacs Among the 3500 packages mirrored on the Emacsmirror there are only three where this change results in lines intended as continuation lines not to be recognised anymore. At the same time this change fixes ~50 errors. There now have to be at least two spaces or one tab after the initial semicolons for a line to be considered a continuation line. (1) and (4) should be documented in the info page. Let me know if you want to do that. elx.el contains some more things that could be merged into lisp-mnt.el, but I would first like to know how these changes are received. Jonas --=-=-= Content-Type: text/x-diff Content-Disposition: attachment; filename=lisp-mnt.patch >From c9a79155d00e48a282d7fce1b6d21838c9fa5a90 Mon Sep 17 00:00:00 2001 From: Jonas Bernoulli Date: Mon, 17 Dec 2012 17:03:41 +0100 Subject: [PATCH] lisp/emacs-lisp/lisp-mnt.el: new function lm-homepage (lm-section-end): the end is now always before the following non-comment text (lm-header): save-match-data (lm-header-multiline): save-match-data, continuation lines now need to be intended more than the first line (lm-with-file): widen and goto beginning of buffer before reusing current buffer --- lisp-mnt.el | 75 ++++++++++++++++++++++++++++++++++++------------------------- 1 file changed, 44 insertions(+), 31 deletions(-) diff --git a/lisp-mnt.el b/lisp-mnt.el index f9a1c5d..7bbc033 100644 --- a/lisp-mnt.el +++ b/lisp-mnt.el @@ -208,10 +208,10 @@ If the given section does not exist, return nil." The HEADER is the section string marking the beginning of the section. If the given section does not exist, return nil. -The end of the section is defined as the beginning of the next -section of the same level or lower. The function -`lisp-outline-level' is used to compute the level of a section. -If no such section exists, return the end of the buffer." +The section ends before the first non-comment text or the next +section of the same level or lower; whatever comes first. The +function `lisp-outline-level' is used to compute the level of +a section." (require 'outline) ;; for outline-regexp. (let ((start (lm-section-start header))) (when start @@ -229,9 +229,15 @@ If no such section exists, return the end of the buffer." (beginning-of-line) (lisp-outline-level)) level))) - (if next-section-found - (line-beginning-position) - (point-max))))))) + (min (if next-section-found + (progn (beginning-of-line 0) + (unless (looking-at " ") + (beginning-of-line 2)) + (point)) + (point-max)) + (progn (goto-char start) + (while (forward-comment 1)) + (point)))))))) (defsubst lm-code-start () "Return the buffer location of the `Code' start marker." @@ -262,35 +268,32 @@ If no such section exists, return the end of the buffer." (defun lm-header (header) "Return the contents of the header named HEADER." - (goto-char (point-min)) - (let ((case-fold-search t)) - (when (and (re-search-forward (lm-get-header-re header) (lm-code-mark) t) - ;; RCS ident likes format "$identifier: data$" - (looking-at - (if (save-excursion - (skip-chars-backward "^$" (match-beginning 0)) - (= (point) (match-beginning 0))) - "[^\n]+" "[^$\n]+"))) - (match-string-no-properties 0)))) + (save-match-data + (goto-char (point-min)) + (let ((case-fold-search t)) + (when (and (re-search-forward (lm-get-header-re header) (lm-code-mark) t) + ;; RCS ident likes format "$identifier: data$" + (looking-at + (if (save-excursion + (skip-chars-backward "^$" (match-beginning 0)) + (= (point) (match-beginning 0))) + "[^\n]+" "[^$\n]+"))) + (match-string-no-properties 0))))) (defun lm-header-multiline (header) "Return the contents of the header named HEADER, with continuation lines. The returned value is a list of strings, one per line." (save-excursion - (goto-char (point-min)) - (let ((res (lm-header header))) - (when res - (setq res (list res)) - (forward-line 1) - (while (and (or (looking-at (concat lm-header-prefix "[\t ]+")) - (and (not (looking-at - (lm-get-header-re "\\sw\\(\\sw\\|\\s_\\)*"))) - (looking-at lm-header-prefix))) - (goto-char (match-end 0)) - (looking-at ".+")) - (setq res (cons (match-string-no-properties 0) res)) - (forward-line 1))) - (nreverse res)))) + (save-match-data + (goto-char (point-min)) + (let ((res (lm-header header))) + (when res + (setq res (list res)) + (forward-line 1) + (while (looking-at "^;+\\(\t\\|[\t\s]\\{2,\\}\\)\\(.+\\)") + (push (match-string-no-properties 2) res) + (forward-line 1))) + (nreverse res))))) ;; These give us smart access to the header fields and commentary @@ -306,6 +309,8 @@ If FILE is nil, execute BODY in the current buffer." (emacs-lisp-mode) ,@body) (save-excursion + (widen) + (goto-char (point-min)) ;; Switching major modes is too drastic, so just switch ;; temporarily to the Emacs Lisp mode syntax table. (with-syntax-table emacs-lisp-mode-syntax-table @@ -489,6 +494,14 @@ absent, return nil." (when start (buffer-substring-no-properties start (lm-commentary-end)))))) +(defun lm-homepage (&optional file) + "Return the homepage in file FILE, or current buffer if FILE is nil." + (let ((page (lm-with-file file + (lm-header "\\(?:x-\\)?\\(?:homepage\\|url\\)")))) + (if (and page (string-match "^<.+>$" page)) + (substring page 1 -1) + page))) + ;;; Verification and synopses (defun lm-insert-at-column (col &rest strings) -- 1.8.0.1 --=-=-=--