view lisp/cedet/ede/source.el @ 104513:a6a812dd2d88

* cedet/semantic/lex.el (semantic-lex-reset-hooks): Doc fix. * cedet/semantic/idle.el (semantic-before-idle-scheduler-reparse-hook) (semantic-after-idle-scheduler-reparse-hook): Rename from *-hooks. Make old name an obsolete alias. * cedet/semantic/edit.el (semantic-after-partial-cache-change-hook) (semantic-change-hooks, semantic-edits-new-change-hooks) (semantic-edits-delete-change-hooks) (semantic-edits-move-change-hook) (semantic-edits-reparse-change-hooks) (semantic-edits-incremental-reparse-failed-hooks): Doc fixes. * cedet/semantic/debug.el (semantic-debug-mode): Rename hook symbols. * cedet/semantic/db-mode.el (semanticdb-mode-hook): Rename from semanticdb-mode-hooks. (global-semanticdb-minor-mode): Use the new name. (semanticdb-hooks): Use semantic-init-db-hook instead of obsolete alias semantic-init-db-hooks. * cedet/semantic/db-global.el (semanticdb-enable-gnu-global-databases): Use semantic-init-hook instead of obsolete alias semantic-init-hooks. * cedet/semantic/db-file.el (semanticdb-save-database-hook): Rename from semanticdb-save-database-hooks. Make old name an obsolete alias. * cedet/semantic/decorate/mode.el (semantic-decorate-pending-decoration-hook): Rename from semantic-decorate-pending-decoration-hooks. Make old name an obsolete alias. * cedet/srecode/map.el (srecode-map-validate-file-for-mode): Use semantic-init-hook instead of obsolete alias semantic-init-hooks. * cedet/semantic/fw.el (semantic-find-file-noselect): Use semantic-init-hook instead of obsolete alias semantic-init-hooks. * cedet/ede/project-am.el (project-am-with-makefile-current): Use semantic-init-hook instead of obsolete alias semantic-init-hooks. * cedet/semantic/util.el (semantic-describe-buffer): Use semantic-init-hook and semantic-init-db-hook instead of obsolete aliases. * cedet/semantic/util-modes.el (semantic-mode-line-update) (semantic-toggle-minor-mode-globally): Use semantic-init-hook instead of obsolete alias semantic-init-hooks. Synch to Eric Ludlam's upstream CEDET repository: * cedet/semantic/bovine/c.el (semantic-c-parse-token-hack-depth): New var. (semantic-c-parse-lexical-token): Save match data when setting up the secondary parse buffer. Allow recursion. Protect against initializing the major mode from throwing errors, ie user hooks. * cedet/semantic/lex-spp.el (semantic-lex-spp-lex-text-string): Protect installing a major mode from throwing errors.
author Chong Yidong <cyd@stupidchicken.com>
date Sat, 26 Sep 2009 17:47:11 +0000
parents 8c4870c15962
children 2d2d7facd575
line wrap: on
line source

;; ede/source.el --- EDE source code object

;;; Copyright (C) 2000, 2008 Free Software Foundation, Inc.

;; Author: Eric M. Ludlam <zappo@gnu.org>
;; Keywords: project, make

;; This file is part of GNU Emacs.

;; GNU Emacs is free software: you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.

;; GNU Emacs is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;; GNU General Public License for more details.

;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs.  If not, see <http://www.gnu.org/licenses/>.

;;; Commentary:

;; Manage different types of source code.  A master list of source code types
;; will be maintained, and used to track target objects, what they accept,
;; and what compilers can be used.

