Changeset 29241

Show
Ignore:
Timestamp:
01/29/09 20:12:40 (4 years ago)
Author:
imakado
Message:

Merge branch 'get-functions-command-async'

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • lang/elisp/php-completion/trunk/php-completion.el

    r29240 r29241  
    100100    (init . (lambda () 
    101101              (with-current-buffer (anything-candidate-buffer 'global) 
    102                 (insert (mapconcat 'identity phpcmp-functions "\n"))))) 
     102                (insert (mapconcat 'identity (phpcmp-get-functions) "\n"))))) 
    103103    (candidates-in-buffer) 
    104104    (type . php-completion) 
     
    169169            (phpcmp-get-initial-input))) 
    170170 
     171 
     172(defvar phpcmp-get-functions-async-buffer-name " *php-completion functions*") 
     173(lexical-let (functions) 
     174  (defun phpcmp-get-functions () 
     175    (or functions 
     176        (prog1 phpcmp-functions 
     177          (phpcmp-async-set-functions)))) 
     178 
     179  (defun phpcmp-clear-functions () 
     180    (setq functions nil)) 
     181 
     182  (defun phpcmp-async-set-functions () 
     183    (or functions 
     184        (let* ((buf-name phpcmp-get-functions-async-buffer-name) 
     185               (process-running? (eq 'run 
     186                                     (let ((proc (get-buffer-process buf-name))) 
     187                                       (when (processp proc) 
     188                                         (process-status proc))))) 
     189               (php-command (executable-find "php"))) 
     190          (when (and (not (phpcmp-tramp-p)) 
     191                     (not process-running?) 
     192                     php-command) 
     193            (phpcmp-async-do 
     194             :buffer-name buf-name 
     195             :command php-command 
     196             :args '("-r" 
     197                     "foreach (get_defined_functions() as $vars) { foreach ($vars as $var) {echo \"$var\n\";}}") 
     198             :callback (lambda () 
     199                         (setq functions (phpcmp-collect-matches "[[:print:]]+"))))))))) 
     200 
     201(defun phpcmp-tramp-p () 
     202  (when (and (featurep 'tramp) 
     203             (fboundp 'tramp-tramp-file-p)) 
     204    (tramp-tramp-file-p (phpcmp-get-current-directory)))) 
     205 
     206(defun phpcmp-get-current-directory () 
     207  (file-name-directory 
     208   (expand-file-name 
     209    (or (buffer-file-name) 
     210        default-directory)))) 
     211 
     212(defun* phpcmp-collect-matches 
     213    (re &optional (count 0) (match-string-fn 'match-string) 
     214        (point-min (point-min)) (point-max (point-max))) 
     215  (save-excursion 
     216    (loop initially (goto-char point-min) 
     217          while (re-search-forward re point-max t) 
     218          collect (funcall match-string-fn count)))) 
     219 
     220(defun* phpcmp-async-do 
     221    (&key command args buffer-name 
     222          (callback 'identity) 
     223          (errorback (lambda() (message (buffer-string))))) 
     224  (lexical-let ((buf (get-buffer-create buffer-name)) 
     225                (callback callback) 
     226                (errorback errorback)) 
     227    (lexical-let 
     228      ((sentinel (lambda (proc event) 
     229         (cond ((and (string= event "finished\n") 
     230                     (= (process-exit-status proc) 0)) 
     231                (with-current-buffer buf 
     232                  (funcall callback))) 
     233               ((and (string= event "finished\n") 
     234                     (/= (process-exit-status proc) 0)) 
     235                (with-current-buffer buf 
     236                  (funcall errorback))))))) 
     237      (set-process-sentinel (apply 'start-process command buf command args) sentinel)))) 
     238 
    171239(defun phpcmp-search-manual (query) 
    172240  (let ((url (phpcmp-search-url query))) 
     
    185253 
    186254(defun phpcmp-build-cands () 
    187   (let ((los (phpcmp-get-cands))) 
    188     (phpcmp-build-cands1 los))) 
     255  (all-completions ac-target (phpcmp-get-cands))) 
    189256 
    190257(defun phpcmp-build-cands-patial () 
    191258  (let ((los (phpcmp-get-cands))) 
    192     (phpcmp-build-cands1 
    193      los 
    194      (lambda (s) 
    195        (and (stringp s) 
    196             (string-match ac-target s) 
    197             (not (string= ac-target s))))))) 
     259    (append (all-completions ac-target los) 
     260            (phpcmp-build-cands1 los)))) 
    198261 
    199 (defun* phpcmp-build-cands1 
    200     (los &optional (filter 
    201                     (lambda (s) 
    202                       (and (stringp s) 
    203                            (string-match (concat "^" ac-target) s) 
    204                            (not (string= ac-target s)))))) 
    205   (loop for s in los 
    206         when (funcall filter s) 
    207         collect s)) 
     262(defun phpcmp-build-cands1 (los) 
     263  (let ((match (lambda (s) 
     264                 (and (stringp s) 
     265                      (string-match ac-target s) 
     266                      (not (string= ac-target s)))))) 
     267    (remove-if-not match los))) 
    208268 
    209269(defun phpcmp-get-cands () 
    210270  (append phpcmp-types 
    211           phpcmp-functions 
     271          (phpcmp-get-functions) 
    212272          phpcmp-constants 
    213273          phpcmp-keywords