Mercurial > emacs
comparison lisp/emulation/viper-ex.el @ 18047:1b06411ccc04
new version
author | Michael Kifer <kifer@cs.stonybrook.edu> |
---|---|
date | Sat, 31 May 1997 00:02:53 +0000 |
parents | de1340e6ddb4 |
children | e92598964ee6 |
comparison
equal
deleted
inserted
replaced
18046:5c0bcd2a1716 | 18047:1b06411ccc04 |
---|---|
1 ;;; viper-ex.el --- functions implementing the Ex commands for Viper | 1 ;;; viper-ex.el --- functions implementing the Ex commands for Viper |
2 | 2 |
3 ;; Copyright (C) 1994, 1995, 1996 Free Software Foundation, Inc. | 3 ;; Copyright (C) 1994, 1995, 1996, 1997 Free Software Foundation, Inc. |
4 | 4 |
5 ;; This file is part of GNU Emacs. | 5 ;; This file is part of GNU Emacs. |
6 | 6 |
7 ;; GNU Emacs is free software; you can redistribute it and/or modify | 7 ;; GNU Emacs is free software; you can redistribute it and/or modify |
8 ;; it under the terms of the GNU General Public License as published by | 8 ;; it under the terms of the GNU General Public License as published by |
17 ;; You should have received a copy of the GNU General Public License | 17 ;; You should have received a copy of the GNU General Public License |
18 ;; along with GNU Emacs; see the file COPYING. If not, write to the | 18 ;; along with GNU Emacs; see the file COPYING. If not, write to the |
19 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, | 19 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
20 ;; Boston, MA 02111-1307, USA. | 20 ;; Boston, MA 02111-1307, USA. |
21 | 21 |
22 | |
23 ;; Code | 22 ;; Code |
24 | 23 |
25 (require 'viper-util) | 24 (provide 'viper-ex) |
26 | 25 |
27 ;; Compiler pacifier | 26 ;; Compiler pacifier |
28 (defvar read-file-name-map) | 27 (defvar read-file-name-map) |
29 ;; end compiler pacifier | 28 (defvar vip-use-register) |
29 (defvar vip-s-string) | |
30 (defvar vip-shift-width) | |
31 (defvar vip-ex-history) | |
32 (defvar vip-related-files-and-buffers-ring) | |
33 (defvar vip-local-search-start-marker) | |
34 (defvar vip-expert-level) | |
35 (defvar vip-custom-file-name) | |
36 (defvar vip-case-fold-search) | |
37 | |
38 (eval-when-compile | |
39 (let ((load-path (cons (expand-file-name ".") load-path))) | |
40 (or (featurep 'viper-util) | |
41 (load "viper-util.el" nil nil 'nosuffix)) | |
42 (or (featurep 'viper-keym) | |
43 (load "viper-keym.el" nil nil 'nosuffix)) | |
44 (or (featurep 'viper) | |
45 (load "viper.el" nil nil 'nosuffix)) | |
46 )) | |
47 ;; end pacifier | |
48 | |
49 (require 'viper-util) | |
50 | |
30 | 51 |
31 ;;; Variables | 52 ;;; Variables |
32 | 53 |
33 (defconst vip-ex-work-buf-name " *ex-working-space*") | 54 (defconst vip-ex-work-buf-name " *ex-working-space*") |
34 (defconst vip-ex-work-buf (get-buffer-create vip-ex-work-buf-name)) | 55 (defconst vip-ex-work-buf (get-buffer-create vip-ex-work-buf-name)) |
635 (setq ex-addresses | 656 (setq ex-addresses |
636 (cons (car ex-addresses) ex-addresses))))) | 657 (cons (car ex-addresses) ex-addresses))))) |
637 | 658 |
638 ;; Get an ex-address as a marker and set ex-flag if a flag is found | 659 ;; Get an ex-address as a marker and set ex-flag if a flag is found |
639 (defun vip-get-ex-address () | 660 (defun vip-get-ex-address () |
640 (let ((address (point-marker)) (cont t)) | 661 (let ((address (point-marker)) |
662 (cont t)) | |
641 (setq ex-token "") | 663 (setq ex-token "") |
642 (setq ex-flag nil) | 664 (setq ex-flag nil) |
643 (while cont | 665 (while cont |
644 (vip-get-ex-token) | 666 (vip-get-ex-token) |
645 (cond ((eq ex-token-type 'command) | 667 (cond ((eq ex-token-type 'command) |
1850 | 1872 |
1851 ;; Ex write command | 1873 ;; Ex write command |
1852 (defun ex-write (q-flag) | 1874 (defun ex-write (q-flag) |
1853 (vip-default-ex-addresses t) | 1875 (vip-default-ex-addresses t) |
1854 (vip-get-ex-file) | 1876 (vip-get-ex-file) |
1855 (let ((end (car ex-addresses)) (beg (car (cdr ex-addresses))) | 1877 (let ((end (car ex-addresses)) |
1878 (beg (car (cdr ex-addresses))) | |
1879 (orig-buf (current-buffer)) | |
1880 (orig-buf-file-name (buffer-file-name)) | |
1881 (orig-buf-name (buffer-name)) | |
1882 (buff-changed-p (buffer-modified-p)) | |
1856 temp-buf writing-same-file region | 1883 temp-buf writing-same-file region |
1857 file-exists writing-whole-file) | 1884 file-exists writing-whole-file) |
1858 (if (> beg end) (error vip-FirstAddrExceedsSecond)) | 1885 (if (> beg end) (error vip-FirstAddrExceedsSecond)) |
1859 (if ex-cmdfile | 1886 (if ex-cmdfile |
1860 (progn | 1887 (progn |
1873 ;; if ex-file is a directory use the file portion of the buffer file name | 1900 ;; if ex-file is a directory use the file portion of the buffer file name |
1874 (if (and (file-directory-p ex-file) | 1901 (if (and (file-directory-p ex-file) |
1875 buffer-file-name | 1902 buffer-file-name |
1876 (not (file-directory-p buffer-file-name))) | 1903 (not (file-directory-p buffer-file-name))) |
1877 (setq ex-file | 1904 (setq ex-file |
1878 (concat ex-file (file-name-nondirectory buffer-file-name)))) | 1905 (concat (file-name-as-directory ex-file) |
1879 | 1906 (file-name-nondirectory buffer-file-name)))) |
1907 | |
1880 (setq file-exists (file-exists-p ex-file) | 1908 (setq file-exists (file-exists-p ex-file) |
1881 writing-same-file (string= ex-file (buffer-file-name))) | 1909 writing-same-file (string= ex-file (buffer-file-name))) |
1882 | 1910 |
1883 (if (and writing-whole-file writing-same-file) | 1911 (if (and writing-whole-file writing-same-file) |
1884 (if (not (buffer-modified-p)) | 1912 (if (not (buffer-modified-p)) |
1885 (message "(No changes need to be saved)") | 1913 (message "(No changes need to be saved)") |
1886 (save-buffer) | 1914 (save-buffer) |
1887 (ex-write-info file-exists ex-file beg end)) | 1915 (save-restriction |
1888 ;; writing some other file or portion of the currents | 1916 (widen) |
1889 ;; file---create temp buffer for it | 1917 (ex-write-info file-exists ex-file (point-min) (point-max)) |
1890 ;; disable undo in that buffer, for efficiency | 1918 )) |
1891 (buffer-disable-undo (setq temp-buf (create-file-buffer ex-file))) | 1919 ;; writing some other file or portion of the current file |
1892 (unwind-protect | 1920 (cond ((and file-exists |
1893 (save-excursion | 1921 (not writing-same-file) |
1894 (if (and file-exists | 1922 (not (yes-or-no-p |
1895 (not writing-same-file) | 1923 (format "File %s exists. Overwrite? " ex-file)))) |
1896 (not (yes-or-no-p | 1924 (error "Quit")) |
1897 (format "File %s exists. Overwrite? " ex-file)))) | 1925 ((and writing-whole-file (not ex-append)) |
1898 (error "Quit") | 1926 (unwind-protect |
1899 (vip-enlarge-region beg end) | 1927 (progn |
1900 (setq region (buffer-substring (point) (mark t))) | 1928 (set-visited-file-name ex-file) |
1901 (set-buffer temp-buf) | 1929 (set-buffer-modified-p t) |
1902 (set-visited-file-name ex-file) | 1930 (save-buffer)) |
1903 (erase-buffer) | 1931 ;; restore the buffer file name |
1904 (if (and file-exists ex-append) | 1932 (set-visited-file-name orig-buf-file-name) |
1905 (insert-file-contents ex-file)) | 1933 (set-buffer-modified-p buff-changed-p) |
1906 (goto-char (point-max)) | 1934 ;; If the buffer wasn't visiting a file, restore buffer name. |
1907 (insert region) | 1935 ;; Name could've been changed by packages such as uniquify. |
1908 (save-buffer) | 1936 (or orig-buf-file-name |
1909 (ex-write-info file-exists ex-file (point-min) (point-max)) | 1937 (progn |
1910 ) | 1938 (unlock-buffer) |
1911 (set-buffer temp-buf) | 1939 (rename-buffer orig-buf-name)))) |
1912 (set-buffer-modified-p nil) | 1940 (save-restriction |
1913 (kill-buffer temp-buf) | 1941 (widen) |
1942 (ex-write-info | |
1943 file-exists ex-file (point-min) (point-max)))) | |
1944 (t ; writing a region | |
1945 (unwind-protect | |
1946 (save-excursion | |
1947 (vip-enlarge-region beg end) | |
1948 (setq region (buffer-substring (point) (mark t))) | |
1949 ;; create temp buffer for the region | |
1950 (setq temp-buf (get-buffer-create " *ex-write*")) | |
1951 (set-buffer temp-buf) | |
1952 (set-visited-file-name ex-file 'noquerry) | |
1953 (erase-buffer) | |
1954 (if (and file-exists ex-append) | |
1955 (insert-file-contents ex-file)) | |
1956 (goto-char (point-max)) | |
1957 (insert region) | |
1958 (save-buffer) | |
1959 (ex-write-info | |
1960 file-exists ex-file (point-min) (point-max)) | |
1961 )) | |
1962 (set-buffer temp-buf) | |
1963 (set-buffer-modified-p nil) | |
1964 (kill-buffer temp-buf)) | |
1914 )) | 1965 )) |
1915 ) | 1966 (set-buffer orig-buf) |
1916 ;; this prevents the loss of data if writing part of the buffer | 1967 ;; this prevents the loss of data if writing part of the buffer |
1917 (if (and (buffer-file-name) writing-same-file) | 1968 (if (and (buffer-file-name) writing-same-file) |
1918 (set-visited-file-modtime)) | 1969 (set-visited-file-modtime)) |
1919 (or writing-whole-file | 1970 (or writing-whole-file |
1920 (not writing-same-file) | 1971 (not writing-same-file) |
2022 (vip-read-event) | 2073 (vip-read-event) |
2023 (kill-buffer " *vip-info*"))) | 2074 (kill-buffer " *vip-info*"))) |
2024 )) | 2075 )) |
2025 | 2076 |
2026 | 2077 |
2027 (provide 'viper-ex) | |
2028 | |
2029 ;;; viper-ex.el ends here | 2078 ;;; viper-ex.el ends here |