From mboxrd@z Thu Jan 1 00:00:00 1970 Path: main.gmane.org!not-for-mail From: Masatake YAMATO Newsgroups: gmane.emacs.devel Subject: Re: narrow-to-here-document Date: Wed, 25 Jun 2003 15:10:15 +0900 (JST) Sender: emacs-devel-bounces+emacs-devel=quimby.gnus.org@gnu.org Message-ID: <20030625.151015.68035851.jet@gyve.org> References: <20030620141028.GA1331@math.berkeley.edu> <20030621.012632.74543482.jet@gyve.org> <3EF73468.1030503@yahoo.com> NNTP-Posting-Host: main.gmane.org Mime-Version: 1.0 Content-Type: Text/Plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Trace: main.gmane.org 1056522034 24885 80.91.224.249 (25 Jun 2003 06:20:34 GMT) X-Complaints-To: usenet@main.gmane.org NNTP-Posting-Date: Wed, 25 Jun 2003 06:20:34 +0000 (UTC) Cc: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+emacs-devel=quimby.gnus.org@gnu.org Wed Jun 25 08:20:20 2003 Return-path: Original-Received: from quimby.gnus.org ([80.91.224.244]) by main.gmane.org with esmtp (Exim 3.35 #1 (Debian)) id 19V3XH-0006Do-00 for ; Wed, 25 Jun 2003 08:13:39 +0200 Original-Received: from monty-python.gnu.org ([199.232.76.173]) by quimby.gnus.org with esmtp (Exim 3.12 #1 (Debian)) id 19V3bA-0000yZ-00 for ; Wed, 25 Jun 2003 08:17:40 +0200 Original-Received: from localhost ([127.0.0.1] helo=monty-python.gnu.org) by monty-python.gnu.org with esmtp (Exim 4.20) id 19V3V6-0000O9-Lu for emacs-devel@quimby.gnus.org; Wed, 25 Jun 2003 02:11:24 -0400 Original-Received: from list by monty-python.gnu.org with tmda-scanned (Exim 4.20) id 19V3Uc-0000IY-7Z for emacs-devel@gnu.org; Wed, 25 Jun 2003 02:10:54 -0400 Original-Received: from mail by monty-python.gnu.org with spam-scanned (Exim 4.20) id 19V3UC-0008WK-ET for emacs-devel@gnu.org; Wed, 25 Jun 2003 02:10:30 -0400 Original-Received: from r-maa.spacetown.ne.jp ([210.130.136.40]) by monty-python.gnu.org with esmtp (Exim 4.20) id 19V3U3-0007z3-Mm for emacs-devel@gnu.org; Wed, 25 Jun 2003 02:10:19 -0400 Original-Received: from localhost (mx.jp.redhat.com [219.96.218.186]) by r-maa.spacetown.ne.jp (8.11.6) with ESMTP id h5P6AFH22170; Wed, 25 Jun 2003 15:10:15 +0900 (JST) Original-To: ihs_4664@yahoo.com In-Reply-To: <3EF73468.1030503@yahoo.com> X-Mailer: Mew version 3.1.52 on Emacs 21.3 / Mule 5.0 (SAKAKI) X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1b5 Precedence: list List-Id: Emacs development discussions. List-Help: List-Post: List-Subscribe: , List-Archive: List-Unsubscribe: , Errors-To: emacs-devel-bounces+emacs-devel=quimby.gnus.org@gnu.org Xref: main.gmane.org gmane.emacs.devel:15226 X-Report-Spam: http://spam.gmane.org/gmane.emacs.devel:15226 I've reflected suggestions to my code. Richard Stallman: 1. The first line of a doc string is supposed to be complete in itself. 2. "here-document" is too long. Kevin Rodgers: 3. Would INCLUDE/IGNORE/CDATA marked sections in SGML/XML/HTML qualify? s or &entity; references are recognized here. ]]> About narrow-to-string, I do nothing yet. I wonder what should I do. Regards, Masatake p.s. Next time, I'll use diff&patch. ;;; hdoc.el --- Generic here document support ;; Copyright (C) 2003 ;; ;; Author: Masatake YAMATO ;;; Commentary: ;;; Code: (defvar hdoc-region 'here-document-region-default "If non-nil, function for `narrow-to-hdoc' to call. This is used to find the beginning and end of the here document region in a script file (see `narrow-to-hdoc'). Major modes can define this to handle the mode's needs. The function should return a cons cell; its car is the position of beginning and cdr is that of end if the point is in a here document region. The function should return `nil' if the point is out of a here document region. ") (defvar hdoc-marker 'here-document-marker-default "If non-nil, function for `narrow-to-hdoc' and `make-indirect-buffer-for-hdoc' to call. This is used to find the marker of the here document region in a script file (see `make-indirect-buffer-for-hdoc' and `narrow-to-hdoc'). A string \"EOF\" is used widely as the marker but other string is also OK. Major modes can define this to handle the mode's needs. The function should return a marker string if the point is in a here document region. Else it should return `nil'. ") (define-key ctl-x-map "nh" 'narrow-to-hdoc) (define-key ctl-x-4-map "h" 'make-indirect-buffer-for-hdoc) (defun narrow-to-hdoc (&optional change-major-mode) "Make text outside current here document region invisible. Local variable `hdoc-region' must be defined in the major mode to use this function. If CHANGE-MAJOR-MODE is non-nil and local variable `hdoc-marker' is defined in the major mode, major mode for the current buffer will be switched; new major mode is selected according to the result of `hdoc-marker'. For example if `hdoc-marker' returns \"EOF.c\", `c-mode' will be selected. Major mode selection is done by `set-auto-mode'. In `set-auto-mode', `hdoc-marker' is used as the buffer's file name temporally. To make text outside of the region visible, use \[widen]." (interactive "P") (let* ((marker (funcall hdoc-marker)) (r (funcall hdoc-region)) (b (car r)) (e (cdr r))) (unless r (error "Cannot find here document region")) (narrow-to-region b e) (if (and change-major-mode marker) (let ((buffer-file-name marker)) (set-auto-mode))))) (defun make-indirect-buffer-for-hdoc (&optional change-major-mode) "Create and return an indirect buffer for current here document region. In the new indirect buffer, the text outside current here document region is invisible(narrowed). Local variables `hdoc-region' and `hdoc-marker' must be defined in the major mode to use this function. CHANGE-MAJOR-MODE is passed to `narrow-to-hdoc'. See also `narrow-to-hdoc'. The new indirect buffer name will be \"original-buffername<") (defun sgml-here-document-region () (let (beginning end) (save-excursion (save-match-data (when (re-search-backward sgml-here-document-beginning-regexp (point-min) t) (setq beginning (match-end 0)) (when (re-search-forward sgml-here-document-end-regexp (point-max) t) (setq end (match-beginning 0)))))) (if (and beginning end (<= (point) end)) (cons beginning end)))) (defun sgml-here-document-marker () (if (sgml-here-document-region) (save-excursion (save-match-data (when (re-search-backward sgml-here-document-beginning-regexp (point-min) t) (match-string 1)))))) (provide 'hdoc) ;; hdoc.el ends here