ZHUOWARE BACKYARD - NOTE INDEX|ZHUOWARE BACKYARD TOP|ZHUOWARE表ページ

[incr tcl] class and method display in Emacs

// Emacsで[incr tcl]のクラス・メソッド名を表示

April 19, 2010 by Zhuo

Abstract // 概要

I have written a tiny emacs-lisp code snippet that displays the current class name and the current method name when C-c c is typed in an [incr tcl] script. Please note, however, that the search is quite simple: it just searches for the nearest class definition and method definition before the pointer; Logically incorrect class/method names may be shown.
// Emacsで[incr tcl]スクリプトを編集中,C-c c とタイプすると現在のクラス名とメソッド名を表示する emacs-lispコードです.ただし,サーチ法は単純で,単にポインタより上の一番近いクラス名・メソッド名定義を探すだけですので,間違ったクラス名・メンバ名が表示される場合もあります.

Preparation // 準備

  1. Save the following part in a file "itcl_sup.el".
    // 次の部分を,"itcl_sup.el"というファイルに保存する.
    ;;
    ;; itcl_sup.el  
    ;;
    ;; Apr. 18, 2010  by zhuo    
    ;; 
    ;; [incr tcl] support; show class-name and method-name
    ;;
    
    (defun itcl-sup-show-class-and-method ()
      "Show itcl-class and itcl-method (if inside). (Apr. 18, 2010 by Zhuo)"
      (interactive)
      (let ((class-line-pos nil)
    	(class-line "(not inside a class)")
    	(method-line "(not inside a method)"))
        (save-excursion
          (end-of-line)
          (if (re-search-backward "itcl::class[ \t]+\\([^ \t]+\\)" nil t)
    	  (progn
    	    (setq class-line-pos (point))
    	    (setq class-line (buffer-substring (match-beginning 1) (match-end 1))))))
        (save-excursion
          (end-of-line)
          (if (re-search-backward "\\(\\(method\\|proc\\|constructor\\|destructor\\)[^}]+}\\).*$" class-line-pos t)
    	  
    	  (setq method-line (buffer-substring (match-beginning 1) (match-end 1)))))
        (princ (concat "CLASS: " class-line "    BLOCK: " method-line))))
    

  2. Put "itcl_sup.el" in emacs/lib/site-lisp or whereever appropriate.
    //この"itcl_sup.el"を,emacs/lib/site-lisp ,あるいは適切な場所に置く.

  3. Add the following codes in your .emacs.
    // つぎのコードを.emacsに追加する.
    (load-library "itcl_sup.el")
    (add-hook 'tcl-mode-hook '(lambda ()
      (local-set-key [(control ?c) ?c] 'itcl-sup-show-class-and-method)))
    

  4. Restart Emacs.
    // Emacsを再起動する.

  5. Congratulations! This functionality is now ready to use. When writing an itcl codes, you can simply type "C-c c" to see the current class-name and the current method name.
    // これで機能が使えるようになる.incr tclのコードを書いているときに,単にControl-c c とタイプすれば,現在ポイントのある位置のクラス名とメソッド名が表示される.

  6. Enjoy.

Discussion // 議論

by Zhuo