From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Mathias Dahl Newsgroups: gmane.emacs.help Subject: Re: hide-region package and cperl Date: Thu, 30 Mar 2006 08:24:08 +0200 Message-ID: References: <87irpxg7ap.fsf-monnier+gnu.emacs.help@gnu.org> NNTP-Posting-Host: main.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: sea.gmane.org 1143700846 27682 80.91.229.2 (30 Mar 2006 06:40:46 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Thu, 30 Mar 2006 06:40:46 +0000 (UTC) Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Thu Mar 30 08:40:38 2006 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by ciao.gmane.org with esmtp (Exim 4.43) id 1FOqpb-0002DP-9B for geh-help-gnu-emacs@m.gmane.org; Thu, 30 Mar 2006 08:40:31 +0200 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1FOqpa-0004pr-Qo for geh-help-gnu-emacs@m.gmane.org; Thu, 30 Mar 2006 01:40:30 -0500 Original-Path: shelby.stanford.edu!newsfeed.stanford.edu!news.tele.dk!news.tele.dk!small.news.tele.dk!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail Original-Newsgroups: gnu.emacs.help Original-Lines: 173 Original-X-Trace: individual.net DoT/iTxgKTr98jUTktnDkAxZKd+lywnHo8sqknq+uuTtWv+kJg User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.0.50 (windows-nt) Cancel-Lock: sha1:Ri2T7q86+DMIhUuSkn3TJaDXFPQ= Original-Xref: shelby.stanford.edu gnu.emacs.help:138456 Original-To: help-gnu-emacs@gnu.org X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:34075 Archived-At: Stefan Monnier writes: >> when applying M-x hide-region-hide on a text in cperl-mode, I can see >> @[]@ tags arround the region, but the text remains visible. >> emacs-version is 21.3.1 >> The function is ok with 22.0.50.1. > >> Does anyone know the cause? > > Yes: it uses the t value for its `invisible' property, but doesn't add it to > the buffer's invisibility spec. As long as the invisibility spec is not > changed by any other major or minor mode, it works, but in general > it's incorrect. > > Also I'd advise the package author not to use the `intangible' property, > since it tends to break other packages when they bump into it. > > > Stefan Thanks for the input, Stefan. I read in the Emacs Lisp Manual about how to handle this. Hopefully I do the right thing now. I also added a toggle between using ellipsis or the user-defined markers as markers for the hidden regions. Now the source also complies with what `checkdoc' likes. I'd appreciate comments on the part of the code that handles the invisible property: ;;; hide-region.el --- hide regions of text using overlays ;; ;; Copyright (C) 2001, 2005, 2006 Mathias Dahl ;; ;; Version: 1.0.2 ;; Keywords: hide, region ;; Author: Mathias Dahl ;; Maintainer: Mathias Dahl ;; URL: http://www.emacswiki.org ;; ;; This file is not part of GNU Emacs. ;; ;; This is free software; you can redistribute it and/or modify it ;; under the terms of the GNU General Public License as published by ;; the Free Software Foundation; either version 2, or (at your option) ;; any later version. ;; ;; This is distributed in the hope that it will be useful, but WITHOUT ;; ANY WARRANTY; without even the implied warranty of MERCHANTABILITY ;; or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public ;; License for more details. ;; ;; You should have received a copy of the GNU General Public License ;; along with GNU Emacs; see the file COPYING. If not, write to the ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, ;; Boston, MA 02111-1307, USA. ;; ;;; Commentary: ;; ;; The function `hide-region-hide' hides the region. You can hide many ;; different regions and they will be "marked" by two configurable ;; strings (so that you know where the hidden text is). ;; ;; The hidden regions is pushed on a kind of hide-region \"ring\". ;; ;; The function `hide-region-unhide' "unhides" one region, starting ;; with the last one you hid. ;; ;;; Bugs ;; ;; Probably many, but none that I know of. Comments and suggestions ;; are welcome! ;; ;;; History: ;; ;; Version 1.0.1 ;; ;; * Seems that the getting-stuck problem have disappeared since Emacs ;; 21.3 was released, so no need anymore for the extra movement ;; commands. ;; ;; * Added the intangible property to the overlays because that seemed ;; to remove a minor getting-stuck problem (the overlay "ate" one ;; keystroke) when navigating around an overlay. Adding the intangible ;; property makes it impossible to navigate into the overlay. ;; ;; * Added custom option to propertize the overlay markers for greater ;; visibility. ;; ;; * Minor code cleanup ;; ;; Version 1.0.2 ;; ;; * Removed the `intangible' property as suggested by Stefan Monnier. ;; ;; * Tried to do the right thing regarding the `invisible' property ;; and `buffer-invisibility-spec'. Let's see how it works. Also ;; suggested by Stefan. ;;; Code: (defgroup hide-region nil "Functions to hide region using an overlay with the invisible property. The text is not affected." :prefix "hide-region-" :group 'convenience) (defcustom hide-region-before-string "@[" "String to mark the beginning of an invisible region. This string is not really placed in the text, it is just shown in the overlay" :type '(string) :group 'hide-region) (defcustom hide-region-after-string "]@" "String to mark the beginning of an invisible region. This string is not really placed in the text, it is just shown in the overlay" :type '(string) :group 'hide-region) (defcustom hide-region-use-marker-string t "Toggles between using ellipsis or user-defined marker. If non-nil, use the user-defined marker strings `hide-region-before-string' and `hide-region-after-string'. If nil, use ellipsis instead." :type '(boolean) :group 'hide-region) (defcustom hide-region-propertize-markers t "If non-nil, add text properties to the region markers." :type 'boolean :group 'hide-region) (defvar hide-region-overlays nil "Variable to store the regions we put an overlay on.") (defun hide-region-hide () "Hides a region. Hides a region by making an invisible overlay over it and save the overlay on the `hide-region-overlays' \"ring\"" (interactive) ;; Use ellipsis instead of user-defined markers (if hide-region-use-marker-string (add-to-invisibility-spec 'hide-region) (add-to-invisibility-spec '(hide-region . t))) (let ((new-overlay (make-overlay (mark) (point)))) (setq hide-region-overlays (append (list new-overlay) hide-region-overlays)) (overlay-put new-overlay 'invisible 'hide-region) ;; Add user-defined markers (when hide-region-use-marker-string (overlay-put new-overlay 'before-string (if hide-region-propertize-markers (propertize hide-region-before-string 'font-lock-face 'region) hide-region-before-string)) (overlay-put new-overlay 'after-string (if hide-region-propertize-markers (propertize hide-region-after-string 'font-lock-face 'region) hide-region-after-string))))) (defun hide-region-unhide () "Unhide a region. Unhide one region at a time, starting with the last one hidden and deleting the overlay from the `hide-region-overlays' \"ring\"." (interactive) (if (car hide-region-overlays) (progn (delete-overlay (car hide-region-overlays)) (setq hide-region-overlays (cdr hide-region-overlays))))) (provide 'hide-region) ;;; hide-region.el ends here