Spelling fixes.
[bpt/emacs.git] / lisp / cedet / ede / autoconf-edit.el
index 03df3f2..c6545dd 100644 (file)
@@ -1,6 +1,6 @@
 ;;; ede/autoconf-edit.el --- Keymap for autoconf
 
-;; Copyright (C) 1998, 1999, 2000, 2009  Free Software Foundation, Inc.
+;; Copyright (C) 1998-2000, 2009-2011  Free Software Foundation, Inc.
 
 ;; Author: Eric M. Ludlam <zappo@gnu.org>
 ;; Keywords: project
 
 ;;; Code:
 (require 'autoconf)
-
-(defvar autoconf-new-automake-string
-  "dnl Process this file with autoconf to produce a configure script
-
-AC_INIT(%s)
-AM_INIT_AUTOMAKE([%s], 0)
-AM_CONFIG_HEADER(config.h)
-
-dnl End the configure script.
-AC_OUTPUT(Makefile, [date > stamp-h] )\n"
-  "This string is used to initialize a new configure.in.
-The default is designed to be used with automake.
-The first %s will be filled with the test file.
-The second %s will be filled with the program name.")
+(declare-function ede-srecode-setup "ede/srecode")
+(declare-function ede-srecode-insert "ede/srecode")
 
 (defun autoconf-new-program (rootdir program testfile)
   "Initialize a new configure.in in ROOTDIR for PROGRAM using TESTFILE.
@@ -49,6 +37,7 @@ PROGRAM is the program to be configured.
 TESTFILE is the file used with AC_INIT.
 configure the initial configure script using `autoconf-new-automake-string'"
   (interactive "DRoot Dir: \nsProgram: \nsTest File: ")
+  (require 'ede/srecode)
   (if (bufferp rootdir)
       (set-buffer rootdir)
     (let ((cf1 (expand-file-name "configure.in" rootdir))
@@ -62,7 +51,12 @@ configure the initial configure script using `autoconf-new-automake-string'"
       (find-file cf2)))
   ;; Note, we only ask about overwrite if a string/path is specified.
   (erase-buffer)
-  (insert (format autoconf-new-automake-string testfile program)))
+  (ede-srecode-setup)
+  (ede-srecode-insert
+   "file:ede-empty"
+   "TEST_FILE" testfile
+   "PROGRAM" program)
+  )
 
 (defvar autoconf-preferred-macro-order
   '("AC_INIT"
@@ -151,42 +145,44 @@ From the autoconf manual:
     (beginning-of-line)
     (looking-at (concat "\\(A[CM]_" macro "\\|" macro "\\)"))))
 
-(defun autoconf-find-last-macro (macro)
+(defun autoconf-find-last-macro (macro &optional ignore-bol)
   "Move to the last occurrence of MACRO in FILE, and return that point.
 The last macro is usually the one in which we would like to insert more
 items such as CHECK_HEADERS."
-  (let ((op (point)))
+  (let ((op (point)) (atbol (if ignore-bol "" "^")))
     (goto-char (point-max))
-    (if (re-search-backward (concat "^" (regexp-quote macro) "\\s-*\\((\\|$\\)") nil t)
+    (if (re-search-backward (concat atbol (regexp-quote macro) "\\s-*\\((\\|$\\)") nil t)
        (progn
-         (beginning-of-line)
+         (unless ignore-bol (beginning-of-line))
          (point))
       (goto-char op)
       nil)))
 
 (defun autoconf-parameter-strip (param)
   "Strip the parameter PARAM  of whitespace and miscellaneous characters."
-  (when (string-match "^\\s-*\\[?\\s-*" param)
+  ;; force greedy match for \n.
+  (when (string-match "\\`\n*\\s-*\\[?\\s-*" param)
     (setq param (substring param (match-end 0))))
-  (when (string-match "\\s-*\\]?\\s-*$" param)
+  (when (string-match "\\s-*\\]?\\s-*\\'" param)
     (setq param (substring param 0  (match-beginning 0))))
   param)
 
-(defun autoconf-parameters-for-macro (macro)
+(defun autoconf-parameters-for-macro (macro &optional ignore-bol ignore-case)
   "Retrieve the parameters to MACRO.
 Returns a list of the arguments passed into MACRO as strings."
-  (save-excursion
-    (when (autoconf-find-last-macro macro)
-      (forward-sexp 1)
-      (mapcar
-       #'autoconf-parameter-strip
-       (when (looking-at "(")
-        (let* ((start (+ (point) 1))
-               (end (save-excursion
-                      (forward-sexp 1)
-                      (- (point) 1)))
-               (ans (buffer-substring-no-properties start end)))
-          (split-string ans "," t)))))))
+  (let ((case-fold-search ignore-case))
+    (save-excursion
+      (when (autoconf-find-last-macro macro ignore-bol)
+       (forward-sexp 1)
+       (mapcar
+        #'autoconf-parameter-strip
+        (when (looking-at "(")
+          (let* ((start (+ (point) 1))
+                 (end (save-excursion
+                        (forward-sexp 1)
+                        (- (point) 1)))
+                 (ans (buffer-substring-no-properties start end)))
+            (split-string ans "," t))))))))
 
 (defun autoconf-position-for-macro (macro)
   "Position the cursor where a new MACRO could be inserted.
@@ -195,7 +191,7 @@ This is to make it compatible with `autoconf-find-last-macro'.
 Assume that MACRO doesn't appear in the buffer yet, so search
 the ordering list `autoconf-preferred-macro-order'."
   ;; Search this list backwards.. heh heh heh
-  ;; This lets us do a reverse search easilly.
+  ;; This lets us do a reverse search easily.
   (let ((ml (member macro (reverse autoconf-preferred-macro-order))))
     (if (not ml) (error "Don't know how to position for %s yet" macro))
     (setq ml (cdr ml))
@@ -385,9 +381,7 @@ INDEX starts at 1."
   (down-list 1)
   (re-search-forward ", ?" nil nil (1- index))
   (let ((end (save-excursion
-              (re-search-forward ",\\|)" (save-excursion
-                                           (end-of-line)
-                                           (point)))
+              (re-search-forward ",\\|)" (point-at-eol))
               (forward-char -1)
               (point))))
     (setq autoconf-deleted-text (buffer-substring (point) end))
@@ -421,5 +415,4 @@ to Makefiles, or other files using Autoconf substitution."
 
 (provide 'ede/autoconf-edit)
 
-;; arch-tag: 5932c433-4fd4-4d5e-ab35-8effd95a405f
 ;;; ede/autoconf-edit.el ends here