[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Orgmode] Cycling visibility of blocks

From: Carsten Dominik
Subject: Re: [Orgmode] Cycling visibility of blocks
Date: Tue, 26 May 2009 19:26:27 +0200

On May 25, 2009, at 10:40 PM, Sebastian Rose wrote:

"Eric Schulte" <address@hidden> writes:
I've applied a slightly changed version of your regexp, and this is now
working for all block types (the resulting file is attached).  Where
could this file be saved? The contrib directory seems like overkill for such a small piece of functionality maybe I should post it up somewhere
on worg?

Hmm - why don't you juste start a `Snippets' section? I don't mind Worg
to grow.
Didn't you see http://wiki.github.com/SebastianRose/org-search.php? Not
doing very much yet, but it's under way :)

Another good place would be inside Org-mode's core IMHO.

I would be happy to integrate this into the core.  Eric, you agree?

- Carsten


;;; org-block-hide.el --- hide blocks in org-mode files

(defvar org-block-hide-src-block-regexp
"#\\+begin_\\([^ ]+\\) ?\\([ \t]+\\([^\n]+\\)\\)?\n\\([^\000]+?\\)# \\+end_\\1")

(defun org-block-hide-src-block-cycle-maybe ()
 (let ((case-fold-search t))
   (if (save-excursion
         (beginning-of-line 1)
         (looking-at org-block-hide-src-block-regexp))
       (progn (call-interactively 'org-block-hide-src-block-cycle)
              t) ;; to signal that we took action
     nil))) ;; to signal that we did not

(defun org-block-hide-src-block-cycle ()
 "Cycle the visibility of the current block"
 ;; should really do this once in an (org-mode hook)
 (add-to-invisibility-spec '(org-block-hide . t))
 (message "trying out source block")
   (if (re-search-forward org-block-hide-src-block-regexp nil t)
       (let ((start (- (match-beginning 4) 1)) ;; beginning of body
             (end (match-end 0))) ;; end of entire body
         (if (memq t (mapcar (lambda (overlay)
(eq (overlay-get overlay 'invisible) 'org-block-hide))
                             (overlays-at start)))
             (remove-overlays start end 'invisible 'org-block-hide)
(overlay-put (make-overlay start end) 'invisible 'org- block-hide)))
     (error "not looking at a source block"))))

;; org-tab-after-check-for-cycling-hook
(add-hook 'org-tab-first-hook 'org-block-hide-src-block-cycle-maybe)

;;; org-block-hide.el ends here

Sebastian Rose, EMMA STIL - mediendesign, Niemeyerstr.6, 30449 Hannover
Tel.:  +49 (0)511 - 36 58 472
Fax:   +49 (0)1805 - 233633 - 11044
mobil: +49 (0)173 - 83 93 417
Email: address@hidden, address@hidden
Http:  www.emma-stil.de

reply via email to

[Prev in Thread] Current Thread [Next in Thread]