Emacs - 相互切换段落

时间:2015-07-14 17:00:15

标签: emacs org-mode paragraphs

我正在寻找一种已经可以在Org-mode中使用标题的解决方案,例如:

* HL1
* HL2 {press: Meta+arrowup}

=>

* HL2
* HL1

(1)我想切换那样的段落。这个想法基本上就是我在某个段落的中间移动点{例如:here []},按下{key + arrowdown},段落将与下一个段落切换。

(2)这样可以在编辑文件时更轻松地重新构建文本。

=>第(2)款现在应在第(1)款之前。 我不确定这是否是一个微不足道的问题。 如果它的 只是一个类似的函数会更合适:

  • Mark paragraph P1
  • 复制
  • 在P2下移动点
  • 粘贴P1

P1和P2的真正切换不会扰乱段落周围的间距。

谢谢,

编辑:找到解决方案:

1.easy:

(global-set-key (kbd "M-ü") 'transpose-paragraphs) ;; forward
(global-set-key (kbd "C-M-ü")
                (lambda () (interactive) (transpose-paragraphs -1)
      (backward-paragraph)
    )) ;; backwards

2.elaborated(在ergoemacs-functions.el中找到 - 目前只有org-mode):

(defmacro ergoemacs-define-org-meta (direction &optional disable)
  "Defines org-mode meta-direction keys.
DIRECTION defines the `org-mode' and `ergoemacs-mode' direction.
DISABLE defines if the option should be disabled by default."
  `(progn
     (defcustom ,(intern (format "ergoemacs-use-ergoemacs-meta%s" direction)) ,(not disable)
       ,(format "Use ergoemacs-mode defined <M-%s>." direction)
       :type 'boolean
       :group 'ergoemacs-mode)
     (defun ,(intern (format "ergoemacs-org-meta%s" direction))  ()
       ,(format "Run `org-meta%s' in the proper context.
When `ergoemacs-use-ergoemacs-meta%s' is non-nil use what ergoemacs-mode defines for <M-%s>.
ARG is the prefix argument for either command." direction direction direction)
       (interactive)
       (cond
        ((or
          (not ,(intern (format "ergoemacs-use-ergoemacs-meta%s" direction)))
          (org-at-heading-p)
          (org-at-item-p)
          (org-at-table-p)
          (and (org-region-active-p)
               (save-excursion
                 (goto-char (region-beginning))
                 (org-at-item-p)))
          (org-with-limited-levels
           (or (org-at-heading-p)
               (and (org-region-active-p)
                    (save-excursion
                      (goto-char (region-beginning))
                      (org-at-heading-p))))))
         ;; (setq prefix-arg current-prefix-arg)
         ;; Send prefix to next function
         (call-interactively ',(intern (format "org-meta%s" direction))))
        (t
         ;; (setq prefix-arg current-prefix-arg)
         ;; Send prefix to next function
         (ergoemacs-lookup-key-and-run ,(format "<M-%s>" direction)))))))
(ergoemacs-define-org-meta "left")
(ergoemacs-define-org-meta "right")
(ergoemacs-define-org-meta "up" t)
(ergoemacs-define-org-meta "down" t)

请确认工作!

1 个答案:

答案 0 :(得分:4)

转段落

transpose-paragraphs听起来像你想要的功能。它是interactive,因此您可以使用M-x调用它。如果您发现需要它很多,请考虑将其绑定到密钥(可能是M-T?)。

编辑(以下讨论摘要)

用户lpoik发现,在他/她的系统中,参数为transpose-paragraphs的{​​{1}}并未将-1置于正确的位置(两段之间),以便随后重复将段落向上移动一次的操作。到达的解决方法是使用point之后移动点:

backward-paragraph

如果你让(defun my-transpose-paragraphs-backward () (interactive "*") (transpose-paragraphs -1) (backward-paragraph)) (global-set-key (kbd "C-M-ü") 'my-transpose-paragraphs-backward) 接受一个数字参数,我不知道这是否也有效:

my-transpose-paragraphs-backward