トップ «前の日記(2007-11-23) 最新 次の日記(2007-11-30)» 編集

follow ikegami__ at http://twitter.com

イネムリネズミ日記

いけがみを召喚するには、出現予定を参考にしてください。三週間前までにメールをくだされば、日程を追加するなどしてスケジュールに組み込むことができるかもしれません。勉強会や個人的な会合、中途採用面接などに応じます。日記に書かないことはこちら

2003|04|05|06|07|11|12|
2004|01|02|03|04|05|06|07|10|11|
2005|01|02|03|04|05|06|07|08|11|
2006|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|11|12|
2010|03|04|12|
2011|02|03|04|06|08|09|10|

2007-11-25 冬日和 [長年日記]

_ Emacsいじり

もうやらねえ!と何回誓ったことか。もうやらない(n回目)。

% wc .emacs etc/emacs-config/*.el
(snip)
    1221    3796   38749 total

_ "delete-trailing-whitespace-except-for-the-current-line" for auto-save-buffers

現在のカーソルがある行を除いた全ての行の文末の空白を取り除く EmacsLisp 関数を作ってみた。 これで、先日のカーソルひょこひょこ病は直った。

(defun delete-trailing-whitespace-except-for-the-current-line ()
  "Delete all the trailing whitespace across the current buffer,
except for the current line where the point is. All whitespace
after the last non-whitespace character in a line is deleted. This
respects narrowing, created by \\[narrow-to-region] and friends. A
formfeed is not considered whitespace by this function."
  (interactive "*")
  (let ((opoint (point)) start l)
    (save-match-data
      (save-excursion
        (save-restriction
          (goto-char (point-min))
          (widen)
          (forward-line 0)
          (setq start (point))
          (goto-char opoint)
          (forward-line 0)
          (setq l (1+ (count-lines 1 (point))))
          (goto-char (point-min))
          (while (and (re-search-forward "\\s-$" nil t)
                      (not (= (count-lines (point-min) (point)) l)))
            (skip-syntax-backward "-" (save-excursion (forward-line 0) (point)))
            ;; Don't delete formfeeds, even if they are considered whitespace.
            (save-match-data
              (if (looking-at ".*\f")
                  (goto-char (match-end 0))))
            (delete-region (point) (match-end 0))))))))

中身は、GNU Emacs21 に付随する simple.el で定義されている what-line と delete-trailing-whitespace をつなげたようなものである。ライセンスはもちろん GPL。

what-line はカーソルのある行を mini-buffer に文字列を表示する関数だったので、 カーソルのある行番号を取得するためには (count-lines (point-min) (point)) する必要がある。 しかし、ここには罠があって、もしバッファが narrowing されていると、取得された値が望みの値 と違うのである。とほほ。

これを作ったあとで、Conal から「なんで行末の空白が気になるんだよ(気にしなければいいじゃ ん)」というまっとうな返事が Haskell-cafe に届いていた。いや、気にしなくてもいいのだけれど、 darcs で管理しているときに、行末の空白という minor change が嫌なんでありまするよ。

_ TempoSnippets for Emacs21

よくわかってないんだけど、次の変更で Emacs21 (on tty) も動くみたいよ。 単にエラーが出る行をコメントアウトしただけなので、 まだ問題が残っているかもしれないが。tty では :underline ができないってことなのかな。

--- /Users/ikegami/install/tempo-snippets.el    2007-11-26 05:26:24.000000000 +0900
+++ /usr/local/share/emacs/site-lisp/tempo-snippets.el  2007-11-26 05:36:41.000000000 +0900
@@ -101,16 +101,16 @@
   "*Face used for editable text in tempo snippets."
   :group 'tempo-snippets)
 
-(defface tempo-snippets-auto-face
-  '((((background dark)) (:underline "steel blue"))
-    (((background light)) (:underline "light cyan")))
-  "*Face used for automatically updating text in tempo snippets."
-  :group 'tempo-snippets)
-
-(defface tempo-snippets-auto-form-face
-  '((default (:inherit 'tempo-snippets-auto-face)))
-  "*Face used for text in tempo snippets that is re-evaluated on input."
-  :group 'tempo-snippets)
+;; (defface tempo-snippets-auto-face
+;;   '((((background dark)) (:underline "steel blue"))
+;;     (((background light)) (:underline "light cyan")))
+;;   "*Face used for automatically updating text in tempo snippets."
+;;   :group 'tempo-snippets)
+
+;; (defface tempo-snippets-auto-form-face
+;;   '((default (:inherit 'tempo-snippets-auto-face)))
+;;   "*Face used for text in tempo snippets that is re-evaluated on input."
+;;   :group 'tempo-snippets)
 
 (defcustom tempo-snippets-interactive t
   "*Insert prompts for snippets.
@@ -260,7 +260,7 @@
         ;; XXX: this assumes on-region to be nil
         (tempo-insert eval-result nil)
         (setq overlay (make-overlay beg (point)))
-        (overlay-put overlay 'face 'tempo-snippets-auto-form-face)
+        ;; (overlay-put overlay 'face 'tempo-snippets-auto-form-face)
         ;; evaporating would cause problems when form before prompt!
         (overlay-put overlay 'tempo-snippets-form form)
         (overlay-put overlay 'modification-hooks
@@ -364,7 +364,7 @@
       (let ((mirrors (overlay-get source 'tempo-snippets-mirrors)))
         (push overlay mirrors)
         (overlay-put source 'tempo-snippets-mirrors mirrors))
-      (overlay-put overlay 'face 'tempo-snippets-auto-face)
+;;       (overlay-put overlay 'face 'tempo-snippets-auto-face)
       (overlay-put overlay 'modification-hooks
                    '(tempo-snippets-delete-overlay))
       (overlay-put overlay 'insert-in-front-hooks

デフォルトの face は背景が水色で、それは嫌なので変更した。

(custom-set-faces
 '(tempo-snippets-editable-face ((((background dark)) (:background "blue")))))

_ Haskell の動的補完

via Emacs の略語展開のメモ ー ありえるえりあ.

試行錯誤で Haskell 用の動的補完を作っていきますよ。とりあえず、今はこれだけ。

(load-library "tempo-snippets")
(tempo-define-snippet "haskell-module"
  '("module " (p "Module: " module) " (" n ") where" n)
  "module"
  "Insert a Haskell module."
  nil)
(tempo-define-snippet "haskell-import"
  '("import " (p "Module: " module) "")
  "import"
  "Insert a declaration of an importing module in Haskell."
  nil)
(tempo-define-snippet "haskell-data-0"
  '("data " (p "Datatype: " datatype) " = " (s datatype))
  "data0"
  "Insert an algebraic datatype in Haskell."
  nil)
(tempo-define-snippet "haskell-data-1"
  '("data " (p "Datatype: " datatype) " = " (s datatype) " { " n > "}")
  "data1"
  "Insert an algebraic datatype in Haskell."
  nil)
(tempo-define-snippet "haskell-data-2"
  '("data " (p "Datatype: " datatype) " = A" n > "| B")
  "data2"
  "Insert an algebraic datatype in Haskell."
  nil)
(tempo-define-snippet "haskell-type"
  '("type " (p "Type: " type) " = " n)
  "type"
  "Insert a type definition in Haskell."
  nil)
(tempo-define-snippet "haskell-newtype"
  '("newtype " (p "Newtype: " newtype) " = " (s newtype) n)
  "newtype"
  "Insert a newtype definition in Haskell."
  nil)
(tempo-define-snippet "haskell-deriving"
  '(> "deriving (" (p "Class: " class) ")")
  "deriving"
  "Insert a deriving clause in Haskell."
  nil)
(tempo-define-snippet "haskell-function"
  '((p "Name: " name) " :: " (p "Type: " type) n (s name) " = ")
  "function"
  "Insert a function in Haskell."
  nil)
(tempo-define-snippet "haskell-main"
  '("main :: IO ()" n "main = do ")
  "main"
  "Insert the Haskell main function."
  nil)

これで、Haskell でも Tempo-Snippets Demo みたいなことができるわけです。やったね。

_ FlymakeHaskell

perl script に恥ずかしいバグがあったので修正しておきました。


出現予定(召喚方法 ikegami@madscientist.jp):

RSS feed を再開しました。RSS の思想を尊重するために全文配信はしません、あしからず。