]> git.ipfire.org Git - thirdparty/gettext.git/commitdiff
awk and bash support (untested)
authorBruno Haible <bruno@clisp.org>
Mon, 13 Aug 2001 20:54:35 +0000 (20:54 +0000)
committerBruno Haible <bruno@clisp.org>
Mon, 13 Aug 2001 20:54:35 +0000 (20:54 +0000)
misc/ChangeLog
misc/po-mode.el

index 5dfdb0db618be8a506880474465f3318f424eb03..9f91e011857d0e3e4f0b996d2387e4a625a5ebc4 100644 (file)
@@ -1,3 +1,9 @@
+2001-08-01  François Pinard  <pinard@iro.umontreal.ca>
+
+       * po-mode.el (po-find-awk-string, po-mark-awk-string,
+       po-find-bash-string, po-mark-bash-string): New functions.
+       (po-preset-string-functions): Add awk and bash support.
+
 2001-08-02  Karl Eichwalder  <ke@suse.de>
 
        * po-mode.el (po-find-file-coding-system-guts): Use ascii instead of
index 25fb42998e4ce8ca34f4e9855133ea907b2d3313..b14c197b6e74a1117220eb27d3ebe70689dc7935 100644 (file)
@@ -2402,12 +2402,17 @@ keyword for subsequent commands, also added to possible completions."
 (defun po-preset-string-functions ()
   "Preset FIND-STRING-FUNCTION and MARK-STRING-FUNCTION according to mode.
 These variables are locally set in source buffer only when not already bound."
-  (let ((pair (cond ((member mode-name '("C" "C++"))
+  (let ((pair (cond ((string-equal mode-name "AWK")
+                    '(po-find-awk-string . po-mark-awk-string))
+                   ((member mode-name '("C" "C++"))
                     '(po-find-c-string . po-mark-c-string))
                    ((string-equal mode-name "Emacs-Lisp")
                     '(po-find-emacs-lisp-string . po-mark-emacs-lisp-string))
                    ((string-equal mode-name "Python")
                     '(po-find-python-string . po-mark-python-string))
+                   ((and (string-equal mode-name "Shell-script")
+                         (string-equal mode-line-process "[bash]"))
+                    '(po-find-bash-string . po-mark-bash-string))
                    (t '(po-find-unknown-string . po-mark-unknown-string)))))
     (or (boundp 'po-find-string-function)
        (set (make-local-variable 'po-find-string-function) (car pair)))
@@ -2422,6 +2427,108 @@ These variables are locally set in source buffer only when not already bound."
   "Dummy function to mark a given string.  May not be called."
   (error (_"Dummy function called")))
 \f
+;;; Awk mode specifics.
+
+(defun po-find-awk-string (keywords)
+  "Find the next Awk string, excluding those marked by any of KEYWORDS.
+Return (CONTENTS START END) for the found string, or nil if none found."
+  (let (start end)
+    (while (and (not start)
+               (re-search-forward "[#/\"]" nil t))
+      (cond ((= (preceding-char) ?#)
+            ;; Disregard comments.
+            (or (search-forward "\n" nil t)
+                (goto-char (point-max))))
+           ((= (preceding-char) ?/)
+            ;; Skip regular expressions.
+            (while (not (= (following-char) ?/))
+              (skip-chars-forward "^/\\\\")
+              (if (= (following-char) ?\\) (forward-char 2)))
+            (forward-char 1))
+           ;; Else find the end of the string.
+           (t (setq start (1- (point)))
+              (while (not (= (following-char) ?\"))
+                (skip-chars-forward "^\"\\\\")
+                (if (= (following-char) ?\\) (forward-char 2)))
+              (forward-char 1)
+              (setq end (point))
+              ;; Check before string either for underline, or for keyword
+              ;; and opening parenthesis.
+              (save-excursion
+                (goto-char start)
+                (cond ((= (preceding-char) ?_)
+                       ;; Disregard already marked strings.
+                       (setq start nil
+                             end nil))
+                      ((= (preceding-char) ?\()
+                       (backward-char 1)
+                       (let ((end-keyword (point)))
+                         (skip-chars-backward "_A-Za-z0-9")
+                         (if (member (list (po-buffer-substring
+                                            (point) end-keyword))
+                                     keywords)
+                             ;; Disregard already marked strings.
+                             (setq start nil
+                                   end nil)))))))))
+    (and start end
+        (list (po-extract-unquoted (current-buffer) start end) start end))))
+
+(defun po-mark-awk-string (start end keyword)
+  "Mark the Awk string, from START to END, with KEYWORD.
+Leave point after marked string."
+  (if (string-equal keyword "_")
+      (progn
+       (goto-char start)
+       (insert "_")
+       (goto-char (1+ end)))
+    (goto-char end)
+    (insert ")")
+    (save-excursion
+      (goto-char start)
+      (insert keyword "("))))
+\f
+;;; Bash mode specifics.
+
+(defun po-find-bash-string (keywords)
+  "Find the next unmarked Bash string.  KEYWORDS are merely ignored.
+Return (CONTENTS START END) for the found string, or nil if none found."
+  (let (start end)
+    (while (and (not start)
+               (re-search-forward "[#'\"]" nil t))
+      (cond ((= (preceding-char) ?#)
+            ;; Disregard comments.
+            (or (search-forward "\n" nil t)
+                (goto-char (point-max))))
+           ((= (preceding-char) ?')
+            ;; Skip single quoted strings.
+            (while (not (= (following-char) ?'))
+              (skip-chars-forward "^'\\\\")
+              (if (= (following-char) ?\\) (forward-char 2)))
+            (forward-char 1))
+           ;; Else find the end of the double quoted string.
+           (t (setq start (1- (point)))
+              (while (not (= (following-char) ?\"))
+                (skip-chars-forward "^\"\\\\")
+                (if (= (following-char) ?\\) (forward-char 2)))
+              (forward-char 1)
+              (setq end (point))
+              ;; Check before string for dollar sign.
+              (save-excursion
+                (goto-char start)
+                (if (= (preceding-char) ?$)
+                    ;; Disregard already marked strings.
+                    (setq start nil
+                          end nil))))))
+    (and start end
+        (list (po-extract-unquoted (current-buffer) start end) start end))))
+
+(defun po-mark-bash-string (start end keyword)
+  "Mark the Bash string, from START to END, with `$'.  KEYWORD is ignored.
+Leave point after marked string."
+  (goto-char start)
+  (insert "$")
+  (goto-char (1+ end)))
+\f
 ;;; C or C++ mode specifics.
 
 ;;; A few long string cases (submitted by Ben Pfaff).