Hatena::Groupcadr

わだばLisperになる このページをアンテナに追加 RSSフィード

2004 | 12 |
2005 | 01 | 02 | 07 | 10 | 11 |
2006 | 06 | 07 | 08 | 09 | 10 | 11 | 12 |
2007 | 01 | 02 | 03 | 04 | 05 | 06 | 07 | 08 | 09 | 10 | 11 | 12 |
2008 | 01 | 02 | 03 | 04 | 05 | 06 | 07 | 08 | 09 | 10 | 11 | 12 |
2009 | 01 | 02 | 03 | 04 | 05 | 06 | 07 | 08 | 09 | 10 | 11 | 12 |
2010 | 01 | 02 | 03 | 04 | 05 | 06 | 07 | 08 | 09 | 10 | 11 | 12 |
2011 | 01 | 02 | 03 | 04 | 05 | 06 | 07 | 11 |

2009-01-15

TIMEもめんどくさい

| 05:39 | TIMEもめんどくさい - わだばLisperになる を含むブックマーク はてなブックマーク - TIMEもめんどくさい - わだばLisperになる

以前に、毎度DESCRIBEを書くのが面倒ということでelispを書いてみましたが、TIMEも面倒なので同じように書いてみました。

どうも最近、SLIMEslime-with-popup-bufferに変更があったみたいでフォーカスの制御を明示的にするようになったようなので前のDESCRIBEのものも修正してみました。

(fib 30)

の上でC-sh-tすると

(fib 30)

;=> 832040
----------
Timing the evaluation of (FIB 30)

User time    =        0.060
System time  =        0.000
Elapsed time =        0.063
Allocation   = 0 bytes
0 Page faults

みたいな窓が出て、qで終了。

;; Emacs lisp
(progn
  ;; time
  (defun slime-time-form ()
    (interactive)
    (let ((defun-at-point (slime-defun-at-point)))
      (slime-eval-and-time
       defun-at-point
       `(swank:eval-and-grab-output
         ,(format "(let ((*trace-output* *standard-output*))(time %s))" defun-at-point)))))
  
  (defun slime-eval-and-time (orig-form form)
    (slime-eval-async form (slime-rcurry #'slime-show-time
                                         (slime-current-package)
                                         orig-form)))
  
  (defun slime-show-time (string package orig-form)
    (slime-with-popup-buffer ("*SLIME Time*" package t t)
      (lisp-mode)
      (princ orig-form)
      (princ "\n;=> ")
      (princ (second string))
      (princ "\n----------\n")
      (princ (first string))
      (goto-char (point-min))))
  
  ;; control-shift-t
  (define-key slime-mode-map
    [(control shift ?t)] 'slime-time-form))
;; Emacs lisp
(progn
  ;; describe
  (defun slime-describe-form ()
    "(Describe) the form at point."
    (interactive)
    (slime-eval-and-describe
     `(swank:eval-and-grab-output
       ,(format "(describe %s)" (slime-defun-at-point)))))

  (defun slime-eval-and-describe (form)
    "Describe FORM in Lisp and display the result in a new buffer."
    (slime-eval-async form (slime-rcurry #'slime-show-describe
                                         (slime-current-package))))

  (defun slime-show-describe (string package)
    (slime-with-popup-buffer ("*SLIME Describe*" package t t)
      (lisp-mode)
      (princ (first string))
      (goto-char (point-min))))

  ;; control-shift-d
  (define-key slime-mode-map
    [(control shift ?d)] 'slime-describe-form))