;;; -*- lexical-binding: t -*- ;; ;; this file: ;; https://dataswamp.org/~incal/emacs-init/dwim.el ;; ;; DWIM code helpers and examples. ;; ;; Advantages to this style: ;; ;; - 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 the default if not explicitely ;; - one can still 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 'dwim)