From mboxrd@z Thu Jan 1 00:00:00 1970 From: Carsten Dominik Subject: Re: [NEW FEATURE] org-hlc.el - hidden-lines-cookies (hlc) for Org-mode Date: Thu, 23 May 2013 10:08:01 +0200 Message-ID: <6219E7E2-9951-4B05-A977-DE0DD1B120BE@gmail.com> References: <87zjvmiw1k.fsf@gmail.com> Mime-Version: 1.0 (Mac OS X Mail 6.3 \(1503\)) Content-Type: multipart/alternative; boundary="Apple-Mail=_880AA766-37A6-4B70-B31C-BF684045FC43" Return-path: Received: from eggs.gnu.org ([208.118.235.92]:58206) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UfQZZ-0007fl-0A for emacs-orgmode@gnu.org; Thu, 23 May 2013 04:08:37 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UfQZB-0004i3-KJ for emacs-orgmode@gnu.org; Thu, 23 May 2013 04:08:28 -0400 Received: from ezel.ic.uva.nl ([146.50.108.158]:55249) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UfQZA-0004cD-Uo for emacs-orgmode@gnu.org; Thu, 23 May 2013 04:08:05 -0400 In-Reply-To: <87zjvmiw1k.fsf@gmail.com> List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: Thorsten Jolitz Cc: emacs-orgmode@gnu.org --Apple-Mail=_880AA766-37A6-4B70-B31C-BF684045FC43 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=us-ascii Hi Thorsten, On 22 mei 2013, at 22:44, Thorsten Jolitz wrote: >=20 > Hi List,=20 >=20 > I ported this from outshine.el (i.e. outline-minor-mode) to Org-mode, > hope it is useful.=20 >=20 > What is it all about? With 'org-hlc'=20 >=20 > ,-------------------------------------------------------------------- > | Behind every folded headline, a little 'cookie' shows the number of > | hidden lines till the next visible headline. > `-------------------------------------------------------------------- >=20 > e.g. >=20 > ,--------------------------------------------------------------------- > | * my-file.org [#13] > | ** Commentary [#1] > | *** About my-file > |=20 > | This file implements extensions for occur-mode. You can think of a > | navi-buffer as a kind of 'remote-control' for an (adecuately) > | outline-structured original-buffer. > |=20 > | *** Usage [#165] > `--------------------------------------------------------------------- This is is definitely a nice feature. Herbert Sitz has this in his vimorganizer implementation for vi, http://vimeo.com/16543959 and we have been jealous of this feature ever since. However, I don't think the implementation is the right one. Modifying the file to display this does not seem right. I would say it should use text properties or maybe overlays for display, and it should be hooked somehow into the folding/unfolding routines to auto-update. Cheers! - Carsten >=20 > I attach the code to this message, you can find the git-repo here: >=20 > ,-------------------------------- > | https://github.com/tj64/org-hlc > | git clone https://github.com/tj64/org-hlc > `------------------------------------------ >=20 > Please let me know if there is interest to include this in Org-mode.=20= >=20 > ----------- > ORG-HLC.EL > ----------- >=20 > ;;; org-hlc.el --- hidden-lines-cookies for folded Org-mode headlines >=20 > ;; Copyright (C) 2013 Thorsten Jolitz >=20 > ;; Author: Thorsten Jolitz > ;; Keywords: org-mode, outline, visibility, overlays >=20 > ;; This file is (NOT YET) part of GNU Emacs. >=20 > ;; GNU Emacs 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 3 of the License, or > ;; (at your option) any later version. >=20 > ;; GNU Emacs 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. >=20 > ;; You should have received a copy of the GNU General Public License > ;; along with GNU Emacs. If not, see . >=20 > ;;; Commentary: >=20 > ;; 'hidden-lines-cookies' (hlc) are small cookies at the end of each = folded > ;; (and visible) headline in an Org-mode buffer that show the number = of hidden > ;; lines before the next visible headline. >=20 > ;; hidden-lines-cookies can be handled with three user commands: > ;; `org-hlc-show-hidden-lines-cookies', = `org-hlc-hide-hidden-lines-cookies', > ;; and the convenience command `org-hlc-toggle-hidden-lines-cookies' = that > ;; toggles between the two other commands conditional on the last one > ;; executed. >=20 > ;; The appearance of the cookies can be customized by changing the = values of > ;; four customizable variables: = `org-hlc-hidden-lines-cookie-left-delimiter' > ;; (with default value "["), = `org-hlc-hidden-lines-cookie-right-delimiter' > ;; (with default value ']), = `org-hlc-hidden-lines-cookie-left-signal-char' > ;; (with default value "#") and > ;; `org-hlc-hidden-lines-cookie-right-signal-char' (with default value = ""). >=20 > ;; Thus an exemplary folded headline with 165 hidden lines before the = next > ;; visible headline might look like this when hidden-lines-cookies are = shown: >=20 > ;; ,----------------- > ;; | *** Headline [#165] > ;; `----------------- >=20 > ;;; Code: >=20 > ;;;; Variables >=20 > (defvar org-hlc-hidden-lines-cookies-on-p nil > "If non-nil, hidden-lines cookies are shown, otherwise hidden.") >=20 > (defgroup org-hlc nil > "Enhanced library for outline navigation in source code buffers." > :prefix "org-hlc-" > :group 'org) >=20 > (defcustom org-hlc-hidden-lines-cookie-left-delimiter "[" > "Left delimiter of cookie that shows number of hidden lines." > :group 'org-hlc > :type 'string) >=20 > (defcustom org-hlc-hidden-lines-cookie-right-delimiter "]" > "Left delimiter of cookie that shows number of hidden lines." > :group 'org-hlc > :type 'string) >=20 > (defcustom org-hlc-hidden-lines-cookie-left-signal-char "#" > "Left signal character of cookie that shows number of hidden lines." > :group 'org-hlc > :type 'string) >=20 > (defcustom org-hlc-hidden-lines-cookie-right-signal-char "" > "Right signal character of cookie that shows number of hidden lines." > :group 'org-hlc > :type 'string) >=20 > (defvar org-hlc-hidden-lines-cookie-format-regexp > (concat > "\\( " > (regexp-quote org-hlc-hidden-lines-cookie-left-delimiter) > (regexp-quote org-hlc-hidden-lines-cookie-left-signal-char) > "\\)" > "\\([[:digit:]]+\\)" > "\\(" > (regexp-quote org-hlc-hidden-lines-cookie-right-signal-char) > ;; FIXME robust enough? > (format "\\%s" org-hlc-hidden-lines-cookie-right-delimiter) > "\\)") > "Matches cookies that show number of hidden lines for folded = subtrees.") >=20 > ;;;; Functions >=20 > ;; Calc and show line number of hidden body for all visible headlines > (defun org-hlc-write-hidden-lines-cookies () > "Show line number of hidden lines in folded headline." > (save-excursion > (goto-char (point-min)) > (and (outline-on-heading-p) > (org-hlc-hidden-lines-cookie-status-changed-p) > (org-hlc-set-hidden-lines-cookie)) > (while (not (eobp)) > (outline-next-visible-heading 1) > (and (outline-on-heading-p) > (org-hlc-hidden-lines-cookie-status-changed-p) > (org-hlc-set-hidden-lines-cookie))))) >=20 >=20 > (defun org-hlc-hidden-lines-cookie-status-changed-p () > "Return non-nil if hidden-lines cookie needs modification." > (save-excursion > (save-match-data > (or (not (outline-body-visible-p)) > (re-search-forward > org-hlc-hidden-lines-cookie-format-regexp > (line-end-position) > 'NO-ERROR))))) >=20 > (defun org-hlc-set-hidden-lines-cookie () > "Calculate and set number of hidden lines in folded headline." > (let* ((folded-p (not (outline-body-visible-p))) > (line-num-current-header (line-number-at-pos)) > (line-num-next-visible-header > (save-excursion > (outline-next-visible-heading 1) > (line-number-at-pos))) > (body-lines > (1- (- line-num-next-visible-header = line-num-current-header)))) > (if (re-search-forward > org-hlc-hidden-lines-cookie-format-regexp > (line-end-position) > 'NO-ERROR) > (cond > ((not folded-p) (replace-match "")) > (folded-p (replace-match (format "%s" body-lines) nil nil nil = 2))) > (show-entry) > (save-excursion > (end-of-line) > (insert > (format > " %s%s%s%s%s" > org-hlc-hidden-lines-cookie-left-delimiter > org-hlc-hidden-lines-cookie-left-signal-char > body-lines > org-hlc-hidden-lines-cookie-right-signal-char > org-hlc-hidden-lines-cookie-right-delimiter))) > (hide-entry)))) >=20 > (defun org-hlc-show-hidden-lines-cookies () > "Show hidden-lines cookies for all visible and folded headlines." > (interactive) > (org-hlc-write-hidden-lines-cookies) > (setq org-hlc-hidden-lines-cookies-on-p 1)) >=20 > (defun org-hlc-hide-hidden-lines-cookies () > "Delete all hidden-lines cookies." > (interactive) > (let* ((base-buf (point-marker)) > (indirect-buf-name > (generate-new-buffer-name > (buffer-name (marker-buffer base-buf))))) > (clone-indirect-buffer indirect-buf-name nil 'NORECORD) > (save-excursion > (switch-to-buffer indirect-buf-name) > (show-all) > (let ((indirect-buf (point-marker))) > (org-hlc-write-hidden-lines-cookies) > (switch-to-buffer (marker-buffer base-buf)) > (kill-buffer (marker-buffer indirect-buf)) > (set-marker indirect-buf nil)) > (set-marker base-buf nil))) > (setq org-hlc-hidden-lines-cookies-on-p nil)) >=20 > (defun org-hlc-toggle-hidden-lines-cookies () > "Toggles status of hidden-lines cookies between shown and hidden." > (interactive) > (if org-hlc-hidden-lines-cookies-on-p > (org-hlc-hide-hidden-lines-cookies) > (org-hlc-show-hidden-lines-cookies))) >=20 > (provide 'org-hlc) >=20 > ;; Local variables: > ;; generated-autoload-file: "org-loaddefs.el" > ;; End: >=20 > ;;; org-hlc.el ends here >=20 >=20 >=20 >=20 > --=20 > cheers, > Thorsten >=20 >=20 >=20 --Apple-Mail=_880AA766-37A6-4B70-B31C-BF684045FC43 Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=us-ascii Hi = Thorsten,

