all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* code folding with <backtab> ?
@ 2012-04-07  8:07 Yagnesh Raghava Yakkala
  2012-04-07  9:18 ` Bastien
       [not found] ` <mailman.675.1333790271.20052.help-gnu-emacs@gnu.org>
  0 siblings, 2 replies; 12+ messages in thread
From: Yagnesh Raghava Yakkala @ 2012-04-07  8:07 UTC (permalink / raw
  To: help-gnu-emacs


Hello all,

Just like org does, folding (or cycling) with its outlines by pressing
backtab(shift+<tab>), I would want every programming language buffer to show
such a /outline/ of the program(buffer) to get a overview of the program I am
working on. I know this depends on the major mode of the current buffer and
combination of suitable minor modes namely outline-minor-mode or
hs-minor-mode. (or may be with CEDET with its semantic parsing)


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.


I hope my question is clear.

Thanks. 
--
YYR




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

* Re: code folding with <backtab> ?
  2012-04-07  8:07 Yagnesh Raghava Yakkala
@ 2012-04-07  9:18 ` Bastien
  2012-04-08  9:37   ` Yagnesh Raghava Yakkala
       [not found] ` <mailman.675.1333790271.20052.help-gnu-emacs@gnu.org>
  1 sibling, 1 reply; 12+ messages in thread
From: Bastien @ 2012-04-07  9:18 UTC (permalink / raw
  To: Yagnesh Raghava Yakkala; +Cc: help-gnu-emacs

Yagnesh Raghava Yakkala <yagnesh@live.com> writes:

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

Add a hook to use `orgstruct-mode' in emacs-lisp buffers:

  (add-hook 'emacs-lisp-mode-hook 'orgstruct-mode)

Define a new `org-cycle-global' command:

  (defun org-cycle-global () (interactive) (org-cycle t))

Set this keybinding:

  (global-set-key (kbd "<backtab>") 'org-cycle-global)

HTH,

-- 
 Bastien



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

* Re: code folding with <backtab> ?
  2012-04-07  9:18 ` Bastien
@ 2012-04-08  9:37   ` Yagnesh Raghava Yakkala
  2012-04-09 10:07     ` Bastien
  2012-04-09 10:54     ` Andreas Röhler
  0 siblings, 2 replies; 12+ messages in thread
From: Yagnesh Raghava Yakkala @ 2012-04-08  9:37 UTC (permalink / raw
  To: help-gnu-emacs


Hello Bastien,

Bastien <bzg@altern.org> writes:

> Yagnesh Raghava Yakkala <yagnesh@live.com> writes:
>
>> 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.
>
> Add a hook to use `orgstruct-mode' in emacs-lisp buffers:
>
>   (add-hook 'emacs-lisp-mode-hook 'orgstruct-mode)
>
> Define a new `org-cycle-global' command:
>
>   (defun org-cycle-global () (interactive) (org-cycle t))
>
> Set this keybinding:
>
>   (global-set-key (kbd "<backtab>") 'org-cycle-global)

Wow this is great, working nice too (except when point is at the end of
buffer). I didn't think, Org itself can be used here. I wonder why its not
working with other programming modes, say perl and python.


Thanks.

-- 
YYR




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

* Re: code folding with <backtab> ?
       [not found] ` <mailman.675.1333790271.20052.help-gnu-emacs@gnu.org>
@ 2012-04-08 14:52   ` Uday Reddy
  2012-04-09 10:08     ` Bastien
  0 siblings, 1 reply; 12+ messages in thread
From: Uday Reddy @ 2012-04-08 14:52 UTC (permalink / raw
  To: Bastien; +Cc: help-gnu-emacs

On 4/7/2012 10:18 AM, Bastien wrote:

> Set this keybinding:
>
>    (global-set-key (kbd "<backtab>") 'org-cycle-global)

That sounds very nice, Bastien.  But how does this work?  I thought 
orgstruct-mode needed *, ** etc. to identify the outlines?

Cheers,
Uday





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

* Re: code folding with <backtab> ?
       [not found] <mailman.674.1333786057.20052.help-gnu-emacs@gnu.org>
@ 2012-04-09  1:00 ` Michael Heerdegen
  2012-04-09 12:05   ` yagnesh raghava
  0 siblings, 1 reply; 12+ messages in thread
From: Michael Heerdegen @ 2012-04-09  1:00 UTC (permalink / raw
  To: help-gnu-emacs

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 <S-mouse-2>) 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 <backtab>
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 <C-tab> 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



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

* Re: code folding with <backtab> ?
  2012-04-08  9:37   ` Yagnesh Raghava Yakkala
@ 2012-04-09 10:07     ` Bastien
  2012-04-09 10:54     ` Andreas Röhler
  1 sibling, 0 replies; 12+ messages in thread
From: Bastien @ 2012-04-09 10:07 UTC (permalink / raw
  To: Yagnesh Raghava Yakkala; +Cc: help-gnu-emacs

Hi Yagnesh,

Yagnesh Raghava Yakkala <yagnesh@live.com> writes:

> Wow this is great, working nice too (except when point is at the end of
> buffer). I didn't think, Org itself can be used here. I wonder why its not
> working with other programming modes, say perl and python.

This is because lisp-mode.el sets the value for ̀outline-regexp':

  (setq outline-regexp ";;;\\(;* [^ \t\n]\\|###autoload\\)\\|(")

I don't know about other modes.  Perhaps you can try to patch Emacs
and set a relevant value for `outline-regexp' (among other changes,
see lisp-mode.el for details.)

HTH,

-- 
 Bastien



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

* Re: code folding with <backtab> ?
  2012-04-08 14:52   ` Uday Reddy
@ 2012-04-09 10:08     ` Bastien
  0 siblings, 0 replies; 12+ messages in thread
From: Bastien @ 2012-04-09 10:08 UTC (permalink / raw
  To: Uday Reddy; +Cc: help-gnu-emacs

Uday Reddy <usr.vm.rocks@gmail.com> writes:

> On 4/7/2012 10:18 AM, Bastien wrote:
>
>> Set this keybinding:
>>
>>    (global-set-key (kbd "<backtab>") 'org-cycle-global)
>
> That sounds very nice, Bastien.  But how does this work?  I thought
> orgstruct-mode needed *, ** etc. to identify the outlines?

For some basic cycling commands, `orgstruct-mode' relies directly on
`outline-regexp' which is defined in outline.el and can be set to a
local value by other major modes (such as emacs-lisp-mode.)

HTH,

-- 
 Bastien



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

* Re: code folding with <backtab> ?
  2012-04-08  9:37   ` Yagnesh Raghava Yakkala
  2012-04-09 10:07     ` Bastien
@ 2012-04-09 10:54     ` Andreas Röhler
  2012-04-09 11:44       ` Yagnesh
  2012-04-09 14:50       ` Bastien
  1 sibling, 2 replies; 12+ messages in thread
From: Andreas Röhler @ 2012-04-09 10:54 UTC (permalink / raw
  To: help-gnu-emacs

Am 08.04.2012 11:37, schrieb Yagnesh Raghava Yakkala:
>
> Hello Bastien,
>
> Bastien<bzg@altern.org>  writes:
>
>> Yagnesh Raghava Yakkala<yagnesh@live.com>  writes:
>>
>>> 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.
>>
>> Add a hook to use `orgstruct-mode' in emacs-lisp buffers:
>>
>>    (add-hook 'emacs-lisp-mode-hook 'orgstruct-mode)
>>
>> Define a new `org-cycle-global' command:
>>
>>    (defun org-cycle-global () (interactive) (org-cycle t))
>>
>> Set this keybinding:
>>
>>    (global-set-key (kbd "<backtab>") 'org-cycle-global)
>
> Wow this is great, working nice too (except when point is at the end of
> buffer). I didn't think, Org itself can be used here. I wonder why its not
> working with other programming modes, say perl and python.
>
>
> Thanks.
>

https://bugs.launchpad.net/python-mode/+bug/977121

a feature request for now



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

* Re: code folding with <backtab> ?
  2012-04-09 10:54     ` Andreas Röhler
@ 2012-04-09 11:44       ` Yagnesh
  2012-04-09 14:50       ` Bastien
  1 sibling, 0 replies; 12+ messages in thread
From: Yagnesh @ 2012-04-09 11:44 UTC (permalink / raw
  To: Andreas Röhler; +Cc: help-gnu-emacs


Hi Andreas,

Andreas Röhler <andreas.roehler@easy-emacs.de> writes:

> Am 08.04.2012 11:37, schrieb Yagnesh Raghava Yakkala:
>>
>> Hello Bastien,
>>
>> Bastien<bzg@altern.org>  writes:
>>
>>> Yagnesh Raghava Yakkala<yagnesh@live.com>  writes:
>>>
>>>> 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.
>>>
>>> Add a hook to use `orgstruct-mode' in emacs-lisp buffers:
>>>
>>>    (add-hook 'emacs-lisp-mode-hook 'orgstruct-mode)
>>>
>>> Define a new `org-cycle-global' command:
>>>
>>>    (defun org-cycle-global () (interactive) (org-cycle t))
>>>
>>> Set this keybinding:
>>>
>>>    (global-set-key (kbd "<backtab>") 'org-cycle-global)
>>
>> Wow this is great, working nice too (except when point is at the end of
>> buffer). I didn't think, Org itself can be used here. I wonder why its not
>> working with other programming modes, say perl and python.
>>
>>
>> Thanks.
>>
>
> https://bugs.launchpad.net/python-mode/+bug/977121
>
> a feature request for now
>
>

Thank you Andreas.

-- 
YYR



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

* Re: code folding with <backtab> ?
  2012-04-09  1:00 ` code folding with <backtab> ? Michael Heerdegen
@ 2012-04-09 12:05   ` yagnesh raghava
  0 siblings, 0 replies; 12+ messages in thread
From: yagnesh raghava @ 2012-04-09 12:05 UTC (permalink / raw
  To: Michael Heerdegen; +Cc: help-gnu-emacs


Hello Michael,

Michael Heerdegen <michael_heerdegen@web.de> writes:

>
> Use hideshow-org, which implements exactly that:
>
> $ git clone git://github.com/secelis/hideshow-org.git

This looks great, I should have googled for it first. Thanks for your clear
explanation. Its working very nice as well., I may want to change the
behaviour a little per mode basis.

Thanks

-- 
YYR



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

* Re: code folding with <backtab> ?
  2012-04-09 10:54     ` Andreas Röhler
  2012-04-09 11:44       ` Yagnesh
@ 2012-04-09 14:50       ` Bastien
  2012-04-09 18:30         ` Andreas Röhler
  1 sibling, 1 reply; 12+ messages in thread
From: Bastien @ 2012-04-09 14:50 UTC (permalink / raw
  To: Andreas Röhler; +Cc: help-gnu-emacs

Hi Andreas,

Andreas Röhler <andreas.roehler@easy-emacs.de> writes:

> https://bugs.launchpad.net/python-mode/+bug/977121
>
> a feature request for now

Thanks for letting the python-mode people know.
Hopefully they will take this into account.

Otherwise we might add this directly into Emacs,
the change is not that big.

Patch welcome,

-- 
 Bastien



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

* Re: code folding with <backtab> ?
  2012-04-09 14:50       ` Bastien
@ 2012-04-09 18:30         ` Andreas Röhler
  0 siblings, 0 replies; 12+ messages in thread
From: Andreas Röhler @ 2012-04-09 18:30 UTC (permalink / raw
  To: Bastien; +Cc: help-gnu-emacs

Am 09.04.2012 16:50, schrieb Bastien:
> Hi Andreas,
>
> Andreas Röhler<andreas.roehler@easy-emacs.de>  writes:
>
>> https://bugs.launchpad.net/python-mode/+bug/977121
>>
>> a feature request for now
>
> Thanks for letting the python-mode people know.
> Hopefully they will take this into account.
>
> Otherwise we might add this directly into Emacs,
> the change is not that big.
>
> Patch welcome,
>

it's available now in current trunk of python-mode.el at

when `py-org-cycle-p' it customized `t'

http://launchpad.net/python-mode



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

end of thread, other threads:[~2012-04-09 18:30 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <mailman.674.1333786057.20052.help-gnu-emacs@gnu.org>
2012-04-09  1:00 ` code folding with <backtab> ? Michael Heerdegen
2012-04-09 12:05   ` yagnesh raghava
2012-04-07  8:07 Yagnesh Raghava Yakkala
2012-04-07  9:18 ` Bastien
2012-04-08  9:37   ` Yagnesh Raghava Yakkala
2012-04-09 10:07     ` Bastien
2012-04-09 10:54     ` Andreas Röhler
2012-04-09 11:44       ` Yagnesh
2012-04-09 14:50       ` Bastien
2012-04-09 18:30         ` Andreas Röhler
     [not found] ` <mailman.675.1333790271.20052.help-gnu-emacs@gnu.org>
2012-04-08 14:52   ` Uday Reddy
2012-04-09 10:08     ` Bastien

Code repositories for project(s) associated with this external index

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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.