Changeset 4973


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

BUFFER-ACTIVATED-HOOK

Location:
trunk/j
Files:
3 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)
  • trunk/j/src/org/armedbear/j/Editor.java

    r4917 r4973  
    33 *
    44 * Copyright (C) 1998-2003 Peter Graves
    5  * $Id: Editor.java,v 1.119 2003-11-30 00:19:57 piso Exp $
     5 * $Id: Editor.java,v 1.120 2003-12-04 19:40:11 piso Exp $
    66 *
    77 * This program is free software; you can redistribute it and/or
     
    758758            if (oldCurrentEditor != null)
    759759                oldCurrentEditor.getLocationBar().repaint();
     760            if (isLispInitialized())
     761                LispAPI.invokeBufferActivatedHook(currentEditor.getBuffer());
    760762        }
    761763    }
     
    59235925        Sidebar.setUpdateFlagInAllFrames(SIDEBAR_ALL);
    59245926
    5925         if (firstTime && isLispInitialized())
    5926             LispAPI.invokeOpenFileHook(buffer);
     5927        if (isLispInitialized()) {
     5928            if (firstTime)
     5929                LispAPI.invokeOpenFileHook(buffer);
     5930            LispAPI.invokeBufferActivatedHook(buffer);
     5931        }
    59275932    }
    59285933
  • trunk/j/src/org/armedbear/lisp/j.lisp

    r4969 r4973  
    1616          defcommand
    1717          open-file-hook
     18          buffer-activated-hook
    1819          after-save-hook
    1920          key-pressed-hook
     
    3940(defun log-debug (control-string &rest args)
    4041  (%log-debug (apply 'format nil control-string args)))
    41 
    42 (defun add-hook (hook function)
    43   (when (symbolp hook)
    44     (unless (boundp hook) (set hook nil))
    45     (let ((hook-functions (symbol-value hook)))
    46       (unless (memq function hook-functions)
    47         (setq hook-functions (cons function hook-functions))
    48         (set hook hook-functions)))))
    49 
    50 (defun invoke-hook (hook &rest args)
    51   (when (symbolp hook)
    52     (unless (boundp hook) (set hook nil))
    53     (let ((hooks (symbol-value hook)))
    54       (dolist (function hooks)
    55         (apply function args)))))
    5642
    5743(defun update-display (&optional ed)
     
    8773         (lambda () (execute-command ,command))))
    8874
     75;;; HOOKS
     76(defun add-hook (hook function)
     77  (when (symbolp hook)
     78    (unless (boundp hook) (set hook nil))
     79    (let ((hook-functions (symbol-value hook)))
     80      (unless (memq function hook-functions)
     81        (setq hook-functions (cons function hook-functions))
     82        (set hook hook-functions)))))
     83
     84(defun invoke-hook (hook &rest args)
     85  (when (symbolp hook)
     86    (unless (boundp hook) (set hook nil))
     87    (let ((hooks (symbol-value hook)))
     88      (dolist (function hooks)
     89        (apply function args)))))
     90
    8991(defvar open-file-hook nil)
     92
     93(defvar buffer-activated-hook nil)
    9094
    9195(defvar after-save-hook nil)
Note: See TracChangeset for help on using the changeset viewer.