diff options
| author | Stefan Monnier | 2005-03-25 00:06:07 +0000 |
|---|---|---|
| committer | Stefan Monnier | 2005-03-25 00:06:07 +0000 |
| commit | 4bd0a5d078287de216a0f3f0a6b546495a30afe2 (patch) | |
| tree | d89fa75ebe26522329568515f133036b2988fbe3 | |
| parent | cd2325cdd387d20d04c10fd84f15a2880a7e8b98 (diff) | |
| download | emacs-4bd0a5d078287de216a0f3f0a6b546495a30afe2.tar.gz emacs-4bd0a5d078287de216a0f3f0a6b546495a30afe2.zip | |
(flymake-ensure-ends-with-slash): Remove.
Substitute file-name-as-directory in the rest of the file.
(flymake-get-common-file-prefix): Rewrite, using compare-strings.
(flymake-replace-region): Remove unused arg `buffer'.
(flymake-check-patch-master-file-buffer): Update calls to it.
(flymake-add-err-info): Remove unused var `count'.
(flymake-mode): Use define-minor-mode.
| -rw-r--r-- | lisp/progmodes/flymake.el | 102 |
1 files changed, 35 insertions, 67 deletions
diff --git a/lisp/progmodes/flymake.el b/lisp/progmodes/flymake.el index b9fa6cf4754..255be0ad3f3 100644 --- a/lisp/progmodes/flymake.el +++ b/lisp/progmodes/flymake.el | |||
| @@ -357,31 +357,14 @@ Return t if so, nil if not." | |||
| 357 | (equal (flymake-fix-file-name file-name-one) | 357 | (equal (flymake-fix-file-name file-name-one) |
| 358 | (flymake-fix-file-name file-name-two))) | 358 | (flymake-fix-file-name file-name-two))) |
| 359 | 359 | ||
| 360 | (defun flymake-ensure-ends-with-slash (filename) | ||
| 361 | ;; Should this really be file-name-as-directory? | ||
| 362 | (if (not (= (elt filename (1- (length filename))) (string-to-char "/"))) | ||
| 363 | (concat filename "/") | ||
| 364 | filename)) | ||
| 365 | |||
| 366 | (defun flymake-get-common-file-prefix (string-one string-two) | 360 | (defun flymake-get-common-file-prefix (string-one string-two) |
| 367 | "Return common prefix for two file names STRING-ONE and STRING-TWO." | 361 | "Return common prefix for two file names STRING-ONE and STRING-TWO." |
| 368 | (when (and string-one string-two) | 362 | (setq string-one (file-name-as-directory string-one)) |
| 369 | (let* ((slash-pos-one -1) | 363 | (setq string-two (file-name-as-directory string-two)) |
| 370 | (slash-pos-two -1) | 364 | (let ((n (compare-strings string-one nil nil string-two nil nil))) |
| 371 | (done nil) | 365 | (if (eq n t) string-one |
| 372 | (prefix nil)) | 366 | (setq n (abs (1+ n))) |
| 373 | (setq string-one (flymake-ensure-ends-with-slash string-one)) | 367 | (file-name-directory (substring string-one 0 n))))) |
| 374 | (setq string-two (flymake-ensure-ends-with-slash string-two)) | ||
| 375 | (while (not done) | ||
| 376 | (setq slash-pos-one (string-match "/" string-one (1+ slash-pos-one))) | ||
| 377 | (setq slash-pos-two (string-match "/" string-two (1+ slash-pos-two))) | ||
| 378 | (if (and slash-pos-one slash-pos-two | ||
| 379 | (= slash-pos-one slash-pos-two) | ||
| 380 | (string= (substring string-one 0 slash-pos-one) (substring string-two 0 slash-pos-two))) | ||
| 381 | (progn | ||
| 382 | (setq prefix (substring string-one 0 (1+ slash-pos-one)))) | ||
| 383 | (setq done t))) | ||
| 384 | prefix))) | ||
| 385 | 368 | ||
| 386 | (defun flymake-build-relative-filename (from-dir to-dir) | 369 | (defun flymake-build-relative-filename (from-dir to-dir) |
| 387 | "Return rel: FROM-DIR/rel == TO-DIR." | 370 | "Return rel: FROM-DIR/rel == TO-DIR." |
| @@ -389,8 +372,8 @@ Return t if so, nil if not." | |||
| 389 | (if (not (equal (elt from-dir 0) (elt to-dir 0))) | 372 | (if (not (equal (elt from-dir 0) (elt to-dir 0))) |
| 390 | (error "First chars in file names %s, %s must be equal (same drive)" | 373 | (error "First chars in file names %s, %s must be equal (same drive)" |
| 391 | from-dir to-dir) | 374 | from-dir to-dir) |
| 392 | (let* ((from (flymake-ensure-ends-with-slash (flymake-fix-file-name from-dir))) | 375 | (let* ((from (file-name-as-directory (flymake-fix-file-name from-dir))) |
| 393 | (to (flymake-ensure-ends-with-slash (flymake-fix-file-name to-dir))) | 376 | (to (file-name-as-directory (flymake-fix-file-name to-dir))) |
| 394 | (prefix (flymake-get-common-file-prefix from to)) | 377 | (prefix (flymake-get-common-file-prefix from to)) |
| 395 | (from-suffix (substring from (length prefix))) | 378 | (from-suffix (substring from (length prefix))) |
| 396 | (up-count (length (flymake-split-string from-suffix "[/]"))) | 379 | (up-count (length (flymake-split-string from-suffix "[/]"))) |
| @@ -513,7 +496,7 @@ instead of reading master file from disk." | |||
| 513 | ;; replace-match is not used here as it fails in | 496 | ;; replace-match is not used here as it fails in |
| 514 | ;; XEmacs with 'last match not a buffer' error as | 497 | ;; XEmacs with 'last match not a buffer' error as |
| 515 | ;; check-includes calls replace-in-string | 498 | ;; check-includes calls replace-in-string |
| 516 | (flymake-replace-region (current-buffer) match-beg match-end | 499 | (flymake-replace-region match-beg match-end |
| 517 | (file-name-nondirectory patched-source-file-name)))) | 500 | (file-name-nondirectory patched-source-file-name)))) |
| 518 | (forward-line 1))) | 501 | (forward-line 1))) |
| 519 | (when found | 502 | (when found |
| @@ -525,12 +508,13 @@ instead of reading master file from disk." | |||
| 525 | (flymake-log 2 "found master file %s" master-file-name)) | 508 | (flymake-log 2 "found master file %s" master-file-name)) |
| 526 | found)) | 509 | found)) |
| 527 | 510 | ||
| 528 | (defun flymake-replace-region (buffer beg end rep) | 511 | (defun flymake-replace-region (beg end rep) |
| 529 | "Replace text in BUFFER in region (BEG END) with REP." | 512 | "Replace text in BUFFER in region (BEG END) with REP." |
| 530 | (save-excursion | 513 | (save-excursion |
| 531 | (delete-region beg end) | 514 | (goto-char end) |
| 532 | (goto-char beg) | 515 | ;; Insert before deleting, so as to better preserve markers's positions. |
| 533 | (insert rep))) | 516 | (insert rep) |
| 517 | (delete-region beg end))) | ||
| 534 | 518 | ||
| 535 | (defun flymake-read-file-to-temp-buffer (file-name) | 519 | (defun flymake-read-file-to-temp-buffer (file-name) |
| 536 | "Insert contents of FILE-NAME into newly created temp buffer." | 520 | "Insert contents of FILE-NAME into newly created temp buffer." |
| @@ -1103,8 +1087,7 @@ Return its components if so, nil if no." | |||
| 1103 | 1087 | ||
| 1104 | (defun flymake-add-err-info (err-info-list line-err-info) | 1088 | (defun flymake-add-err-info (err-info-list line-err-info) |
| 1105 | "Add error info (file line type text) to err info list preserving sort order." | 1089 | "Add error info (file line type text) to err info list preserving sort order." |
| 1106 | (let* ((count (length err-info-list)) | 1090 | (let* ((line-no (if (flymake-ler-get-file line-err-info) 1 (flymake-ler-get-line line-err-info))) |
| 1107 | (line-no (if (flymake-ler-get-file line-err-info) 1 (flymake-ler-get-line line-err-info))) | ||
| 1108 | (info-and-pos (flymake-find-err-info err-info-list line-no)) | 1091 | (info-and-pos (flymake-find-err-info err-info-list line-no)) |
| 1109 | (exists (car info-and-pos)) | 1092 | (exists (car info-and-pos)) |
| 1110 | (pos (nth 1 info-and-pos)) | 1093 | (pos (nth 1 info-and-pos)) |
| @@ -1462,12 +1445,7 @@ Return first 'INCLUDE-DIRS/REL-FILE-NAME' that exists, or just REL-FILE-NAME if | |||
| 1462 | (goto-line line)))) | 1445 | (goto-line line)))) |
| 1463 | 1446 | ||
| 1464 | ;; flymake minor mode declarations | 1447 | ;; flymake minor mode declarations |
| 1465 | (defvar flymake-mode nil) | 1448 | (defvar flymake-mode-line nil) |
| 1466 | |||
| 1467 | (make-variable-buffer-local 'flymake-mode) | ||
| 1468 | |||
| 1469 | (defvar flymake-mode-line nil | ||
| 1470 | "") | ||
| 1471 | 1449 | ||
| 1472 | (make-variable-buffer-local 'flymake-mode-line) | 1450 | (make-variable-buffer-local 'flymake-mode-line) |
| 1473 | 1451 | ||
| @@ -1532,24 +1510,16 @@ Return first 'INCLUDE-DIRS/REL-FILE-NAME' that exists, or just REL-FILE-NAME if | |||
| 1532 | (flymake-log 0 "switched OFF Flymake mode for buffer %s due to fatal status %s, warning %s" | 1510 | (flymake-log 0 "switched OFF Flymake mode for buffer %s due to fatal status %s, warning %s" |
| 1533 | (buffer-name buffer) status warning))) | 1511 | (buffer-name buffer) status warning))) |
| 1534 | 1512 | ||
| 1535 | (defun flymake-mode (&optional arg) | 1513 | (define-minor-mode flymake-mode |
| 1536 | "Toggle flymake mode on/off." | 1514 | "Minor mode to do on-the-fly syntax checking. |
| 1537 | (interactive) | 1515 | When called interactively, toggles the minor mode. |
| 1538 | (let ((old-flymake-mode flymake-mode) | 1516 | With arg, turn Flymake mode on if and only if arg is positive." |
| 1539 | (turn-on nil)) | 1517 | :lighter flymake-mode-line |
| 1540 | 1518 | (if flymake-mode | |
| 1541 | (setq turn-on | 1519 | (if (flymake-can-syntax-check-file (buffer-file-name)) |
| 1542 | (if (null arg) | 1520 | (flymake-mode-on) |
| 1543 | (not flymake-mode) | 1521 | (flymake-log 2 "flymake cannot check syntax in buffer %s" (buffer-name))) |
| 1544 | ;else | 1522 | (flymake-mode-off))) |
| 1545 | (> (prefix-numeric-value arg) 0))) | ||
| 1546 | |||
| 1547 | (if turn-on | ||
| 1548 | (if (flymake-can-syntax-check-file (buffer-file-name)) | ||
| 1549 | (flymake-mode-on) | ||
| 1550 | (flymake-log 2 "flymake cannot check syntax in buffer %s" (buffer-name))) | ||
| 1551 | (flymake-mode-off)) | ||
| 1552 | (force-mode-line-update))) | ||
| 1553 | 1523 | ||
| 1554 | (defcustom flymake-start-syntax-check-on-find-file t | 1524 | (defcustom flymake-start-syntax-check-on-find-file t |
| 1555 | "Start syntax check on find file." | 1525 | "Start syntax check on find file." |
| @@ -1557,10 +1527,6 @@ Return first 'INCLUDE-DIRS/REL-FILE-NAME' that exists, or just REL-FILE-NAME if | |||
| 1557 | :type 'boolean) | 1527 | :type 'boolean) |
| 1558 | 1528 | ||
| 1559 | ;;;###autoload | 1529 | ;;;###autoload |
| 1560 | (unless (assq 'flymake-mode minor-mode-alist) | ||
| 1561 | (setq minor-mode-alist (cons '(flymake-mode flymake-mode-line) minor-mode-alist))) | ||
| 1562 | |||
| 1563 | ;;;###autoload | ||
| 1564 | (defun flymake-mode-on () | 1530 | (defun flymake-mode-on () |
| 1565 | "Turn flymake mode on." | 1531 | "Turn flymake mode on." |
| 1566 | (when (not flymake-mode) | 1532 | (when (not flymake-mode) |
| @@ -1719,9 +1685,9 @@ Return first 'INCLUDE-DIRS/REL-FILE-NAME' that exists, or just REL-FILE-NAME if | |||
| 1719 | 1685 | ||
| 1720 | (let* ((dir (file-name-directory file-name)) | 1686 | (let* ((dir (file-name-directory file-name)) |
| 1721 | (slash-pos (string-match "/" dir)) | 1687 | (slash-pos (string-match "/" dir)) |
| 1722 | (temp-dir (concat (flymake-ensure-ends-with-slash (flymake-get-temp-dir)) (substring dir (1+ slash-pos))))) | 1688 | (temp-dir (concat (file-name-as-directory (flymake-get-temp-dir)) (substring dir (1+ slash-pos))))) |
| 1723 | 1689 | ||
| 1724 | (file-truename (concat (flymake-ensure-ends-with-slash temp-dir) | 1690 | (file-truename (concat (file-name-as-directory temp-dir) |
| 1725 | (file-name-nondirectory file-name))))) | 1691 | (file-name-nondirectory file-name))))) |
| 1726 | 1692 | ||
| 1727 | (defun flymake-strrchr (str ch) | 1693 | (defun flymake-strrchr (str ch) |
| @@ -1741,7 +1707,7 @@ Return first 'INCLUDE-DIRS/REL-FILE-NAME' that exists, or just REL-FILE-NAME if | |||
| 1741 | 1707 | ||
| 1742 | (while (> (length suffix) 0) | 1708 | (while (> (length suffix) 0) |
| 1743 | ;;+(flymake-log 0 "suffix=%s" suffix) | 1709 | ;;+(flymake-log 0 "suffix=%s" suffix) |
| 1744 | (flymake-safe-delete-directory (file-truename (concat (flymake-ensure-ends-with-slash temp-dir) suffix))) | 1710 | (flymake-safe-delete-directory (file-truename (concat (file-name-as-directory temp-dir) suffix))) |
| 1745 | (setq slash-pos (flymake-strrchr suffix (string-to-char "/"))) | 1711 | (setq slash-pos (flymake-strrchr suffix (string-to-char "/"))) |
| 1746 | (if slash-pos | 1712 | (if slash-pos |
| 1747 | (setq suffix (substring suffix 0 slash-pos)) | 1713 | (setq suffix (substring suffix 0 slash-pos)) |
| @@ -1957,9 +1923,11 @@ Use CREATE-TEMP-F for creating temp copy." | |||
| 1957 | 1923 | ||
| 1958 | ;;;; perl-specific init-cleanup routines | 1924 | ;;;; perl-specific init-cleanup routines |
| 1959 | (defun flymake-perl-init (buffer) | 1925 | (defun flymake-perl-init (buffer) |
| 1960 | (let* ((temp-file (flymake-init-create-temp-buffer-copy buffer 'flymake-create-temp-inplace)) | 1926 | (let* ((temp-file (flymake-init-create-temp-buffer-copy |
| 1961 | (local-file (concat (flymake-build-relative-filename (file-name-directory (buffer-file-name (current-buffer))) | 1927 | buffer 'flymake-create-temp-inplace)) |
| 1962 | (file-name-directory temp-file)) | 1928 | (local-file (concat (flymake-build-relative-filename |
| 1929 | (file-name-directory buffer-file-name) | ||
| 1930 | (file-name-directory temp-file)) | ||
| 1963 | (file-name-nondirectory temp-file)))) | 1931 | (file-name-nondirectory temp-file)))) |
| 1964 | (list "perl" (list "-wc " local-file)))) | 1932 | (list "perl" (list "-wc " local-file)))) |
| 1965 | 1933 | ||
| @@ -1983,7 +1951,7 @@ Use CREATE-TEMP-F for creating temp copy." | |||
| 1983 | '(".")) | 1951 | '(".")) |
| 1984 | 1952 | ||
| 1985 | ;;;; xml-specific init-cleanup routines | 1953 | ;;;; xml-specific init-cleanup routines |
| 1986 | (defun flymake-xml-init(buffer) | 1954 | (defun flymake-xml-init (buffer) |
| 1987 | (list "xml" (list "val" (flymake-init-create-temp-buffer-copy buffer 'flymake-create-temp-inplace)))) | 1955 | (list "xml" (list "val" (flymake-init-create-temp-buffer-copy buffer 'flymake-create-temp-inplace)))) |
| 1988 | 1956 | ||
| 1989 | (provide 'flymake) | 1957 | (provide 'flymake) |