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: narrow-to-here-document Date: Fri, 20 Jun 2003 22:59:09 +0900 (JST) Sender: emacs-devel-bounces+emacs-devel=quimby.gnus.org@gnu.org Message-ID: <20030620.225909.39171959.jet@gyve.org> 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 1056117965 8321 80.91.224.249 (20 Jun 2003 14:06:05 GMT) X-Complaints-To: usenet@main.gmane.org NNTP-Posting-Date: Fri, 20 Jun 2003 14:06:05 +0000 (UTC) Cc: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+emacs-devel=quimby.gnus.org@gnu.org Fri Jun 20 16:06:03 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 19TMT7-0001r7-00 for ; Fri, 20 Jun 2003 16:02:21 +0200 Original-Received: from monty-python.gnu.org ([199.232.76.173]) by quimby.gnus.org with esmtp (Exim 3.12 #1 (Debian)) id 19TMUj-0002aV-00 for ; Fri, 20 Jun 2003 16:04:01 +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 19TMT2-00050S-JR for emacs-devel@quimby.gnus.org; Fri, 20 Jun 2003 10:02:16 -0400 Original-Received: from list by monty-python.gnu.org with tmda-scanned (Exim 4.20) id 19TMSi-0004vy-He for emacs-devel@gnu.org; Fri, 20 Jun 2003 10:01:56 -0400 Original-Received: from mail by monty-python.gnu.org with spam-scanned (Exim 4.20) id 19TMSg-0004tZ-6c for emacs-devel@gnu.org; Fri, 20 Jun 2003 10:01:55 -0400 Original-Received: from r-maa.spacetown.ne.jp ([210.130.136.40]) by monty-python.gnu.org with esmtp (Exim 4.20) id 19TMQ5-0003zt-Kj for emacs-devel@gnu.org; Fri, 20 Jun 2003 09:59:13 -0400 Original-Received: from localhost (p4108-ipad13sapodori.hokkaido.ocn.ne.jp [219.162.65.108]) by r-maa.spacetown.ne.jp (8.11.6) with ESMTP id h5KDxAV03426; Fri, 20 Jun 2003 22:59:10 +0900 (JST) Original-To: cperl@ilyaz.org 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:15171 X-Report-Spam: http://spam.gmane.org/gmane.emacs.devel:15171 I've written a new function, narrot-to-here-document. This might be useful to edit here document region in a script file. How to you think to add this feature to emacs? The implementation has two parts. 1. hdoc.el --- Generic here document support 2. sh-script.el and cperl-mode.el adapters hdoc.el requires two function implementations, here-document-region and here-document-marker for each major modes in which narrot-to-here-document is enabled. I've written the functions for sh-script.el and cperl-mode.el. ;;; hdoc.el --- Generic here document support ;; Copyright (C) 2003 ??? ;; ;; Author: Masatake YAMATO ;;; Code: (defvar here-document-region nil "If non-nil, function for `narrow-to-here-document' to call. This is used to find the beginning and end of the here document region in a script file (see `narrow-to-here-document'). 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 here-document-marker nil "If non-nil, function for `narrow-to-here-document' and `make-indirect-buffer-for-here-document' to call. This is used to find the marker of the here document region in a script file (see `make-indirect-buffer-for-here-document' and `narrow-to-here-document'). 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-here-document) (define-key ctl-x-4-map "h" 'make-indirect-buffer-for-here-document) (defun narrow-to-here-document (&optional change-major-mode) "Make text outside current here document region invisible. Local variable `here-document-region' must be defined in the major mode to use this function. If CHANGE-MAJOR-MODE is non-nil and local variable `here-document-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 `here-document-marker'. For example if `here-document-marker' returns \"EOF.c\", `c-mode' will be selected. Major mode selection is done by `set-auto-mode'. In `set-auto-mode', `here-document-marker' is used as the buffer's file name temporally. To make text outside of the region visible, use \[widen]." (interactive "P") (unless here-document-region (error "%s: `%s' is not supported in this major mode." mode-name this-command)) (let* ((marker (if here-document-marker (funcall here-document-marker))) (r (funcall here-document-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-here-document (&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 `here-document-region' and `here-document-marker' must be defined in the major mode to use this function. CHANGE-MAJOR-MODE is passed to `narrow-to-here-document'. See also `narrow-to-here-document'. The new indirect buffer name will be \"original-buffername<