Function: corfu-popupinfo--get-location

corfu-popupinfo--get-location is a byte-compiled function defined in corfu-popupinfo.el.

Signature

(corfu-popupinfo--get-location CANDIDATE)

Documentation

Get source at location of CANDIDATE.

Source Code

;; Defined in ~/.emacs.d/elpa/corfu-20260813.950/corfu-popupinfo.el
(defun corfu-popupinfo--get-location (candidate)
  "Get source at location of CANDIDATE."
  (save-excursion
    (let ((old-buffers (buffer-list)) (buffer nil))
      (unwind-protect
          (when-let
              ((fun (corfu--metadata-get 'company-location))
               ;; BUG: company-location may throw errors if location is not found
               (loc (ignore-errors (funcall fun candidate)))
               ((setq buffer
                      (or (and (bufferp (car loc)) (car loc))
                          (get-file-buffer (car loc))
                          (let ((inhibit-message t)
                                (message-log-max nil)
                                (inhibit-redisplay t)
                                (enable-dir-local-variables nil)
                                (enable-local-variables :safe)
                                (non-essential t)
                                (delay-mode-hooks t)
                                (find-file-hook
                                 (list
                                  (static-if (>= emacs-major-version 30)
                                      'global-font-lock-mode-enable-in-buffer
                                    'global-font-lock-mode-check-buffers))))
                            (find-file-noselect (car loc) t))))))
            (with-current-buffer buffer
              (save-excursion
                (without-restriction
                  (goto-char (point-min))
                  (when-let* ((pos (cdr loc)))
                    (if (bufferp (car loc))
                        (goto-char pos)
                      (forward-line (1- pos))))
                  (let ((beg (point)))
                    ;; Support a little bit of scrolling.
                    (forward-line (* 10 corfu-popupinfo-max-height))
                    (when jit-lock-mode
                      (jit-lock-fontify-now beg (point)))
                    (let ((res (buffer-substring beg (point))))
                      (and (not (string-blank-p res)) res)))))))
        (when (and (bound-and-true-p hl-line-mode) (fboundp 'hl-line-highlight))
          (hl-line-highlight))
        (when (and buffer (not (memq buffer old-buffers)))
          (kill-buffer buffer))))))