Mercurial > emacs
changeset 837:a8aef92e0025
*** empty log message ***
author | Richard M. Stallman <rms@gnu.org> |
---|---|
date | Wed, 22 Jul 1992 01:36:20 +0000 |
parents | a7cc5061c4de |
children | c8798ebd7d95 |
files | lisp/add-log.el lisp/progmodes/c-mode.el |
diffstat | 2 files changed, 154 insertions(+), 96 deletions(-) [+] |
line wrap: on
line diff
--- a/lisp/add-log.el Wed Jul 22 01:19:00 1992 +0000 +++ b/lisp/add-log.el Wed Jul 22 01:36:20 1992 +0000 @@ -75,8 +75,8 @@ buffer-file-name) (substring buffer-file-name (match-end 0)) (file-name-nondirectory buffer-file-name)))) - ;; Never want to add a change log entry for the ChangeLog buffer itself. - (if (equal file-name entry) + ;; Never want to add a change log entry for the ChangeLog file itself. + (if (equal entry "ChangeLog") (setq entry nil defun nil)) (if (and other-window (not (equal file-name buffer-file-name))) @@ -115,11 +115,16 @@ entry-boundary t) (1- (match-end 0))))))) + ;; Now insert the new line for this entry. (cond (entry-position ;; Move to the existing entry for the same file. (goto-char entry-position) (re-search-forward "^\\s *$") - (open-line 1) + (beginning-of-line) + (while (looking-at "^\\s *$") + (delete-region (point) (save-excursion (forward-line 1) (point)))) + (insert "\n\n") + (forward-line -2) (indent-relative-maybe)) (empty-entry ;; Put this file name into the existing empty entry. @@ -131,14 +136,13 @@ (forward-line 1) (while (looking-at "\\sW") (forward-line 1)) - (delete-region (point) - (progn - (skip-chars-backward "\n") - (point))) - (open-line 3) - (forward-line 2) + (while (looking-at "^\\s *$") + (delete-region (point) (save-excursion (forward-line 1) (point)))) + (insert "\n\n\n") + (forward-line -2) (indent-to left-margin) (insert "* " (or entry "")))) + ;; Now insert the function name, if we have one. ;; Point is at the entry for this file, ;; either at the end of the line or at the first blank line. (if defun @@ -151,10 +155,11 @@ "" " ") "(" defun "): ")) + ;; No function name, so put in a colon unless we have just a star. (if (not (save-excursion (beginning-of-line 1) (looking-at "\\s *\\(\\*\\s *\\)?$"))) - (insert ":"))))) + (insert ": "))))) ;;;###autoload (define-key ctl-x-4-map "a" 'add-change-log-entry-other-window) @@ -172,8 +177,7 @@ (defun change-log-mode () "Major mode for editting change logs; like Indented Text Mode. -Prevents numeric backups and sets `left-margin' to 8 and `fill-column' -to 74. +Prevents numeric backups and sets `left-margin' to 8 and `fill-column'to 74. New log entries are usually made with \\[add-change-log-entry]." (interactive) (kill-all-local-variables) @@ -213,47 +217,65 @@ Has a preference of looking backwards." (save-excursion - (cond ((memq major-mode '(emacs-lisp-mode lisp-mode)) - (beginning-of-defun) - (forward-word 1) - (skip-chars-forward " ") - (buffer-substring (point) - (progn (forward-sexp 1) (point)))) - ((eq major-mode 'c-mode) - ;; must be inside function body for this to work - (beginning-of-defun) - (forward-line -1) - (while (looking-at "[ \t\n]") ; skip typedefs of arglist - (forward-line -1)) - (down-list 1) ; into arglist - (backward-up-list 1) - (skip-chars-backward " \t") - (buffer-substring (point) - (progn (backward-sexp 1) - (point)))) - ((memq major-mode - '(TeX-mode plain-TeX-mode LaTeX-mode;; tex-mode.el - plain-tex-mode latex-mode;; cmutex.el - )) - (if (re-search-backward - "\\\\\\(sub\\)*\\(section\\|paragraph\\|chapter\\)" nil t) - (progn - (goto-char (match-beginning 0)) - (buffer-substring (1+ (point));; without initial backslash - (progn - (end-of-line) - (point)))))) - ((eq major-mode 'texinfo-mode) - (if (re-search-backward "^@node[ \t]+\\([^,]+\\)," nil t) - (buffer-substring (match-beginning 1) - (match-end 1)))) - (t - ;; If all else fails, try heuristics - (let (case-fold-search) - (if (re-search-backward add-log-current-defun-header-regexp - (- (point) 10000) - t) + (let ((location (point))) + (cond ((memq major-mode '(emacs-lisp-mode lisp-mode scheme-mode)) + ;; If we are now precisely a the beginning of a defun, + ;; make sure beginning-of-defun finds that one + ;; rather than the previous one. + (forward-char 1) + (beginning-of-defun) + ;; Make sure we are really inside the defun found, not after it. + (if (save-excursion (end-of-defun) + (< location (point))) + (progn + (forward-word 1) + (skip-chars-forward " ") + (buffer-substring (point) + (progn (forward-sexp 1) (point)))))) + ((or (eq major-mode 'c-mode) + (eq major-mode 'c++-mode)) + ;; See if we are in the beginning part of a function, + ;; before the open brace. If so, advance forward. + (while (not (or (looking-at "{") + (looking-at "\\s *$"))) + (forward-line 1)) + (forward-char 1) + (beginning-of-defun) + (if (save-excursion (end-of-defun) + (< location (point))) + (progn + (forward-line -1) + (while (looking-at "[ \t\n]") ; skip typedefs of arglist + (forward-line -1)) + (down-list 1) ; into arglist + (backward-up-list 1) + (skip-chars-backward " \t") + (buffer-substring (point) + (progn (backward-sexp 1) + (point)))))) + ((memq major-mode + '(TeX-mode plain-TeX-mode LaTeX-mode;; tex-mode.el + plain-tex-mode latex-mode;; cmutex.el + )) + (if (re-search-backward + "\\\\\\(sub\\)*\\(section\\|paragraph\\|chapter\\)" nil t) + (progn + (goto-char (match-beginning 0)) + (buffer-substring (1+ (point));; without initial backslash + (progn + (end-of-line) + (point)))))) + ((eq major-mode 'texinfo-mode) + (if (re-search-backward "^@node[ \t]+\\([^,]+\\)," nil t) (buffer-substring (match-beginning 1) - (match-end 1)))))))) + (match-end 1)))) + (t + ;; If all else fails, try heuristics + (let (case-fold-search) + (if (re-search-backward add-log-current-defun-header-regexp + (- (point) 10000) + t) + (buffer-substring (match-beginning 1) + (match-end 1))))))))) ;;; add-log.el ends here
--- a/lisp/progmodes/c-mode.el Wed Jul 22 01:19:00 1992 +0000 +++ b/lisp/progmodes/c-mode.el Wed Jul 22 01:36:20 1992 +0000 @@ -130,42 +130,6 @@ "*Non-nil means TAB in C mode should always reindent the current line, regardless of where in the line point is when the TAB command is used.") -(defun set-c-style (&optional style) - "Set up the c-mode style variables from the c-style variable or if - STYLE argument is given, use that. It makes the c indentation style - variables buffer local." - (interactive) - (let ((c-styles (mapcar 'car c-style-alist))) - (if (interactive-p) - (setq style - (let ((style-string ; get style name with completion - (completing-read - (format "Set c mode indentation style to (default %s): " - default-c-style) - (vconcat c-styles) - (function (lambda (arg) (memq arg c-styles))) - ))) - (if (string-equal "" style-string) - default-c-style - (intern style-string)) - ))) - (setq style (or style c-style)) ; use c-style if style is nil - (make-local-variable 'c-style) - (if (memq style c-styles) - (setq c-style style) - (error "Bad c style: %s" style) - ) - (message "c-style: %s" c-style) - ; finally, set the indentation style variables making each one local - (mapcar (function (lambda (c-style-pair) - (make-local-variable (car c-style-pair)) - (set (car c-style-pair) - (cdr c-style-pair)))) - (cdr (assq c-style c-style-alist))) - c-style - ) - ) - (defun c-mode () "Major mode for editing C code. Expression and list commands understand all C brackets. @@ -1066,18 +1030,90 @@ (indent-c-exp endmark) (set-marker endmark nil)))) -(defun set-c-style (style) +(defun set-c-style (style &optional global) "Set C-mode variables to use one of several different indentation styles. -Takes one argument, a string representing the desired style. -Available styles are GNU, K&R, BSD and Whitesmith." +The arguments are a string representing the desired style +and a flag which, if non-nil, means to set the style globally. +\(Interactively, the flag comes from the prefix argument.) +Available styles are GNU, K&R, BSD and Whitesmith. (interactive (list (completing-read "Use which C indentation style? " - c-style-alist nil t))) + c-style-alist nil t) + current-prefix-arg)) (let ((vars (cdr (assoc style c-style-alist)))) - (if vars - (if (interactive-p) (message "Using %s C indentation style" style)) - (error "Bogus style type, \"%s\"" style)) + (or vars + (error "Invalid C indentation style `%s'" style)) (while vars + (or global + (make-local-variable (car (car vars)))) (set (car (car vars)) (cdr (car vars))) (setq vars (cdr vars))))) + +;;; This page handles insertion and removal of backslashes for C macros. + +(defvar c-backslash-column 48 + "*Minimum column for end-of-line backslashes of macro definitions.") + +(defun c-backslash-region (from to delete-flag) + "Insert, align, or delete end-of-line backslashes on the lines in the region. +With no argument, inserts backslashes and aligns existing backslashes. +With an argument, deletes the backslashes. + +This function does not modify the last line of the region if the region ends +right at the start of the following line; it does not modify blank lines +at the start of the region. So you can put the region around an entire macro +definition and conveniently use this command." + (interactive "r\nP") + (save-excursion + (goto-char from) + (let ((column c-backslash-column) + (endmark (make-marker))) + (move-marker endmark to) + ;; Compute the smallest column number past the ends of all the lines. + (if (not delete-flag) + (while (< (point) to) + (end-of-line) + (if (= (preceding-char) ?\\) + (progn (forward-char -1) + (skip-chars-backward " \t"))) + (setq column (max column (1+ (current-column)))) + (forward-line 1))) + ;; Adjust upward to a tab column, if that doesn't push past the margin. + (if (> (% column tab-width) 0) + (let ((adjusted (* (/ (+ column tab-width -1) tab-width) tab-width))) + (if (< adjusted (window-width)) + (setq column adjusted)))) + ;; Don't modify blank lines at start of region. + (goto-char from) + (while (and (< (point) endmark) (eolp)) + (forward-line 1)) + ;; Add or remove backslashes on all the lines. + (while (and (< (point) endmark) + ;; Don't backslashify the last line + ;; if the region ends right at the start of the next line. + (save-excursion + (forward-line 1) + (< (point) endmark))) + (if (not delete-flag) + (c-append-backslash column) + (c-delete-backslash)) + (forward-line 1)) + (move-marker endmark nil)))) + +(defun c-append-backslash (column) + (end-of-line) + ;; Note that "\\\\" is needed to get one backslash. + (if (= (preceding-char) ?\\) + (progn (forward-char -1) + (delete-horizontal-space) + (indent-to column)) + (indent-to column) + (insert "\\"))) + +(defun c-delete-backslash () + (end-of-line) + (forward-char -1) + (if (looking-at "\\\\") + (delete-region (1+ (point)) + (progn (skip-chars-backward " \t") (point))))) ;;; c-mode.el ends here