On 22 mei 2013, at 22:44, = Thorsten Jolitz <tjolitz@gmail.com> = wrote:


Hi List,

I ported this from outshine.el (i.e. = outline-minor-mode) to Org-mode,
hope it is useful.

What is = it all about? With 'org-hlc' =

,-----------------------------------------------------------------= ---
| Behind every folded headline, a little 'cookie' shows the = number of
| hidden lines till the next visible = headline.
`------------------------------------------------------------= --------

e.g.

,---------------------------------------------= ------------------------
| * my-file.org [#13]
| ** Commentary = [#1]
| *** About my-file
|
|  This file implements = extensions for occur-mode. You can think of a
|  navi-buffer as = a kind of 'remote-control' for an (adecuately)
| =  outline-structured original-buffer.
|
| *** Usage = [#165]
`---------------------------------------------------------------= ------



This = is is definitely a nice feature.  Herbert Sitz has
this = in his vimorganizer implementation for vi,


and we have been jealous of this feature ever = since.


However, I = don't think the implementation is the right
one. =  Modifying the file to display this does not seem = right.
I would say it should use text properties or = maybe
overlays for display, and it should be hooked = somehow into the
folding/unfolding routines to = auto-update.

Cheers!

- = Carsten


I attach the code to = this message, you can find the git-repo = here:

