* Newbie Conditional Problem
@ 2003-01-17 15:19 CarlC
2003-01-17 15:36 ` Friedrich Dominicus
` (4 more replies)
0 siblings, 5 replies; 14+ messages in thread
From: CarlC @ 2003-01-17 15:19 UTC (permalink / raw)
Hi.
I have written my first elisp function. (pause for roar of crowd). I am
getting an error while trying to process my first conditional and debug is
not helping me. This is for emacs 21.2.1.
(let ((line (current-line)))
(forward-word 1)
(if (> (current-line) line) ((goto-line line) (end-of-line))))
...
(defun current-line ()
"Return the vertical position of point..."
(+ (count-lines (window-start) (point))
(if (= (current-column) 0) 1 0)
-1))
When the if statement is true, I get an error: Invalid function: (goto-line
line)
Anybody? Thanks in advance.
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: Newbie Conditional Problem
2003-01-17 15:19 Newbie Conditional Problem CarlC
@ 2003-01-17 15:36 ` Friedrich Dominicus
2003-01-17 16:09 ` CarlC
2003-01-17 16:19 ` Brendan Halpin
` (3 subsequent siblings)
4 siblings, 1 reply; 14+ messages in thread
From: Friedrich Dominicus @ 2003-01-17 15:36 UTC (permalink / raw)
"CarlC" <carlc@snowbd.com> writes:
> Hi.
>
> I have written my first elisp function. (pause for roar of crowd). I am
> getting an error while trying to process my first conditional and debug is
> not helping me. This is for emacs 21.2.1.
>
> (let ((line (current-line)))
> (forward-word 1)
> (if (> (current-line) line) ((goto-line line) (end-of-line))))
> ...
> (defun current-line ()
> "Return the vertical position of point..."
> (+ (count-lines (window-start) (point))
> (if (= (current-column) 0) 1 0)
> -1))
I guess current-line is wrong the documentation for windows start
gives `window-start' is a built-in function
(window-start BUFFER &optional WHICH-FRAMES WHICH-DEVICES) and the -1
is probably wrong too.
Documentation:
ans search all devices.
I can't see how if fits. Try this
(defun current-line ()
"Return the vertical position of point within the current buffer."
(+ (count-lines (point-min) (point))
(if (= (current-column) 0) 1 0)))
Regards
Friedrich
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: Newbie Conditional Problem
2003-01-17 15:36 ` Friedrich Dominicus
@ 2003-01-17 16:09 ` CarlC
2003-01-18 6:27 ` Friedrich Dominicus
0 siblings, 1 reply; 14+ messages in thread
From: CarlC @ 2003-01-17 16:09 UTC (permalink / raw)
"Friedrich Dominicus" <frido@q-software-solutions.com> wrote in message
news:87ptqvokj8.fsf@fbigm.here...
> I guess current-line is wrong the documentation for windows start
>
> gives `window-start' is a built-in function
> (window-start BUFFER &optional WHICH-FRAMES WHICH-DEVICES) and the -1
> is probably wrong too.
>
> I can't see how if fits. Try this
> (defun current-line ()
> "Return the vertical position of point within the current buffer."
> (+ (count-lines (point-min) (point))
> (if (= (current-column) 0) 1 0)))
I copied the current-line function out of a manual. It seems to give good
results for this application. I have now replaced with your function and get
the same error. It doesn't seem to be related to the current-line function.
I am very frustrated that there doesn't seem to be a variable to return the
current line number like there is for current-column. The value is shown on
my mode line. Why do I have to copy a function to get this value???
Thanks for the help Friedrich. Any more suggestions?
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: Newbie Conditional Problem
2003-01-17 15:19 Newbie Conditional Problem CarlC
2003-01-17 15:36 ` Friedrich Dominicus
@ 2003-01-17 16:19 ` Brendan Halpin
[not found] ` <x54r87zrdo.fsf@lola.goethe.zz>
` (2 subsequent siblings)
4 siblings, 0 replies; 14+ messages in thread
From: Brendan Halpin @ 2003-01-17 16:19 UTC (permalink / raw)
"CarlC" <carlc@snowbd.com> writes:
> Hi.
>
> I have written my first elisp function. (pause for roar of crowd). I am
> getting an error while trying to process my first conditional and debug is
> not helping me. This is for emacs 21.2.1.
>
> (let ((line (current-line)))
> (forward-word 1)
> (if (> (current-line) line) ((goto-line line) (end-of-line))))
Extra paren: ^^
(if (> (current-line) line) (goto-line line) (end-of-line))))
> When the if statement is true, I get an error: Invalid function: (goto-line
> line)
i.e. it should say "Invalid function: no-such-defun" without the
leading "(".
Brendan
--
Brendan Halpin, Department of Sociology, University of Limerick, Ireland
Tel: w +353-61-213147 f +353-61-202569 h +353-61-390476; Room F2-025 x 3147
<mailto:brendan.halpin@ul.ie> <http://wivenhoe.staff8.ul.ie/~brendan>
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: Newbie Conditional Problem
[not found] ` <x54r87zrdo.fsf@lola.goethe.zz>
@ 2003-01-17 16:46 ` CarlC
2003-01-17 16:52 ` David Kastrup
0 siblings, 1 reply; 14+ messages in thread
From: CarlC @ 2003-01-17 16:46 UTC (permalink / raw)
"David Kastrup" <dak@gnu.org> wrote in message
news:x54r87zrdo.fsf@lola.goethe.zz...
> Well, what do you expect? (goto-line line) is no function, and you
> use it in the place of one, namely immediately after an opening
What do I expect ... how thought provoking. The manual shows:
Command: goto-line line
This function ...
C-f h goto-line RET shows:
goto-line is an interactive compiled Lisp function in `simple'.
(goto-line ARG)
Goto line ARG, counting from line 1 at beginning of buffer.
I am new to this. Is it technically a command or function? Can it be used
immediatly after an opening parenthesis? It seems to work fine outside of
this conditional. I can put other commands in the conditional and they fail,
also.
> parenthesis of a non-special form. I recommend that you instead use
> progn after the opening parenthesis. Look it up with
>
> C-h f progn RET
progn is a special form.
(progn BODY ...)
Eval BODY forms sequentially and return value of last one.
This doesn't tell me a whole lot. I get an invalid function using progn,
also. Is it a function?
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: Newbie Conditional Problem
2003-01-17 16:46 ` CarlC
@ 2003-01-17 16:52 ` David Kastrup
2003-01-17 17:24 ` CarlC
0 siblings, 1 reply; 14+ messages in thread
From: David Kastrup @ 2003-01-17 16:52 UTC (permalink / raw)
"CarlC" <carlc@snowbd.com> writes:
> "David Kastrup" <dak@gnu.org> wrote in message
> news:x54r87zrdo.fsf@lola.goethe.zz...
> > Well, what do you expect? (goto-line line) is no function, and you
> > use it in the place of one, namely immediately after an opening
>
> C-f h goto-line RET shows:
>
> goto-line is an interactive compiled Lisp function in `simple'.
See? goto-line is a function. (goto-line line) is a function call.
> (goto-line ARG)
This is supposed to illustrate how goto-line is called. A function
call is not the same as a function.
> Goto line ARG, counting from line 1 at beginning of buffer.
>
> I am new to this. Is it technically a command or function? Can it be
> used immediatly after an opening parenthesis?
goto-line is a function. It can be "used" immediately after an
opening parenthesis. This is not what Emacs complained about. Emacs
complained about using (goto-line line) after an opening
parenthesis. (goto-line line) is not a function, it is a function
call.
> It seems to work fine outside of this conditional.
No, it doesn't. (goto-line line) will work fine.
((goto-line line) ...) will not.
> I can put other commands in the conditional and they fail, also.
You don't put them in the conditional. You put them in the
function call place of a function that you want to have as the body
of the conditional.
> > parenthesis of a non-special form. I recommend that you instead use
> > progn after the opening parenthesis. Look it up with
> >
> > C-h f progn RET
>
> progn is a special form.
> (progn BODY ...)
>
> Eval BODY forms sequentially and return value of last one.
>
> This doesn't tell me a whole lot. I get an invalid function using progn,
> also. Is it a function?
(progn (goto-line line) (goto-line line))
would be a valid form.
((goto-line line) (goto-line line))
isn't, and because of the first function call in it which is used as
if it were a function.
--
David Kastrup, Kriemhildstr. 15, 44793 Bochum
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: Newbie Conditional Problem
2003-01-17 16:52 ` David Kastrup
@ 2003-01-17 17:24 ` CarlC
0 siblings, 0 replies; 14+ messages in thread
From: CarlC @ 2003-01-17 17:24 UTC (permalink / raw)
"David Kastrup" <dak@gnu.org> wrote in message
news:x5vg0nyaza.fsf@lola.goethe.zz...
> (progn (goto-line line) (goto-line line))
>
> would be a valid form.
>
> ((goto-line line) (goto-line line))
>
> isn't, and because of the first function call in it which is used as
> if it were a function.
Thank you, David. That was very informative. Much more than progn
description.
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: Newbie Conditional Problem
2003-01-17 15:19 Newbie Conditional Problem CarlC
` (2 preceding siblings ...)
[not found] ` <x54r87zrdo.fsf@lola.goethe.zz>
@ 2003-01-17 17:42 ` Stefan Monnier <foo@acm.com>
2003-01-18 17:36 ` Kai Großjohann
4 siblings, 0 replies; 14+ messages in thread
From: Stefan Monnier <foo@acm.com> @ 2003-01-17 17:42 UTC (permalink / raw)
> (if (> (current-line) line) ((goto-line line) (end-of-line))))
In Lisp, every parenthesis counts. You can't use (...) as a grouping
mechanism to override some default precedence (after all, there is no
precedence). If you want to group two statements such as
(goto-line line) and (end-of-line) into a single statement, you
need to use (progn (goto-line line) (end-of-line)).
Stefan
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: Newbie Conditional Problem
2003-01-17 16:09 ` CarlC
@ 2003-01-18 6:27 ` Friedrich Dominicus
2003-01-18 13:35 ` Johan Bockgård
2003-01-18 13:48 ` Christopher J. White
0 siblings, 2 replies; 14+ messages in thread
From: Friedrich Dominicus @ 2003-01-18 6:27 UTC (permalink / raw)
"CarlC" <carlc@snowbd.com> writes:
> "Friedrich Dominicus" <frido@q-software-solutions.com> wrote in message
> news:87ptqvokj8.fsf@fbigm.here...
> > I guess current-line is wrong the documentation for windows start
> >
> > gives `window-start' is a built-in function
> > (window-start BUFFER &optional WHICH-FRAMES WHICH-DEVICES) and the -1
> > is probably wrong too.
> >
> > I can't see how if fits. Try this
> > (defun current-line ()
> > "Return the vertical position of point within the current buffer."
> > (+ (count-lines (point-min) (point))
> > (if (= (current-column) 0) 1 0)))
>
> I copied the current-line function out of a manual.
Anyway given the given documentation does it not make sense. The other
error you had was pointed out in other mail
(let ((line (current-line)))
(forward-word 1)
(if (> (current-line) line) ((goto-line line)
^ this is too much
(end-of-line))))
I even do not understand what you want. Do you want to go to the end
of the following line? End of the current line?
let us try to understand your code
(let ((line (current-line))) ;; this give you a simple number with my
current-line (if that is what you want)
(forward-word 1) moves forward onw word from point
(if (> (current-line) line) ;; if we moved one line down
;; assuming you meant
(progn (goto-line line) (end-of-line))))
;; this means go back one line (back to the line you started from
But what does it give you? It makes no sense. The code just moves you
to the end of the current line that is simply to call (end-of-line)
not more
So what do you want to do?
Do you want to go ot the end of a specified line? Then do
(defun goto-end-of-line (lineno)
(interactive "NWhich line should I go? ")
(goto-line lineno)
(end-of-line))
Do you want to simply get the line number you are in?
(defun which-line-am-I-in ()
(interactive)
(message (format "You are in line %d" (current-line))))
We just can help you if we know what you want to do. So if you have
programming problem than
a) show us your code
b) tell us what you expect it to do
c) tell us what's actually happening
Just then will we be able to give a suggestion.
Regards
Friedrich
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: Newbie Conditional Problem
2003-01-18 6:27 ` Friedrich Dominicus
@ 2003-01-18 13:35 ` Johan Bockgård
2003-01-18 16:59 ` Friedrich Dominicus
2003-01-18 13:48 ` Christopher J. White
1 sibling, 1 reply; 14+ messages in thread
From: Johan Bockgård @ 2003-01-18 13:35 UTC (permalink / raw)
Friedrich Dominicus <frido@q-software-solutions.com> writes:
> Do you want to simply get the line number you are in?
> (defun which-line-am-I-in ()
> (interactive)
> (message (format "You are in line %d" (current-line))))
Only there is no current-line.
Try M-x what-line.
/Johan
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: Newbie Conditional Problem
2003-01-18 6:27 ` Friedrich Dominicus
2003-01-18 13:35 ` Johan Bockgård
@ 2003-01-18 13:48 ` Christopher J. White
2003-01-18 17:03 ` Friedrich Dominicus
1 sibling, 1 reply; 14+ messages in thread
From: Christopher J. White @ 2003-01-18 13:48 UTC (permalink / raw)
>>>>> "fd" == Friedrich Dominicus <frido@q-software-solutions.com> writes:
fd> let us try to understand your code
fd> (let ((line (current-line))) ;; this give you a simple number with my
fd> current-line (if that is what you want)
fd> (forward-word 1) moves forward onw word from point
fd> (if (> (current-line) line) ;; if we moved one line down
fd> ;; assuming you meant
fd> (progn (goto-line line) (end-of-line))))
fd> ;; this means go back one line (back to the line you started from
fd> But what does it give you? It makes no sense. The code just moves you
fd> to the end of the current line that is simply to call (end-of-line)
fd> not more
As I understand it, it's a forward-word function that keeps the
cursor on the current line. If forward-word would move the cursor
beyond the current line, just go to the end of the (current) line.
Could be useful I suppose.
...cj
--
------------------------------------------------------------------------------
Christopher J. White chris@grierwhite.com
------------------------------------------------------------------------------
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: Newbie Conditional Problem
2003-01-18 13:35 ` Johan Bockgård
@ 2003-01-18 16:59 ` Friedrich Dominicus
0 siblings, 0 replies; 14+ messages in thread
From: Friedrich Dominicus @ 2003-01-18 16:59 UTC (permalink / raw)
bojohan@helm.dd.chalmers.se (Johan Bockgård) writes:
> Friedrich Dominicus <frido@q-software-solutions.com> writes:
>
> > Do you want to simply get the line number you are in?
> > (defun which-line-am-I-in ()
> > (interactive)
> > (message (format "You are in line %d" (current-line))))
>
> Only there is no current-line.
> Try M-x what-line.
Well I send an implementation of current-line too.
Regards
Friedrich
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: Newbie Conditional Problem
2003-01-18 13:48 ` Christopher J. White
@ 2003-01-18 17:03 ` Friedrich Dominicus
0 siblings, 0 replies; 14+ messages in thread
From: Friedrich Dominicus @ 2003-01-18 17:03 UTC (permalink / raw)
chris@grierwhite.com (Christopher J. White) writes:
> >>>>> "fd" == Friedrich Dominicus <frido@q-software-solutions.com> writes:
>
> fd> let us try to understand your code
>
> fd> (let ((line (current-line))) ;; this give you a simple number with my
> fd> current-line (if that is what you want)
> fd> (forward-word 1) moves forward onw word from point
> fd> (if (> (current-line) line) ;; if we moved one line down
> fd> ;; assuming you meant
> fd> (progn (goto-line line) (end-of-line))))
> fd> ;; this means go back one line (back to the line you started from
>
> fd> But what does it give you? It makes no sense. The code just moves you
> fd> to the end of the current line that is simply to call (end-of-line)
> fd> not more
>
> As I understand it, it's a forward-word function that keeps the
> cursor on the current line.
Well I suggest you try it go to the end of a line and run
M-x forward-word you'll be on the next line after the first word.
In this case
is current-line > line -> I go back one line with (goto-line) and
there I move to the end of the line if I' do not move down line
nothing will happens. So what is it if you move move forward a word
and move down a line you go back and than to the end of the current
line. That makes no sénse.
> If forward-word would move the cursor
> beyond the current line, just go to the end of the (current) line.
> Could be useful I suppose.
For what?
Friedrich
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: Newbie Conditional Problem
2003-01-17 15:19 Newbie Conditional Problem CarlC
` (3 preceding siblings ...)
2003-01-17 17:42 ` Stefan Monnier <foo@acm.com>
@ 2003-01-18 17:36 ` Kai Großjohann
4 siblings, 0 replies; 14+ messages in thread
From: Kai Großjohann @ 2003-01-18 17:36 UTC (permalink / raw)
"CarlC" <carlc@snowbd.com> writes:
> (let ((line (current-line)))
> (forward-word 1)
> (if (> (current-line) line) ((goto-line line) (end-of-line))))
How about this:
(let ((p (line-end-position)))
(forward-word 1)
(when (> (point) p) (goto-char p)))
If your Emacs does not have the function line-end-position, you can
write (save-excursion (end-of-line) (point)) instead.
--
Ambibibentists unite!
^ permalink raw reply [flat|nested] 14+ messages in thread
end of thread, other threads:[~2003-01-18 17:36 UTC | newest]
Thread overview: 14+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2003-01-17 15:19 Newbie Conditional Problem CarlC
2003-01-17 15:36 ` Friedrich Dominicus
2003-01-17 16:09 ` CarlC
2003-01-18 6:27 ` Friedrich Dominicus
2003-01-18 13:35 ` Johan Bockgård
2003-01-18 16:59 ` Friedrich Dominicus
2003-01-18 13:48 ` Christopher J. White
2003-01-18 17:03 ` Friedrich Dominicus
2003-01-17 16:19 ` Brendan Halpin
[not found] ` <x54r87zrdo.fsf@lola.goethe.zz>
2003-01-17 16:46 ` CarlC
2003-01-17 16:52 ` David Kastrup
2003-01-17 17:24 ` CarlC
2003-01-17 17:42 ` Stefan Monnier <foo@acm.com>
2003-01-18 17:36 ` Kai Großjohann
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.