emacs-orgmode
[Top][All Lists]
Advanced

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

Re: [O] org-metaup / org-metadown nerfed in 7.9.1


From: Anthony Lander
Subject: Re: [O] org-metaup / org-metadown nerfed in 7.9.1
Date: Wed, 19 Sep 2012 10:50:33 -0400

Hi Trevor,

On 12-Sep-19, at 10:44 AM, Trevor Vartanoff wrote:

> And so, example 2, I was receiving "cannot drag element forward/backward" 
> when I was in a heading with no line breaks. That is, a heading where 
> paragraphs are separated with return + indent rather than a full line break 
> of return + return.

I use the M-up/dn behaviour a lot to move property lines up and down. I added 
some hooks to restore that functionality since property lines aren't recognized 
as elements. Here's the code. You might be able to adapt it to do what you want.

Hope it helps,

  -Anthony

; Fix M-<up> and M-<down> to move individual lines inside a property drawer
(add-hook 'org-metaup-hook 'my-org-metaup-hook)
(defun my-org-metaup-hook ()
  "When on a property line, use M-<up> to move the line up"
  (when (org-region-active-p) (return nil))

  (let ((element (car (org-element-at-point))))
    (if (eq element 'property-drawer)
        (let* ((position (- (point) (line-beginning-position)))
               (a (save-excursion (move-beginning-of-line 1) (point)))
               (b (save-excursion (move-end-of-line 1) (point)))
               (c (save-excursion (goto-char a)
                                  (move-beginning-of-line 0)))
               (d (save-excursion (goto-char a)
                                  (move-end-of-line 0) (point))))
          (transpose-regions a b c d)
          (goto-char c)
          (forward-char position)
          t)
        nil)))

(add-hook 'org-metadown-hook 'my-org-metadown-hook)
(defun my-org-metadown-hook ()
  "When on a property line, use M-<down> to move the line down"
  (when (org-region-active-p) (return nil))

  (let ((element (car (org-element-at-point))))
    (if (eq element 'property-drawer)
        (let* ((position (- (point) (line-beginning-position)))
               (at-end-of-line (eq (point) (line-end-position)))
               (a (save-excursion (move-beginning-of-line 1)))
               (b (save-excursion (move-end-of-line 1) (point)))
               (c (save-excursion (next-line)
                                  (move-beginning-of-line 1)))
               (d (save-excursion (next-line)
                                  (move-end-of-line 1) (point))))
          (transpose-regions a b c d)
          (move-beginning-of-line 1)
          (if at-end-of-line            ; Strange boundary condition at end of 
line
              (progn 
                (next-line)             ; Goes to wrong place. So instead just
                (move-end-of-line 1))   ; go to end of line.
              (forward-char position))
          t)
        nil)))




reply via email to

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