emacs-devel
[Top][All Lists]
Advanced

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

tab binding for hs-minor mode


From: A Soare
Subject: tab binding for hs-minor mode
Date: Mon, 18 Apr 2011 11:28:33 +0000 (UTC)
User-agent: Loom/3.14 (http://gmane.org/)

;; called once on a line that contains a hidden block, shows the
;; block; otherwise calls the default action of TAB; called twice on a
;; line that does not contain a hidden block, hide the block from the
;; current position of the cursor
(defun tab-hs-hide ( &optional arg )
  (interactive "P")
  (let ((sl (save-excursion (move-beginning-of-line nil) (point) ) )
        (el (save-excursion (move-end-of-line nil) (point) ) )
        obj)
    (catch 'stop
      (dotimes (i (- el sl))
        (mapc
         (lambda (overlay)
           (when (eq 'hs (overlay-get overlay 'invisible))
             (setq obj t)))
         (overlays-at (+ i sl)))
        (and obj (throw 'stop 'stop) ) ) )
    (cond ((and (null obj)
                (eq last-command this-command) )
           (hs-hide-block) )
          (obj
           (progn
             (move-beginning-of-line nil)
             (hs-show-block) ) )
          (t
           (save-excursion
             (funcall (lookup-key (current-global-map) (kbd "^I") ) arg ) ) ) ) 
) )

(define-key hs-minor-mode-map [tab] 'tab-hs-hide )




reply via email to

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