@@ -1485,51 +1485,54 @@ kernel, but the prefix used by `jupyter-completion-at-point'. See
14851485MATCHES are the completion matches returned by the kernel,
14861486METADATA is any extra data associated with MATCHES that was
14871487supplied by the kernel."
1488- (let* ((matches (append matches nil ))
1489- (tail matches)
1490- ; ; TODO Handle the :start, :end, and :signature fields
1491- (types (append (plist-get metadata :_jupyter_types_experimental ) nil ))
1492- (buf))
1488+ (let (buf)
14931489 (save-current-buffer
14941490 (unwind-protect
1495- (while tail
1496- (cond
1497- ((string-match jupyter-completion-argument-regexp (car tail))
1498- (let* ((str (car tail))
1499- (args-str (match-string 1 str))
1500- (end (match-end 1 ))
1501- (path (match-string 2 str))
1502- (line (string-to-number (match-string 3 str)))
1503- (snippet (progn
1504- (unless buf
1505- (setq buf (generate-new-buffer " *temp*" ))
1506- (set-buffer buf))
1507- (insert args-str)
1508- (goto-char (point-min ))
1509- (prog1 (jupyter-completion--make-arg-snippet
1510- (jupyter-completion--arg-extract))
1511- (erase-buffer )))))
1512- (setcar tail (substring (car tail) 0 end))
1513- (put-text-property 0 1 'snippet snippet (car tail))
1514- (put-text-property 0 1 'location (cons path line) (car tail))
1515- (put-text-property 0 1 'docsig (car tail) (car tail))))
1516- ; ; TODO: This is specific to the results that
1517- ; ; the python kernel returns, make a support
1518- ; ; function?
1519- ((string-match-p " \\ ." (car tail))
1520- (setcar tail (car (last (split-string (car tail) " \\ ." ))))))
1521- (setq tail (cdr tail)))
1491+ (cl-loop
1492+ for i from 0 below (length matches)
1493+ for match = (aref matches i)
1494+ do
1495+ (put-text-property 0 1 'docsig match match )
1496+ (cond
1497+ ((string-match jupyter-completion-argument-regexp match )
1498+ (let* ((str match )
1499+ (args-str (match-string 1 str))
1500+ (end (match-end 1 ))
1501+ (path (match-string 2 str))
1502+ (line (string-to-number (match-string 3 str)))
1503+ (snippet (progn
1504+ (unless buf
1505+ (setq buf (generate-new-buffer " *temp*" ))
1506+ (set-buffer buf))
1507+ (insert args-str)
1508+ (goto-char (point-min ))
1509+ (prog1 (jupyter-completion--make-arg-snippet
1510+ (jupyter-completion--arg-extract))
1511+ (erase-buffer )))))
1512+ (setq match (aset matches i (substring match 0 end)))
1513+ (put-text-property 0 1 'snippet snippet match )
1514+ (put-text-property 0 1 'location (cons path line) match )))
1515+ ; ; TODO: This is specific to the results that
1516+ ; ; the python kernel returns, make a support
1517+ ; ; function?
1518+ ((string-match-p " \\ ." match )
1519+ (aset matches i (car (last (split-string match " \\ ." )))))))
15221520 (when buf (kill-buffer buf))))
15231521 ; ; When a type is supplied add it as an annotation
1524- (when types
1522+ (when-let* (( types ( plist-get metadata :_jupyter_types_experimental )))
15251523 (let ((max-len (apply #'max (mapcar #'length matches))))
1526- (cl-mapc
1527- (lambda (match meta )
1528- (let* ((prefix (make-string (1+ (- max-len (length match ))) ? ))
1529- (annot (concat prefix (plist-get meta :type ))))
1530- (put-text-property 0 1 'annot annot match )))
1531- matches types)))
1532- matches))
1524+ (cl-loop
1525+ for i from 0 below (length matches)
1526+ for match = (aref matches i)
1527+ for meta = (aref types i)
1528+ do (let* ((prefix (make-string (1+ (- max-len (length match ))) ?\s ))
1529+ (annot (concat prefix (plist-get meta :type )))
1530+ (sig (plist-get meta :signature )))
1531+ (put-text-property
1532+ 0 1 'docsig
1533+ (concat (get-text-property 0 'docsig match ) sig) match )
1534+ (put-text-property 0 1 'annot annot match )))))
1535+ (append matches nil )))
15331536
15341537; ;;;; Completion at point interface
15351538
0 commit comments