help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: (interactive) and &optional


From: Jean Louis
Subject: Re: (interactive) and &optional
Date: Thu, 30 Mar 2023 22:04:29 +0300
User-agent: Mutt/2.2.9+54 (af2080d) (2022-11-21)

* Emanuel Berg <incal@dataswamp.org> [2023-03-27 08:05]:
> > (defun search-something (&optional query)
> >    "Search something by using QUERY."
> >    (interactive)
> >    (let ((query (or query (read-from-minibuffer "Query: "))))
> >      (message query)))
> 
> This has the same problem as before, it should look something
> like this:
> 
> ;;; -*- lexical-binding: t -*-
> ;;
> ;; this file:
> ;;   https://dataswamp.org/~incal/emacs-init/geh.el
> 
> (defun search-something (&optional query)
>   "Search something by using QUERY."
>   (interactive "sQuery: ")
>   (unless (and (stringp query)
>                (not (string= "" query)) )
>     (setq query "default search") )
>   (message query) )
> 
> ;; (search-something "love")         ; love
> ;; (search-something)                ; default search
> ;; M-x search-something RET RET      ; default search
> ;; M-x search-something RET love RET ; love

That is your design opinion that it should look like that as related to
`interactive', and my design is that I avoid putting questions within
`interactive' declaration. I find it simpler, more visible, easier to
understand, readable, and freeer. For example I can remove
(interactive) from function for function still to work, without
restructuring, sometimes I find I do not want function any more to be
a command.

-- 
Jean

Take action in Free Software Foundation campaigns:
https://www.fsf.org/campaigns

In support of Richard M. Stallman
https://stallmansupport.org/



reply via email to

[Prev in Thread] Current Thread [Next in Thread]