emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* Make M-up and M-down transpose paragraphs in org buffers
@ 2011-06-21 23:08 Paul Sexton
  2011-06-28 17:14 ` Bastien
  0 siblings, 1 reply; 3+ messages in thread
From: Paul Sexton @ 2011-06-21 23:08 UTC (permalink / raw)
  To: emacs-orgmode

By default, if used within ordinary paragraphs in org mode, M-up and M-down 
transpose *lines* (not sentences). This was not useful to me. The following 
code makes these keys transpose paragraphs, keeping the point at the start
of the moved paragraph. Behaviour in tables and headings is unaffected. It
would be easy to modify this to transpose sentences.


(defun org-transpose-paragraphs (arg)
  (interactive)
  (when (and (not (or (org-at-table-p) (org-on-heading-p) (org-at-item-p)))
             (thing-at-point 'sentence))
    (transpose-paragraphs arg)
    (backward-paragraph)
    (re-search-forward "[[:graph:]]")
    (goto-char (match-beginning 0))
    t))

(add-to-list 'org-metaup-hook 
  (lambda () (interactive) (org-transpose-paragraphs -1)))
(add-to-list 'org-metadown-hook 
  (lambda () (interactive) (org-transpose-paragraphs 1)))

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

* Re: Make M-up and M-down transpose paragraphs in org buffers
  2011-06-21 23:08 Make M-up and M-down transpose paragraphs in org buffers Paul Sexton
@ 2011-06-28 17:14 ` Bastien
  2011-06-28 18:44   ` Nicolas Goaziou
  0 siblings, 1 reply; 3+ messages in thread
From: Bastien @ 2011-06-28 17:14 UTC (permalink / raw)
  To: Paul Sexton; +Cc: emacs-orgmode

Hi Paul,

Paul Sexton <psexton@xnet.co.nz> writes:

> By default, if used within ordinary paragraphs in org mode, M-up and M-down 
> transpose *lines* (not sentences). This was not useful to me. 

To me neither.

> The following 
> code makes these keys transpose paragraphs, keeping the point at the start
> of the moved paragraph. Behaviour in tables and headings is unaffected. It
> would be easy to modify this to transpose sentences.

I like it, and have a patch to integrate this directly in org-metaup and
org-metadown.  

There is one problem though: when you try to move down a paragraph when
it is followed by a list, Emacs doesn't understand the list should be
treated as a paragraph.  

Any idea on how to circumvent this?  Or should we live with this and
implement the solution?

Thanks for this idea,

-- 
 Bastien

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

* Re: Make M-up and M-down transpose paragraphs in org buffers
  2011-06-28 17:14 ` Bastien
@ 2011-06-28 18:44   ` Nicolas Goaziou
  0 siblings, 0 replies; 3+ messages in thread
From: Nicolas Goaziou @ 2011-06-28 18:44 UTC (permalink / raw)
  To: Bastien; +Cc: emacs-orgmode, Paul Sexton

Hello,

Bastien <bzg@altern.org> writes:

> There is one problem though: when you try to move down a paragraph when
> it is followed by a list, Emacs doesn't understand the list should be
> treated as a paragraph.  
>
> Any idea on how to circumvent this?  Or should we live with this and
> implement the solution?

Imo, a clean way to implement this (because it would also simplify
existing functions) would be to define a forward paragraph-function for
Org. It isn't difficult, but it raises some questions that need to be
answered. For example, should forward-paragraph move into constructs or
skip them. I.e. if point is outside a block and that block contains
paragraphs, should forward-paragraph skip the block or move inside?

Regards,

-- 
Nicolas Goaziou

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

end of thread, other threads:[~2011-06-28 18:44 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-06-21 23:08 Make M-up and M-down transpose paragraphs in org buffers Paul Sexton
2011-06-28 17:14 ` Bastien
2011-06-28 18:44   ` Nicolas Goaziou

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

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