and a small aubergine...
30 November 2006
 
some small emacisms

Here's a few small emacsisms ive been working on, they're all small things that I've written on a whim to help with work

recursive-grep-open

Wrote this to help a co-worker, it basicly uses grep -r to search files and will open each file that returned a match
(defun recursive-grep-open (where pattern)
 "searches where for pattern using a recursive grep and will open all files that match"
 (interactive "DWhere: \nsPattern: ")
 (with-temp-buffer
   (call-process "grep"
                 nil
                 '(t nil)
                 nil
                 "-rl"
                 pattern
                 where)
   (goto-char (point-min))
   (while (< (point) (point-max))       (let ((cp (point)))         (end-of-line)         (find-file (buffer-substring cp (point)))         (beginning-of-line 2))))) 

audit-this

I often have to go through a bunch of code and write notes, I wrote audit-this to help this process. Since I store my notes in emacs-wiki, this snippet will copy hilighted text in a buffer into a destination wiki buffer (set with audit-set-destination) with a heading for the filename, the line number and message which is prompted for and the code snippet itself.
(defvar audit-destination-buffer nil)

(defun audit-set-destination (buffer)
 (interactive "bDestination Buffer: ")
 (setq tm-audit-destination-buffer buffer))


(defun audit-this (beg end message)
 (interactive "r\nsMessage: ")
 (save-excursion
   (let* ((buffer-name      (buffer-name))
          (source-buf       (current-buffer))
          (where            (or tm-audit-destination-buffer
                                (read-buffer "Audit buffer: ")))
          (file-heading     (format "\n* File: %s\n" buffer-name))
          (text             (buffer-substring beg end))
          (start-line       (progn (goto-char beg)
                                   (line-number-at-pos)))
          (chunk            (format "\n** Line: %d\n - %s\n%s\n"
                                    start-line
                                    message
                                    text)))
     (switch-to-buffer where)
     (save-excursion
       (goto-char (point-min))
       (if (not (re-search-forward (format "^\\* File: %s$" buffer-name) nil t))
           (progn (goto-char (point-max))
                  (insert file-heading)))
       (insert chunk))
     (switch-to-buffer source-buf))))

add-function-to-header-line

This one could probably be implemented better! This function will put the name of the current (perl) function in buffer headline. It adds itself as a hook onto post-command-hook, is there a better place for this?
;; slightly nasty
;; this could probably be optomised, but
(defun add-function-name-to-header-line ()
 "adds the name of the current function into the header line"
 (if (eq major-mode 'cperl-mode)
     (progn
       (save-excursion
         (if (re-search-backward "^sub\s+\\([a-zA-Z0-9_]+\\)" nil t)
             (setq header-line-format (format "function: %s" (match-string 1)))
           (setq header-line-format nil))))))
(add-to-list 'post-command-hook 'add-function-name-to-header-line)


helpful-buffer-name

This one will rename the current cperl buffer to the name of the package that this perl file is in (if it is even in one).

(defun helpful-buffer-name ()
 (interactive)
 (save-excursion
     (goto-char (point-min))
     (if (re-search-forward "^package \\(.+\\);" nil t)
         (let ((pkg (match-string 1)))
           (if (get-buffer pkg)
               (rename-buffer (format "%s (%s)"
                                      pkg
                                      (buffer-file-name))
                              t)
             (rename-buffer pkg))))))
                             
(add-hook 'cperl-mode-hook (lambda () (helpful-buffer-name)))

I hope some of you out there find this stuff useful!

edit: Changed the headings so they look better on planet lisp.. sorry guys.

 
Comments:
Isn't recursive-grep-open very similar to find-grep-dired ?
 
yes it is, I actually wrote it for a coworker that uses xemacs.
 
you may find findr interesting
 
Have you tried `which-function-mode'? I don't know if it works for Perl but it works for Java and similar. It displays the current function's name in the mode line.
 
The H1s look really horrible on planet lisp.
 
l3hJlx Your blog is great. Articles is interesting!
 
Ocifnf Nice Article.
 
actually, that's brilliant. Thank you. I'm going to pass that on to a couple of people.
 
Wonderful blog.
 
Wonderful blog.
 
actually, that's brilliant. Thank you. I'm going to pass that on to a couple of people.
 
Wonderful blog.
 
Nice Article.
 
Please write anything else!
 
Hello all!
 
eP7ZNl actually, that's brilliant. Thank you. I'm going to pass that on to a couple of people.
 
Hello all!
 
あなたの精神年齢を占ってみよう!当サイトは、みんなの「精神年齢度」をチェックする性格診断のサイトです。精神年齢度には、期待以上の意外な結果があるかも??興味がある方はぜひどうぞ
 
さあ、今夏も新たな出会いを経験してみませんか?当サイトは円助交際の逆、つまり女性が男性を円助する『逆円助交際』を提供します。逆円交際を未経験の方でも気軽に遊べる大人のマッチングシステムです。年齢上限・容姿・経験一切問いません。男性の方は無料で登録して頂けます。貴方も新たな出会いを経験してみませんか
 
みんなの精神年齢を測定できる、メンタル年齢チェッカーで秘められた年齢がズバリわかっちゃう!かわいいあの子も実は精神年齢オバサンということも…合コンや話のネタに一度チャレンジしてみよう
 
童貞卒業を考えているなら、迷わずココ!今まで童貞とヤッた事がない女性というのは意外と多いものです。そんな彼女たちは一度童貞とやってみたいと考えるのは自然な事と言えるでしょう。当サイトにはそんな好奇心旺盛な女性たちが登録されています
 
Post a Comment



<< Home

My Photo
Name: Jon Philpott
Location: Los Angeles, California, United States

Yet another code monkey from London, living in LA.

Links

  • Planet Lisp

    ARCHIVES
    June 2006 / July 2006 / August 2006 / September 2006 / November 2006 / May 2007 / June 2007 / August 2007 /


    Powered by Blogger