Mercurial > hg > xemacs-beta
comparison lisp/files.el @ 5766:182d01410b8d
Add mode-require-final-newline from GNU. Thanks GNU.
lisp/ChangeLog:
2013-09-15 Mats Lidell <matsl@cxemacs.org>
* files.el (mode-require-final-newline): Variable synced from
GNU. Thank you GNU. Allows modes to control final newlines.
(require-final-newline): Add action on visiting and visiting or
saving in sync with GNU.
* text-mode.el (text-mode): Use mode-require-final-newline.
man/ChangeLog:
2013-09-15 Mats Lidell <matsl@xemacs.org>
* xemacs/files.texi (Saving): New variable
mode-require-final-newline. Update info for
require-final-newline.
tests/ChangeLog:
2013-09-15 Mats Lidell <matsl@xemacs.org>
* automated/files-tests.el: New file. Test new states in
require-final-newline and new variable
mode-require-final-newline.
author | Mats Lidell <mats.lidell@cag.se> |
---|---|
date | Mon, 16 Sep 2013 00:00:12 +0200 |
parents | cc852bdbdbaa |
children | bbe4146603db |
comparison
equal
deleted
inserted
replaced
5765:e88d026f3917 | 5766:182d01410b8d |
---|---|
1 ;;; files.el --- file input and output commands for XEmacs. | 1 ;;; files.el --- file input and output commands for XEmacs. |
2 | 2 |
3 ;; Copyright (C) 1985-1987, 1992-1995, 1997 Free Software Foundation, Inc. | 3 ;; Copyright (C) 1985-1987, 1992-1995, 1997, 2013 Free Software Foundation, Inc. |
4 ;; Copyright (C) 1995 Sun Microsystems. | 4 ;; Copyright (C) 1995 Sun Microsystems. |
5 ;; Copyright (C) 2001, 2002, 2003 Ben Wing. | 5 ;; Copyright (C) 2001, 2002, 2003 Ben Wing. |
6 | 6 |
7 ;; Maintainer: XEmacs Development Team | 7 ;; Maintainer: XEmacs Development Team |
8 ;; Keywords: extensions, dumped | 8 ;; Keywords: extensions, dumped |
295 Includes the new backup. Must be > 0" | 295 Includes the new backup. Must be > 0" |
296 :type 'integer | 296 :type 'integer |
297 :group 'backup) | 297 :group 'backup) |
298 | 298 |
299 (defcustom require-final-newline nil | 299 (defcustom require-final-newline nil |
300 "*Value of t says silently ensure a file ends in a newline when it is saved. | 300 "Whether to add a newline automatically at the end of the file. |
301 Non-nil but not t says ask user whether to add a newline when there isn't one. | 301 |
302 nil means don't add newlines." | 302 A value of t means do this only when the file is about to be saved. |
303 :type '(choice (const :tag "Off" nil) | 303 A value of `visit' means do this right after the file is visited. |
304 (const :tag "Add" t) | 304 A value of `visit-save' means do it at both of those times. |
305 (sexp :tag "Ask" :format "%t\n" ask)) | 305 Any other non-nil value means ask user whether to add a newline, when saving. |
306 :group 'editing-basics) | 306 A value of nil means don't add newlines. |
307 | |
308 Certain major modes set this locally to the value obtained | |
309 from `mode-require-final-newline'." | |
310 :type '(choice (const :tag "When visiting" visit) | |
311 (const :tag "When saving" t) | |
312 (const :tag "When visiting or saving" visit-save) | |
313 (const :tag "Don't add newlines" nil) | |
314 (other :tag "Ask each time" ask)) | |
315 :group 'editing-basics | |
316 :version "21.5.35") | |
317 | |
318 (defcustom mode-require-final-newline t | |
319 "Whether to add a newline at end of file, in certain major modes. | |
320 Those modes set `require-final-newline' to this value when you enable them. | |
321 They do so because they are often used for files that are supposed | |
322 to end in newlines, and the question is how to arrange that. | |
323 | |
324 A value of t means do this only when the file is about to be saved. | |
325 A value of `visit' means do this right after the file is visited. | |
326 A value of `visit-save' means do it at both of those times. | |
327 Any other non-nil value means ask user whether to add a newline, when saving. | |
328 | |
329 A value of nil means do not add newlines. That is a risky choice in this | |
330 variable since this value is used for modes for files that ought to have | |
331 final newlines. So if you set this to nil, you must explicitly check and | |
332 add a final newline, whenever you save a file that really needs one." | |
333 :type '(choice (const :tag "When visiting" visit) | |
334 (const :tag "When saving" t) | |
335 (const :tag "When visiting or saving" visit-save) | |
336 (const :tag "Don't add newlines" nil) | |
337 (other :tag "Ask each time" ask)) | |
338 :group 'editing-basics | |
339 :version "21.5.35") | |
307 | 340 |
308 (defcustom auto-save-default t | 341 (defcustom auto-save-default t |
309 "*Non-nil says by default do auto-saving of every file-visiting buffer." | 342 "*Non-nil says by default do auto-saving of every file-visiting buffer." |
310 :type 'boolean | 343 :type 'boolean |
311 :group 'auto-save) | 344 :group 'auto-save) |
1574 (unless nomodes | 1607 (unless nomodes |
1575 ;; #### No view-mode-disable. | 1608 ;; #### No view-mode-disable. |
1576 ; (when view-read-only | 1609 ; (when view-read-only |
1577 ; (and-boundp 'view-mode (view-mode-disable))) | 1610 ; (and-boundp 'view-mode (view-mode-disable))) |
1578 (normal-mode t) | 1611 (normal-mode t) |
1612 ;; If requested, add a newline at the end of the file. | |
1613 (and (memq require-final-newline '(visit visit-save)) | |
1614 (> (point-max) (point-min)) | |
1615 (/= (char-after (1- (point-max))) ?\n) | |
1616 (not (and (eq selective-display t) | |
1617 (= (char-after (1- (point-max))) ?\r))) | |
1618 (not buffer-read-only) | |
1619 (save-excursion | |
1620 (goto-char (point-max)) | |
1621 (ignore-errors (insert "\n")))) | |
1579 (when (and buffer-read-only | 1622 (when (and buffer-read-only |
1580 view-read-only | 1623 view-read-only |
1581 (not (eq (get major-mode 'mode-class) 'special))) | 1624 (not (eq (get major-mode 'mode-class) 'special))) |
1582 (view-mode)) | 1625 (view-mode)) |
1583 (run-hooks 'find-file-hooks))) | 1626 (run-hooks 'find-file-hooks))) |
2831 (not find-file-literally) | 2874 (not find-file-literally) |
2832 (not (eq (char-after (1- (point-max))) ?\n)) | 2875 (not (eq (char-after (1- (point-max))) ?\n)) |
2833 (not (and (eq selective-display t) | 2876 (not (and (eq selective-display t) |
2834 (eq (char-after (1- (point-max))) ?\r))) | 2877 (eq (char-after (1- (point-max))) ?\r))) |
2835 (or (eq require-final-newline t) | 2878 (or (eq require-final-newline t) |
2879 (eq require-final-newline 'visit-save) | |
2836 (and require-final-newline | 2880 (and require-final-newline |
2837 (y-or-n-p | 2881 (y-or-n-p |
2838 (format "Buffer %s does not end in newline. Add one? " | 2882 (format "Buffer %s does not end in newline. Add one? " |
2839 (buffer-name))))) | 2883 (buffer-name))))) |
2840 (save-excursion | 2884 (save-excursion |