stumpwm-devel
[Top][All Lists]
Advanced

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

Re: [STUMP] [PATCH] Fixed problem with completion of `where-is' command,


From: Ben Spencer
Subject: Re: [STUMP] [PATCH] Fixed problem with completion of `where-is' command, now it also recognises not existent commands giving a proper message
Date: Mon, 21 Mar 2011 15:35:29 +0000
User-agent: Mutt/1.5.20 (2009-06-14)

On Fri, Mar 18, 2011 at 01:49:49AM +0000, Wojciech Meyer wrote:
> Please see the new (It's been two years to look at it again! :)) patch,
> for the command completion of `where-is' command. As mentioned I've
> introduced a new macro `with-command-completion', but maybe eventually
> we'd need a completely different approach and just extend `defcommand'
> macro syntax. For now, however introducing the macro seems to be
> a reasonable thing to do to avoid code duplication.


Hi Wojciech,

> +(defmacro with-command-completion (prompt initial-input cmd &body body)
> +  "Prompt user with @var{prompt}, bind the command name into @{cmd}
> +check for errors, commands existence then evaluate @{body}."
> +  `(let ((cmd (completing-read (current-screen) ,prompt 
> +                               (all-commands) :initial-input (or 
> initial-input ""))))
> +     (unless ,cmd
> +       (throw 'error :abort))
> +     (when (and (plusp (length ,cmd))
> +     (if (not (get-command-structure cmd))
> +         (throw 'error (format nil "Command '~a' not found." cmd))
> +       ,@body)))))

Unless I've misunderstood what it's doing, this macro is missing some
,s - the current version depends on the names of the CMD and
INITIAL-INPUT variables in the calling code.

Also I believe the last bit could be simplified to:

     (when (plusp (length ,cmd))
       (if (get-command-structure ,cmd)
           (progn ,@body)
           (throw 'error (format nil "Command '~a' not found." ,cmd))))

(the progn would be necessary if the body contained more than one
clause).

That said, this problem seems like a candidate for a
define-stumpwm-type rather than a custom macro.  Is this infeasible
for some reason?

Ben



reply via email to

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