Changeset 15428 for lang/elisp

Show
Ignore:
Timestamp:
07/08/08 01:11:03 (5 months ago)
Author:
imakado
Message:

perldoc -mで開くアクションを追加

Files:
1 modified

Legend:

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

    r14626 r15428  
    168168  (initial-input "") 
    169169  state 
     170  default-action-state 
     171  persistent-action-buffer-point 
    170172  using-modules 
    171173  current-buffer 
     
    313315     (error (plcmp-log "Error plcmp-ignore-errors :  %s" (error-message-string e))))) 
    314316 
     317;; idea: anything-dabbrev-expand.el 
     318(lexical-let ((store-times 0)) 
     319  (defun plcmp-seq-times (command-name &optional max) 
     320    (let ((max (or max -99))) 
     321      (if (eq last-command command-name) 
     322          (if (= (incf store-times) max) 
     323              (setq store-times 0) 
     324            store-times) 
     325        (setq store-times 0))))) 
     326 
    315327;;; log 
    316328(defvar plcmp-debug nil) 
     
    403415        else 
    404416        collect s into methods 
    405         finally return (nconc methods unders 
    406                         ;; (sort methods 'string<) 
    407                         ;;                               (sort unders 'string<) 
    408                               ))) 
     417        finally return (nconc methods unders))) 
    409418 
    410419(defsubst plcmp-inspect-methods (module) 
     
    492501      (using-modules installed-modules current-package 
    493502                     current-buffer obj-instance-of-module-maybe-alist 
    494                      current-object other-perl-buffers) 
     503                     current-object other-perl-buffers default-action-state) 
    495504    ;; initialize slots 
    496505    (setf installed-modules (plcmp-fetch-installed-modules struct) 
     
    501510          obj-instance-of-module-maybe-alist (plcmp-get-obj-instance-of-module-maybe-alist struct) 
    502511          other-perl-buffers (plcmp-get-other-perl-buffers struct) 
    503           current-object "") 
     512          current-object "" 
     513          default-action-state nil 
     514          persistent-action-buffer-point nil) 
    504515 
    505516    ;; initialize variable 
     
    534545               (string-match "^\\(\\$self\\|__PACKAGE__\\)$" obj-str)) 
    535546          (setf initial-input start-input 
    536                 state 'setf 
     547                state 'self 
    537548                current-object obj-str)) 
    538549         ;; methods 
     
    820831;;;; %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
    821832;;; actions 
    822 (defun plcmp-insert (candidate) 
     833(defun plcmp-insert (struct candidate) 
    823834  (plcmp-with-completion-data-slots plcmp-data 
    824       (initial-input) 
    825     (delete-backward-char (length initial-input)) 
    826     (insert (plcmp-get-real-candidate candidate)))) 
     835      (initial-input default-action-state persistent-action-buffer-point) 
     836    (cond 
     837     ((eq default-action-state 'perldoc-m) 
     838      (multiple-value-bind (output-buf module method) 
     839                           (plcmp-perldoc-m-create-buffer struct candidate) 
     840        (pop-to-buffer output-buf) 
     841        (goto-char persistent-action-buffer-point))) 
     842     (t 
     843      (delete-backward-char (length initial-input)) 
     844      (insert (plcmp-get-real-candidate candidate)))))) 
    827845 
    828846(defun plcmp-insert-modulename (candidate) 
     
    899917 
    900918(defun plcmp-fontify-re-search-forward (regexp) 
    901   (when (re-search-forward regexp nil t) 
    902     (let ((beg (match-beginning 1)) 
    903           (end (match-end 1))) 
    904       (when (and beg end) 
    905         (if (overlayp plcmp-overlay) 
    906             (move-overlay plcmp-overlay beg end (current-buffer)) 
    907           (setq plcmp-overlay (make-overlay beg end))) 
    908         (overlay-put plcmp-overlay 'face plcmp-search-match-face))))) 
     919  (let ((struct plcmp-data)) ;TODO 
     920    (plcmp-with-completion-data-slots struct 
     921        (persistent-action-buffer-point) 
     922      (when (re-search-forward regexp nil t) 
     923        (let ((beg (match-beginning 1)) 
     924              (end (match-end 1))) 
     925          ;; remember point 
     926          (setq persistent-action-buffer-point (point)) 
     927           
     928          (when (and beg end) 
     929            (if (overlayp plcmp-overlay) 
     930                (move-overlay plcmp-overlay beg end (current-buffer)) 
     931              (setq plcmp-overlay (make-overlay beg end))) 
     932            (overlay-put plcmp-overlay 'face plcmp-search-match-face))))))) 
    909933 
    910934(defun plcmp-visit-and-re-search-forward (regexp buffer-name) 
     
    10061030       (plcmp-open-perldoc modname 'module pop-to-buffer))))) 
    10071031 
     1032(defun plcmp-perldoc-m-create-buffer (struct candidate) 
     1033  (let (module method) 
     1034    (plcmp-acond 
     1035      ((plcmp-get-module-and-method-by-candidate struct candidate) 
     1036       (setq module (first it) 
     1037             method (second it))) 
     1038      (t 
     1039       (setq module (plcmp-get-real-candidate candidate)))) 
     1040    (let ((cperl-mode-hook nil) 
     1041          (output-buf (concat "*Perldoc -m " module "*"))) 
     1042      (cond 
     1043       ((buffer-live-p (get-buffer output-buf)) 
     1044        (values output-buf module method)) 
     1045       (t 
     1046        (shell-command (concat "perldoc -m " module) output-buf) 
     1047 
     1048        (with-current-buffer output-buf 
     1049          (goto-char (point-min)) 
     1050          (cperl-mode)) 
     1051 
     1052        (values output-buf module method)))))) 
     1053 
     1054(defun plcmp-perldoc-m (struct candidate) 
     1055  (multiple-value-bind (output-buf module method) 
     1056                       (plcmp-perldoc-m-create-buffer struct candidate) 
     1057    (let* ((re (cond ((null method) 
     1058                      "") 
     1059                     ((= (plcmp-seq-times 'plcmp-persistent-perldoc-m) 0) 
     1060                      (rx-to-string `(and "sub" (1+ space) (group (eval ,method))))) 
     1061                     (t 
     1062                      (rx-to-string `(and symbol-start (group (eval ,method)) symbol-end)))))) 
     1063      (plcmp-visit-and-re-search-forward re output-buf)))) 
     1064 
     1065(defun plcmp-persistent-perldoc-m () 
     1066  (interactive) 
     1067  (let ((struct plcmp-data)) 
     1068    (plcmp-with-completion-data-slots struct 
     1069        (default-action-state) 
     1070      (save-selected-window 
     1071        (select-window (get-buffer-window plcmp-anything-buffer)) 
     1072        (select-window (setq minibuffer-scroll-window 
     1073                             (if (one-window-p t) (split-window) (next-window (selected-window) 1)))) 
     1074        (let* ((plcmp-anything-window (get-buffer-window plcmp-anything-buffer)) 
     1075               (selection (if plcmp-anything-saved-sources 
     1076                              ;; the action list is shown 
     1077                              plcmp-anything-saved-selection 
     1078                            (plcmp-anything-get-selection)))) 
     1079          (set-window-dedicated-p plcmp-anything-window t) 
     1080          (unwind-protect 
     1081              (progn 
     1082                (setq default-action-state 'perldoc-m) 
     1083                (plcmp-perldoc-m struct selection)) 
     1084            (set-window-dedicated-p plcmp-anything-window nil))))))) 
    10081085 
    10091086(defun plcmp-open-module-file (struct candidate) 
     
    10481125 
    10491126    ;; call action with selection 
    1050     ;;(define-key map (kbd "M") 'plcmp-action-insert-modulename) 
     1127    (define-key map (kbd "M") 'plcmp-persistent-perldoc-m) 
    10511128    (define-key map (kbd "D") 'plcmp-action-perldoc) 
    10521129    (define-key map (kbd "O") 'plcmp-action-open-module-file) 
     
    11111188(defvar plcmp-anything-type-attributes 
    11121189  `((plcmp 
    1113      (action . (("Insert" . plcmp-insert) 
     1190     (action . (("Insert" . (lambda (candidate) 
     1191                              (plcmp-insert plcmp-data candidate))) 
    11141192                ("Open module file" . (lambda (candidate) 
    11151193                                        (plcmp-open-module-file plcmp-data candidate))) 
    11161194                ("Perldoc" . (lambda (candidate) 
    11171195                               (plcmp-perldoc plcmp-data candidate))) 
     1196                ("Perldoc -m" . (lambda (candidate) 
     1197                                  (plcmp-perldoc-m plcmp-data candidate))) 
    11181198                )) 
    11191199     (persistent-action . (lambda (candidate) 
     
    11831263 
    11841264(defvar plcmp-anything-source-all 
    1185   `((name . "installed-modules") 
     1265  `((name . "All") 
    11861266    (type . plcmp) 
    11871267    (init . (lambda () 
     
    12691349  (interactive) 
    12701350  (plcmp-call-action-by-action-name "Open module file")) 
     1351 
     1352(defun plcmp-action-perldoc-m () 
     1353    (interactive) 
     1354    (plcmp-call-action-by-action-name "Perldoc -m")) 
    12711355 
    12721356(defun plcmp-action-perldoc () 
     
    13231407            (if (null initial-pattern) 
    13241408                (read-string "pattern: ") 
    1325               (read-string "pattern: " initial-pattern) 
    1326               (plcmp-anything-check-minibuffer-input)) 
     1409              (read-string "pattern: " initial-pattern)) 
    13271410            )) 
    13281411      (plcmp-anything-cleanup)