* If clause depending on name of the day
@ 2012-04-03 19:16 Sven Bretfeld
2012-04-03 19:32 ` Lars Ljung
0 siblings, 1 reply; 7+ messages in thread
From: Sven Bretfeld @ 2012-04-03 19:16 UTC (permalink / raw)
To: help-gnu-emacs
Hi all
Is it possible to have an if-condition that looks for the current day?
So that the then-expression does something different on Tuesday than on
Friday?
This is not working:
(if (string-equal 'current-time-string ".*Tue.*")
(delete-other-windows)
(split-window-horizontally))
Thanks for help
Sven
p.s. unnecessary to mention that I have only a weak knowledge of elisp.
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: If clause depending on name of the day
2012-04-03 19:16 If clause depending on name of the day Sven Bretfeld
@ 2012-04-03 19:32 ` Lars Ljung
2012-04-03 19:57 ` Drew Adams
` (2 more replies)
0 siblings, 3 replies; 7+ messages in thread
From: Lars Ljung @ 2012-04-03 19:32 UTC (permalink / raw)
To: help-gnu-emacs
"Sven Bretfeld" <sven.bretfeld@gmx.ch> writes:
> Is it possible to have an if-condition that looks for the current day?
> So that the then-expression does something different on Tuesday than on
> Friday?
(nth 6 (decode-time)) returns 0-6 for Sunday-Saturday.
--
Lars Ljung
^ permalink raw reply [flat|nested] 7+ messages in thread
* RE: If clause depending on name of the day
2012-04-03 19:32 ` Lars Ljung
@ 2012-04-03 19:57 ` Drew Adams
2012-04-03 20:05 ` PJ Weisberg
[not found] ` <mailman.462.1333483518.20052.help-gnu-emacs@gnu.org>
2 siblings, 0 replies; 7+ messages in thread
From: Drew Adams @ 2012-04-03 19:57 UTC (permalink / raw)
To: 'Lars Ljung', help-gnu-emacs
> > Is it possible to have an if-condition that looks for the
> > current day? So that the then-expression does something
> > different on Tuesday than on Friday? This is not working:
> >
> > (if (string-equal 'current-time-string ".*Tue.*")
^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^
> > (delete-other-windows)
> > (split-window-horizontally))
>
> (nth 6 (decode-time)) returns 0-6 for Sunday-Saturday.
Plus, to address the code originally suggested:
1. `current-time-string' is a function that returns the time string when
invoked. To invoke it you would use: (current-time-string), not
'current-time-string.
2. You are trying to match a regexp against a literal string, but you are using
the wrong function (`string-equal') to do it. Use `string-match-p' for matching
(or `string-match' if that's not available). (`string-equal' does literal
comparison.)
(But Lars's answer provides a better solution than formatting a time string and
then matching it.)
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: If clause depending on name of the day
2012-04-03 19:32 ` Lars Ljung
2012-04-03 19:57 ` Drew Adams
@ 2012-04-03 20:05 ` PJ Weisberg
[not found] ` <mailman.462.1333483518.20052.help-gnu-emacs@gnu.org>
2 siblings, 0 replies; 7+ messages in thread
From: PJ Weisberg @ 2012-04-03 20:05 UTC (permalink / raw)
To: help-gnu-emacs
On Tue, Apr 3, 2012 at 12:32 PM, Lars Ljung <lars@matholka.se> wrote:
> "Sven Bretfeld" <sven.bretfeld@gmx.ch> writes:
>> Is it possible to have an if-condition that looks for the current day?
>> So that the then-expression does something different on Tuesday than on
>> Friday?
>
> (nth 6 (decode-time)) returns 0-6 for Sunday-Saturday.
So you could do something like this:
(require 'cl)
(case (nth 6 (decode-time))
(0
(message "Today is Sunday"))
((1 3 5)
(message "Today is Monday, Wednesday, or Friday"))
(2
(message "Today is Tuesday"))
(t
(message "It's some other day.")))
-PJ
Gehm's Corollary to Clark's Law: Any technology distinguishable from
magic is insufficiently advanced.
^ permalink raw reply [flat|nested] 7+ messages in thread
[parent not found: <mailman.462.1333483518.20052.help-gnu-emacs@gnu.org>]
* Re: If clause depending on name of the day
[not found] ` <mailman.462.1333483518.20052.help-gnu-emacs@gnu.org>
@ 2012-04-03 21:03 ` Pascal J. Bourguignon
0 siblings, 0 replies; 7+ messages in thread
From: Pascal J. Bourguignon @ 2012-04-03 21:03 UTC (permalink / raw)
To: help-gnu-emacs
PJ Weisberg <pj@irregularexpressions.net> writes:
> On Tue, Apr 3, 2012 at 12:32 PM, Lars Ljung <lars@matholka.se> wrote:
>> "Sven Bretfeld" <sven.bretfeld@gmx.ch> writes:
>>> Is it possible to have an if-condition that looks for the current day?
>>> So that the then-expression does something different on Tuesday than on
>>> Friday?
>>
>> (nth 6 (decode-time)) returns 0-6 for Sunday-Saturday.
>
> So you could do something like this:
>
> (require 'cl)
> (case (nth 6 (decode-time))
> (0
> (message "Today is Sunday"))
> ((1 3 5)
> (message "Today is Monday, Wednesday, or Friday"))
> (2
> (message "Today is Tuesday"))
> (t
> (message "It's some other day.")))
(message "Today is %s" (aref ["Sunday" "Monday" "Tuesday" "Wednesday"
"Thirsday" "Friday" "Saturday"]
(nth 6 (decode-time))))
--> "Today is Tuesday"
--
__Pascal Bourguignon__ http://www.informatimago.com/
A bad day in () is better than a good day in {}.
^ permalink raw reply [flat|nested] 7+ messages in thread
[parent not found: <mailman.458.1333480607.20052.help-gnu-emacs@gnu.org>]
* Re: If clause depending on name of the day
[not found] <mailman.458.1333480607.20052.help-gnu-emacs@gnu.org>
@ 2012-04-03 19:50 ` Pascal J. Bourguignon
2012-04-03 20:58 ` Sven Bretfeld
0 siblings, 1 reply; 7+ messages in thread
From: Pascal J. Bourguignon @ 2012-04-03 19:50 UTC (permalink / raw)
To: help-gnu-emacs
"Sven Bretfeld" <sven.bretfeld@gmx.ch> writes:
> Is it possible to have an if-condition that looks for the current day?
> So that the then-expression does something different on Tuesday than on
> Friday?
>
> This is not working:
>
> (if (string-equal 'current-time-string ".*Tue.*")
> (delete-other-windows)
> (split-window-horizontally))
What Lars said.
Otherwise you would have wanted:
(require 'cl)
(search "Tue" (current-time-string)) ; search a substring
or:
(string-match "Tue" (current-time-string)) ; search a regexp.
> p.s. unnecessary to mention that I have only a weak knowledge of elisp.
An Introduction to Programming in Emacs Lisp
http://www.gnu.org/software/emacs/emacs-lisp-intro/
(for non-programmers)
Emacs Lisp Manual
http://www.gnu.org/software/emacs/manual/elisp.html
--
__Pascal Bourguignon__ http://www.informatimago.com/
A bad day in () is better than a good day in {}.
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: If clause depending on name of the day
2012-04-03 19:50 ` Pascal J. Bourguignon
@ 2012-04-03 20:58 ` Sven Bretfeld
0 siblings, 0 replies; 7+ messages in thread
From: Sven Bretfeld @ 2012-04-03 20:58 UTC (permalink / raw)
To: help-gnu-emacs
Dear all
"Pascal J. Bourguignon" <pjb@informatimago.com> writes:
> "Sven Bretfeld" <sven.bretfeld@gmx.ch> writes:
>
>> Is it possible to have an if-condition that looks for the current day?
>> So that the then-expression does something different on Tuesday than on
>> Friday?
>>
>> This is not working:
>>
>> (if (string-equal 'current-time-string ".*Tue.*")
>> (delete-other-windows)
>> (split-window-horizontally))
>
> What Lars said.
> Otherwise you would have wanted:
>
> (require 'cl)
>
> (search "Tue" (current-time-string)) ; search a substring
>
> or:
>
> (string-match "Tue" (current-time-string)) ; search a regexp.
This is working just as I wanted it to. Thank you very much.
>> p.s. unnecessary to mention that I have only a weak knowledge of elisp.
>
> An Introduction to Programming in Emacs Lisp
> http://www.gnu.org/software/emacs/emacs-lisp-intro/
> (for non-programmers)
Bookmarked for later reading. Thanks.
Sven
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2012-04-03 21:03 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-04-03 19:16 If clause depending on name of the day Sven Bretfeld
2012-04-03 19:32 ` Lars Ljung
2012-04-03 19:57 ` Drew Adams
2012-04-03 20:05 ` PJ Weisberg
[not found] ` <mailman.462.1333483518.20052.help-gnu-emacs@gnu.org>
2012-04-03 21:03 ` Pascal J. Bourguignon
[not found] <mailman.458.1333480607.20052.help-gnu-emacs@gnu.org>
2012-04-03 19:50 ` Pascal J. Bourguignon
2012-04-03 20:58 ` Sven Bretfeld
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).