Xah Talk Show 2022-01-22 emacs lisp coding narrow-to-region, sort-lines, hilight-unicode, emacs vs xemacs
- Timestamp
- 54:03 emacs vs xemacs, richard stallman, open source schism
- write
xah-narrow-to-region
. if no region, just current text block. put in Xah Fly Keys, give it a key.
- write
xah-sort-lines
, that works on current block if no region. put in Xah Fly Keys, give it a key.
- write
xah-hilight-unicode
(defun xah-narrow-to-region ()
"Same as `narrow-to-region', but if no selection, narrow to the current block.
Version 2022-01-22"
(interactive)
(if (region-active-p)
(progn
(narrow-to-region (region-beginning) (region-end)))
(progn
(let ($p1 $p2)
(save-excursion
(if (re-search-backward "\n[ \t]*\n" nil 1)
(progn (goto-char (match-end 0))
(setq $p1 (point)))
(setq $p1 (point)))
(if (re-search-forward "\n[ \t]*\n" nil 1)
(progn (goto-char (match-beginning 0))
(setq $p2 (point)))
(setq $p2 (point))))
(narrow-to-region $p1 $p2)))))
(defun xah-sort-lines ()
"Like `sort-lines' but if no region, do the current block.
Created: 2022-01-22
Version: 2025-03-25"
(interactive)
(let (xbeg xend)
(seq-setq (xbeg xend) (if (region-active-p) (list (region-beginning) (region-end)) (list (save-excursion (if (re-search-backward "\n[ \t]*\n" nil 1) (match-end 0) (point))) (save-excursion (if (re-search-forward "\n[ \t]*\n" nil 1) (match-beginning 0) (point))))))
(sort-lines current-prefix-arg xbeg xend)))
(defun xah-hilight-unicode ()
"Highlight all unicode chars in current buffer or selection.
Version 2022-01-22 2022-01-24"
(interactive)
(let ($p1 $p2)
(if (region-active-p)
(setq $p1 (region-beginning) $p2 (region-end))
(setq $p1 (point-min) $p2 (point-max)))
(save-restriction
(narrow-to-region $p1 $p2)
(goto-char (point-min))
(while (re-search-forward "[^[:ascii:]]+" nil t)
(put-text-property (match-beginning 0) (match-end 0) 'font-lock-face '(:background "red"))))))
xah_talk_show_2022-01-22.txt