From mboxrd@z Thu Jan 1 00:00:00 1970 Path: main.gmane.org!not-for-mail From: Juha Vierinen Newsgroups: gmane.emacs.devel Subject: Furna's fisheye minor mode Date: Tue, 20 Jan 2004 17:00:01 +0200 Sender: emacs-devel-bounces+emacs-devel=quimby.gnus.org@gnu.org Message-ID: <400D4271.6070602@tml.hut.fi> NNTP-Posting-Host: deer.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="------------070807020106000805050805" X-Trace: sea.gmane.org 1074612326 32008 80.91.224.253 (20 Jan 2004 15:25:26 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Tue, 20 Jan 2004 15:25:26 +0000 (UTC) Original-X-From: emacs-devel-bounces+emacs-devel=quimby.gnus.org@gnu.org Tue Jan 20 16:25:17 2004 Return-path: Original-Received: from quimby.gnus.org ([80.91.224.244]) by deer.gmane.org with esmtp (Exim 3.35 #1 (Debian)) id 1Aixkj-000062-00 for ; Tue, 20 Jan 2004 16:25:17 +0100 Original-Received: from monty-python.gnu.org ([199.232.76.173]) by quimby.gnus.org with esmtp (Exim 3.35 #1 (Debian)) id 1Aixki-0004rz-00 for ; Tue, 20 Jan 2004 16:25:16 +0100 Original-Received: from localhost ([127.0.0.1] helo=monty-python.gnu.org) by monty-python.gnu.org with esmtp (Exim 4.24) id 1AixTP-0000NN-6H for emacs-devel@quimby.gnus.org; Tue, 20 Jan 2004 10:07:23 -0500 Original-Received: from list by monty-python.gnu.org with tmda-scanned (Exim 4.24) id 1AixSt-0000N4-MT for emacs-devel@gnu.org; Tue, 20 Jan 2004 10:06:51 -0500 Original-Received: from mail by monty-python.gnu.org with spam-scanned (Exim 4.24) id 1AixSN-0000Hj-5S for emacs-devel@gnu.org; Tue, 20 Jan 2004 10:06:50 -0500 Original-Received: from [130.233.228.93] (helo=smtp-3.hut.fi) by monty-python.gnu.org with esmtp (TLSv1:DES-CBC3-SHA:168) (Exim 4.24) id 1AixNI-0007Ka-Ea for emacs-devel@gnu.org; Tue, 20 Jan 2004 10:01:04 -0500 Original-Received: from tml.hut.fi (laatikko.tml.hut.fi [130.233.44.195]) by smtp-3.hut.fi (8.12.10/8.12.10) with ESMTP id i0KF01bi026550 for ; Tue, 20 Jan 2004 17:00:01 +0200 User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.3) Gecko/20030805 X-Accept-Language: en-us, en Original-To: emacs-devel@gnu.org X-Enigmail-Version: 0.74.3.0 X-Enigmail-Supports: pgp-inline, pgp-mime X-RAVMilter-Version: 8.4.3(snapshot 20030212) (smtp-3.hut.fi) X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.2 Precedence: list List-Id: Emacs development discussions. List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+emacs-devel=quimby.gnus.org@gnu.org Xref: main.gmane.org gmane.emacs.devel:19340 X-Report-Spam: http://spam.gmane.org/gmane.emacs.devel:19340 This is a multi-part message in MIME format. --------------070807020106000805050805 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit Hi, I have attached a minor mode for emacs 21 that dynamically filters out stuff that is indented. It is a bit similar to hideshow, hidelines and outline, but it works on the indentation level instead of the semantics of some programming language. The mode is slow with very large files, because I couldn't figure out how to check if the point is in the visible region of the buffer. Also, the only way I could detect that the point had moved was by saving the point position and checking if it has changed in the post-command-hook. The question is, what is the right way to check that the point has moved? How do I know if the point is in the visible region of the buffer? juha --------------070807020106000805050805 Content-Type: text/plain; name="fisheye.el" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="fisheye.el" ;;; fisheye.el --- ;; ;; Furna's fisheye mode. Nice for editing large source code files ;; ;; Author: Juha Vierinen ;; (use your blind spot) ;; ;;; Commentary ;; ;; The simplest way to make fisheye work is to add the following ;; lines to your .emacs file: ;; ;; (autoload 'fisheye "fisheye" "Fisheye mode" t) ;; ;; and 'fisheye-minor-mode' to toggle on/off ;; ;; Internal functions mapped to key-strokes ;; ;; I recommend using spaces for intendation ;; (setq indent-tabs-mode nil) ;; ;; Tested on Emacs 21.2.1 and 21.3.1 ;; ;; todo ;; - better doi and lod functions (language specific) ;; ;; GPL ;; (defcustom fisheye-minor-mode-hook nil "*Hook called when fisheye minor mode is activated or deactivated." :type 'hook :group 'fisheye :version "21.1") ;(defvar fisheye-minor-mode nil ; "Non-nil if using fisheye mode as a minor mode of some other mode. ;Use the command `fisheye-minor-mode' to toggle or set this variable.") (defvar fisheye-minor-mode-map nil "Keymap for fisheye minor mode.") ;;;###autoload (define-minor-mode fisheye-minor-mode "Toggle fisheye minor mode. With ARG, turn fisheye minor mode on if ARG is positive, off otherwise. When fisheye minor mode is on, the menu bar is augmented with fisheye commands and the fisheye commands are enabled. The value '(fe) is added to `buffer-invisibility-spec'. The main commands are: `fisheye-point-moved' and 'fisheye-show-all-invisible'. Turning fisheye minor mode off reverts the menu bar and the variables to default values and disables the fisheye commands. Lastly, the normal hook `fisheye-minor-mode-hook' is run using `run-hooks'. Key bindings: \\{fisheye-minor-mode-map}" nil " Fisheye" nil (if fisheye-minor-mode (progn (set (make-local-variable 'line-move-ignore-invisible) t) ;; use '(fe . t) if you want ellipses for hidden overlays (add-to-invisibility-spec '(fe)) (add-hook 'post-command-hook 'fisheye-yoho)) (fisheye-show-all-invisible) (remove-from-invisibility-spec '(fe)) (remove-hook 'post-command-hook 'fisheye-yoho)) (run-hooks 'fisheye-minor-mode-hook)) ;; internal variables (defvar fisheye-old-point 1 "keeps track of the previous point placement.") ;(defvar fisheye-minor-mode 1 "is fisheye mode on or not") (defvar fisheye-min-level-visible 1 "The level that cannot be hidden") (defvar fisheye-max-level-detected 10 "The largest level of detail recognized") (defvar fisheye-doi-visible 7 "The level that cannot be hidden") (defvar fisheye-visible-area 20 "The visible area that is not folded (in lines)") (defvar fisheye-inside-lodcount 0) (defvar fisheye-tab-spaces 8 "tab equals eight spaces") (defvar fisheye-invisible-list-cursor 0 "An index indicating the position of the point in the invisible areas list") (defvar fisheye-invisible-areas-list () "List of invisible overlays used by fisheye-mode") (defun fisheye-add-invisible-overlay (start end) "Add an overlay from `start' to `end' in the current buffer. Push the overlay onto the fisheye-invisible-areas-list list" (let ((overlay (make-overlay start end))) (setq fisheye-invisible-areas-list (fisheye-addn (+ (length fisheye-invisible-areas-list) 1) fisheye-invisible-areas-list overlay)) (overlay-put overlay 'invisible '(fe)))) (defun fisheye-add-invisible-overlay-at (n start end) "Add an overlay from `start' to `end' in the current buffer. Push the overlay onto the fisheye-invisible-areas-list list" (let ((overlay (make-overlay start end))) (setq fisheye-invisible-areas-list (fisheye-addn n fisheye-invisible-areas-list overlay)) (overlay-put overlay 'invisible '(fe)))) (defun fisheye-toggle () "Toggle fisheye mode, show all hidden lines" (if (eq fisheye-minor-mode nil) (setq fisheye-minor-mode 1) (setq fisheye-minor-mode nil) (fisheye-show-all-invisible))) (defun fisheye-yoho () (if (and (not (equal fisheye-old-point (point))) (not (eq fisheye-minor-mode nil))) (fisheye-point-moved)) (setq fisheye-old-point (point))) (defun fisheye-move (direction) "Move one step in some direction" (let ((new-point (point)) (start-position)) (save-excursion (goto-char fisheye-old-point) (forward-line (* direction (+ fisheye-visible-area 1))) (if (< (fisheye-doi (point) fisheye-old-point) fisheye-doi-visible) (if (= direction 1) (fisheye-delete-overlay-after fisheye-invisible-list-cursor) (fisheye-delete-overlay-before fisheye-invisible-list-cursor) (setq fisheye-invisible-list-cursor (- fisheye-invisible-list-cursor 1)))) (goto-char fisheye-old-point) (forward-line (* direction (- fisheye-visible-area))) (if (>= (fisheye-doi (point) new-point) fisheye-doi-visible) () (beginning-of-line) (setq start-position (point)) (end-of-line) (fisheye-add-invisible-overlay-at (+ fisheye-invisible-list-cursor 1) start-position (+ 1 (point))) (if (= direction 1) (setq fisheye-invisible-list-cursor (+ fisheye-invisible-list-cursor 1))))))) (defun fisheye-delete-overlay-after (cursor) (if (> cursor (length fisheye-invisible-areas-list)) () (delete-overlay (nth cursor fisheye-invisible-areas-list)) (setq fisheye-invisible-areas-list (fisheye-remn (+ cursor 1) fisheye-invisible-areas-list)))) (defun fisheye-delete-overlay-before (cursor) (if (< cursor 1) () (delete-overlay (nth (- cursor 1) fisheye-invisible-areas-list)) (setq fisheye-invisible-areas-list (fisheye-remn cursor fisheye-invisible-areas-list)))) (defun fisheye-point-moved () "The point has moved, so we brute force the buffer, this is done initially, and also if the point has radically moved" (interactive) (if (and (not (eq fisheye-invisible-areas-list nil)) (= (fisheye-count-lines (point) fisheye-old-point) 1)) (if (> (- (point) fisheye-old-point) 0) (fisheye-move 1) (fisheye-move -1)) (if (> (fisheye-count-lines (point) fisheye-old-point) 0) (let ((focus-point (point)) (start-position) (end-point (point-max))) (save-excursion (fisheye-show-all-invisible) (setq fisheye-invisible-list-cursor 0) (goto-char (point-min)) (while (and (save-excursion (end-of-line) (not (eobp))) (< (point) end-point)) (beginning-of-line) (if (>= (fisheye-doi (point) focus-point) fisheye-doi-visible) (forward-line 1) (setq start-position (point)) (end-of-line) (fisheye-add-invisible-overlay start-position (+ 1 (point))) (if (< (point) focus-point) (setq fisheye-invisible-list-cursor (+ fisheye-invisible-list-cursor 1))) (forward-line 1)))))))) (defun fisheye-lod (current-point) "The relevance the level of detail of the current line. Override, if you want something special" (let ((level 1) (tmp-point)) (save-excursion (goto-char current-point) (beginning-of-line) ;; if plain newline, then level of detail is highest (should be filtered out) (if (eq (char-after (point)) 10) (setq level fisheye-max-level-detected) (while (and (or (eq (char-after (point)) 32) (eq (char-after (point)) 9)) (< level fisheye-max-level-detected) (not (eolp))) (if (eq (char-after (point)) 32) (setq level (+ level 1)) (setq level (+ level fisheye-tab-spaces))) (goto-char (forward-point 1))))) level)) (defun fisheye-doi (current-point focus-point) "Degree of interest function. Simple window, with fixed size, also we display all sufficiently low level details (lines that have small enough lod, defined in fisheye-min-level-visible" (let ((doi nil) (distance nil)) (setq distance (fisheye-count-lines focus-point current-point)) (if (< distance fisheye-visible-area) (setq doi fisheye-doi-visible) (setq doi (- (+ fisheye-doi-visible fisheye-min-level-visible) (fisheye-lod current-point)))) doi)) (defun fisheye-show-all-invisible () "Show all hidden area, when fisheye is toggled off" (interactive) (mapcar (lambda (overlay) (delete-overlay overlay)) fisheye-invisible-areas-list) (setq fisheye-invisible-areas-list ())) (defun fisheye-remn (n l) (if (= n 1) (setq l (cdr l)) (setcdr (nthcdr (- n 2) l) (nthcdr n l))) l) (defun fisheye-addn (n l o) (if (< n 2) (setq l (cons o l)) (setcdr (nthcdr (- n 2) l) (cons o (nthcdr (- n 1) l)))) l) (defun fisheye-count-lines (a b) (let ((point-a) (point-b) (lines)) (save-excursion (goto-char a) (beginning-of-line) (setq point-a (point)) (goto-char b) (beginning-of-line) (setq point-b (point)) (setq lines (count-lines point-a point-b))) lines)) (provide 'fisheye) --------------070807020106000805050805 Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Emacs-devel mailing list Emacs-devel@gnu.org http://mail.gnu.org/mailman/listinfo/emacs-devel --------------070807020106000805050805--