org-metadown in regular text reddit / emacs ---------------------------------------------------------------------- lilytex · 2022-12-17 01:09 I use org-metadown to swap two elements of a list in org mode, and I'd like to swap any two org mode lines. I've found this snippet: [Using M-up and M-down to transpose paragraphs](https://orgmode.org/worg/org-hacks.html#orgcb907ce) : however it moves the whole org-element (for example a paragraph), and I want something simply line-based. I've tried to define this hook: (add-to-list 'org-metaup-hook (lambda () (interactive) (prog2 (transpose-lines 1) (previous- line 2)))) (add-to-list 'org-metadown-hook (lambda () (interactive) (progn (next-line 1) (transpose-lines -1) (previous-line 1)))) But is doing strange things and I don't understand transpose-lines very well. It seems like there is no way for the cursor move along with the line you are moving up and down. Is there a simpler way to do this? ---------------------------------------------------------------------- MitchellMarquez42 · 2022-12-17 02:00 Does (save-excursion) do anything? ---------------------------------------------------------------------- FluentFelicity · 2022-12-17 03:04 Does transpose-lines, bound to C-x C-t do the job? ---------------------------------------------------------------------- yantar92 · 2022-12-17 06:09 You can customize `org-metaup-hook` ---------------------------------------------------------------------- lilytex · 2022-12-17 09:30 Yes! I forgot about this, thanks ---------------------------------------------------------------------- lilytex · 2022-12-17 22:51 At the end the solution I've used is defining a new function and assign the same keybindings as org-metaup: (defun org-metaup-universal () (interactive) (condition-case nil (org-metaup) (user-error (save-excursion (forward-line 1) (transpose-lines -1)) (forward-line -1)))) Whenever `org-metaup` doesn't work because it's not on a list element for example, it throws an `user-error` and fall backs to the function that simply swaps two lines