Devel-PerlySense

 view release on metacpan or  search on metacpan

lib/Devel/PerlySense/external/emacs/perly-sense.el  view on Meta::CPAN

  (lexical-let
      ((command-string command)
       (callback-fun callback))
;;     (message "Calling (%s)" command-string)
    (async-shell-command-to-string
     command
     (lambda (response)
;;        (message "Called (%s), got (%s)" command-string response)
       (funcall callback-fun response)
       ))))



(defun ps/async-command-on-current-file-location (command callback &optional options)
  "Call perly_sense COMMAND with the current file and row/col,
call CALLBACK with the parsed result as a sexp"
  (unless options (setq options ""))
  (lexical-let ((callback-fun callback))
    (ps/async-shell-command-to-string
     (format "perly_sense %s \"--file=%s\" --row=%s --col=%s %s --width_display=%s"
             command
             (buffer-file-name)
             (ps/current-line)
             (+ 1 (current-column))
             options
             (- (window-width) 2))
     (lambda (output)
       (funcall callback-fun (ps/parse-sexp output))
       )
     )))



(defun ps/coverage-command (command)
  "Return a shell command to run COMMAND under
Devel::CoverX::Covered

Note: will currently only work in Unix-like shells because of the
way PERL5OPT is set."
  (format
   "cover -delete;
PERL5OPT=-MDevel::Cover %s;
covered runs"
   command)
  )



(defun ps/run-file-with-options (options &optional run-with-coverage)
  "Run the current file with OPTIONS passed to perly_sense"
  (let* (
         (result-alist     (ps/command-on-current-file-location "run_file" options))
         (dir-run-from     (alist-value result-alist "dir_run_from"))
         (command-run      (alist-value result-alist "command_run"))
         (type-source-file (alist-value result-alist "type_source_file"))
         (message-string   (alist-value result-alist "message")))
    (if command-run
        (progn

          ;; Test::Class integration
          (setenv "TEST_METHOD"
                  (if ps/tc/current-method
                      (format "^%s$" ps/tc/current-method)
                    nil))

          (let ((command-effective
                 (if run-with-coverage
                     (ps/coverage-command command-run)
                   command-run)
                 )
                (post-compile-lambda
                 (if run-with-coverage
                     (lambda ()
                       (ps/enable-and-reload-coverage (current-buffer)))
                   nil))
                )

            (ps/run-file-run-command
             command-effective
             dir-run-from
             post-compile-lambda)
            )
          )
      )
    (if message-string
        (message message-string)
      )
    )
  )



(defun ps/run-file (&optional use-alternate-command run-with-coverage)
  "Run the current file"
  (interactive "P")

  ;;If it's the compilation buffer, recompile, else run file
  (if (string= (buffer-name) "*compilation*")
      (progn
        (message "Recompile file...")
        (recompile)
        )

    (message "Run File...")
    (let ((alternate-command-option
           (if use-alternate-command "--use_alternate_command" "")))
      (ps/run-file-with-options alternate-command-option run-with-coverage)
      )
    )
  )



(defun ps/is-cpan-module-installed? (module-name)
  "Return t if MODULE-NAME is installed, else nil."
  (with-temp-buffer
    (shell-command (format "perl -M%s -e 1" module-name) t nil)
    ;; Empty buffer ==> no output ==> module is installed
    (eq (point-max) (point-min))))




( run in 1.360 second using v1.01-cache-2.11-cpan-4ac696b4eb4 )