Ignore:
Timestamp:
12/04/03 19:41:34 (18 years ago)
Author:
piso
Message:

BUFFER-ACTIVATED-HOOK

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/j/examples/init.lisp

    r4240 r4973  
    11;;; init.lisp
    2 ;;; $Id: init.lisp,v 1.14 2003-10-07 14:30:16 piso Exp $
     2;;; $Id: init.lisp,v 1.15 2003-12-04 19:41:34 piso Exp $
    33
    44;;; ~/.j/init.lisp (if it exists) is loaded automatically when j starts up.
     
    4747(add-hook 'open-file-hook 'my-open-file-hook)
    4848
     49;; Helper function for MY-BUFFER-ACTIVATED-HOOK.
     50(defun sub-p (pathname dirname)
     51  "Returns T if PATHNAME is in DIRNAME or one of its subdirectories"
     52  (let ((dirname-length (length dirname)))
     53    (and (> (length pathname) dirname-length)
     54         (string= (subseq pathname 0 dirname-length) dirname))))
     55
     56(defun my-buffer-activated-hook (buf)
     57  (let ((pathname (buffer-pathname buf)))
     58    ;; PATHNAME might be NIL (not all buffers have associated files).
     59    (when pathname
     60      (let ((type (pathname-type pathname)))
     61        ;; We only care about Lisp and Java buffers.
     62        (when (member type '("lisp" "lsp" "cl" "java") :test 'string=)
     63          (let ((tagpath
     64                 (cond ((sub-p pathname "/home/peter/cmucl/src/")
     65                        "/home/peter/cmucl/src/code:/home/peter/cmucl/src/compiler:/home/peter/cmucl/src/pcl")
     66                       ((sub-p pathname "/home/peter/cl-bench/")
     67                        "/home/peter/cl-bench:/home/peter/cl-bench/files:/home/peter/depot/j/src/org/armedbear/lisp")
     68                       (t ; default case: no change
     69                        nil))))
     70            ;; If we end up here with a non-NIL TAGPATH, use it to set the
     71            ;; buffer-specific value of the TAG-PATH preference for the current
     72            ;; buffer.
     73            (when tagpath
     74              (setf (variable-value 'tag-path :buffer) tagpath))))))))
     75
     76;; Install our hook function.
     77(add-hook 'buffer-activated-hook 'my-buffer-activated-hook)
     78
    4979;; Call ADJUST-APPEARANCE after saving ~/.j/prefs.
    5080(defun my-after-save-hook (buf)
Note: See TracChangeset for help on using the changeset viewer.