I have written a function snippet that copies a paragraph to the kill-ring
. I try to collect different point positions and corresponding line numbers:
bop
- begin of paragraphblnum
- line umber of the paragraph begineop
- end of paragraphelnum
- line number of the paragraph ending
...see below code
and store them in some variable via setq
. I know that I'm using here a global variable context in a false way. What is the equivalent code using a local variables scope only?
To be clear, none of variables (bop, eop, blnum, elnum
) will be used outside of the function context.
CODE
(defun my/copy-paragraph ()
"Copy a paragraph to the kill ring."
(interactive)
(backward-paragraph)
(setq bop (point))
(setq blnum (line-number-at-pos))
(forward-paragraph)
(setq elnum (line-number-at-pos))
(setq eop (point))
(kill-ring-save bop eop)
(move-beginning-of-line nil)
(forward-line)
(message "Copy paragraph from '%s' line %d - %d to kill-ring "
(buffer-name) blnum elnum))