,--------------------------------
| https://github.com/tj64/org-hlc
| git clone
https://github.com/tj64/org-hlc
`------------------------------------------

Please let me = know if there is interest to include this in Org-mode. =

-----------
ORG-HLC.EL
-----------

;;; org-hlc.el = --- hidden-lines-cookies for folded Org-mode headlines

;; = Copyright (C) 2013 Thorsten Jolitz

;; Author: Thorsten Jolitz = <tjolitz at gmail dot com>
;; Keywords: org-mode, outline, = visibility, overlays

;; This file is (NOT YET) part of GNU = Emacs.

;; GNU Emacs 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 3 of = the License, or
;; (at your option) any later version.

;; GNU = Emacs 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.  If not, see <
http://www.gnu.org/licenses/>= .

;;; Commentary:

;; 'hidden-lines-cookies' (hlc) are = small cookies at the end of each folded
;; (and visible) headline in = an Org-mode buffer that show the number of hidden
;; lines before the = next visible headline.

;; hidden-lines-cookies can be handled = with three user commands:
;; `org-hlc-show-hidden-lines-cookies', = `org-hlc-hide-hidden-lines-cookies',
;; and the convenience command = `org-hlc-toggle-hidden-lines-cookies' that
;; toggles between the two = other commands conditional on the last one
;; executed.

;; The = appearance of the cookies can be customized by changing the values = of
;; four customizable variables: = `org-hlc-hidden-lines-cookie-left-delimiter'
;; (with default value = "["), `org-hlc-hidden-lines-cookie-right-delimiter'
;; (with default = value ']), `org-hlc-hidden-lines-cookie-left-signal-char'
;; (with = default value "#") and
;; = `org-hlc-hidden-lines-cookie-right-signal-char' (with default value = "").

;; Thus an exemplary folded headline with 165 hidden lines = before the next
;; visible headline might look like this when = hidden-lines-cookies are shown:

;; ,-----------------
;; | *** = Headline [#165]
;; `-----------------

