Function: symbol-under-point

symbol-under-point is a byte-compiled function defined in completion.el.gz.

Signature

(symbol-under-point)

Documentation

Return the symbol that the point is currently on.

But only if it is longer than completion-min-length.

Source Code

;; Defined in /usr/src/emacs/lisp/completion.el.gz
(defun symbol-under-point ()
  "Return the symbol that the point is currently on.
But only if it is longer than `completion-min-length'."
  (with-syntax-table completion-syntax-table
    (when (memq (char-syntax (following-char)) '(?w ?_))
      ;; Cursor is on following-char and after preceding-char
      (let ((saved-point (point)))
        (setq cmpl-symbol-start (scan-sexps (1+ saved-point) -1)
              cmpl-symbol-end (scan-sexps saved-point 1))
        ;; Remove chars to ignore at the start.
        (cond ((= (char-syntax (char-after cmpl-symbol-start)) ?w)
               (goto-char cmpl-symbol-start)
               (forward-word-strictly 1)
               (setq cmpl-symbol-start (point))
               (goto-char saved-point)))
        ;; Remove chars to ignore at the end.
        (cond ((= (char-syntax (char-after (1- cmpl-symbol-end))) ?w)
               (goto-char cmpl-symbol-end)
               (forward-word-strictly -1)
               (setq cmpl-symbol-end (point))
               (goto-char saved-point)))
        ;; Return completion if the length is reasonable.
        (if (and (<= completion-min-length
                     (- cmpl-symbol-end cmpl-symbol-start))
                 (<= (- cmpl-symbol-end cmpl-symbol-start)
                     completion-max-length))
            (buffer-substring-no-properties
             cmpl-symbol-start cmpl-symbol-end))))))