]> code.delx.au - gnu-emacs/blobdiff - lisp/cedet/ede/autoconf-edit.el
Update copyright year to 2015
[gnu-emacs] / lisp / cedet / ede / autoconf-edit.el
index 666ba0b0a06b2af89261e3bdfd396a0db5158e6a..687b8a0f5ade131be3885e516adb2877dd37a4ff 100644 (file)
@@ -1,6 +1,6 @@
 ;;; ede/autoconf-edit.el --- Keymap for autoconf
 
-;; Copyright (C) 1998-2000, 2009-201 Free Software Foundation, Inc.
+;; Copyright (C) 1998-2000, 2009-2015 Free Software Foundation, Inc.
 
 ;; Author: Eric M. Ludlam <zappo@gnu.org>
 ;; Keywords: project
@@ -31,7 +31,7 @@
 (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.
+  "Initialize a new configure.ac in ROOTDIR for PROGRAM using TESTFILE.
 ROOTDIR is the root directory of a given autoconf controlled project.
 PROGRAM is the program to be configured.
 TESTFILE is the file used with AC_INIT.
@@ -60,6 +60,7 @@ configure the initial configure script using `autoconf-new-automake-string'"
 
 (defvar autoconf-preferred-macro-order
   '("AC_INIT"
+    "AC_CONFIG_SRCDIR"
     "AM_INIT_AUTOMAKE"
     "AM_CONFIG_HEADER"
     ;; Arg parsing
@@ -165,6 +166,9 @@ items such as CHECK_HEADERS."
     (setq param (substring param (match-end 0))))
   (when (string-match "\\s-*\\]?\\s-*\\'" param)
     (setq param (substring param 0  (match-beginning 0))))
+  ;; Look for occurrences of backslash newline
+  (while (string-match "\\s-*\\\\\\s-*\n\\s-*" param)
+    (setq param (replace-match " " t t param)))
   param)
 
 (defun autoconf-parameters-for-macro (macro &optional ignore-bol ignore-case)
@@ -325,7 +329,7 @@ Optional argument PARAM is the parameter to pass to the macro as one string."
   "Position the cursor where PROG is queried.
 PROG is the VARIABLE to use in autoconf to identify the program.
 PROG excludes the _PROG suffix.  Thus if PROG were EMACS, then the
-variable in configure.in would be EMACS_PROG."
+variable in configure.ac would be EMACS_PROG."
   (let ((op (point))
        (found t)
        (builtin (assoc prog autoconf-program-builtin)))
@@ -373,6 +377,38 @@ Optional argument BODY is the code to execute which edits the autoconf file."
              (string= autoconf-deleted-text autoconf-inserted-text))
         (set-buffer-modified-p nil))))
 
+(defun autoconf-parameter-count ()
+  "Return the number of parameters to the function on the current line."
+  (save-excursion
+    (beginning-of-line)
+    (let* ((end-of-cmd
+           (save-excursion
+             (if (re-search-forward "(" (point-at-eol) t)
+                 (progn
+                   (forward-char -1)
+                   (forward-sexp 1)
+                   (point))
+               ;; Else, just return EOL.
+               (point-at-eol))))
+          (cnt 0))
+      (save-restriction
+       (narrow-to-region (point-at-bol) end-of-cmd)
+       (condition-case nil
+           (progn
+             (down-list 1)
+             (while (re-search-forward ", ?" end-of-cmd t)
+               (setq cnt (1+ cnt)))
+             (cond ((> cnt 1)
+                    ;; If the # is > 1, then there is one fewer , than args.
+                    (1+ cnt))
+                   ((not (looking-at "\\s-*)"))
+                    ;; If there are 0 args, then we have to see if there is one arg.
+                    (1+ cnt))
+                   (t
+                    ;; Else, just return the 0.
+                    cnt)))
+         (error 0))))))
+
 (defun autoconf-delete-parameter (index)
   "Delete the INDEXth parameter from the macro starting on the current line.
 Leaves the cursor where a new parameter can be inserted.
@@ -396,12 +432,19 @@ INDEX starts at 1."
   "Set the version used with automake to VERSION."
   (if (not (stringp version))
       (signal 'wrong-type-argument '(stringp version)))
-  (if (not (autoconf-find-last-macro "AM_INIT_AUTOMAKE"))
-      (error "Cannot update version")
-    ;; Move to correct position.
+  (if (and (autoconf-find-last-macro "AM_INIT_AUTOMAKE")
+          (>= (autoconf-parameter-count) 2))
+      ;; We can edit right here.
+      nil
+    ;; Else, look for AC init instead.
+    (if (not (and (autoconf-find-last-macro "AC_INIT")
+                 (>= (autoconf-parameter-count) 2)))
+      (error "Cannot update version")))
+
+    ;; Perform the edit.
     (autoconf-edit-cycle
      (autoconf-delete-parameter 2)
-     (autoconf-insert version))))
+     (autoconf-insert (concat "[" version "]"))))
 
 (defun autoconf-set-output (outputlist)
   "Set the files created in AC_OUTPUT to OUTPUTLIST.