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

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

Re: help create function alias


From: Barry Margolin
Subject: Re: help create function alias
Date: Wed, 08 Dec 2010 15:29:08 -0000
User-agent: MT-NewsWatcher/3.5.3b3 (Intel Mac OS X)

In article <i78deq$ue5$1@lust.ihug.co.nz>, Adam <nospam@example.com> 
wrote:

> Pascal J. Bourguignon wrote:
> 
> > Adam <nospam@example.com> writes:
> > 
> >>> Marc Mientki wrote:
> >> [ ... ]
> >>
> >> Here's the (insert-date) function.  Which I now find doesn't
> >> work when called from the changed (id) example below.
> >>
> >> M-x id  returns "Wrong type argument: stringp, nil"
> >> Strange, as I never used M-x insert-date  with any prefix-argument.
> >> Indeed am not sure how I'd do that (to use its options).
> >>
> >> (defun insert-date (prefix)
> >>     "Insert the current date. With prefix-argument, use ISO format. With
> >>    two prefix arguments, write out the day and month name."
> >>     (interactive "P")
> >>     (let ((format (cond
> >>                    ((not prefix) "%A, %d %B %Y")
> >>                    ((equal prefix '(4)) "%Y-%m-%d")
> >>                    ((equal prefix '(16)) "%A, %d. %B %Y")))
> >>           (system-time-locale "de_DE"))
> >>       (insert (format-time-string format))))
> > 
> > (defalias 'id 'insert-date)
> > 
> > M-x id RET     --> Monday, 20 September 2010
> > C-y M-x id RET --> 2010-09-20
> 
> Thanks. I saw alias somewhere recently, but couldn't 
> er.. didn't find it in a search looking for it simply 
> by name. 
> 
> Out of interest, how does one use the (insert-date) function 
> above with a prefix ? 
> 
> e.g.  C-u 4 M-x insert-date   returns an error, and 
> evaluating (insert-date 4) is not right. 

See the Emacs Lisp Reference Manual section on prefix arguments.  If you 
enter a number explicitly, the prefix argument is just the number.  But 
if you do C-u M-x insert-date or C-u C-u M-x insert-date, it puts the 
default argument in a list, which is what the function expects.

-- 
Barry Margolin, barmar@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***
*** PLEASE don't copy me on replies, I'll read them in the group ***


reply via email to

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