;;; Code:

;;;; = Variables

(defvar org-hlc-hidden-lines-cookies-on-p nil
=  "If non-nil, hidden-lines cookies are shown, otherwise = hidden.")

(defgroup org-hlc nil
 "Enhanced library for = outline navigation in source code buffers."
 :prefix = "org-hlc-"
 :group 'org)

(defcustom = org-hlc-hidden-lines-cookie-left-delimiter "["
 "Left delimiter = of cookie that shows number of hidden lines."
 :group = 'org-hlc
 :type 'string)

(defcustom = org-hlc-hidden-lines-cookie-right-delimiter "]"
 "Left = delimiter of cookie that shows number of hidden lines."
 :group = 'org-hlc
 :type 'string)

(defcustom = org-hlc-hidden-lines-cookie-left-signal-char "#"
 "Left signal = character of cookie that shows number of hidden lines."
 :group = 'org-hlc
 :type 'string)

(defcustom = org-hlc-hidden-lines-cookie-right-signal-char ""
 "Right signal = character of cookie that shows number of hidden lines."
 :group = 'org-hlc
 :type 'string)

(defvar = org-hlc-hidden-lines-cookie-format-regexp
 (concat
=   "\\( "
  (regexp-quote = org-hlc-hidden-lines-cookie-left-delimiter)
=   (regexp-quote = org-hlc-hidden-lines-cookie-left-signal-char)
  "\\)"
=   "\\([[:digit:]]+\\)"
  "\\("
=   (regexp-quote = org-hlc-hidden-lines-cookie-right-signal-char)
  ;; FIXME = robust enough?
  (format "\\%s" = org-hlc-hidden-lines-cookie-right-delimiter)
  "\\)")
=  "Matches cookies that show number of hidden lines for folded = subtrees.")

;;;; Functions

;; Calc and show line number of = hidden body for all visible headlines
(defun = org-hlc-write-hidden-lines-cookies ()
 "Show line number of = hidden lines in folded headline."
 (save-excursion
=    (goto-char (point-min))
   (and = (outline-on-heading-p)
=         (org-hlc-hidden-lines-cook= ie-status-changed-p)
=         (org-hlc-set-hidden-lines-= cookie))
   (while (not (eobp))
=      (outline-next-visible-heading 1)
=      (and (outline-on-heading-p)
=           (org-hlc-hidde= n-lines-cookie-status-changed-p)
=           (org-hlc-set-h= idden-lines-cookie)))))


(defun = org-hlc-hidden-lines-cookie-status-changed-p ()
 "Return = non-nil if hidden-lines cookie needs modification."
=  (save-excursion
   (save-match-data
=      (or (not (outline-body-visible-p))
=          (re-search-forward =           org-hlc-hidden= -lines-cookie-format-regexp
=           (line-end-posi= tion)
=           'NO-ERROR)))))=

(defun org-hlc-set-hidden-lines-cookie ()
 "Calculate = and set number of hidden lines in folded headline."
 (let* = ((folded-p (not (outline-body-visible-p)))
=         (line-num-current-header = (line-number-at-pos))
=         (line-num-next-visible-hea= der
=          (save-excursion
=            (outline= -next-visible-heading 1)
=            (line-nu= mber-at-pos)))
=         (body-lines
=          (1- (- = line-num-next-visible-header line-num-current-header))))
=    (if (re-search-forward
=         org-hlc-hidden-lines-cooki= e-format-regexp
=         (line-end-position)
=         'NO-ERROR)
=        (cond
=         ((not folded-p) = (replace-match ""))
=         (folded-p (replace-match = (format "%s" body-lines) nil nil nil 2)))
=      (show-entry)
=      (save-excursion
=        (end-of-line)
=        (insert
=         (format
=          " %s%s%s%s%s"
=          org-hlc-hidden-lines= -cookie-left-delimiter
=          org-hlc-hidden-lines= -cookie-left-signal-char
=          body-lines
=          org-hlc-hidden-lines= -cookie-right-signal-char
=          org-hlc-hidden-lines= -cookie-right-delimiter)))
=      (hide-entry))))

(defun = org-hlc-show-hidden-lines-cookies ()
 "Show hidden-lines = cookies for all visible and folded headlines."
=  (interactive)
 (org-hlc-write-hidden-lines-cookies)
=  (setq org-hlc-hidden-lines-cookies-on-p 1))

(defun = org-hlc-hide-hidden-lines-cookies ()
 "Delete all hidden-lines = cookies."
 (interactive)
 (let* ((base-buf = (point-marker))
=         (indirect-buf-name
=          (generate-new-buffer= -name
=           (buffer-name = (marker-buffer base-buf)))))
=    (clone-indirect-buffer indirect-buf-name nil = 'NORECORD)
   (save-excursion
=      (switch-to-buffer indirect-buf-name)
=      (show-all)
=      (let ((indirect-buf (point-marker)))
=        (org-hlc-write-hidden-lines-cook= ies)
       (switch-to-buffer = (marker-buffer base-buf))
=        (kill-buffer (marker-buffer = indirect-buf))
       (set-marker = indirect-buf nil))
     (set-marker = base-buf nil)))
 (setq org-hlc-hidden-lines-cookies-on-p = nil))

(defun org-hlc-toggle-hidden-lines-cookies ()
=  "Toggles status of hidden-lines cookies between shown and = hidden."
 (interactive)
 (if = org-hlc-hidden-lines-cookies-on-p
=      (org-hlc-hide-hidden-lines-cookies)
=    (org-hlc-show-hidden-lines-cookies)))

(provide = 'org-hlc)

;; Local variables:
;; generated-autoload-file: = "org-loaddefs.el"
;; End:

;;; org-hlc.el ends = here




-- =
cheers,
Thorsten




= --Apple-Mail=_880AA766-37A6-4B70-B31C-BF684045FC43--