Changeset 19304 for lang/elisp
- Timestamp:
- 09/15/08 01:18:36 (5 years ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
lang/elisp/perl-completion/branch/1.0/perl-completion.el
r19252 r19304 37 37 ;; TODO: 38 38 ;; set-perl5lib 39 39 ;; open doc -> occur 40 40 41 41 ;;;code: … … 46 46 (require 'rx) 47 47 48 49 50 48 51 (defgroup perl-completion nil 49 52 "" … … 60 63 (regexp ,plcmp-perl-ident-re))))) 61 64 62 (defvar plcmp-perl-package-re "[a-zA-Z 0-9:]+")65 (defvar plcmp-perl-package-re "[a-zA-Z:]+") 63 66 64 67 (defvar plcmp-builtin-functions … … 122 125 123 126 ;;; macros 127 128 ;; perl5 lib 129 ;; idea: http://svn.coderepos.org/share/lang/elisp/set-perl5lib/set-perl5lib.el 130 ;; http://d.hatena.ne.jp/sun-basix/20080117/1200528765 (Japanese) 131 ; (buffer-file-name default-directory 132 (defcustom plcmp-lib-directory-re "lib/" 133 "regexp, used in `plcmp--get-lib-path' to get library path. 134 eg, when directory of buffer is \"~/someproject/lib/hoge.pm\" and this value is \"lib/\" 135 set \"~/someproject/lib\" to PERL5LIB automatically during perl-completion's command invocation." 136 :group 'perl-completion) 137 138 (defvar plcmp-additional-lib-directories nil 139 "list of string(directory),each directory set to PERL5LIB during perl-completion's command invocation. 140 this variable is buffer local") ;buffer local 141 (make-variable-buffer-local 'plcmp-additional-lib-directories) 142 143 (defun plcmp-cmd-set-additional-lib-directory () 144 "ask directory, then set directory to `plcmp-additional-lib-directories'" 145 (interactive) 146 (let* ((dir (read-directory-name "set to PERL5LIB(this buffer only): " nil nil t)) 147 (dir (directory-file-name dir))) 148 (when (and (stringp dir) 149 (file-exists-p dir)) 150 (add-to-list 'plcmp-additional-lib-directories dir) 151 (message "added %s to PERL5LIB" dir)))) 152 153 (defun plcmp--get-lib-path () 154 "return string(additional library path)" 155 (let ((dir (plcmp-get-current-directory)) 156 (lib-re (rx-to-string `(and (group 157 bol 158 (* not-newline) 159 ,plcmp-lib-directory-re))))) 160 (when (string-match lib-re dir) 161 (let ((lib-dir (match-string 1 dir))) 162 (and (stringp lib-dir) 163 (file-exists-p lib-dir) 164 (directory-file-name lib-dir)))))) 165 166 (defmacro plcmp-with-set-perl5-lib (&rest body) 167 "Set each path that value of `plcmp--get-lib-path' to PERL5LIB. 168 then execute BODY" 169 `(let ((process-environment (copy-sequence process-environment))) 170 (require 'env) 171 (let ((additional-lib-list (append plcmp-additional-lib-directories 172 (when (plcmp--get-lib-path) 173 (list (plcmp--get-lib-path))))) 174 (old-perl5lib (or (getenv "PERL5LIB") ""))) 175 (when additional-lib-list 176 (let* ((additional-lib-str (mapconcat 'identity additional-lib-list path-separator)) 177 (current-perl5lib (concat additional-lib-str path-separator old-perl5lib))) 178 (when (and (stringp current-perl5lib) 179 (not (equal "" current-perl5lib))) 180 (setenv "PERL5LIB" current-perl5lib) 181 (plcmp-log "plcmp-with-set-perl5-lib PERL5LIB: %s" current-perl5lib)) 182 (progn 183 ,@body)))))) 184 185 124 186 (defmacro define-plcmp-command (command-name-with-no-prefix args &rest body) 125 187 (let* ((prefix "plcmp-cmd-") … … 129 191 (interactive) 130 192 (unwind-protect 131 (p rogn (plcmp-initialize-variables)132 (progn133 ,@body))193 (plcmp-with-set-perl5-lib 194 (progn (plcmp-initialize-variables) 195 ,@body)) 134 196 (plcmp-cleanup))))) 135 197 (put 'define-plcmp-command 'lisp-indent-function 'defun) … … 157 219 158 220 (defsubst plcmp-notfound-p (s) 159 (string-match "^Can't locate [^ \t]+ in" s)) 221 (anything-aif (string-match "^Can't locate [^ \t]+ in" s) 222 (prog1 it 223 (plcmp-log "module notfound errmsg: %s" s)))) 160 224 161 225 (defsubst plcmp-tramp-p () 162 226 (when (and (featurep 'tramp) 163 227 (fboundp 'tramp-tramp-file-p)) 164 (tramp-tramp-file-p (plcmp-get-current-directory)))) 228 (let* ((dir (plcmp-get-current-directory)) 229 (tramp? (tramp-tramp-file-p dir))) 230 (when tramp? 231 (prog1 tramp? 232 (plcmp-log "plcmp-tramp-p return non-nil: %s" dir)))))) 165 233 166 234 (defsubst plcmp-insert-each-line (los) … … 192 260 collect source into unmatch-sources 193 261 finally (return (nconc match-sources unmatch-sources)))) 194 (error sources))) 195 ;;(plcmp-re-sort-sources "variable" (plcmp-get-sources-for-complete-all)) 196 197 (defun* plcmp-collect-matches 262 (error (plcmp-log "Error: plcmp-re-sort-sources\nregexps: %s\nsources: %s" 263 regexps 264 sources) 265 sources))) 266 267 (defsubst* plcmp-collect-matches 198 268 (re &optional (count 0) (match-string-fn 'match-string) 199 269 (point-min (point-min)) (point-max (point-max))) … … 202 272 while (re-search-forward re point-max t) 203 273 collect (funcall match-string-fn count)))) 274 275 (defun plcmp-get-occur-fn () 276 "return `occur-by-moccur if installed color-moccur.el otherwise return `occur" 277 (if (require 'color-moccur nil t) 278 'occur-by-moccur 279 'occur)) 280 204 281 205 282 ;;; log … … 210 287 (defun plcmp-log (&rest messages) 211 288 (ignore-errors 212 (let* ((str (or (ignore-errors (apply 'format messages)) 213 (prin1-to-string messages))) 214 (strn (concat str "\n"))) 215 (when plcmp-debug 289 (when plcmp-debug 290 (require 'pp) 291 (let* ((str (or (ignore-errors (apply 'format messages)) 292 (pp-to-string messages))) 293 (strn (concat str "\n"))) 216 294 (with-current-buffer (plcmp-log-buf) 217 295 (goto-char (point-max)) 218 (insert strn)) )219 str)))296 (insert strn)) 297 str)))) 220 298 (defun plcmp-message (&rest args) 221 299 (when plcmp-debug 222 (apply 'message args))) 300 (prog1 (apply 'message args) 301 (apply 'plcmp-log args)))) 223 302 224 303 … … 233 312 (end (condition-case e 234 313 (cond 235 ((some (lambda (s) (string-equal s preceding-string)) '("$" "@" " &" "&"))314 ((some (lambda (s) (string-equal s preceding-string)) '("$" "@" "%" "&")) 236 315 (backward-char) 237 316 (point)) … … 247 326 " " 248 327 ""))))) 249 (values initial-input real-initial-input))))) 328 (prog1 (values initial-input real-initial-input) 329 (plcmp-log "plcmp-get-initial-real-input-list:\ninitial-input: %s\nreal-initial-input: %s" 330 initial-input 331 real-initial-input)))))) 250 332 251 333 ;;; installed modules … … 281 363 (unless (zerop (buffer-size)) 282 364 (setq plcmp-installed-modules (plcmp-collect-matches plcmp-perl-package-re)) 283 (plcmp-message "cached installed modules %s" plcmp-installed-modules))))) 365 (message "finished getting installed modules asynchronously.") 366 (plcmp-log "cached installed modules %s" plcmp-installed-modules))))) 284 367 285 368 (defun plcmp--installed-modules-asynchronously () … … 301 384 proc)) 302 385 303 ;; (plcmp--installed-modules-asynchronously) 304 305 306 ;; todo: ne (length plcmp--installed-modules-synchronously) 307 (defun plcmp--installed-modules-perl () 308 (let* ((str (shell-command-to-string (concat " perl -e ' use File::Find; @dirs = grep { q{.} ne $_} @INC" 309 "; my $dir_name = $dir" 310 " ;my $mods = sub { if ( -f && /.pm$/ ) { print $File::Find::name, \"\n\"; } }; find $mods, @dirs; ' "))) 311 (files (delete-dups (delete "" (delete "." (split-string str "\n")))))) 312 (loop for file in files 313 collect (plcmp--package-name file)))) 314 315 (defun plcmp--package-name (file) 316 (let ((re (rx-to-string `(and "package" 317 (+ space) 318 (group 319 (regexp ,plcmp-perl-package-re)) 320 (* space) 321 ";" 322 )))) 323 (when (and (stringp file) 324 (file-exists-p file) 325 (file-readable-p file)) 326 (with-temp-buffer 327 (insert-file-contents file) 328 (goto-char (point-min)) 329 (when (re-search-forward re nil t) 330 (match-string-no-properties 1)))))) 331 386 332 387 ;;; current package 333 388 (defvar plcmp-current-package-name "") … … 345 400 (goto-char (point-min)) 346 401 (when (re-search-forward re nil t) 347 (setq plcmp-current-package-name 348 (match-string-no-properties 1)))))) 402 (match-string-no-properties 1))))) 349 403 350 404 (defvar plcmp-using-modules nil) … … 401 455 (plcmp-collect-matches plcmp-sub-re 1 'match-string-no-properties)) 402 456 457 (defun plcmp-get-module-file-path (module-name) 458 (let* ((path (shell-command-to-string (concat "perldoc -l " (shell-quote-argument module-name)))) 459 (path (plcmp-trim path))) 460 (and (file-exists-p path) 461 path))) 462 403 463 (defun plcmp--inspect-module-scrape (module-name) 404 464 (when (and (stringp module-name) 405 465 (plcmp-module-p module-name)) 406 (let* ((path (shell-command-to-string (concat "perldoc -l " 407 module-name))) 408 (path (plcmp-trim path))) 466 (let* ((path (plcmp-get-module-file-path module-name))) 409 467 (when (and (stringp path) 410 468 (file-exists-p path) … … 415 473 416 474 (defsubst plcmp--inspect-module (module-name) 417 (or (plcmp--inspect-module-class-inspector module-name) 418 (plcmp--inspect-module-scrape module-name))) 475 (prog1 (or (plcmp--inspect-module-class-inspector module-name) 476 (plcmp--inspect-module-scrape module-name)) 477 (message "getting methods %s ..." module-name))) 419 478 420 479 … … 429 488 430 489 ;; module-name -> source 490 (defvar plcmp--mk-module-source-name " Methods") 491 431 492 (defun plcmp--mk-module-source (module-name) 432 493 (anything-aif (assoc-default module-name plcmp-module-methods-alist) 433 `((name . ,(concat module-name " Methods"))434 (type . plcmp-completion )494 `((name . ,(concat module-name plcmp--mk-module-source-name)) 495 (type . plcmp-completion-method) 435 496 (init . (lambda () 436 497 (with-current-buffer (anything-candidate-buffer 'global) … … 482 543 (hash . (list of hashes)) 483 544 (functions . (list of functions)))") 484 (add-hook 'plcmp--command-cleanup-hook (lambda () (setq plcmp-current-buffer-words-alist nil))) 485 486 ;; (with-current-buffer "Plagger.pm" 487 ;; (plcmp-get-face-words '(font-lock-variable-name-face))) 545 (add-hook 'plcmp--command-cleanup-hook 546 (lambda () 547 (setq plcmp-current-buffer-words-alist nil))) 488 548 489 549 … … 502 562 (defun plcmp-get-current-buffer-variables () 503 563 (let ((alist (plcmp-get-current-buffer-words-alist))) 504 (assoc-default 'variable alist 'eq))) 505 506 (defvar plcmp-anything-source-current-buffer-variables 564 (prog1 (assoc-default 'variable alist 'eq) 565 (plcmp-log "getting current buffer variables")))) 566 567 (defvar plcmp-anything-source-completion-current-buffer-variables 507 568 `((name . "buffer variables") 508 569 (type . plcmp-completion) … … 515 576 (defun plcmp-get-current-buffer-arrays () 516 577 (let ((alist (plcmp-get-current-buffer-words-alist))) 517 (assoc-default 'array plcmp-current-buffer-words-alist 'eq))) 518 519 (defvar plcmp-anything-source-current-buffer-arrays 578 (prog1 (assoc-default 'array alist 'eq) 579 (plcmp-log "getting current buffer arrays")))) 580 581 (defvar plcmp-anything-source-completion-current-buffer-arrays 520 582 `((name . "buffer arrays") 521 583 (type . plcmp-completion) … … 528 590 (defun plcmp-get-current-buffer-hashes () 529 591 (let ((alist (plcmp-get-current-buffer-words-alist))) 530 (assoc-default 'hash alist 'eq))) 531 532 (defvar plcmp-anything-source-current-buffer-hashes 592 (prog1 (assoc-default 'hash alist 'eq) 593 (plcmp-log "getting current buffer hashes")))) 594 595 (defvar plcmp-anything-source-completion-current-buffer-hashes 533 596 `((name . "buffer hashes") 534 597 (type . plcmp-completion) … … 541 604 (defun plcmp-get-current-buffer-functions () 542 605 (let ((alist (plcmp-get-current-buffer-words-alist))) 543 (assoc-default 'function alist 'eq))) 544 545 (defvar plcmp-anything-source-current-buffer-functions 606 (prog1 (assoc-default 'function alist 'eq) 607 (plcmp-log "getting current buffer functions")))) 608 609 (defvar plcmp-anything-source-completion-current-buffer-functions 546 610 `((name . "buffer functions") 547 611 (type . plcmp-completion) … … 555 619 ;;; other buffer words 556 620 (defvar plcmp-perl-buffer-re "\\.p[lm]$") 621 (defvar plcmp-other-perl-buffers-words-faces 622 '(font-lock-function-name-face 623 font-lock-variable-name-face 624 font-lock-keyword-face 625 font-lock-builtin-face 626 font-lock-type-face 627 cperl-array-face 628 cperl-hash-face)) 629 557 630 (defun plcmp-get-other-perl-buffers-words () 558 631 (let ((perl-buffers (remove-if-not (lambda (buf) 559 632 (string-match plcmp-perl-buffer-re (buffer-name buf))) 560 633 (buffer-list)))) 561 ( loop for buffer in perl-buffers562 nconc (with-current-buffer buffer563 (plcmp-get-face-words)))))564 634 (prog1 (loop for buffer in perl-buffers 635 nconc (with-current-buffer buffer 636 (plcmp-get-face-words plcmp-other-perl-buffers-words-faces))) 637 (plcmp-log "length of other perl-buffers: %s" (length perl-buffers))))) 565 638 566 639 … … 626 699 ;;;; Anything 627 700 ;;;; %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 701 702 (defun plcmp--anything-get-current-source-name () 703 "Return the source name for the current selection." 704 (declare (special source)) 705 ;; The name `anything-get-current-source' should be used in init function etc. 706 (if (and (boundp 'anything-source-name) (stringp anything-source-name)) 707 anything-source-name 708 (with-current-buffer (anything-buffer-get) 709 ;; This goto-char shouldn't be necessary, but point is moved to 710 ;; point-min somewhere else which shouldn't happen. 711 (goto-char (overlay-start anything-selection-overlay)) 712 (let* ((header-pos (anything-get-previous-header-pos))) 713 (save-excursion 714 (assert header-pos) 715 (goto-char header-pos) 716 (prog1 (buffer-substring-no-properties 717 (line-beginning-position) (line-end-position)) 718 (plcmp-log "plcmp-anything-get-current-source-name: %s" 719 (buffer-substring-no-properties 720 (line-beginning-position) (line-end-position))))))))) 721 722 (defun plcmp-get-current-module-name () 723 (let* ((module (plcmp--anything-get-current-source-name))) 724 (when (string-match 725 (rx-to-string `(and 726 bol 727 (group 728 (regexp ,plcmp-perl-package-re)) 729 ,plcmp--mk-module-source-name)) 730 module) 731 (match-string 1 module)))) 732 628 733 (defvar plcmp-type-completion 629 734 '(plcmp-completion 630 735 (action . (("Insert" . plcmp-insert) 631 ("Open module file" . plcmp-open-module-file) 736 ;; ("Open module file" . plcmp-open-module-file) 737 ;; ("Open module file other window" . 738 ;; (lambda (candidate) 739 ;; (plcmp-open-module-file candidate 740 ;; 'switch-to-buffer-other-window))) 741 ;; ("Open module file other frame" . 742 ;; (lambda (candidate) 743 ;; (plcmp-open-module-file candidate 744 ;; 'switch-to-buffer-other-frame))) 745 746 ("Add to kill-ring" . kill-new) 747 ("Insert source name" . 748 (lambda (candidate) 749 (let ((name (plcmp-anything-get-current-source-name))) 750 (and (stringp name) 751 (insert name))))) 752 )))) 753 (add-to-list 'anything-type-attributes plcmp-type-completion) 754 755 (defvar plcmp-type-completion-method 756 '(plcmp-completion-method 757 (action . (("Insert" . plcmp-insert) 758 ("Open module file" . 759 (lambda (method) 760 (let ((module (plcmp-get-current-module-name))) 761 (plcmp-open-module-file module)))) 632 762 ("Open module file other window" . 633 (lambda ( candidate)634 ( plcmp-open-module-file candidate635 'switch-to-buffer-other-window)))763 (lambda (method) 764 (let ((module-name (plcmp-get-current-module-name))) 765 (plcmp-open-module-file module-name 'pop-to-buffer)))) 636 766 ("Open module file other frame" . 637 767 (lambda (candidate) 638 (plcmp-open-module-file candidate 639 'switch-to-buffer-other-frame))) 640 ("Add command to kill-ring" . kill-new) 641 ;; ("Perldoc" . (lambda (candidate) 642 ;; (plcmp-perldoc plcmp-data candidate))) 643 ;; ("Perldoc -m" . (lambda (candidate) 644 ;; (plcmp-perldoc-m plcmp-data candidate))) 768 (let ((module-name (plcmp-get-current-module-name))) 769 (plcmp-open-module-file module-name 770 'switch-to-buffer-other-frame)))) 771 ("Add to kill-ring" . kill-new) 772 ("Insert source name" . 773 (lambda (candidate) 774 (let ((name (plcmp-anything-get-current-source-name))) 775 (and (stringp name) 776 (insert name))))) 645 777 )))) 778 (add-to-list 'anything-type-attributes plcmp-type-completion-method) 646 779 647 780 (defvar plcmp-type-man … … 659 792 (lambda (candidate) 660 793 (plcmp-open-doc candidate 'man 'switch-to-buffer-other-frame))) 794 ("occur man buffer" . 795 (lambda (candidate) 796 (when (plcmp-open-doc candidate 'man) 797 (call-interactively (plcmp-get-occur-fn) candidate)))) 661 798 ("Insert man name" . insert) 662 ("Add commandto kill-ring" . kill-new)))))799 ("Add man name to kill-ring" . kill-new))))) 663 800 664 801 (defvar plcmp-type-perldoc 665 802 '(plcmp-perldoc 666 803 (action . ()))) 667 668 ;; append plcmp-* types to `anything-type-attributes'669 (add-to-list 'anything-type-attributes plcmp-type-completion)670 804 (add-to-list 'anything-type-attributes plcmp-type-man) 671 805 … … 675 809 676 810 ;;; perldoc 677 (defun plcmp-get-man-buffer (topic)811 (defun* plcmp-get-man-buffer (topic &optional (type 'module)) 678 812 "like `Man-getpage-in-background' but call process synchronously. 679 813 return buffer or nil unless process return 0" 680 814 (require 'man) 681 (let* ((man-args topic) 815 (let* ((manual-program (ecase type 816 (module "perldoc") 817 (man manual-program) 818 (function "perldoc -f") 819 (variable "perldoc perlvar"))) 820 (man-args topic) 682 821 (bufname (concat "*Man " man-args "*")) 683 822 (buffer (get-buffer bufname))) … … 743 882 (defun* plcmp-open-doc (topic &optional (type 'module) (show-fn 'switch-to-buffer)) 744 883 (require 'man) 745 (let ((manual-program (ecase type 746 (module "perldoc") 747 (man manual-program) 748 (function "perldoc -f") 749 (variable "perldoc perlvar")))) 750 (let ((manbuf (plcmp-get-man-buffer topic))) 751 (when (bufferp manbuf) 752 (funcall show-fn manbuf))))) 884 (let ((manbuf (plcmp-get-man-buffer topic type))) 885 (when (and (bufferp manbuf) 886 (functionp show-fn)) 887 (funcall show-fn manbuf)))) 888 753 889 754 890 ;;; open module file 755 891 (defun plcmp--find-module-file-no-select (module-name) 756 892 (when (plcmp-module-p module-name) 757 (let* ((path ( shell-command-to-string (concat "perldoc -l " module-name)))758 (path (expand-file-name (plcmp-trim path))))893 (let* ((path (plcmp-get-module-file-path module-name)) 894 (path (expand-file-name path))) 759 895 (when (and (file-exists-p path) 760 896 (file-readable-p path)) … … 807 943 (type . plcmp-completion) 808 944 (init . (lambda () 809 (let ((words (plcmp-get-buffer-dabbrevs))) 945 (let* ((words (plcmp-get-buffer-dabbrevs)) 946 (words (delete plcmp-real-initial-input words))) 810 947 (with-current-buffer (anything-candidate-buffer 'global) 811 948 (plcmp-insert-each-line words))))) 949 (requires-pattern . 4) 812 950 (candidates-in-buffer))) 813 951 … … 818 956 (with-current-buffer (anything-candidate-buffer 'global) 819 957 (plcmp-insert-each-line (plcmp-get-other-perl-buffers-words))))) 958 (requires-pattern . 3) 820 959 (candidates-in-buffer))) 960 821 961 822 962 ;; man, perldoc … … 850 990 ;;; complete-all 851 991 (defvar plcmp-completion-all-static-sources 852 '(plcmp-anything-source-completion-buffer-dabbrevs 992 '( 993 plcmp-anything-source-completion-buffer-dabbrevs 994 plcmp-anything-source-completion-using-modules 995 plcmp-anything-source-completion-current-buffer-variables 996 plcmp-anything-source-completion-current-buffer-arrays 997 plcmp-anything-source-completion-current-buffer-hashes 998 plcmp-anything-source-completion-current-buffer-functions 999 plcmp-anything-source-completion-builtin-variables 1000 plcmp-anything-source-completion-builtin-functions 853 1001 plcmp-anything-source-completion-other-perl-buffers-words 854 plcmp-anything-source-completion-builtin-variables 855 plcmp-anything-source-completion-builtin-functions 856 plcmp-anything-source-completion-using-modules 857 plcmp-anything-source-completion-installed-modules)) 1002 plcmp-anything-source-completion-installed-modules 1003 )) 858 1004 859 1005 (defun plcmp-get-sources-for-complete-all () … … 901 1047 (save-excursion (or (ignore-errors (backward-sexp) 902 1048 (point)) 903 (point)))))) 904 (cond 905 ;; package 906 ;; $self->`!!' 907 ;; __PACKAGE__->`!!' 908 ((and (plcmp-method-p) 909 (string-match (rx bol 910 (or "$self" 911 "__PACKAGE__") 912 eol) 913 obj-str)) 914 'package) 915 ;; method 916 ;; Foo->`!!' 917 ((plcmp-method-p) 918 'method) 919 ;; variable 920 ;; $foo`!!' 921 ((string-equal "$" (plcmp-preceding-string 1)) 922 'variable) 923 ;; array 924 ((string-equal "@" (plcmp-preceding-string 1)) 925 'array) 926 ;; hash 927 ((string-equal "%" (plcmp-preceding-string 1)) 928 'array) 929 ;; function 930 ((string-equal "&" (plcmp-preceding-string 1)) 931 'function) 932 ;; installed-module 933 ;; use `!!' 934 ((string-match (rx bol (* space) "use" (+ space)) 935 (buffer-substring (point-at-bol) (point))) 936 'installed-module) 937 (t 938 'otherwise)))))) 1049 (point))))) 1050 (context-sym (cond 1051 ;; package 1052 ;; $self->`!!' 1053 ;; __PACKAGE__->`!!' 1054 ((and (plcmp-method-p) 1055 (string-match (rx bol 1056 (or "$self" 1057 "__PACKAGE__") 1058 eol) 1059 obj-str)) 1060 'package) 1061 ;; method 1062 ;; Foo->`!!' 1063 ((plcmp-method-p) 1064 'method) 1065 ;; variable 1066 ;; $foo`!!' 1067 ((string-equal "$" (plcmp-preceding-string 1)) 1068 'variable) 1069 ;; array 1070 ((string-equal "@" (plcmp-preceding-string 1)) 1071 'array) 1072 ;; hash 1073 ((string-equal "%" (plcmp-preceding-string 1)) 1074 'array) 1075 ;; function 1076 ((string-equal "&" (plcmp-preceding-string 1)) 1077 'function) 1078 ;; installed-module 1079 ;; use `!!' 1080 ((string-match (rx bol (* space) "use" (+ space)) 1081 (buffer-substring (point-at-bol) (point))) 1082 'installed-module) 1083 (t 1084 'otherwise)))) 1085 (prog1 context-sym 1086 (plcmp-log "plcmp--get-context-symbol: %s" context-sym)))))) 1087 939 1088 ;; TODO 940 1089 (defun plcmp-get-sources-for-smart-complete () 941 1090 "return sources" 942 (let ((ctx-sym (plcmp--get-context-symbol))) 1091 (let ((ctx-sym (plcmp--get-context-symbol)) 1092 (all-sources (plcmp-get-sources-for-complete-all))) 943 1093 (case ctx-sym 1094 (method (plcmp-re-sort-sources "method" 1095 all-sources)) 1096 (variable (plcmp-re-sort-sources "variable" 1097 all-sources)) 1098 (array (plcmp-re-sort-sources "array" 1099 all-sources)) 1100 (hash (plcmp-re-sort-sources "hash" 1101 all-sources)) 1102 (function (plcmp-re-sort-sources "function" 1103 all-sources)) 1104 (installed-module (plcmp-re-sort-sources "installed modules" 1105 all-sources)) 944 1106 (otherwise (plcmp-get-sources-for-complete-all))))) 1107 1108 (define-plcmp-command smart-complete () 1109 (plcmp-log "smart-complete called line: %s`!!'" 1110 (buffer-substring (point-at-bol) (point))) 1111 (anything (plcmp-get-sources-for-smart-complete) plcmp-initial-input)) 945 1112 946 1113 ;;; document … … 958 1125 (dolist (variable plcmp--cached-variables) 959 1126 (set variable nil)) 960 (message "cleared all caches")) 1127 (or plcmp-installed-modules 1128 (plcmp-with-set-perl5-lib 1129 (plcmp--installed-modules-asynchronously))) 1130 (message "cleared all caches and getting installed modules asynchronously")) 961 1131 962 1132 (defun plcmp-cmd-show-environment () … … 989 1159 (browse-url-default-browser uri)))))))) 990 1160 1161 1162 ;;; %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 1163 ;;; Mode 1164 ;;; %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 1165 1166 ;;; keymap 1167 (defvar plcmp-mode-map 1168 (let ((map (make-sparse-keymap))) 1169 (define-key map (kbd "C-RET") 'plcmp-cmd-smart-complete) 1170 (define-key map (kbd "C-<return>") 'plcmp-cmd-smart-complete) 1171 (define-key map (kbd "C-c a") 'plcmp-cmd-complete-all) 1172 (define-key map (kbd "C-c c") 'plcmp-cmd-clear-all-caches) 1173 (define-key map (kbd "C-c d") 'plcmp-cmd-show-doc) 1174 (define-key map (kbd "C-c m") 'plcmp-cmd-menu) 1175 1176 map)) 1177 1178 (define-minor-mode perl-completion-mode "" nil " PLCompletion" plcmp-mode-map nil 1179 (or plcmp-installed-modules 1180 (plcmp--installed-modules-asynchronously))) 991 1181 992 1182 … … 1067 1257 1068 1258 1069 1070 1071 ;;; %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%1072 ;;; Mode1073 ;;; %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%1074 1075 ;; perl5 lib1076 ;; idea: http://svn.coderepos.org/share/lang/elisp/set-perl5lib/set-perl5lib.el1077 ;; http://d.hatena.ne.jp/sun-basix/20080117/1200528765 (Japanese)1078 (defvar plcmp-lib-directory-re "lib/")1079 (defun plcmp--get-lib-path ()1080 (let ((dir (plcmp-get-current-directory))1081 (lib-re (rx-to-string `(and (group1082 (* not-newline)1083 ,plcmp-lib-directory-re)))))1084 (when (string-match lib-re dir)1085 (let ((lib-dir (match-string 1 dir)))1086 (directory-file-name lib-dir)))))1087 1088 ;;; keymap1089 (defvar plcmp-mode-map1090 (let ((map (make-sparse-keymap)))1091 (define-key map (kbd "C-RET") 'plcmp-cmd-complete-all)1092 (define-key map (kbd "C-<return>") 'plcmp-cmd-complete-all)1093 (define-key map (kbd "C-c c") 'plcmp-cmd-clear-all-caches)1094 (define-key map (kbd "C-c d") 'plcmp-cmd-show-doc)1095 (define-key map (kbd "C-c m") 'plcmp-cmd-menu)1096 1097 map))1098 1099 (define-minor-mode perl-completion-mode "" nil " PLCompletion" plcmp-mode-map nil1100 (plcmp-get-installed-modules))1101 1102 1259 (provide 'perl-completion) 1103 1104 1260 ;;; perl-completion.el ends here
![(please configure the [header_logo] section in trac.ini)](/share/chrome/site/your_project_logo.png)