Function: c-point
c-point is a macro defined in cc-defs.el.gz.
Signature
(c-point POSITION &optional POINT)
Documentation
Return the value of certain commonly referenced POSITIONs relative to POINT.
The current point is used if POINT isn't specified. POSITION can be one of the following symbols:
bol -- beginning of line
boll -- beginning of logical line (i.e. without preceding escaped NL)
eol -- end of line
eoll -- end of logical line (i.e. without escaped NL)
bod -- beginning of defun
eod -- end of defun
boi -- beginning of indentation
ionl -- indentation of next line
iopl -- indentation of previous line
bonl -- beginning of next line
eonl -- end of next line
bopl -- beginning of previous line
eopl -- end of previous line
bosws -- beginning of syntactic whitespace
eosws -- end of syntactic whitespace
If the referenced position doesn't exist, the closest accessible point to it is returned. This function does not modify the point or the mark.
Source Code
;; Defined in /usr/src/emacs/lisp/progmodes/cc-defs.el.gz
(defmacro c-point (position &optional point)
"Return the value of certain commonly referenced POSITIONs relative to POINT.
The current point is used if POINT isn't specified. POSITION can be
one of the following symbols:
`bol' -- beginning of line
`boll' -- beginning of logical line (i.e. without preceding escaped NL)
`eol' -- end of line
`eoll' -- end of logical line (i.e. without escaped NL)
`bod' -- beginning of defun
`eod' -- end of defun
`boi' -- beginning of indentation
`ionl' -- indentation of next line
`iopl' -- indentation of previous line
`bonl' -- beginning of next line
`eonl' -- end of next line
`bopl' -- beginning of previous line
`eopl' -- end of previous line
`bosws' -- beginning of syntactic whitespace
`eosws' -- end of syntactic whitespace
If the referenced position doesn't exist, the closest accessible point
to it is returned. This function does not modify the point or the mark."
(declare (debug t))
(if (eq (car-safe position) 'quote)
(let ((position (eval position)))
(cond
((eq position 'bol)
(if (and (cc-bytecomp-fboundp 'line-beginning-position) (not point))
'(line-beginning-position)
`(save-excursion
,@(if point `((goto-char ,point)))
(beginning-of-line)
(point))))
((eq position 'boll)
`(save-excursion
,@(if point `((goto-char ,point)))
(while (progn (beginning-of-line)
(when (not (bobp))
(eq (char-before (1- (point))) ?\\)))
(backward-char))
(point)))
((eq position 'eol)
(if (and (cc-bytecomp-fboundp 'line-end-position) (not point))
'(line-end-position)
`(save-excursion
,@(if point `((goto-char ,point)))
(end-of-line)
(point))))
((eq position 'eoll)
`(save-excursion
,@(if point `((goto-char ,point)))
(while (and
(not (eobp))
(progn
(end-of-line)
(c-is-escaped (point))
;; (prog1 (eq (logand 1 (skip-chars-backward "\\\\")) 1))
))
(forward-line))
(end-of-line)
(point)))
((eq position 'boi)
`(save-excursion
,@(if point `((goto-char ,point)))
(back-to-indentation)
(point)))
((eq position 'bod)
`(save-excursion
,@(if point `((goto-char ,point)))
(c-beginning-of-defun-1)
(point)))
((eq position 'eod)
`(save-excursion
,@(if point `((goto-char ,point)))
(c-end-of-defun-1)
(point)))
((eq position 'bopl)
(if (and (cc-bytecomp-fboundp 'line-beginning-position) (not point))
'(line-beginning-position 0)
`(save-excursion
,@(if point `((goto-char ,point)))
(forward-line -1)
(point))))
((eq position 'bonl)
(if (and (cc-bytecomp-fboundp 'line-beginning-position) (not point))
'(line-beginning-position 2)
`(save-excursion
,@(if point `((goto-char ,point)))
(forward-line 1)
(point))))
((eq position 'eopl)
(if (and (cc-bytecomp-fboundp 'line-end-position) (not point))
'(line-end-position 0)
`(save-excursion
,@(if point `((goto-char ,point)))
(beginning-of-line)
(or (bobp) (backward-char))
(point))))
((eq position 'eonl)
(if (and (cc-bytecomp-fboundp 'line-end-position) (not point))
'(line-end-position 2)
`(save-excursion
,@(if point `((goto-char ,point)))
(forward-line 1)
(end-of-line)
(point))))
((eq position 'iopl)
`(save-excursion
,@(if point `((goto-char ,point)))
(forward-line -1)
(back-to-indentation)
(point)))
((eq position 'ionl)
`(save-excursion
,@(if point `((goto-char ,point)))
(forward-line 1)
(back-to-indentation)
(point)))
((eq position 'bosws)
`(save-excursion
,@(if point `((goto-char ,point)))
(c-backward-syntactic-ws)
(point)))
((eq position 'eosws)
`(save-excursion
,@(if point `((goto-char ,point)))
(c-forward-syntactic-ws)
(point)))
(t (error "Unknown buffer position requested: %s" position))))
;; The bulk of this should perhaps be in a function to avoid large
;; expansions, but this case is not used anywhere in CC Mode (and
;; probably not anywhere else either) so we only have it to be on
;; the safe side.
(message "Warning: c-point long expansion")
`(save-excursion
,@(if point `((goto-char ,point)))
(let ((position ,position))
(cond
((eq position 'bol) (beginning-of-line))
((eq position 'eol) (end-of-line))
((eq position 'boi) (back-to-indentation))
((eq position 'bod) (c-beginning-of-defun-1))
((eq position 'eod) (c-end-of-defun-1))
((eq position 'bopl) (forward-line -1))
((eq position 'bonl) (forward-line 1))
((eq position 'eopl) (progn
(beginning-of-line)
(or (bobp) (backward-char))))
((eq position 'eonl) (progn
(forward-line 1)
(end-of-line)))
((eq position 'iopl) (progn
(forward-line -1)
(back-to-indentation)))
((eq position 'ionl) (progn
(forward-line 1)
(back-to-indentation)))
((eq position 'bosws) (c-backward-syntactic-ws))
((eq position 'eosws) (c-forward-syntactic-ws))
(t (error "Unknown buffer position requested: %s" position))))
(point))))