* [Warning] cl-count (And Other Options)
@ 2012-11-30 22:01 Eric James Michael Ritz
2012-11-30 22:20 ` Dmitry Gutov
0 siblings, 1 reply; 3+ messages in thread
From: Eric James Michael Ritz @ 2012-11-30 22:01 UTC (permalink / raw)
To: help-gnu-emacs
First my apologies if this email would be more appropriate elsewhere.
I am currently using GNU Emacs 24.2.90.1 (i686-pc-linux-gnu, GTK+
Version 2.24.13), compiled on the 24th of November 2012. In a
function in my php-mode [1] I have the following function definition:
(defun php-unindent-closure ()
(let ((syntax (mapcar 'car c-syntactic-context)))
(if (and (member 'arglist-cont-nonempty syntax)
(or
(member 'statement-block-intro syntax)
(member 'brace-list-intro syntax)
(member 'brace-list-close syntax)
(member 'block-close syntax)))
(save-excursion
(let ((count-func (if (fboundp 'cl-count) #'cl-count
#'count)())))
(beginning-of-line)
(delete-char (* (cl-count 'arglist-cont-nonempty syntax)
c-basic-offset))))))
The key thing to note (unless you see something glaringly wrong with
it) is the call to `cl-count`. When I compile the file containing the
function I receive the following warning:
Compiling file /home/eric/Projects/php-mode/php-mode.el at Fri Nov
30 16:49:05 2012
In php-unindent-closure:
php-mode.el:436:8:Warning: malformed let binding: `(count-func (if
(fboundp
(quote cl-count)) (function cl-count) (function count)) nil)
The warning leads me to believe that use of `cl-count` is not
encouraged. Is that the case? And if so, what would be my best
alternative which would not trigger a warning?
Thank you in advanced!
[1]: https://github.com/ejmr/php-mode
--
ejmr
南無妙法蓮華經
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [Warning] cl-count (And Other Options)
2012-11-30 22:01 [Warning] cl-count (And Other Options) Eric James Michael Ritz
@ 2012-11-30 22:20 ` Dmitry Gutov
2012-11-30 22:58 ` Drew Adams
0 siblings, 1 reply; 3+ messages in thread
From: Dmitry Gutov @ 2012-11-30 22:20 UTC (permalink / raw)
To: Eric James Michael Ritz; +Cc: help-gnu-emacs
Eric James Michael Ritz <lobbyjones@gmail.com> writes:
> First my apologies if this email would be more appropriate elsewhere.
>
> I am currently using GNU Emacs 24.2.90.1 (i686-pc-linux-gnu, GTK+
> Version 2.24.13), compiled on the 24th of November 2012. In a
> function in my php-mode [1] I have the following function definition:
>
> (defun php-unindent-closure ()
> (let ((syntax (mapcar 'car c-syntactic-context)))
> (if (and (member 'arglist-cont-nonempty syntax)
> (or
> (member 'statement-block-intro syntax)
> (member 'brace-list-intro syntax)
> (member 'brace-list-close syntax)
> (member 'block-close syntax)))
> (save-excursion
> (let ((count-func (if (fboundp 'cl-count) #'cl-count #'count)())))
> (beginning-of-line)
> (delete-char (* (cl-count 'arglist-cont-nonempty syntax)
> c-basic-offset))))))
>
> The key thing to note (unless you see something glaringly wrong with
> it) is the call to `cl-count`. When I compile the file containing the
> function I receive the following warning:
>
> Compiling file /home/eric/Projects/php-mode/php-mode.el at Fri Nov 30
> 16:49:05 2012
>
> In php-unindent-closure:
> php-mode.el:436:8:Warning: malformed let binding: `(count-func (if (fboundp
> (quote cl-count)) (function cl-count) (function count)) nil)
>
> The warning leads me to believe that use of `cl-count` is not
> encouraged. Is that the case? And if so, what would be my best
> alternative which would not trigger a warning?
The warning tries to tell you that you have a spurious "()" in the let
binding form, after the value you are assigning to count-func.
It doesn't mention the actual problems:
1) The let form's body is empty, while it should contain the code that
goes after it.
2) Replace that (cl-count ...) with (funcall count-func ...).
But what Drew meant, I think, if for you the create a prefixed function
alias, not local value binding. The former would just look better in
code.
^ permalink raw reply [flat|nested] 3+ messages in thread
* RE: [Warning] cl-count (And Other Options)
2012-11-30 22:20 ` Dmitry Gutov
@ 2012-11-30 22:58 ` Drew Adams
0 siblings, 0 replies; 3+ messages in thread
From: Drew Adams @ 2012-11-30 22:58 UTC (permalink / raw)
To: 'Dmitry Gutov', 'Eric James Michael Ritz'; +Cc: help-gnu-emacs
> > (let ((count-func (if (fboundp 'cl-count) #'cl-count #'count)())))
> > ...
> > (delete-char (* (cl-count ...)...
> >
> > php-mode.el:436:8:Warning: malformed let binding:
>
> The warning tries to tell you that ...
the let binding is malformed. ;-)
> 2) Replace that (cl-count ...) with (funcall count-func ...).
Yes. Calling `cl-count' just, well, calls `cl-count'. ;-)
The point was to call `cl-count' if it exists, or call `count' if not. `count'
is defined if `cl-count' is not defined. Older Emacs uses the name `count';
newer Emacs uses the name `cl-count'.
> But what Drew meant, I think, if for you the create a prefixed
> function alias, not local value binding. The former would just
> look better in code.
That's OK too.
But all I really meant was to call the function that exists, whether it is named
`cl-count' or `count'. One or the other is available, and they presumably do
the same thing.
Look first for a function with the newer name, `cl-count'. If that does not
exist then use `count', which must exist prior to the introduction of
`cl-count'.
If you have only one or a few occurrences of `cl-count' in your code, you could
just replace them with a funcall of the right function, as indicated above. If
you have a lot of them, or if you prefer (e.g. to ease maintenance), you can
create your own (non-local) function that calls the right one, and then use that
everywhere in your code.
(defun my-count (&rest args)
(if (fboundp 'cl-count)
(apply #'cl-count args)
(apply #'count args)))
Or just:
(defalias 'my-count (if (fboundp 'cl-count) #'cl-count #'count))
Then (delete-char (* (my-count ...)... etc.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2012-11-30 22:58 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-11-30 22:01 [Warning] cl-count (And Other Options) Eric James Michael Ritz
2012-11-30 22:20 ` Dmitry Gutov
2012-11-30 22:58 ` Drew Adams
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.