emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* [NEW FEATURE] org-hlc.el - hidden-lines-cookies (hlc) for Org-mode
@ 2013-05-22 20:44 Thorsten Jolitz
  2013-05-23  7:19 ` Rainer M. Krug
  2013-05-23  8:08 ` Carsten Dominik
  0 siblings, 2 replies; 9+ messages in thread
From: Thorsten Jolitz @ 2013-05-22 20:44 UTC (permalink / raw)
  To: emacs-orgmode


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]
`---------------------------------------------------------------------

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-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)))))


(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)))))

(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))))

(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-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))

(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

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [NEW FEATURE] org-hlc.el - hidden-lines-cookies (hlc) for Org-mode
  2013-05-22 20:44 [NEW FEATURE] org-hlc.el - hidden-lines-cookies (hlc) for Org-mode Thorsten Jolitz
@ 2013-05-23  7:19 ` Rainer M. Krug
  2013-05-23  8:08 ` Carsten Dominik
  1 sibling, 0 replies; 9+ messages in thread
From: Rainer M. Krug @ 2013-05-23  7:19 UTC (permalink / raw)
  To: emacs-orgmode

[-- Attachment #1: Type: text/plain, Size: 8791 bytes --]



Thorsten Jolitz <tjolitz@gmail.com> writes:

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

That looks very nice indeed and a very nice addition to the ellipsis
shown - I would definitely support that it is included in org and I
would use it.

Cheers,

Rainer


>
> 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]
> `---------------------------------------------------------------------
>
> 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-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)))))
>
>
> (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)))))
>
> (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))))
>
> (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-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))
>
> (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

-- 
Rainer M. Krug

[-- Attachment #2: Type: application/pgp-signature, Size: 489 bytes --]

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [NEW FEATURE] org-hlc.el - hidden-lines-cookies (hlc) for Org-mode
  2013-05-22 20:44 [NEW FEATURE] org-hlc.el - hidden-lines-cookies (hlc) for Org-mode Thorsten Jolitz
  2013-05-23  7:19 ` Rainer M. Krug
@ 2013-05-23  8:08 ` Carsten Dominik
  2013-05-23 10:30   ` Thorsten Jolitz
  2013-05-24 13:52   ` Thorsten Jolitz
  1 sibling, 2 replies; 9+ messages in thread
From: Carsten Dominik @ 2013-05-23  8:08 UTC (permalink / raw)
  To: Thorsten Jolitz; +Cc: emacs-orgmode

[-- Attachment #1: Type: text/plain, Size: 9135 bytes --]

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,

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

> 
> 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-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)))))
> 
> 
> (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)))))
> 
> (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))))
> 
> (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-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))
> 
> (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
> 
> 
> 


[-- Attachment #2: Type: text/html, Size: 12411 bytes --]

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [NEW FEATURE] org-hlc.el - hidden-lines-cookies (hlc) for Org-mode
  2013-05-23  8:08 ` Carsten Dominik
@ 2013-05-23 10:30   ` Thorsten Jolitz
  2013-05-24  5:34     ` Nick Dokos
  2013-05-24 13:52   ` Thorsten Jolitz
  1 sibling, 1 reply; 9+ messages in thread
From: Thorsten Jolitz @ 2013-05-23 10:30 UTC (permalink / raw)
  To: emacs-orgmode

Carsten Dominik <carsten.dominik@gmail.com> writes:

Hi Carsten,

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

>     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.
>     `--------------------------------------------------------------------

> This is is definitely a nice feature. [...] 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

I have not done anything with text properties or overlays before, so I
have to take it look at the docs, but I guess this would only affect
small parts of the implementation (do something with properties/overlays
instead of inserting/deleting text). 

> , and it should be hooked somehow into the folding/unfolding routines
> to auto-update.

Thats what I thought too, but I ran into a problem I could not solve so
far, so this user-command based implementation (show the cookies on
demand) is kind of the second-best solution (better then nothing). 

Here is a thread related to the problem mentioned, unfortunately with no
posts except my own so far:

,-----------------------------------------------------------------------
| http://lists.gnu.org/archive/html/help-gnu-emacs/2013-05/msg00511.html
`-----------------------------------------------------------------------

-- 
cheers,
Thorsten

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [NEW FEATURE] org-hlc.el - hidden-lines-cookies (hlc) for Org-mode
  2013-05-23 10:30   ` Thorsten Jolitz
@ 2013-05-24  5:34     ` Nick Dokos
  2013-05-24 13:56       ` Thorsten Jolitz
  0 siblings, 1 reply; 9+ messages in thread
From: Nick Dokos @ 2013-05-24  5:34 UTC (permalink / raw)
  To: emacs-orgmode

Thorsten Jolitz <tjolitz@gmail.com> writes:

>> , and it should be hooked somehow into the folding/unfolding routines
>> to auto-update.
>
> Thats what I thought too, but I ran into a problem I could not solve so
> far, so this user-command based implementation (show the cookies on
> demand) is kind of the second-best solution (better then nothing). 
>
> Here is a thread related to the problem mentioned, unfortunately with no
> posts except my own so far:
>
> ,-----------------------------------------------------------------------
> | http://lists.gnu.org/archive/html/help-gnu-emacs/2013-05/msg00511.html
> `-----------------------------------------------------------------------

You can try increasing max-specpdl-size: read the doc for it. If you are
asking for a bounded amount of resources but that amount is bigger than
what emacs is willing to give you, then increasing the size should work.
OTOH, if you are asking for unlimited resources (e.g. you have an
infinite recursion somewhere), then increasing the limit will only allow
you to go a little further before blowing up again.

So try making it 10 or even 100 times bigger and see what you get (and
try it on a throwaway emacs instance, not the working instance). If it
still blows up, you'll have to look at your code carefully: chances are
there is a programming error.
-- 
Nick

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [NEW FEATURE] org-hlc.el - hidden-lines-cookies (hlc) for Org-mode
  2013-05-23  8:08 ` Carsten Dominik
  2013-05-23 10:30   ` Thorsten Jolitz
@ 2013-05-24 13:52   ` Thorsten Jolitz
  2013-05-24 15:49     ` François Pinard
  1 sibling, 1 reply; 9+ messages in thread
From: Thorsten Jolitz @ 2013-05-24 13:52 UTC (permalink / raw)
  To: emacs-orgmode; +Cc: François Pinard

Carsten Dominik <carsten.dominik@gmail.com> writes:

Hi Carsten, Hi List,

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

> However, I don't think the implementation is the right
> one.

it happened again - François Pinard already had a fully fledged
implementation of my "new" org-mode feature: 'org-weights.el'

,--------------------------------------
| https://github.com/pinard/org-weights
`--------------------------------------

But this time I was saved from implementing a completely independent
version of the same idea (see 'outorg.el' vs 'poporg.el') but rather
forked his library on github and merged my ideas/code with his:

,------------------------------------
| https://github.com/tj64/org-weights
`------------------------------------

Although the details are still a bit buggy, the general mechanism
already works.

1. 'org-weights' works with Org-mode as well as with outshine buffers
now (including Emacs Lisp files with conventional headers (^;;;+ ). It
might even work with plain outline buffers.

2. 'org-weights' now offers to display the headline-weights (number of
subtrees and number of paragraphs) or hidden-lines-cookies (the number
of (hidden) lines till the next visible headline.

Here are a few examples (don't bother about the numbers, they are made
up, since I cannot copy overlays):

1. Org-mode/subtree-weights:

,-----------------------------------------------
| * Header 1                       *    2 + 1...
| ** Header 2a                     **   1
|
| text text text text text
| text text text text text
|
| ** Header 2b                     **   1
`-----------------------------------------------

2. Outshine Emacs Lisp/subtree-weights:

,--------------------------------------------------
| ;; * Header 1                       *    2 + 1...
| ;; ** Header 2a                     **   1
|
| text text text text text
| text text text text text
|
| ;; ** Header 2b                     **   1
|
`--------------------------------------------------

3. Conventional Emacs-Lisp/hidden-lines-cookies

,--------------------------------
| ;;; Header 1   [#1]
| ;;;; Header 2a  [#4]
|
| text text text text text
| text text text text text
|
| ;;;; Header 2b [#2]
|
`--------------------------------

4. Outshine PicoLisp/hidden-lines-cookies

,--------------------------------
| ## * Header 1   [#1]
| ## ** Header 2a  [#4]
|
| text text text text text
| text text text text text
|
| ## ** Header 2b [#2]
|
`--------------------------------

'org-weights' is implemented with overlays, so the files are not
touched. Command 'org-weights-mode' toggles activation, and
'org-weights-or-cookies' switches between subtree-weights and
hidden-lines-cookies.

Actually the hidden-lines-cookies are not really about hidden-lines
anymore in this implementation, because I adapted to the semantics of
'org-weights' that shows the overlay-info for *all* headlines except the
one where point is on.

Besides the still buggy details for outshine buffers (the calculated
numbers are not always quite right), one problem I hit is that a
visibility change does not uptdate all cookies/weights at once, they are
only updated headline per headline when point is moved up and down.

Is that for performance reasons?

--
cheers,
Thorsten

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [NEW FEATURE] org-hlc.el - hidden-lines-cookies (hlc) for Org-mode
  2013-05-24  5:34     ` Nick Dokos
@ 2013-05-24 13:56       ` Thorsten Jolitz
  0 siblings, 0 replies; 9+ messages in thread
From: Thorsten Jolitz @ 2013-05-24 13:56 UTC (permalink / raw)
  To: emacs-orgmode

Nick Dokos <ndokos@gmail.com> writes:

> Thorsten Jolitz <tjolitz@gmail.com> writes:
>
>>> , and it should be hooked somehow into the folding/unfolding routines
>>> to auto-update.
>>
>> Thats what I thought too, but I ran into a problem I could not solve so
>> far, so this user-command based implementation (show the cookies on
>> demand) is kind of the second-best solution (better then nothing). 
>>
>> Here is a thread related to the problem mentioned, unfortunately with no
>> posts except my own so far:
>>
>> ,-----------------------------------------------------------------------
>> | http://lists.gnu.org/archive/html/help-gnu-emacs/2013-05/msg00511.html
>> `-----------------------------------------------------------------------
>
> You can try increasing max-specpdl-size: read the doc for it. If you are
> asking for a bounded amount of resources but that amount is bigger than
> what emacs is willing to give you, then increasing the size should work.
> OTOH, if you are asking for unlimited resources (e.g. you have an
> infinite recursion somewhere), then increasing the limit will only allow
> you to go a little further before blowing up again.
>
> So try making it 10 or even 100 times bigger and see what you get (and
> try it on a throwaway emacs instance, not the working instance). If it
> still blows up, you'll have to look at your code carefully: chances are
> there is a programming error.

I read about that, but I did not simply want to increase the limit
because looking at my code I thought it should not use so much bindings. 

However, the problem is more or less obsolete now since I switched to a
completely different implementation using overlays - see my post with
regards to 'org-weights.el'.

Thanks for the info anyway. 

-- 
cheers,
Thorsten

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [NEW FEATURE] org-hlc.el - hidden-lines-cookies (hlc) for Org-mode
  2013-05-24 13:52   ` Thorsten Jolitz
@ 2013-05-24 15:49     ` François Pinard
  2013-05-24 17:45       ` Thorsten Jolitz
  0 siblings, 1 reply; 9+ messages in thread
From: François Pinard @ 2013-05-24 15:49 UTC (permalink / raw)
  To: emacs-orgmode

Thorsten Jolitz <tjolitz@gmail.com> writes:

> it happened again [...]- François Pinard already had a fully fledged
> implementation of my "new" org-mode feature: 'org-weights.el'

You're quite generous when you say "full fledged" :-).  There are many
details in which I find org-weights.el unsatisfactory, but as it is
sufficient as it stands for my day-to-day usage, I'm not overly pushing
on it (the pun is purely accidental).

> | * Header 1                       *    2 + 1...

> | ## * Header 1   [#1]

I find the "*    2 + 1" far too verbose, in that it uses too much horizontal
space, I much prefer the compact aspect of "[#1]".  What would be ideal,
but I do not know if it can be organized, would keep the weights or
hidden-lines information always glued to the ellipsis, and not hiding
any underlying text as org-weights currently does.  On the other hand,
there are some virtue to the vertical alignment of weight information.
Sigh!  Nothing is perfect...

> [...] shows the overlay-info for *all* headlines except the one where
> point is on.

That exception is a sad and questionable workaround, for being able to
edit the current line.  When, in normal and standard Org mode, I edit a
line which has an ellipsis at the end, I may edit the line like any
other one without seeing undesired effects.  org-weights should be
equally capable, and there should be no reason (ideally) to hide the
information for the line where the point is, merely for editing to work.

> one problem I hit is that a visibility change does not uptdate all
> cookies/weights at once, they are only updated headline per headline
> when point is moved up and down.  Is that for performance reasons?

See the Caveats section at the end of org-weights documentation.
Normally, the information to be updated may be minimized to the header
above the line holding point, and then, recursively up.  But there is a
bug in this optimization when a header is demoted (as explained in
Caveats).  Another performance-related detail is the quadratic behaviour
which may be seen in big, deeply nested Org files: it could be avoided
by cleverly saving (in a hidden way) information on computations already
done, and reusing it instead of recomputing it many times.  But as usual
with most cached optimization, it is difficult to get fully right.

François

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [NEW FEATURE] org-hlc.el - hidden-lines-cookies (hlc) for Org-mode
  2013-05-24 15:49     ` François Pinard
@ 2013-05-24 17:45       ` Thorsten Jolitz
  0 siblings, 0 replies; 9+ messages in thread
From: Thorsten Jolitz @ 2013-05-24 17:45 UTC (permalink / raw)
  To: emacs-orgmode

François Pinard <pinard@iro.umontreal.ca> writes:

Hi Francios, 

> You're quite generous when you say "full fledged" :-).  There are many
> details in which I find org-weights.el unsatisfactory, but as it is
> sufficient as it stands for my day-to-day usage, I'm not overly pushing
> on it (the pun is purely accidental).
>
>> | * Header 1                       *    2 + 1...
>
>> | ## * Header 1   [#1]
>
> I find the "*    2 + 1" far too verbose, in that it uses too much horizontal
> space, I much prefer the compact aspect of "[#1]".  

The weights are a bit heavy, and I had to move them to column 65 to make
them fit in a vertically splitted screen. But they carry more
information of course, the question is if one can process this
information quickly enough, or if one single number is not enough to
give an impression of the subtrees 'weight'. Or maybe 

,----------------------
| * Header 1   [2/1]...
`----------------------

is easier on the eyes than 

,-----------------------------------------------
| * Header 1                       *    2 + 1...
`-----------------------------------------------

> What would be ideal, but I do not know if it can be organized, would
> keep the weights or hidden-lines information always glued to the
> ellipsis, and not hiding any underlying text as org-weights currently
> does. On the other hand, there are some virtue to the vertical
> alignment of weight information. Sigh! Nothing is perfect...

It would be easy to make the position of the weight/cookie a user option
- either direcctly behind the headline text, or aligned at a certain
column. 

>> [...] shows the overlay-info for *all* headlines except the one where
>> point is on.
>
> That exception is a sad and questionable workaround, for being able to
> edit the current line.  When, in normal and standard Org mode, I edit a
> line which has an ellipsis at the end, I may edit the line like any
> other one without seeing undesired effects.  org-weights should be
> equally capable, and there should be no reason (ideally) to hide the
> information for the line where the point is, merely for editing to work.

I would still like to have my original idea (which was actually a user
request for outshine.el by Jonas Bernoulli): show the number of hidden
lines only when the headline is folded, and update with every visibility
change.

>> one problem I hit is that a visibility change does not uptdate all
>> cookies/weights at once, they are only updated headline per headline
>> when point is moved up and down.  Is that for performance reasons?
>
> See the Caveats section at the end of org-weights documentation.
> Normally, the information to be updated may be minimized to the header
> above the line holding point, and then, recursively up.  But there is a
> bug in this optimization when a header is demoted (as explained in
> Caveats).  Another performance-related detail is the quadratic behaviour
> which may be seen in big, deeply nested Org files: it could be avoided
> by cleverly saving (in a hidden way) information on computations already
> done, and reusing it instead of recomputing it many times.  But as usual
> with most cached optimization, it is difficult to get fully right.

This task seems to bring Emacs to its limits, at least in 5000+ lines
outshine buffers (e.g. my init.el). 

So maybe its not that suited for a visibility-change hook, but rather
for occasional activation by an explicit user command?

-- 
cheers,
Thorsten

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2013-05-24 17:46 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-05-22 20:44 [NEW FEATURE] org-hlc.el - hidden-lines-cookies (hlc) for Org-mode Thorsten Jolitz
2013-05-23  7:19 ` Rainer M. Krug
2013-05-23  8:08 ` Carsten Dominik
2013-05-23 10:30   ` Thorsten Jolitz
2013-05-24  5:34     ` Nick Dokos
2013-05-24 13:56       ` Thorsten Jolitz
2013-05-24 13:52   ` Thorsten Jolitz
2013-05-24 15:49     ` François Pinard
2013-05-24 17:45       ` Thorsten Jolitz

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).