;;; -*- lexical-binding: t -*- ;; ;; DWIM code helpers and examples. ;; ;; Advantages: ;; ;; - the same default interactively and from Lisp ;; - the default is the whole buffer ;; - the region is never used from Lisp ;; - the variables are always set, to default fallback if not explicitly ;; - one can have preceding, non-optional arguments ;; -------------------------------------------------------------------------- (defun use-region () (if (use-region-p) (list (region-beginning) (region-end)) (list nil nil))) ;; -------------------------------------------------------------------------- (defun test-dwim (&optional beg end) (interactive (use-region)) (or beg (setq beg (point-min))) (or end (setq end (point-max))) (message "%d %d" beg end)) (defun test-dwim-2 (re &optional beg end) (interactive `(,(read-regexp "regexp: ") ,@(use-region))) (or beg (setq beg (point-min))) (or end (setq end (point-max))) (message "%s %d %d" re beg end)) ;; -------------------------------------------------------------------------- (provide 'luki-dwim)