unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* [PATCH] New command `outline-narrow-to-subtree'
@ 2011-08-15 13:46 Bastien
  2011-08-15 14:11 ` Leo
  0 siblings, 1 reply; 5+ messages in thread
From: Bastien @ 2011-08-15 13:46 UTC (permalink / raw)
  To: emacs-devel

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

Attached is a patch to outline.el defining a new command
`outline-narrow-to-subtree' (bound to `C-c @ C-s').

Let me know if this is okay to apply this patch: before 
Org 7.7, people could use `org-narrow-to-subtree' in buffers
with outline-mode or outline-minor-mode, so this patch can
be considered a fix rather than a new functionality.  But 
maybe it's borderline.

Thanks,


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: outline.el.patch --]
[-- Type: text/x-patch, Size: 951 bytes --]

--- lisp/outline.el	2011-04-19 13:44:55 +0000
+++ lisp/outline.el	2011-08-15 13:41:50 +0000
@@ -83,6 +83,7 @@
     (define-key map "\C-k" 'show-branches)
     (define-key map "\C-q" 'hide-sublevels)
     (define-key map "\C-o" 'hide-other)
+    (define-key map "\C-s" 'outline-narrow-to-subtree)
     (define-key map "\C-^" 'outline-move-subtree-up)
     (define-key map "\C-v" 'outline-move-subtree-down)
     (define-key map [(control ?<)] 'outline-promote)
@@ -1116,6 +1117,18 @@
 		    (insert "\n\n"))))))
 	  (kill-new (buffer-string)))))))
 
+(defun outline-narrow-to-subtree ()
+  "Narrow buffer to the current subtree."
+  (interactive)
+  (save-excursion
+    (save-match-data
+      (narrow-to-region
+       (progn (outline-back-to-heading t) (point))
+       (progn (outline-end-of-subtree)
+	      (if (and (outline-on-heading-p t) (not (eobp))) 
+		  (backward-char 1))
+	      (point))))))
+
 (provide 'outline)
 (provide 'noutline)
 

[-- Attachment #3: Type: text/plain, Size: 15 bytes --]



-- 
 Bastien

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

* Re: [PATCH] New command `outline-narrow-to-subtree'
  2011-08-15 13:46 [PATCH] New command `outline-narrow-to-subtree' Bastien
@ 2011-08-15 14:11 ` Leo
  2011-08-15 14:47   ` Bastien
  0 siblings, 1 reply; 5+ messages in thread
From: Leo @ 2011-08-15 14:11 UTC (permalink / raw)
  To: emacs-devel

On 2011-08-15 21:46 +0800, Bastien wrote:
> Attached is a patch to outline.el defining a new command
> `outline-narrow-to-subtree' (bound to `C-c @ C-s').

That key seems to be already bound to show-subtree (emacs-23 here).

C-x n s is a good key binding. There is no reason for org-mode to put
some of its commands in narrow-map which are only usable in org-mode.

Leo




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

* Re: [PATCH] New command `outline-narrow-to-subtree'
  2011-08-15 14:11 ` Leo
@ 2011-08-15 14:47   ` Bastien
  2011-08-19  7:31     ` Leo
  0 siblings, 1 reply; 5+ messages in thread
From: Bastien @ 2011-08-15 14:47 UTC (permalink / raw)
  To: Leo; +Cc: emacs-devel

Hi Leo,

Leo <sdl.web@gmail.com> writes:

> On 2011-08-15 21:46 +0800, Bastien wrote:
>> Attached is a patch to outline.el defining a new command
>> `outline-narrow-to-subtree' (bound to `C-c @ C-s').
>
> That key seems to be already bound to show-subtree (emacs-23 here).

Right.  I suggest using `C-c @ n' then.

> C-x n s is a good key binding. There is no reason for org-mode to put
> some of its commands in narrow-map which are only usable in org-mode.

I assumed the purpose of `narrow-map' was to contain all commands
related to narrowing, even if they are not globally available.  But 
I'm probably wrong.

Can some expert confirm this?

If I'm wrong, then the `org-narrow-to-subtree' keybinding belongs to the
`org-mode-map' the same way than `outline-narrow-to-subtree' belongs to
the `outline-mode-map'.

-- 
 Bastien



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

* Re: [PATCH] New command `outline-narrow-to-subtree'
  2011-08-15 14:47   ` Bastien
@ 2011-08-19  7:31     ` Leo
  2011-08-19 12:59       ` Bastien
  0 siblings, 1 reply; 5+ messages in thread
From: Leo @ 2011-08-19  7:31 UTC (permalink / raw)
  To: Bastien; +Cc: emacs-devel

On 2011-08-15 22:47 +0800, Bastien wrote:
>> That key seems to be already bound to show-subtree (emacs-23 here).
>
> Right.  I suggest using `C-c @ n' then.
>
>> C-x n s is a good key binding. There is no reason for org-mode to put
>> some of its commands in narrow-map which are only usable in org-mode.
>
> I assumed the purpose of `narrow-map' was to contain all commands
> related to narrowing, even if they are not globally available.  But 
> I'm probably wrong.
>
> Can some expert confirm this?
>
> If I'm wrong, then the `org-narrow-to-subtree' keybinding belongs to the
> `org-mode-map' the same way than `outline-narrow-to-subtree' belongs to
> the `outline-mode-map'.

How about something like this?

We add an interface function narrow-to-subtree which is bound globally
to C-x n s.

(defvar narrow-to-subtree-function nil
  "Function to call to narrow to a subtree.")

(defun narrow-to-subtree ()
  (interactive)
  (if (functionp narrow-to-subtree-function)
      (funcall narrow-to-subtree-function)
    (error "Don't know how to narrow to a subtree in current buffer")))

then outline-mode, allout, org-mode and others can each provide its
specific narrow-to-subtree-function.

WDYT?

Leo



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

* Re: [PATCH] New command `outline-narrow-to-subtree'
  2011-08-19  7:31     ` Leo
@ 2011-08-19 12:59       ` Bastien
  0 siblings, 0 replies; 5+ messages in thread
From: Bastien @ 2011-08-19 12:59 UTC (permalink / raw)
  To: Leo; +Cc: emacs-devel

Hi Leo,

Leo <sdl.web@gmail.com> writes:

> We add an interface function narrow-to-subtree which is bound globally
> to C-x n s.
>
> (defvar narrow-to-subtree-function nil
>   "Function to call to narrow to a subtree.")
>
> (defun narrow-to-subtree ()
>   (interactive)
>   (if (functionp narrow-to-subtree-function)
>       (funcall narrow-to-subtree-function)
>     (error "Don't know how to narrow to a subtree in current buffer")))
>
> then outline-mode, allout, org-mode and others can each provide its
> specific narrow-to-subtree-function.

I see how this solution would add the ̀narrow-to-subtree' command to the
narrow-map -- but what is a "subtree" outside org-mode and outline-mode?

If we add outline-narrow-to-subtree, then we have all we we need for Org
and outline-mode.

The question is then: does `narrow-map' need to know about every
narrow-to-* functions that mode can define for themselves?

I'd be curious about people's input.

-- 
 Bastien



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

end of thread, other threads:[~2011-08-19 12:59 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-08-15 13:46 [PATCH] New command `outline-narrow-to-subtree' Bastien
2011-08-15 14:11 ` Leo
2011-08-15 14:47   ` Bastien
2011-08-19  7:31     ` Leo
2011-08-19 12:59       ` Bastien

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

	https://git.savannah.gnu.org/cgit/emacs.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).