Function: sql-copy-column
sql-copy-column is an interactive and byte-compiled function defined
in sql.el.gz.
Signature
(sql-copy-column)
Documentation
Copy current column to the end of buffer.
Inserts SELECT or commas if appropriate.
Key Bindings
Source Code
;; Defined in /usr/src/emacs/lisp/progmodes/sql.el.gz
(defun sql-copy-column ()
"Copy current column to the end of buffer.
Inserts SELECT or commas if appropriate."
(interactive)
(let ((column))
(save-excursion
(setq column (buffer-substring-no-properties
(progn (forward-char 1) (backward-sexp 1) (point))
(progn (forward-sexp 1) (point))))
(goto-char (point-max))
(let ((bol (comint-line-beginning-position)))
(cond
;; if empty command line, insert SELECT
((= bol (point))
(insert "SELECT "))
;; else if appending to INTO .* (, SELECT or ORDER BY, insert a comma
((save-excursion
(re-search-backward "\\b\\(\\(into\\s-+\\S-+\\s-+(\\)\\|select\\|order by\\) .+"
bol t))
(insert ", "))
;; else insert a space
(t
(if (eq (preceding-char) ?\s)
nil
(insert " ")))))
;; in any case, insert the column
(insert column)
(message "%s" column))))