[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [External] : interactive to do `use-region-p'
From: |
Emanuel Berg |
Subject: |
Re: [External] : interactive to do `use-region-p' |
Date: |
Mon, 07 Nov 2022 13:28:13 +0100 |
User-agent: |
Gnus/5.13 (Gnus v5.13) |
Drew Adams wrote:
>>> use that with (interactive `(,@(DTRT))).
>>
>> A.k.a (interactive (DTRT)), right?
>
> ;-) Yup/oops.
>
> I was thinking of the more general case of
> region/buffer-limit args, plus additional args.
>
> (defun foo (beg end other)
> (interactive `(,@(dtrt) ,(+ 2 7)))
> ...)
You mean like this?
;;; -*- lexical-binding: t -*-
;;
;; this file:
;; https://dataswamp.org/~incal/emacs-init/enum.el
(require 'cl-lib)
(require 'subr-x)
(defun enum (&optional beg end suf)
"Enumerate each line from BEG to END, counting from one.
Use SUF as a suffix to the digits inserted.
BEG defaults to the beginning of the buffer,
END defaults to the end of the buffer, and
SUF defaults to \". \""
(interactive
`(,@(if (use-region-p)
(list (region-beginning) (region-end))
(list nil nil) )
,(when current-prefix-arg
(read-string "suffix: ") )))
(or beg (setq beg (point-min)))
(or end (setq end (point-max)))
(or suf (setq suf ". "))
(goto-char beg)
(let*((lines (count-lines beg end))
(pad-len (length (number-to-string lines))) )
(cl-loop
for line from 1 to lines do
(goto-char (line-beginning-position))
(insert
(format "%s%s" (string-pad (number-to-string line) pad-len nil t) suf) )
(forward-line) )))
--
underground experts united
https://dataswamp.org/~incal
Re: [External] : interactive to do `use-region-p', Emanuel Berg, 2022/11/07