diff options
| author | Richard M. Stallman | 1997-03-24 05:30:10 +0000 |
|---|---|---|
| committer | Richard M. Stallman | 1997-03-24 05:30:10 +0000 |
| commit | dfa9e6fcb058ccf586cc5be830ac61a038c63844 (patch) | |
| tree | 65a4310d520a38c8183738289df1857115394fd8 | |
| parent | ef5a63450913aa5b846081e56a717b174227a196 (diff) | |
| download | emacs-dfa9e6fcb058ccf586cc5be830ac61a038c63844.tar.gz emacs-dfa9e6fcb058ccf586cc5be830ac61a038c63844.zip | |
(makefile-backslash-align): New variable.
(makefile-backslash-region): Re-imported from cc-mode; modified to
handle makefile-backslash-align.
(makefile-append-backslash, makefile-delete-backslash):
Re-imported from cc-mode.
(makefile-backslashify-current-line): Function deleted.
(makefile-fill-paragraph): New function.
(makefile-mode-map): Bind C-c C-c to comment-region.
(makefile-mode): Set fill-paragraph to makefile-fill-paragraph.
| -rw-r--r-- | lisp/progmodes/make-mode.el | 184 |
1 files changed, 140 insertions, 44 deletions
diff --git a/lisp/progmodes/make-mode.el b/lisp/progmodes/make-mode.el index 7c7580a7f20..2cea25c6441 100644 --- a/lisp/progmodes/make-mode.el +++ b/lisp/progmodes/make-mode.el | |||
| @@ -62,8 +62,6 @@ | |||
| 62 | ;; | 62 | ;; |
| 63 | ;; To Do: | 63 | ;; To Do: |
| 64 | ;; | 64 | ;; |
| 65 | ;; * makefile-backslash-region should be given better behavior. | ||
| 66 | ;; * Consider binding C-c C-c to comment-region (like cc-mode). | ||
| 67 | ;; * Eliminate electric stuff entirely. | 65 | ;; * Eliminate electric stuff entirely. |
| 68 | ;; * It might be nice to highlight targets differently depending on | 66 | ;; * It might be nice to highlight targets differently depending on |
| 69 | ;; whether they are up-to-date or not. Not sure how this would | 67 | ;; whether they are up-to-date or not. Not sure how this would |
| @@ -138,6 +136,9 @@ up or down in the browser.") | |||
| 138 | (defvar makefile-backslash-column 48 | 136 | (defvar makefile-backslash-column 48 |
| 139 | "*Column in which `makefile-backslash-region' inserts backslashes.") | 137 | "*Column in which `makefile-backslash-region' inserts backslashes.") |
| 140 | 138 | ||
| 139 | (defvar makefile-backslash-align t | ||
| 140 | "If non-nil, `makefile-backslash-region' will align backslashes.") | ||
| 141 | |||
| 141 | (defvar makefile-browser-selected-mark "+ " | 142 | (defvar makefile-browser-selected-mark "+ " |
| 142 | "String used to mark selected entries in the browser.") | 143 | "String used to mark selected entries in the browser.") |
| 143 | 144 | ||
| @@ -290,6 +291,7 @@ The function must satisfy this calling convention: | |||
| 290 | (define-key makefile-mode-map "." 'makefile-electric-dot))) | 291 | (define-key makefile-mode-map "." 'makefile-electric-dot))) |
| 291 | (define-key makefile-mode-map "\C-c\C-f" 'makefile-pickup-filenames-as-targets) | 292 | (define-key makefile-mode-map "\C-c\C-f" 'makefile-pickup-filenames-as-targets) |
| 292 | (define-key makefile-mode-map "\C-c\C-b" 'makefile-switch-to-browser) | 293 | (define-key makefile-mode-map "\C-c\C-b" 'makefile-switch-to-browser) |
| 294 | (define-key makefile-mode-map "\C-c\C-c" 'comment-region) | ||
| 293 | (define-key makefile-mode-map "\C-c\C-p" 'makefile-pickup-everything) | 295 | (define-key makefile-mode-map "\C-c\C-p" 'makefile-pickup-everything) |
| 294 | (define-key makefile-mode-map "\C-c\C-u" 'makefile-create-up-to-date-overview) | 296 | (define-key makefile-mode-map "\C-c\C-u" 'makefile-create-up-to-date-overview) |
| 295 | (define-key makefile-mode-map "\C-c\C-i" 'makefile-insert-gmake-function) | 297 | (define-key makefile-mode-map "\C-c\C-i" 'makefile-insert-gmake-function) |
| @@ -508,6 +510,10 @@ makefile-special-targets-list: | |||
| 508 | (make-local-variable 'dabbrev-abbrev-skip-leading-regexp) | 510 | (make-local-variable 'dabbrev-abbrev-skip-leading-regexp) |
| 509 | (setq dabbrev-abbrev-skip-leading-regexp "\\$") | 511 | (setq dabbrev-abbrev-skip-leading-regexp "\\$") |
| 510 | 512 | ||
| 513 | ;; Filling. | ||
| 514 | (make-local-variable 'fill-paragraph-function) | ||
| 515 | (setq fill-paragraph-function 'makefile-fill-paragraph) | ||
| 516 | |||
| 511 | ;; Comment stuff. | 517 | ;; Comment stuff. |
| 512 | (make-local-variable 'comment-start) | 518 | (make-local-variable 'comment-start) |
| 513 | (setq comment-start "#") | 519 | (setq comment-start "#") |
| @@ -835,51 +841,141 @@ The context determines which are considered." | |||
| 835 | 841 | ||
| 836 | ;; Backslashification. Stolen from cc-mode.el. | 842 | ;; Backslashification. Stolen from cc-mode.el. |
| 837 | 843 | ||
| 838 | (defun makefile-backslashify-current-line (doit) | 844 | (defun makefile-backslash-region (from to delete-flag) |
| 839 | (end-of-line) | 845 | "Insert, align, or delete end-of-line backslashes on the lines in the region. |
| 840 | (if doit | 846 | With no argument, inserts backslashes and aligns existing backslashes. |
| 841 | (if (not (save-excursion | 847 | With an argument, deletes the backslashes. |
| 842 | (forward-char -1) | 848 | |
| 843 | (eq (char-after (point)) ?\\ ))) | 849 | This function does not modify the last line of the region if the region ends |
| 844 | (progn | 850 | right at the start of the following line; it does not modify blank lines |
| 845 | (if (>= (current-column) makefile-backslash-column) | 851 | at the start of the region. So you can put the region around an entire macro |
| 846 | (insert " \\") | 852 | definition and conveniently use this command." |
| 847 | (while (<= (current-column) makefile-backslash-column) | ||
| 848 | (insert "\t") | ||
| 849 | (end-of-line)) | ||
| 850 | (delete-char -1) | ||
| 851 | (while (< (current-column) makefile-backslash-column) | ||
| 852 | (insert " ") | ||
| 853 | (end-of-line)) | ||
| 854 | (insert "\\")))) | ||
| 855 | (if (not (bolp)) | ||
| 856 | (progn | ||
| 857 | (forward-char -1) | ||
| 858 | (if (eq (char-after (point)) ?\\ ) | ||
| 859 | (let ((saved (save-excursion | ||
| 860 | (end-of-line) | ||
| 861 | (point)))) | ||
| 862 | (skip-chars-backward " \t") | ||
| 863 | (delete-region (point) saved))))))) | ||
| 864 | |||
| 865 | (defun makefile-backslash-region (beg end arg) | ||
| 866 | "Insert backslashes at end of every line in region. | ||
| 867 | Useful for defining multi-line rules. | ||
| 868 | If called with a prefix argument, trailing backslashes are removed." | ||
| 869 | (interactive "r\nP") | 853 | (interactive "r\nP") |
| 870 | (save-excursion | 854 | (save-excursion |
| 871 | (let ((do-lastline-p (progn (goto-char end) (not (bolp))))) | 855 | (goto-char from) |
| 856 | (let ((column makefile-backslash-column) | ||
| 857 | (endmark (make-marker))) | ||
| 858 | (move-marker endmark to) | ||
| 859 | ;; Compute the smallest column number past the ends of all the lines. | ||
| 860 | (if makefile-backslash-align | ||
| 861 | (progn | ||
| 862 | (if (not delete-flag) | ||
| 863 | (while (< (point) to) | ||
| 864 | (end-of-line) | ||
| 865 | (if (= (preceding-char) ?\\) | ||
| 866 | (progn (forward-char -1) | ||
| 867 | (skip-chars-backward " \t"))) | ||
| 868 | (setq column (max column (1+ (current-column)))) | ||
| 869 | (forward-line 1))) | ||
| 870 | ;; Adjust upward to a tab column, if that doesn't push | ||
| 871 | ;; past the margin. | ||
| 872 | (if (> (% column tab-width) 0) | ||
| 873 | (let ((adjusted (* (/ (+ column tab-width -1) tab-width) | ||
| 874 | tab-width))) | ||
| 875 | (if (< adjusted (window-width)) | ||
| 876 | (setq column adjusted)))))) | ||
| 877 | ;; Don't modify blank lines at start of region. | ||
| 878 | (goto-char from) | ||
| 879 | (while (and (< (point) endmark) (eolp)) | ||
| 880 | (forward-line 1)) | ||
| 881 | ;; Add or remove backslashes on all the lines. | ||
| 882 | (while (and (< (point) endmark) | ||
| 883 | ;; Don't backslashify the last line | ||
| 884 | ;; if the region ends right at the start of the next line. | ||
| 885 | (save-excursion | ||
| 886 | (forward-line 1) | ||
| 887 | (< (point) endmark))) | ||
| 888 | (if (not delete-flag) | ||
| 889 | (makefile-append-backslash column) | ||
| 890 | (makefile-delete-backslash)) | ||
| 891 | (forward-line 1)) | ||
| 892 | (move-marker endmark nil)))) | ||
| 893 | |||
| 894 | (defun makefile-append-backslash (column) | ||
| 895 | (end-of-line) | ||
| 896 | ;; Note that "\\\\" is needed to get one backslash. | ||
| 897 | (if (= (preceding-char) ?\\) | ||
| 898 | (progn (forward-char -1) | ||
| 899 | (delete-horizontal-space) | ||
| 900 | (indent-to column (if makefile-backslash-align nil 1))) | ||
| 901 | (indent-to column (if makefile-backslash-align nil 1)) | ||
| 902 | (insert "\\"))) | ||
| 903 | |||
| 904 | (defun makefile-delete-backslash () | ||
| 905 | (end-of-line) | ||
| 906 | (or (bolp) | ||
| 907 | (progn | ||
| 908 | (forward-char -1) | ||
| 909 | (if (looking-at "\\\\") | ||
| 910 | (delete-region (1+ (point)) | ||
| 911 | (progn (skip-chars-backward " \t") (point))))))) | ||
| 912 | |||
| 913 | |||
| 914 | |||
| 915 | ;; Filling | ||
| 916 | |||
| 917 | (defun makefile-fill-paragraph (arg) | ||
| 918 | ;; Fill comments, backslashed lines, and variable definitions | ||
| 919 | ;; specially. | ||
| 920 | (save-excursion | ||
| 921 | (beginning-of-line) | ||
| 922 | (cond | ||
| 923 | ((looking-at "^#+ ") | ||
| 924 | ;; Found a comment. Set the fill prefix and then fill. | ||
| 925 | (let ((fill-prefix (buffer-substring-no-properties (match-beginning 0) | ||
| 926 | (match-end 0))) | ||
| 927 | (fill-paragraph-function nil)) | ||
| 928 | (fill-paragraph nil) | ||
| 929 | t)) | ||
| 930 | |||
| 931 | ;; Must look for backslashed-region before looking for variable | ||
| 932 | ;; assignment. | ||
| 933 | ((save-excursion | ||
| 934 | (end-of-line) | ||
| 935 | (or | ||
| 936 | (= (preceding-char) ?\\) | ||
| 937 | (progn | ||
| 938 | (end-of-line -1) | ||
| 939 | (= (preceding-char) ?\\)))) | ||
| 940 | ;; A backslash region. Find beginning and end, remove | ||
| 941 | ;; backslashes, fill, and then reapply backslahes. | ||
| 942 | (end-of-line) | ||
| 943 | (let ((beginning | ||
| 944 | (save-excursion | ||
| 945 | (end-of-line 0) | ||
| 946 | (while (= (preceding-char) ?\\) | ||
| 947 | (end-of-line 0)) | ||
| 948 | (forward-char) | ||
| 949 | (point))) | ||
| 950 | (end | ||
| 951 | (save-excursion | ||
| 952 | (while (= (preceding-char) ?\\) | ||
| 953 | (end-of-line 2)) | ||
| 954 | (point)))) | ||
| 955 | (save-restriction | ||
| 956 | (narrow-to-region beginning end) | ||
| 957 | (makefile-backslash-region (point-min) (point-max) t) | ||
| 958 | (let ((fill-paragraph-function nil)) | ||
| 959 | (fill-paragraph nil)) | ||
| 960 | (makefile-backslash-region (point-min) (point-max) nil) | ||
| 961 | (goto-char (point-max)) | ||
| 962 | (if (< (skip-chars-backward "\n") 0) | ||
| 963 | (delete-region (point) (point-max)))))) | ||
| 964 | |||
| 965 | ((looking-at makefile-macroassign-regex) | ||
| 966 | ;; Have a macro assign. Fill just this line, and then backslash | ||
| 967 | ;; resulting region. | ||
| 872 | (save-restriction | 968 | (save-restriction |
| 873 | (narrow-to-region beg end) | 969 | (narrow-to-region (point) (save-excursion |
| 874 | (goto-char (point-min)) | 970 | (end-of-line) |
| 875 | (while (not (save-excursion | 971 | (forward-char) |
| 876 | (forward-line 1) | 972 | (point))) |
| 877 | (eobp))) | 973 | (let ((fill-paragraph-function nil)) |
| 878 | (makefile-backslashify-current-line (null arg)) | 974 | (fill-paragraph nil)) |
| 879 | (forward-line 1))) | 975 | (makefile-backslash-region (point-min) (point-max) nil))))) |
| 880 | (and do-lastline-p | 976 | |
| 881 | (progn (goto-char end) | 977 | ;; Always return non-nil so we don't fill anything else. |
| 882 | (makefile-backslashify-current-line (null arg))))))) | 978 | t) |
| 883 | 979 | ||
| 884 | 980 | ||
| 885 | 981 | ||