Here is what I want to do: I want to find out, where the cursor is
before I insert some text: if it is at the end of a line I ensure
that it is here (end-of-line), write a new line (new-line) go to
the beginning of that line. This function is supposed to be called
by those functions that must insert text at the beginning
line.
(defun g-where ()
"Determines where we are"
(interactive)
(if (bolp) ; at the end of a line ?
()
((end-of-line)
(new-line)
(beginning-of-line))))
The code is certainly somewhat crude as it is one of my first
emacs-functions I wrote.
1. C-h f if
,----
| if is a special form in `C source code'.
|
| (if COND THEN ELSE...)
|
| If COND yields non-nil, do THEN, else do ELSE...
| Returns the value of THEN or the value of the last of the ELSE's.
| THEN must be one expression, but ELSE... can be zero or more expressions.
| If COND yields nil, and there are no ELSE's, the value is nil.
|
`----
You are using (if COND THEN (ELSE...)), not (if COND THEN ELSE...).
2. No such function: `new-line'.
If you just want to insert a newline unless point is at the beginning of the
line (and do nothing otherwise), then just do that:
(defun foo ()
(interactive)
(unless (bolp) (insert "\n")))
Or if you want the return value to let you know whether you were at bolp to
begin with, then:
(defun foo ()
(interactive)
(if (bolp)
nil ; We were at bolp
(insert "\n")
t)) ; We weren't at bolp