[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: favorite subject DWIM
From: |
Emanuel Berg |
Subject: |
Re: favorite subject DWIM |
Date: |
Sun, 15 Aug 2021 06:30:46 +0200 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux) |
Abhiseck Paira wrote:
>> ;;; -*- lexical-binding: t -*-
>> ;;;
>> ;;; this file:
>> ;;; https://dataswamp.org/~incal/public_html/emacs-init/dwim.el
>
> This file is not found (404).
You are right, here is the correct URL:
https://dataswamp.org/~incal/emacs-init/dwim.el
I still yank the whole file, last.
>> (defun test-dwim (&optional beg end)
>> (interactive (when (use-region-p)
>> (list (region-beginning) (region-end)) ))
>> (let ((bg (or beg (point-min)))
>> (ed (or end (point-max))) )
>> (list bg ed) ))
>
> Why do you have interactive declaration? [...] Wouldn't most
> of the time this function be called by some other function?
It depends on the actual function but since it involves the
region it is probably used most often interactively.
> Nit-picking: I think the let form is unnecessary.
Here the values are only returned but one can think of more
complicated stuff where the values are used repeatedly.
But actually it isn't a bad thing to be clear about that step
and get it over first thing, it is needed for the &optional
arguments which will be nil if called from Lisp
without arguments.
>> (when nil
>> (progn
>> (set-mark 10)
>> (forward-line 3)
>> (call-interactively #'test-dwim) ) ; (10 500)
>>
>> (call-interactively #'test-dwim) ; ( 1 604)
>>
>> (test-dwim 30 100) ; (30 100)
>>
>> (test-dwim) ; ( 1 604)
>> )
>
> Since I couldn't find your file, I may be lacking context,
> what it seems here you're testing the function?
Yes, as you see it can be used with a region, without a region
(whole buffer acted upon - DWIM), with arguments from Lisp,
and without - in which case again the whole buffer will be
used, so the interactive/no-region is analogous to
from-Lisp/no-arguments.
DWIM!
;;; -*- lexical-binding: t -*-
;;;
;;; this file:
;;; https://dataswamp.org/~incal/emacs-init/dwim.el
(defun test-dwim (&optional beg end)
(interactive (when (use-region-p)
(list (region-beginning) (region-end)) ))
(let ((bg (or beg (point-min)))
(ed (or end (point-max))) )
(list bg ed) ))
(when nil
(progn
(set-mark 10)
(forward-line 3)
(call-interactively #'test-dwim) ) ; (10 500)
(call-interactively #'test-dwim) ; ( 1 604)
(test-dwim 30 100) ; (30 100)
(test-dwim) ; ( 1 604)
)
--
underground experts united
https://dataswamp.org/~incal