From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Michael Heerdegen Newsgroups: gmane.emacs.help Subject: Re: code folding with ? Date: Mon, 09 Apr 2012 03:00:59 +0200 Message-ID: <87lim51zxw.fsf@web.de> References: NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: dough.gmane.org 1333933264 17160 80.91.229.3 (9 Apr 2012 01:01:04 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Mon, 9 Apr 2012 01:01:04 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Mon Apr 09 03:01:03 2012 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1SH2yd-0000UA-8M for geh-help-gnu-emacs@m.gmane.org; Mon, 09 Apr 2012 03:01:03 +0200 Original-Received: from localhost ([::1]:52628 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SH2yc-0003gY-EB for geh-help-gnu-emacs@m.gmane.org; Sun, 08 Apr 2012 21:01:02 -0400 Original-Received: from eggs.gnu.org ([208.118.235.92]:51968) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SH2yX-0003gS-HW for help-gnu-emacs@gnu.org; Sun, 08 Apr 2012 21:00:58 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1SH2yV-0001nJ-CS for help-gnu-emacs@gnu.org; Sun, 08 Apr 2012 21:00:57 -0400 Original-Received: from fmmailgate06.web.de ([217.72.192.247]:53418) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SH2yV-0001nA-2N for help-gnu-emacs@gnu.org; Sun, 08 Apr 2012 21:00:55 -0400 Original-Received: from moweb002.kundenserver.de (moweb002.kundenserver.de [172.19.20.108]) by fmmailgate06.web.de (Postfix) with ESMTP id 238DA117F820 for ; Mon, 9 Apr 2012 02:59:09 +0200 (CEST) Original-Received: from snow.dragon ([82.113.121.227]) by smtp.web.de (mrweb001) with ESMTPA (Nemesis) id 0LeLmv-1RyiMo207R-00q9zL; Mon, 09 Apr 2012 02:59:08 +0200 In-Reply-To: (Yagnesh Raghava Yakkala's message of "Sat, 07 Apr 2012 17:07:07 +0900") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.0.95 (gnu/linux) X-Provags-ID: V02:K0:KPOqixaerQ5F+pjzJ4B/tA2FHMyfvjLqGY9AP7ygG4D a0RyXp4PHYLRIV4tCF0Huj5NBDAml5ovYcXpvbR8s0KjF72b2M RYdvx424Ky9OtoFgmbaHvkZOc1CfIqwC7wdo0+XsY89qWJI6fB pHm9RI7+byx84JEajGyo2EourQ8CDf2ryDlLeVSuxBPzW/fV8x 8Yc4w673kaIG3OgjWPzWiu8bec13JYscBEiq5F0Ykw= X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.4-2.6 X-Received-From: 217.72.192.247 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:84381 Archived-At: Hello Yagnesh, if you decide to use "hideshow", then you can use what follows. I like hideshow very much for elisp, although the standard keys for `hs-minor-mode' are horrible. > To begin with elisp, can anybody tell me how to make backtab to show > the outline of the buffer at least for two levels. I mean first press > would show me buffer folded upto top level comments, defuns, > defcustoms and defvars and the second press would show me entire > buffer. Use hideshow-org, which implements exactly that: $ git clone git://github.com/secelis/hideshow-org.git It also lets you do hide/unhide comfortably with TAB, like in org. Note that you can also always (un)hide with `hs-mouse-toggle-hiding' (bound to ) when you use hideshow. Some more stuff to try: 1. WRT choosing default hiding level, you can use something like that: (eval-after-load "hideshow" '(make-variable-buffer-local 'hs-hide-all-non-comment-function)) (add-hook 'hs-minor-mode-hook (lambda () (easy-menu-add-item nil '("Hide/Show") '("\"Hide All\" method" ["Default" (setq hs-hide-all-non-comment-function nil) :style toggle :selected (null hs-hide-all-non-comment-function)] ["Level 1" (setq hs-hide-all-non-comment-function 'my-hs-hide-level-1) :style toggle :selected (eq hs-hide-all-non-comment-function 'my-hs-hide-level-1)] ["Level 2" (setq hs-hide-all-non-comment-function 'my-hs-hide-level-2) :style toggle :selected (eq hs-hide-all-non-comment-function 'my-hs-hide-level-2)] ["Level 3" (setq hs-hide-all-non-comment-function 'my-hs-hide-level-3) :style toggle :selected (eq hs-hide-all-non-comment-function 'my-hs-hide-level-3)])))) (defun my-hs-hide-level-1 () (hs-hide-level 1) (forward-sexp 1)) (defun my-hs-hide-level-2 () (hs-hide-level 2) (forward-sexp 1)) (defun my-hs-hide-level-3 () (hs-hide-level 3) (forward-sexp 1)) It adds an entry to the "Hide/Show" minor mode menu that lets you choose the default hiding level if you do "Hide All" (C-c @ C-M-h, or when using hideshow-org). 2. You can control how the hide ellipsis should look like. I myself use this configuration, which adds a count of the number of lines hidden, a tooltip, and uses a different color: (defun my-hs-ellipsis (ov) (when (eq 'code (overlay-get ov 'hs)) (overlay-put ov 'display (propertize (format " ... / %d" (count-lines (overlay-start ov) (overlay-end ov))) 'help-echo (format "Toggle visibility: %s" (where-is-internal 'hs-mouse-toggle-hiding nil 'FIRST-ONLY)) 'face 'font-lock-preprocessor-face)))) (eval-after-load "hideshow" '(setq hs-set-up-overlay 'my-hs-ellipsis)) 3. This defines to show a nice fisheye like view of the current top level form, adjusted to the current position of point (= the cursor). (defun hs-fisheye-1 (position level minp maxp) (goto-char minp) (while (progn (forward-comment (buffer-size)) (and (< (point) maxp) (re-search-forward hs-block-start-regexp maxp t))) (when (save-match-data (not (nth 8 (syntax-ppss)))) ; not inside comments or strings (goto-char (match-beginning hs-block-start-mdata-select)) (let ((end-of-sexp (save-excursion (forward-comment (buffer-size)) (when (< (point) maxp) (funcall hs-forward-sexp-func) (1- (point)))))) (if (and (<= (point) position) end-of-sexp (<= position end-of-sexp)) (hs-fisheye-1 position level (1+ (point)) end-of-sexp) (case level ((0) (hs-hide-block)) (t (hs-hide-level level)))) (goto-char end-of-sexp))))) (defun hs-fisheye (level) "Hide current top-level block recursivly, revealing context of point. The prefix arg determines the hiding level for each block hidden. With prefix arg < 0, show the whole current top level sexp." (interactive "p") (if (< level 0) (save-excursion (goto-char (syntax-ppss-toplevel-pos (syntax-ppss))) (hs-show-block)) (let* ((minp (or (syntax-ppss-toplevel-pos (syntax-ppss)) (error "%s" "Not inside a toplevel form"))) (maxp (save-excursion (goto-char minp) (funcall hs-forward-sexp-func) (point)))) (unless hs-allow-nesting (hs-discard-overlays minp maxp)) (save-excursion (hs-fisheye-1 (point) level minp maxp))))) (add-hook 'hs-minor-mode-hook #'(lambda () (define-key hs-minor-mode-map [(control tab)] 'hs-fisheye))) 4. If you want to have some more colorful views, also have a look at rainbow-delimiters.el: EmacsWiki: http://www.emacswiki.org/emacs/RainbowDelimiters Github: http://github.com/jlr/rainbow-delimiters Michael