Emacs - 相互切换段落
Emacs - switch paragraphs with each other
我正在寻找一个在 Org-mode 中已经可行的解决方案,例如:
* HL1
* HL2 {press: Meta+arrowup}
=>
* HL2
* HL1
(1) 我想这样切换段落。这个想法基本上是我将点移到段落中间的某处{example:here []},按{key + arrowdown}然后该段落将与下面的下一个段落切换。
(2) 这样可以更轻松地在编辑论文时重组文本。
=> 第(2) 段现在应该在第(1) 段之前。
我不确定这是否是一个微不足道的问题。
如果它是 而不是 只是一个函数会更合适:
- 标记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)
请确认有效!
转置段落
transpose-paragraphs
听起来像你想要的功能。它是 interactive
,因此您可以使用 M-x
调用它。如果你发现你非常需要它,考虑将它绑定到一个键上(也许M-T
?)。
编辑(讨论摘要如下)
用户 lpoik 发现,在 his/her 系统上,参数为 -1
的 transpose-paragraphs
没有将 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
接受数字参数是否也有效:
(defun my-transpose-paragraphs-backward (arg)
(interactive "*p")
(transpose-paragraphs (- arg))
(backward-paragraph))
我正在寻找一个在 Org-mode 中已经可行的解决方案,例如:
* HL1
* HL2 {press: Meta+arrowup}
=>
* HL2
* HL1
(1) 我想这样切换段落。这个想法基本上是我将点移到段落中间的某处{example:here []},按{key + arrowdown}然后该段落将与下面的下一个段落切换。
(2) 这样可以更轻松地在编辑论文时重组文本。
=> 第(2) 段现在应该在第(1) 段之前。 我不确定这是否是一个微不足道的问题。 如果它是 而不是 只是一个函数会更合适:
- 标记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)
请确认有效!
转置段落
transpose-paragraphs
听起来像你想要的功能。它是 interactive
,因此您可以使用 M-x
调用它。如果你发现你非常需要它,考虑将它绑定到一个键上(也许M-T
?)。
编辑(讨论摘要如下)
用户 lpoik 发现,在 his/her 系统上,参数为 -1
的 transpose-paragraphs
没有将 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
接受数字参数是否也有效:
(defun my-transpose-paragraphs-backward (arg)
(interactive "*p")
(transpose-paragraphs (- arg))
(backward-paragraph))