Function: completion--insert-horizontal

completion--insert-horizontal is a byte-compiled function defined in minibuffer.el.gz.

Signature

(completion--insert-horizontal STRINGS GROUP-FUN LENGTH WWIDTH COLWIDTH COLUMNS)

Source Code

;; Defined in /usr/src/emacs/lisp/minibuffer.el.gz
(defun completion--insert-horizontal (strings group-fun
                                              length wwidth
                                              colwidth _columns)
  (let ((column 0)
        (first t)
	(last-title nil)
        (last-string nil))
    (dolist (str strings)
      (unless (equal last-string str) ; Remove (consecutive) duplicates.
	(setq last-string str)
        (when group-fun
          (let ((title (funcall group-fun (if (consp str) (car str) str) nil)))
            (unless (equal title last-title)
              (setq last-title title)
              (when title
                (insert (if first "" "\n") (format completions-group-format title) "\n")
                (setq column 0
                      first t)))))
	(unless first
          ;; FIXME: `string-width' doesn't pay attention to
          ;; `display' properties.
	  (if (< wwidth (+ column (max colwidth
                                       (if (consp str)
                                           (apply #'+ (mapcar #'string-width str))
                                         (string-width str)))))
	      ;; No space for `str' at point, move to next line.
	      (progn (insert "\n") (setq column 0))
	    (insert " \t")
	    ;; Leave the space unpropertized so that in the case we're
	    ;; already past the goal column, there is still
	    ;; a space displayed.
	    (set-text-properties (1- (point)) (point)
				 ;; We can set tab-width using
				 ;; completion-tab-width, but
				 ;; the caller can prefer using
				 ;; \t to align prefixes.
				 `(display (space :align-to ,column)))
	    nil))
        (setq first nil)
        (completion--insert str group-fun)
	;; Next column to align to.
	(setq column (+ column
			;; Round up to a whole number of columns.
			(* colwidth (ceiling length colwidth))))))))