source.el 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. ;; ede/source.el --- EDE source code object
  2. ;; Copyright (C) 2000, 2008-2012 Free Software Foundation, Inc.
  3. ;; Author: Eric M. Ludlam <zappo@gnu.org>
  4. ;; Keywords: project, make
  5. ;; This file is part of GNU Emacs.
  6. ;; GNU Emacs is free software: you can redistribute it and/or modify
  7. ;; it under the terms of the GNU General Public License as published by
  8. ;; the Free Software Foundation, either version 3 of the License, or
  9. ;; (at your option) any later version.
  10. ;; GNU Emacs is distributed in the hope that it will be useful,
  11. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. ;; GNU General Public License for more details.
  14. ;; You should have received a copy of the GNU General Public License
  15. ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
  16. ;;; Commentary:
  17. ;; Manage different types of source code. A master list of source code types
  18. ;; will be maintained, and used to track target objects, what they accept,
  19. ;; and what compilers can be used.
  20. (require 'eieio-base)
  21. ;;; Code:
  22. (defclass ede-sourcecode (eieio-instance-inheritor)
  23. ((name :initarg :name
  24. :type string
  25. :documentation
  26. "The name of this type of source code.
  27. Such as \"C\" or \"Emacs Lisp\"")
  28. (sourcepattern :initarg :sourcepattern
  29. :initform ".*"
  30. :type string
  31. :documentation
  32. "Emacs regexp matching sourcecode this target accepts.")
  33. (auxsourcepattern :initarg :auxsourcepattern
  34. :initform nil
  35. :type (or null string)
  36. :documentation
  37. "Emacs regexp matching auxiliary source code this target accepts.
  38. Aux source are source code files needed for compilation, which are not compiled
  39. themselves.")
  40. (enable-subdirectories :initarg :enable-subdirectories
  41. :initform nil
  42. :type boolean
  43. :documentation
  44. "Non nil if this sourcecode type uses subdirectories.
  45. If sourcecode always lives near the target creating it, this should be nil.
  46. If sourcecode can, or typically lives in a subdirectory of the owning
  47. target, set this to t.")
  48. (garbagepattern :initarg :garbagepattern
  49. :initform nil
  50. :type list
  51. :documentation
  52. "Shell file regexp matching files considered as garbage.
  53. This is a list of items added to an `rm' command when executing a `clean'
  54. type directive.")
  55. )
  56. "Description of some type of source code.
  57. Objects will use sourcecode objects to define the types of source
  58. that they are willing to use.")
  59. (defvar ede-sourcecode-list nil
  60. "The master list of all EDE compilers.")
  61. ;;; Methods
  62. ;;
  63. (defmethod initialize-instance :AFTER ((this ede-sourcecode) &rest fields)
  64. "Make sure that all ede compiler objects are cached in
  65. `ede-compiler-list'."
  66. (let ((lst ede-sourcecode-list))
  67. ;; Find an object of the same name.
  68. (while (and lst (not (string= (oref this name) (oref (car lst) name))))
  69. (setq lst (cdr lst)))
  70. (if lst
  71. ;; Replace old definition
  72. (setcar lst this)
  73. ;; Add to the beginning of the list.
  74. (setq ede-sourcecode-list (cons this ede-sourcecode-list)))))
  75. (defmethod ede-want-file-p ((this ede-sourcecode) filename)
  76. "Return non-nil if sourcecode definition THIS will take FILENAME."
  77. (or (ede-want-file-source-p this filename)
  78. (ede-want-file-auxiliary-p this filename)))
  79. (defmethod ede-want-file-source-p ((this ede-sourcecode) filename)
  80. "Return non-nil if THIS will take FILENAME as an auxiliary ."
  81. (let ((case-fold-search nil))
  82. (string-match (oref this sourcepattern) filename)))
  83. (defmethod ede-want-file-auxiliary-p ((this ede-sourcecode) filename)
  84. "Return non-nil if THIS will take FILENAME as an auxiliary ."
  85. (let ((case-fold-search nil))
  86. (and (slot-boundp this 'auxsourcepattern)
  87. (oref this auxsourcepattern)
  88. (string-match (oref this auxsourcepattern) filename))))
  89. (defmethod ede-want-any-source-files-p ((this ede-sourcecode) filenames)
  90. "Return non-nil if THIS will accept any source files in FILENAMES."
  91. (let (found)
  92. (while (and (not found) filenames)
  93. (setq found (ede-want-file-source-p this (pop filenames))))
  94. found))
  95. (defmethod ede-want-any-auxiliary-files-p ((this ede-sourcecode) filenames)
  96. "Return non-nil if THIS will accept any aux files in FILENAMES."
  97. (let (found)
  98. (while (and (not found) filenames)
  99. (setq found (ede-want-file-auxiliary-p this (pop filenames))))
  100. found))
  101. (defmethod ede-want-any-files-p ((this ede-sourcecode) filenames)
  102. "Return non-nil if THIS will accept any files in FILENAMES."
  103. (let (found)
  104. (while (and (not found) filenames)
  105. (setq found (ede-want-file-p this (pop filenames))))
  106. found))
  107. (defmethod ede-buffer-header-file ((this ede-sourcecode) filename)
  108. "Return a list of file names of header files for THIS with FILENAME.
  109. Used to guess header files, but uses the auxsource regular expression."
  110. (let ((dn (file-name-directory filename))
  111. (ts (file-name-sans-extension (file-name-nondirectory filename)))
  112. (ae (oref this auxsourcepattern)))
  113. (if (not ae)
  114. nil
  115. (directory-files dn t (concat (regexp-quote ts) ae)))))
  116. ;;; Utility functions
  117. ;;
  118. (when nil
  119. ;; not used at the moment.
  120. (defun ede-source-find (name)
  121. "Find the sourcecode object based on NAME."
  122. (object-assoc name :name ede-sourcecode-list))
  123. (defun ede-source-match (file)
  124. "Find the list of sourcecode objects which matches FILE."
  125. (let ((lst ede-sourcecode-list)
  126. (match nil))
  127. (while lst
  128. ;; ede-file-mine doesn't exist yet
  129. (if (ede-file-mine (car lst) file)
  130. (setq match (cons (car lst) match)))
  131. (setq lst (cdr lst)))
  132. match))
  133. )
  134. ;;; Master list of source code types
  135. ;;
  136. ;; This must appear at the end so that the init method will work.
  137. (defvar ede-source-scheme
  138. (ede-sourcecode "ede-source-scheme"
  139. :name "Scheme"
  140. :sourcepattern "\\.scm$")
  141. "Scheme source code definition.")
  142. ;;(defvar ede-source-
  143. ;; (ede-sourcecode "ede-source-"
  144. ;; :name ""
  145. ;; :sourcepattern "\\.$"
  146. ;; :garbagepattern '("*."))
  147. ;; " source code definition.")
  148. (provide 'ede/source)
  149. ;;; ede/source.el ends here