Changeset 19503
- Timestamp:
- 09/18/08 18:34:06 (4 months ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
lang/elisp/perl-completion/branch/1.0/perl-completion.el
r19304 r19503 29 29 30 30 31 32 ;;builtin variables:33 ;; (search . ((lambda (re arg1 arg2)34 ;; (re-search-forward (regexp-quote re) nil t))))35 36 37 31 ;; TODO: 38 32 ;; set-perl5lib 39 33 ;; open doc -> occur 34 ;; when remote(tramp) set-perl5lib 35 ;; plcmp-cmd-show-environment 40 36 41 37 ;;;code: … … 141 137 (make-variable-buffer-local 'plcmp-additional-lib-directories) 142 138 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)))) 139 152 140 153 141 (defun plcmp--get-lib-path () … … 179 167 (not (equal "" current-perl5lib))) 180 168 (setenv "PERL5LIB" current-perl5lib) 181 (plcmp-log "plcmp-with-set-perl5-lib PERL5LIB: %s" current-perl5lib)) 182 (progn183 ,@body))))))169 (plcmp-log "plcmp-with-set-perl5-lib PERL5LIB: %s" current-perl5lib))))) 170 (progn 171 ,@body))) 184 172 185 173 … … 249 237 regexps)))) 250 238 251 (defun plcmp-re-sort-sources (regexps sources )239 (defun plcmp-re-sort-sources (regexps sources &optional reverse) 252 240 (condition-case e 253 (let ((regexps (if (stringp regexps) (list regexps) regexps))254 (match-sources)255 (unmatch-sources))256 (loop for source in sources241 (let* ((regexps (if (stringp regexps) (list regexps) regexps)) 242 (match-sources) 243 (unmatch-sources) 244 (sorted-sources (loop for source in sources 257 245 if (plcmp--re-match-sources1 regexps source) 258 246 collect source into match-sources 259 247 else 260 248 collect source into unmatch-sources 261 finally (return (nconc match-sources unmatch-sources)))) 249 finally return (if reverse 250 (nconc unmatch-sources match-sources) 251 (nconc match-sources unmatch-sources))))) 252 (prog1 sorted-sources 253 (plcmp-log "plcmp-re-sort-sources: %s" sorted-sources))) 262 254 (error (plcmp-log "Error: plcmp-re-sort-sources\nregexps: %s\nsources: %s" 263 255 regexps 264 256 sources) 265 sources)))257 sources))) 266 258 267 259 (defsubst* plcmp-collect-matches … … 290 282 (require 'pp) 291 283 (let* ((str (or (ignore-errors (apply 'format messages)) 292 (pp-to-string messages)))284 (pp-to-string (car messages)))) 293 285 (strn (concat str "\n"))) 294 286 (with-current-buffer (plcmp-log-buf) … … 304 296 (defvar plcmp-initial-input "") 305 297 (defvar plcmp-real-initial-input "real initial-input if required `anything-match-plugin' initial-input is not real initial-input") 298 299 (defun plcmp--fullname () 300 (save-excursion 301 (let ((start (point))) 302 (skip-chars-backward "a-zA-Z0-9_") 303 (let ((str (plcmp-preceding-string 2))) 304 (when (string-equal str "::") 305 (buffer-substring-no-properties start (point))))))) 306 307 306 308 (defun plcmp-get-initial-real-input-list () 307 309 "return list (initial-input real-initial-input)" 308 310 (save-excursion 309 (let ((start (point))) 310 (skip-syntax-backward "w_") 311 (let* ((preceding-string (char-to-string (preceding-char))) 312 (end (condition-case e 313 (cond 314 ((some (lambda (s) (string-equal s preceding-string)) '("$" "@" "%" "&")) 315 (backward-char) 316 (point)) 317 (t 318 (point))) 319 (error (point)))) 320 (real-initial-input 321 (buffer-substring-no-properties start end)) 322 (initial-input 323 (regexp-quote 324 (concat real-initial-input 325 (if (featurep 'anything-match-plugin) 326 " " 327 ""))))) 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)))))) 311 (let* ((start (point)) 312 (real-initial-input 313 (cond 314 ((plcmp--fullname)) 315 (t 316 (skip-syntax-backward "w_") 317 (let* ((preceding-string (char-to-string (preceding-char))) 318 (end (condition-case e 319 (cond 320 ((some (lambda (s) (string-equal s preceding-string)) '("$" "@" "%" "&")) 321 (backward-char) 322 (point)) 323 (t 324 (point))) 325 (error (point))))) 326 (buffer-substring-no-properties start end))))) 327 (initial-input 328 (regexp-quote 329 (concat real-initial-input 330 (if (and (featurep 'anything-match-plugin) 331 (not (string-equal real-initial-input ""))) 332 " " 333 ""))))) 334 (prog1 (values initial-input real-initial-input) 335 (plcmp-log "plcmp-get-initial-real-input-list:\ninitial-input: %s\nreal-initial-input: %s" 336 initial-input 337 real-initial-input))))) 338 332 339 333 340 ;;; installed modules … … 338 345 (unless (plcmp-tramp-p) 339 346 (or plcmp-installed-modules 340 ( prog1 (plcmp--installed-modules-synchronously)341 (plcmp--installed-modules-asynchronously)))))347 (setq plcmp-installed-modules 348 (plcmp--installed-modules-synchronously))))) 342 349 343 350 (defun plcmp--installed-modules-synchronously () … … 350 357 "| perl -nle 's/package\s+(.+);/$1/; print' " 351 358 "| sort " 352 "| uniq "))) 359 "| uniq " 360 ))) 353 361 (modules (split-string modules-str "\n"))) 354 362 (message "done") … … 370 378 (message "fetching installed modules...") 371 379 (let* ((command "find") 372 (args (concat " find`perl -e 'pop @INC; print join(q{ }, @INC);'`"380 (args (concat "`perl -e 'pop @INC; print join(q{ }, @INC);'`" 373 381 " -name '*.pm' -type f " 374 382 "| xargs grep -E -h -o 'package [a-zA-Z0-9:]+;' " … … 458 466 (let* ((path (shell-command-to-string (concat "perldoc -l " (shell-quote-argument module-name)))) 459 467 (path (plcmp-trim path))) 460 (and (file-exists-p path) 468 (and (stringp path) 469 (file-exists-p path) 461 470 path))) 462 471 … … 493 502 (anything-aif (assoc-default module-name plcmp-module-methods-alist) 494 503 `((name . ,(concat module-name plcmp--mk-module-source-name)) 495 (type . plcmp-completion-method) 504 (action . (("Insert" . plcmp-insert) 505 ("Show doc" . 506 (lambda (candidate) 507 (let* ((module (plcmp-get-current-module-name)) 508 (buf (plcmp-get-man-buffer module 'module))) 509 (save-selected-window 510 (pop-to-buffer buf))))) 511 ("Show doc and go" . 512 (lambda (candidate) 513 (let* ((module (plcmp-get-current-module-name)) 514 (buf (plcmp-get-man-buffer module 'module))) 515 (pop-to-buffer buf)))) 516 ("Open module file" . 517 (lambda (method) 518 (let ((module (plcmp-get-current-module-name))) 519 (plcmp-open-module-file module)))) 520 ("Open module file other window" . 521 (lambda (method) 522 (let ((module-name (plcmp-get-current-module-name))) 523 (plcmp-open-module-file module-name 'pop-to-buffer)))) 524 ("Open module file other frame" . 525 (lambda (candidate) 526 (let ((module-name (plcmp-get-current-module-name))) 527 (plcmp-open-module-file module-name 528 'switch-to-buffer-other-frame)))) 529 ("Add to kill-ring" . kill-new) 530 ("Insert source name" . 531 (lambda (candidate) 532 (let ((name (plcmp-anything-get-current-source-name))) 533 (and (stringp name) 534 (insert name))))) 535 )) 496 536 (init . (lambda () 497 537 (with-current-buffer (anything-candidate-buffer 'global) … … 619 659 ;;; other buffer words 620 660 (defvar plcmp-perl-buffer-re "\\.p[lm]$") 661 (defvar plcmp-other-perl-buffer-limit-number 30) 621 662 (defvar plcmp-other-perl-buffers-words-faces 622 663 '(font-lock-function-name-face … … 629 670 630 671 (defun plcmp-get-other-perl-buffers-words () 631 (let ((perl-buffers (remove-if-not (lambda (buf)672 (let* ((perl-buffers (remove-if-not (lambda (buf) 632 673 (string-match plcmp-perl-buffer-re (buffer-name buf))) 633 (buffer-list)))) 674 (buffer-list))) 675 (perl-buffers (subseq perl-buffers 0 plcmp-other-perl-buffer-limit-number))) 634 676 (prog1 (loop for buffer in perl-buffers 677 when (bufferp buffer) 635 678 nconc (with-current-buffer buffer 636 679 (plcmp-get-face-words plcmp-other-perl-buffers-words-faces))) 637 680 (plcmp-log "length of other perl-buffers: %s" (length perl-buffers))))) 638 681 682 683 (defun plcmp--mk-other-perl-buffer-source (source-name faces buffer-name) 684 `((name . ,(concat source-name " *" buffer-name "*")) 685 (action . (("Insert" . plcmp-insert))) 686 (init . (lambda () 687 (let ((words (with-current-buffer (get-buffer ,buffer-name) 688 (plcmp-get-face-words ',faces)))) 689 (with-current-buffer (anything-candidate-buffer 'global) 690 (plcmp-insert-each-line words))))) 691 (candidates-in-buffer))) 692 693 (defun plcmp--sources-other-perl-buffers (source-name faces) 694 (let* ((perl-buffers (remove-if-not (lambda (buf) 695 (string-match plcmp-perl-buffer-re (buffer-name buf))) 696 (buffer-list))) 697 (perl-buffers (subseq perl-buffers 0 plcmp-other-perl-buffer-limit-number)) 698 (sources (loop for buffer in perl-buffers 699 when (bufferp buffer) 700 collect (with-current-buffer buffer 701 (plcmp--mk-other-perl-buffer-source 702 source-name 703 faces 704 (buffer-name buffer)))))) 705 (prog1 sources 706 (plcmp-log "plcmp--sources-other-perl-buffers:") 707 (plcmp-log sources)))) 708 709 (defun plcmp-get-sources-other-perl-buffers-variable () 710 (plcmp--sources-other-perl-buffers "variables" '(font-lock-variable-name-face))) 711 712 (defun plcmp-get-sources-other-perl-buffers-hashes () 713 (plcmp--sources-other-perl-buffers "hashes" '(cperl-hash-face))) 714 715 (defun plcmp-get-sources-other-perl-buffers-arrays () 716 (plcmp--sources-other-perl-buffers "arrays" '(cperl-array-face))) 717 718 (defun plcmp-get-sources-other-perl-buffers-functions () 719 (plcmp--sources-other-perl-buffers "functions" '(font-lock-function-name-face))) 639 720 640 721 ;;; man … … 731 812 (match-string 1 module)))) 732 813 814 ;;;TODO 815 (defun plcmp-completion-get-man-buffer (candidate) 816 "return manpage buffer ,called in completion source action" 817 (let* ((name (plcmp--anything-get-current-source-name)) 818 (ret (cond 819 ((string-equal name "builtin functions") 820 (plcmp-get-man-buffer candidate 'function)) 821 ((or (string-equal name "using modules") 822 (string-equal name "installed modules")) 823 (plcmp-get-man-buffer candidate)) 824 ((string-equal name "builtin variables") 825 (plcmp-get-man-buffer "" 'variables)) 826 ((string-match (concat plcmp--mk-module-source-name "$") 827 name) 828 (plcmp-get-current-module-name))))) 829 (prog1 ret 830 (plcmp-log "plcmp-completion-get-man-buffer candidate: %s return: %s" 831 candidate 832 ret)))) 833 834 733 835 (defvar plcmp-type-completion 734 836 '(plcmp-completion 735 837 (action . (("Insert" . plcmp-insert) 838 ("Show man" . 839 (lambda (candidate) 840 (anything-aif (plcmp-completion-get-man-buffer candidate) 841 (switch-to-buffer it)))) 736 842 ;; ("Open module file" . plcmp-open-module-file) 737 843 ;; ("Open module file other window" . … … 795 901 (lambda (candidate) 796 902 (when (plcmp-open-doc candidate 'man) 797 (call-interactively (plcmp-get-occur-fn) candidate)))) 903 (call-interactively (plcmp-get-occur-fn) 904 (regexp-quote candidate))))) 798 905 ("Insert man name" . insert) 799 906 ("Add man name to kill-ring" . kill-new))))) … … 818 925 (function "perldoc -f") 819 926 (variable "perldoc perlvar"))) 820 (man-args topic) 821 (bufname (concat "*Man " man-args "*")) 822 (buffer (get-buffer bufname))) 823 (if buffer 824 buffer 825 (require 'env) 826 (message "Invoking %s %s in the background" manual-program man-args) 827 (setq buffer (generate-new-buffer bufname)) 828 (with-current-buffer buffer 829 (setq buffer-undo-list t) 830 (setq Man-original-frame (selected-frame)) 831 (setq Man-arguments man-args)) 832 (let ((process-environment (copy-sequence process-environment)) 927 (command (if (eq type 'variable) 928 manual-program 929 (concat manual-program " " topic))) 930 (bufname (concat "*perldoc " topic "*")) 931 (buffer (get-buffer-create bufname))) 932 (require 'env) 933 (let ((process-environment (copy-sequence process-environment)) 833 934 ;; The following is so Awk script gets \n intact 834 935 ;; But don't prevent decoding of the outside. … … 848 949 ;; Prevent any attempt to use display terminal fanciness. 849 950 (setenv "TERM" "dumb") 850 ;; In Debian Woody, at least, we get overlong lines under X 851 ;; unless COLUMNS or MANWIDTH is set. This isn't a problem on 852 ;; a tty. man(1) says: 853 ;; MANWIDTH 854 ;; If $MANWIDTH is set, its value is used as the line 855 ;; length for which manual pages should be formatted. 856 ;; If it is not set, manual pages will be formatted 857 ;; with a line length appropriate to the current ter- 858 ;; minal (using an ioctl(2) if available, the value of 859 ;; $COLUMNS, or falling back to 80 characters if nei- 860 ;; ther is available). 861 (if window-system 862 (unless (or (getenv "MANWIDTH") (getenv "COLUMNS")) 863 ;; This isn't strictly correct, since we don't know how 864 ;; the page will actually be displayed, but it seems 865 ;; reasonable. 866 (setenv "COLUMNS" (number-to-string 867 (cond 868 ((and (integerp Man-width) (> Man-width 0)) 869 Man-width) 870 (Man-width (frame-width)) 871 ((window-width))))))) 872 (setenv "GROFF_NO_SGR" "1") 873 (let ((exit-status 874 (call-process shell-file-name nil (list buffer nil) nil 875 shell-command-switch 876 (format (Man-build-man-command) man-args))) 877 (msg "")) 878 (when (and (numberp exit-status) 879 (= exit-status 0)) 880 (get-buffer bufname))))))) 951 (save-window-excursion (shell-command command bufname)) 952 (get-buffer bufname)))) 881 953 882 954 (defun* plcmp-open-doc (topic &optional (type 'module) (show-fn 'switch-to-buffer)) … … 906 978 (defvar plcmp-anything-source-completion-using-modules 907 979 `((name . "using modules") 908 (type . plcmp-completion) 980 (action . (("Insert" . plcmp-insert) 981 ("Show doc" . 982 (lambda (candidate) 983 (let ((buf (plcmp-get-man-buffer candidate 'module))) 984 (save-selected-window 985 (pop-to-buffer buf))))) 986 ("Show doc and go" . 987 (lambda (candidate) 988 (let ((buf (plcmp-get-man-buffer candidate 'module))) 989 (pop-to-buffer buf)))) 990 ("occur" . 991 (lambda (candidate) 992 (let ((buf (plcmp-get-man-buffer candidate 'module))) 993 (switch-to-buffer buf) 994 (call-interactively (plcmp-get-occur-fn))))) 995 ("Add to kill-ring" . kill-new))) 909 996 (init . (lambda () 910 997 (with-current-buffer (anything-candidate-buffer 'global) … … 914 1001 (defvar plcmp-anything-source-completion-builtin-functions 915 1002 `((name . "builtin functions") 916 (type . plcmp-completion) 1003 (action . (("Insert" . plcmp-insert) 1004 ("Show doc" . 1005 (lambda (candidate) 1006 (let ((buf (plcmp-get-man-buffer candidate 'function))) 1007 (save-selected-window 1008 (pop-to-buffer buf))))) 1009 ("Show doc and go" . 1010 (lambda (candidate) 1011 (let ((buf (plcmp-get-man-buffer candidate 'function))) 1012 (switch-to-buffer-other-window buf)))) 1013 ("occur" . 1014 (lambda (candidate) 1015 (let ((buf (plcmp-get-man-buffer candidate 'function))) 1016 (switch-to-buffer buf) 1017 (funcall (plcmp-get-occur-fn) 1018 (regexp-quote candidate) 1019 nil)))) 1020 ("Add to kill-ring" . kill-new))) 917 1021 (init . (lambda () 918 1022 (with-current-buffer (anything-candidate-buffer 'global) … … 922 1026 (defvar plcmp-anything-source-completion-builtin-variables 923 1027 `((name . "builtin variables") 924 (type . plcmp-completion) 1028 (action . (("Insert" . plcmp-insert) 1029 ("Show doc" . 1030 (lambda (candidate) 1031 (let ((buf (plcmp-get-man-buffer candidate 'variable)) 1032 (re (rx-to-string `(and bol (= 4 space) 1033 (group (eval ,candidate)) 1034 (syntax whitespace))))) 1035 (with-current-buffer buf 1036 (re-search-forward re nil t)) 1037 (save-selected-window 1038 (pop-to-buffer buf))))) 1039 ("Show doc and go" . 1040 (lambda (candidate) 1041 (let ((buf (plcmp-get-man-buffer candidate 'variable)) 1042 (re (rx-to-string `(and bol (= 4 space) 1043 (group (eval ,candidate)) 1044 (syntax whitespace))))) 1045 (switch-to-buffer-other-window buf) 1046 (re-search-forward re nil t)))) 1047 ("occur" . 1048 (lambda (candidate) 1049 (let ((buf (plcmp-get-man-buffer candidate 'variable))) 1050 (switch-to-buffer buf) 1051 (funcall (plcmp-get-occur-fn) 1052 (regexp-quote candidate) 1053 nil)))) 1054 ("Add to kill-ring" . kill-new))) 925 1055 (init . (lambda () 926 1056 (with-current-buffer (anything-candidate-buffer 'global) … … 932 1062 (defvar plcmp-anything-source-completion-installed-modules 933 1063 `((name . "installed modules") 934 (type . plcmp-completion) 1064 (action . (("Insert" . plcmp-insert) 1065 ("Show doc" . 1066 (lambda (candidate) 1067 (let ((buf (plcmp-get-man-buffer candidate 'module))) 1068 (save-selected-window 1069 (pop-to-buffer buf))))) 1070 ("Show doc and go" . 1071 (lambda (candidate) 1072 (let ((buf (plcmp-get-man-buffer candidate 'module))) 1073 (pop-to-buffer buf)))) 1074 ("occur" . 1075 (lambda (candidate) 1076 (let ((buf (plcmp-get-man-buffer candidate 'module))) 1077 (switch-to-buffer buf) 1078 (call-interactively (plcmp-get-occur-fn))))) 1079 ("Add to kill-ring" . kill-new))) 935 1080 (init . (lambda () 936 1081 (with-current-buffer (anything-candidate-buffer 'global) … … 941 1086 (defvar plcmp-anything-source-completion-buffer-dabbrevs 942 1087 `((name . "buffer dabbrevs") 943 (type . plcmp-completion) 1088 (action . (("Insert" . plcmp-insert) 1089 ("occur" . 1090 (lambda (candidate) 1091 (funcall (plcmp-get-occur-fn) 1092 (regexp-quote candidate) 1093 nil))) 1094 ("Add to kill-ring" . kill-new))) 944 1095 (init . (lambda () 945 1096 (let* ((words (plcmp-get-buffer-dabbrevs)) … … 952 1103 (defvar plcmp-anything-source-completion-other-perl-buffers-words 953 1104 `((name . "other buffer keywords") 954 ( type . plcmp-completion)1105 (action . (("Insert" . plcmp-insert))) 955 1106 (init . (lambda () 956 1107 (with-current-buffer (anything-candidate-buffer 'global) … … 963 1114 (defvar plcmp-anything-source-doc-man-pages 964 1115 '((name . "perl man pages") 965 ( type . plcmp-doc)1116 (action . (("Show man" . woman))) 966 1117 (init . (lambda () 967 1118 (with-current-buffer (anything-candidate-buffer 'global) … … 969 1120 (candidates-in-buffer))) 970 1121 1122 (defvar plcmp-anything-source-doc-using-modules 1123 '((name . "using modules") 1124 (action . (("Show doc" . 1125 (lambda (candidate) 1126 (let ((buf (plcmp-get-man-buffer candidate 'module))) 1127 (save-selected-window 1128 (pop-to-buffer buf))))) 1129 ("Show doc and go" . 1130 (lambda (candidate) 1131 (let ((buf (plcmp-get-man-buffer candidate 'module))) 1132 (switch-to-buffer buf)))) 1133 ("occur doc buffer" . 1134 (lambda (candidate) 1135 (let ((buf (plcmp-get-man-buffer candidate 'module))) 1136 (switch-to-buffer buf) 1137 (call-interactively (plcmp-get-occur-fn) 1138 (regexp-quote candidate))))) 1139 ("Add to kill-ring" . kill-new))) 1140 (init . (lambda () 1141 (with-current-buffer (anything-candidate-buffer 'global) 1142 (plcmp-insert-each-line plcmp-using-modules)))) 1143 (candidates-in-buffer))) 1144 1145 (defvar plcmp-anything-source-doc-installed-modules 1146 '((name . "installed modules") 1147 (action . (("Show doc" . 1148 (lambda (candidate) 1149 (let ((buf (plcmp-get-man-buffer candidate 'module))) 1150 (save-selected-window 1151 (pop-to-buffer buf))))) 1152 ("Show doc and go" . 1153 (lambda (candidate) 1154 (let ((buf (plcmp-get-man-buffer candidate 'module))) 1155 (switch-to-buffer buf)))) 1156 ("occur doc buffer" . 1157 (lambda (candidate) 1158 (let ((buf (plcmp-get-man-buffer candidate 'module))) 1159 (switch-to-buffer buf) 1160 (call-interactively (plcmp-get-occur-fn))))) 1161 ("Add to kill-ring" . kill-new))) 1162 (init . (lambda () 1163 (with-current-buffer (anything-candidate-buffer 'global) 1164 (plcmp-insert-each-line plcmp-installed-modules)))) 1165 (candidates-in-buffer))) 1166 1167 971 1168 ;; menu 972 1169 (defvar plcmp-anything-source-menu 973 '((name . "perl-completion menu")1170 `((name . "perl-completion menu") 974 1171 (type . command) 975 (init . (lambda () 976 (with-current-buffer (anything-candidate-buffer 'global) 977 (let ((commands (loop for sym being the symbols 978 for s = (symbol-name sym) 979
![(please configure the [header_logo] section in trac.ini)](/share/chrome/site/your_project_logo.png)