@@ -31,10 +31,41 @@ If SUB is not found in FULL, returns nil."
3131 ; ; Extract the suffix (from end of match to end of full)
3232 (suffix (substring full end nil )))
3333 ; ; Return the list of (prefix sub suffix)
34- (list sub prefix suffix))
34+ (list (pf-complete-ann sub full)
35+ (pf-complete-ann prefix full)
36+ (pf-complete-ann suffix full)
37+ ; ; sub prefix suffix
38+ ))
3539 ; ; Substring not found, return nil
3640 nil )))
3741
42+ (defun pf-longest-common-substring-containing (sub strings )
43+ " return STRINGS lcs,containing SUB。"
44+ (when (< (length strings) 1 )
45+ (error " need at least on string in STRINGS " ))
46+
47+ (let ((result " " )
48+ (first-str (car strings))
49+ (other-strs (cdr strings)))
50+
51+ ; ; gen candiates from first string and check
52+ (dotimes (start (length first-str))
53+ (dotimes (len (- (length first-str) start))
54+ (let ((current-len (- (length first-str) start len))
55+ (candidate (substring first-str start (- (length first-str) len))))
56+ (when (and (>= current-len (length result))
57+ (string-match-p (regexp-quote sub) candidate)
58+ (cl-every (lambda (s )
59+ (string-match-p (regexp-quote candidate) s))
60+ other-strs))
61+ (setq result candidate)))))
62+
63+ (if (> (length result) 0 ) result nil )))
64+
65+ (defun pf-anno (sub full )
66+ " anno to make completions UI workd"
67+ (list full " " " " ))
68+
3869(defun pf-ffp1-buffer (dir s )
3970 (let ((this-try (concat dir s)))
4071 (if (file-exists-p this-try)
@@ -46,13 +77,14 @@ If SUB is not found in FULL, returns nil."
4677 nil ))))
4778
4879(defun pf-loclist ()
49- (let ((pf-list-buf (pf-ffp1-buffer default-directory " full_list.txt " )))
80+ (let ((pf-list-buf (pf-ffp1-buffer default-directory pf-list-name )))
5081 (switch-to-buffer (current-buffer ))
5182 (if (not (eq pf-list-buf (current-buffer )))
5283 pf-list-buf
5384 nil )))
5485
5586(defconst pf-limit 50 " limit the search count of pf-find" )
87+ (defconst pf-list-name " full_list.txt" " my custom file for pf-find to find and search" )
5688
5789(defun pf-head-col (buf word )
5890 (save-excursion
@@ -85,11 +117,31 @@ If SUB is not found in FULL, returns nil."
85117 (seq-filter pred ret)
86118 ret)))
87119
120+ (defun pf-complete-ann (cand full )
121+ (message " [%s ] in [%s ] " cand full)
122+ ; ; cand)
123+ (if (and full cand (stringp cand) (stringp full) (> (length cand) 1 ))
124+ (progn
125+ (message " put [%s ] in [%s ] " cand full)
126+ (put-text-property
127+ 1 (length cand)
128+ 'completion--string (substring-no-properties full)
129+ cand)
130+ cand)
131+ cand))
132+
133+ ; ; (defun pf-make-complete-aff (v)
134+ ; ; (lambda (completions)
135+ ; ; ;; (message "[[%s]]" completions)
136+ ; ; (seq-filter 'identity
137+ ; ; (mapcar (lambda (x)
138+ ; ; ;; (lambda (cand) (pf-complete-ann cand x)) ;; 'identity
139+ ; ; ;; (pf-split-string-by-substring v x)
140+ ; ; (pf-anno v x)
141+ ; ; )
142+ ; ; completions))))
88143(defun pf-make-complete-aff (v )
89- (lambda (completions )
90- ; ; (message "[[%s]]" completions)
91- (seq-filter 'identity
92- (mapcar (lambda (x ) (pf-split-string-by-substring v x)) completions))))
144+ #'identity )
93145
94146(defun pf-make-complete-colfun (ctx )
95147 (lambda (rstring pred flag )
@@ -99,6 +151,7 @@ If SUB is not found in FULL, returns nil."
99151 (cond ((eq ret nil ) nil )
100152 ((and (eq (length ret) 1 ) (eq (car ret) rstring)) t )
101153 ((eq (length ret) 1 ) (car ret))
154+ ((< (length ret) (1- pf-limit)) (pf-longest-common-substring-containing rstring ret))
102155 (t rstring))))
103156 ((eq flag t )
104157 (pf-complete-test rstring pred ctx))
@@ -114,7 +167,7 @@ If SUB is not found in FULL, returns nil."
114167 ; ; `((affixation-function
115168 ; ; . ,(pf-make-complete-aff rstring)))))
116169 (cons 'metadata `((affixation-function
117- . ,(pf-make-complete-aff rstring)))))
170+ . ,(pf-make-complete-aff rstring)))))
118171 ; ; (cons 'metadata `((affixation-function
119172 ; ; . ,#'make-complete-col-aff-fun))))
120173 ((and (consp flag) (eq (car flag) 'boundaries ))
@@ -123,6 +176,6 @@ If SUB is not found in FULL, returns nil."
123176
124177(defun pf-find ()
125178 (interactive )
126- (pf-fffp (completing-read " : " (pf-make-complete-colfun '()))))
179+ (pf-fffp (completing-read " PF:: " (pf-make-complete-colfun '()))))
127180
128181; ;; (global-set-key (kbd "C-c p") 'pf-find)
0 commit comments