(require 'eieio-base)

;;; Code:
(defclass ede-sourcecode (eieio-instance-inheritor)
  ((name :initarg :name
	 :type string
	 :documentation
	 "The name of this type of source code.
Such as \"C\" or \"Emacs Lisp\"")
   (sourcepattern :initarg :sourcepattern
		  :initform ".*"
		  :type string
		  :documentation
		  "Emacs regexp matching sourcecode this target accepts.")
   (auxsourcepattern :initarg :auxsourcepattern
		     :initform nil
		     :type (or null string)
		     :documentation
		     "Emacs regexp matching auxiliary source code this target accepts.
Aux source are source code files needed for compilation, which are not compiled
themselves.")
   (enable-subdirectories :initarg :enable-subdirectories
			  :initform nil
			  :type boolean
			  :documentation
			  "Non nil if this sourcecode type uses subdirectories.
If sourcecode always lives near the target creating it, this should be nil.
If sourcecode can, or typically lives in a subdirectory of the owning
target, set this to t.")
   (garbagepattern :initarg :garbagepattern
		   :initform nil
		   :type list
		   :documentation
		   "Shell file regexp matching files considered as garbage.
This is a list of items added to an `rm' command when executing a `clean'
type directive.")
   )
  "Description of some type of source code.
Objects will use sourcecode objects to define the types of source
that they are willing to use.")

(defvar ede-sourcecode-list nil
  "The master list of all EDE compilers.")

;;; Methods
;;
(defmethod initialize-instance :AFTER ((this ede-sourcecode) &rest fields)
  "Make sure that all ede compiler objects are cached in
`ede-compiler-list'."
  (let ((lst ede-sourcecode-list))
    ;; Find an object of the same name.
    (while (and lst (not (string= (oref this name) (oref (car lst) name))))
      (setq lst (cdr lst)))
    (if lst
	;; Replace old definition
	(setcar lst this)
      ;; Add to the beginning of the list.
      (setq ede-sourcecode-list (cons this ede-sourcecode-list)))))

(defmethod ede-want-file-p ((this ede-sourcecode) filename)
  "Return non-nil if sourcecode definition THIS will take FILENAME."
  (or (ede-want-file-source-p this filename)
      (ede-want-file-auxiliary-p this filename)))

(defmethod ede-want-file-source-p ((this ede-sourcecode) filename)
  "Return non-nil if THIS will take FILENAME as an auxiliary ."
  (let ((case-fold-search nil))
    (string-match (oref this sourcepattern) filename)))

(defmethod ede-want-file-auxiliary-p ((this ede-sourcecode) filename)
  "Return non-nil if THIS will take FILENAME as an auxiliary ."
  (let ((case-fold-search nil))
    (and (slot-boundp this 'auxsourcepattern)
	 (oref this auxsourcepattern)
	 (string-match (oref this auxsourcepattern) filename))))

(defmethod ede-want-any-source-files-p ((this ede-sourcecode) filenames)
  "Return non-nil if THIS will accept any source files in FILENAMES."
  (let (found)
    (while (and (not found) filenames)
      (setq found (ede-want-file-source-p this (pop filenames))))))

(defmethod ede-want-any-auxiliary-files-p ((this ede-sourcecode) filenames)
  "Return non-nil if THIS will accept any aux files in FILENAMES."
  (let (found)
    (while (and (not found) filenames)
      (setq found (ede-want-file-auxiliary-p this (pop filenames))))))

(defmethod ede-want-any-files-p ((this ede-sourcecode) filenames)
  "Return non-nil if THIS will accept any files in FILENAMES."
  (let (found)
    (while (and (not found) filenames)
      (setq found (ede-want-file-p this (pop filenames))))))

(defmethod ede-buffer-header-file ((this ede-sourcecode) filename)
  "Return a list of file names of header files for THIS with FILENAME.
Used to guess header files, but uses the auxsource regular expression."
  (let ((dn (file-name-directory filename))
	(ts (file-name-sans-extension (file-name-nondirectory filename)))
	(ae (oref this auxsourcepattern)))
    (if (not ae)
	nil
      (directory-files dn t (concat (regexp-quote ts) ae)))))

;;; Utility functions
;;
(when nil
  ;; not used at the moment.
(defun ede-source-find (name)
  "Find the sourcecode object based on NAME."
  (object-assoc name :name ede-sourcecode-list))

(defun ede-source-match (file)
  "Find the list of soucecode objects which matches FILE."
  (let ((lst ede-sourcecode-list)
	(match nil))
    (while lst
      ;; ede-file-mine doesn't exist yet
      (if (ede-file-mine (car lst) file)
	  (setq match (cons (car lst) match)))
      (setq lst (cdr lst)))
    match))
)
;;; Master list of source code types
;;
;; This must appear at the end so that the init method will work.
(defvar ede-source-scheme
  (ede-sourcecode "ede-source-scheme"
		  :name "Scheme"
		  :sourcepattern "\\.scm$")
  "Scheme source code definition.")

;;(defvar ede-source-
;;  (ede-sourcecode "ede-source-"
;;		    :name ""
;;		    :sourcepattern "\\.$"
;;		    :garbagepattern '("*."))
;;  " source code definition.")

(provide 'ede/source)

;;; ede/source.el ends here