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

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

Re: Making a function than can only be used interactively


From: Jean Louis
Subject: Re: Making a function than can only be used interactively
Date: Tue, 5 Jul 2022 20:35:01 +0300
User-agent: Mutt/+ () (2022-06-11)

* Christopher Dimech <dimech@gmx.com> [2022-07-05 00:41]:
> (defun foo (a b c)
> (interactive ...)
> 
> (if (equal a 1)
>   (let* (h (read-from-minibuffer ...))
>   ... ))
> ...)
> 
> Although discouraged, the above could make sense, but completely wrong to use
> non-interactively.

I think it is OK to use it non-interactively. 

`interactive' description says "Specify a way of parsing arguments for
interactive use of a function." 

See (info "(elisp) Using Interactive")

Here is sample function that I use:

(defun cf-hyperscope-assign-tasks-for-many (&optional id)
  "Assign tasks with information of many contacts"
  (interactive)
  (when-tabulated-id "people"
      (let* ((assignee (cf-people-search-id nil "Assign to which person? "))
             (task (rcd-ask "Describe the task to be assigned: "))
             (prefix (rcd-ask "Prefix for task: " "Call"))
             (set (hyperscope-select-set)))
        (rcd-tabulated-iterate-generic 
         id
         (lambda (id)
           (let* ((name (concat prefix " " (cf-full-contact-name id)))
                  (description (concat "⟦ 
(hyperscope-related-contact-contacts-information hyperscope-current-id) ⟧\n\n" 
task))
                  (hyperscope-id (hyperscope-add-generic name "" nil 31 10 set 
nil description nil id assignee)))
             (hlink-update-action-status-1 hyperscope-id 2)))
         "Assign Tasks"))))

And I may as well invoke function non-interactively, when there is
`interactive`, it means it is a command and accessible through M-x and
may be bound to keys.

-- 
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]