Xah Talk Show 2022-03-04 emacs lisp coding and tutorial. swap/transpose text blocks
focused emacs lisp coding and tutorial. a command to swap current text block with previous. no random topic.
- emacs lisp write
xah-transpose-block
transpose-chars
transpose-lines
transpose-paragraphs
transpose-regions
transpose-sentences
transpose-sexps
transpose-words
(defun xah-transpose-block () "swap the current text block with the previous. Version 2022-03-04" (interactive) (let (($curCursPos (point)) $c1 ; current block begin $c2 ; current Block End $p1 ; prev Block Begin $p2 ; prev Block end ) (save-excursion (if (re-search-forward "\n[ \t]*\n+" nil "move") (setq $c2 (match-beginning 0)) (setq $c2 (point))) (goto-char $curCursPos) (if (re-search-backward "\n[ \t]*\n+" nil "move") (progn (setq $c1 (match-end 0)) (skip-chars-backward "\n \t") (setq $p2 (point))) (error "No previous block.")) (goto-char $p2) (if (re-search-backward "\n[ \t]*\n+" nil "move") (setq $p1 (match-end 0)) (setq $p1 (point))) (transpose-regions $p1 $p2 $c1 $c2))) ;; ) (global-set-key (kbd "C-d") 'xah-transpose-block)