Mercurial > emacs
annotate lisp/pcvs-util.el @ 94540:55cb4c49dc98
The day wehen vc-toggle-ready-only was a good idea is long gone.
author | Eric S. Raymond <esr@snark.thyrsus.com> |
---|---|
date | Fri, 02 May 2008 07:12:59 +0000 |
parents | b41935af6fe9 |
children | ee5932bf781d |
rev | line source |
---|---|
38422
7a94f1c588c4
Some fixes to follow coding conventions.
Pavel Janík <Pavel@Janik.cz>
parents:
37338
diff
changeset
|
1 ;;; pcvs-util.el --- utility functions for PCL-CVS -*- byte-compile-dynamic: t -*- |
28088
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2 |
56956
14b1949ce3d4
(cvs-string-prefix-p): Use compare-strings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
55791
diff
changeset
|
3 ;; Copyright (C) 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, |
79721 | 4 ;; 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008 Free Software Foundation, Inc. |
28088
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
5 |
70292
2b77fa42947f
Update my email address.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
69746
diff
changeset
|
6 ;; Author: Stefan Monnier <monnier@iro.umontreal.ca> |
28088
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
7 ;; Keywords: pcl-cvs |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
8 |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
9 ;; This file is part of GNU Emacs. |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
10 |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
11 ;; GNU Emacs is free software; you can redistribute it and/or modify |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
12 ;; it under the terms of the GNU General Public License as published by |
78236
9355f9b7bbff
Switch license to GPLv3 or later.
Glenn Morris <rgm@gnu.org>
parents:
78082
diff
changeset
|
13 ;; the Free Software Foundation; either version 3, or (at your option) |
28088
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
14 ;; any later version. |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
15 |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
16 ;; GNU Emacs is distributed in the hope that it will be useful, |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
19 ;; GNU General Public License for more details. |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
20 |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
21 ;; You should have received a copy of the GNU General Public License |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
22 ;; along with GNU Emacs; see the file COPYING. If not, write to the |
64091 | 23 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
24 ;; Boston, MA 02110-1301, USA. | |
28088
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
25 |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
26 ;;; Commentary: |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
27 |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
28 |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
29 ;;; Code: |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
30 |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
31 (eval-when-compile (require 'cl)) |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
32 |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
33 ;;;; |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
34 ;;;; list processing |
33229
c76308387eec
(cvs-butlast, cvs-nbutlast): New (copied from CL).
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
30618
diff
changeset
|
35 ;;;; |
28088
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
36 |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
37 (defsubst cvs-car (x) (if (consp x) (car x) x)) |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
38 (defalias 'cvs-cdr 'cdr-safe) |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
39 (defsubst cvs-append (&rest xs) |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
40 (apply 'append (mapcar (lambda (x) (if (listp x) x (list x))) xs))) |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
41 |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
42 (defsubst cvs-every (-cvs-every-f -cvs-every-l) |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
43 (while (consp -cvs-every-l) |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
44 (unless (funcall -cvs-every-f (pop -cvs-every-l)) |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
45 (setq -cvs-every-l t))) |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
46 (not -cvs-every-l)) |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
47 |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
48 (defun cvs-union (xs ys) |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
49 (let ((zs ys)) |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
50 (dolist (x xs zs) |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
51 (unless (member x ys) (push x zs))))) |
49597
e88404e8f2cf
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
42205
diff
changeset
|
52 |
28088
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
53 (defun cvs-map (-cvs-map-f &rest -cvs-map-ls) |
93821
882bd14c76fc
(cvs-map): Avoid recursion :-(
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
79721
diff
changeset
|
54 (let ((accum ())) |
882bd14c76fc
(cvs-map): Avoid recursion :-(
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
79721
diff
changeset
|
55 (while (not (cvs-every 'null -cvs-map-ls)) |
882bd14c76fc
(cvs-map): Avoid recursion :-(
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
79721
diff
changeset
|
56 (push (apply -cvs-map-f (mapcar 'car -cvs-map-ls)) accum) |
882bd14c76fc
(cvs-map): Avoid recursion :-(
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
79721
diff
changeset
|
57 (setq -cvs-map-ls (mapcar 'cdr -cvs-map-ls))) |
882bd14c76fc
(cvs-map): Avoid recursion :-(
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
79721
diff
changeset
|
58 (nreverse accum))) |
28088
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
59 |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
60 (defun cvs-first (l &optional n) |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
61 (if (null n) (car l) |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
62 (when l |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
63 (let* ((nl (list (pop l))) |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
64 (ret nl)) |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
65 (while (and l (> n 1)) |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
66 (setcdr nl (list (pop l))) |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
67 (setq nl (cdr nl)) |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
68 (decf n)) |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
69 ret)))) |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
70 |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
71 (defun cvs-partition (p l) |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
72 "Partition a list L into two lists based on predicate P. |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
73 The function returns a `cons' cell where the `car' contains |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
74 elements of L for which P is true while the `cdr' contains |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
75 the other elements. The ordering among elements is maintained." |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
76 (let (car cdr) |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
77 (dolist (x l) |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
78 (if (funcall p x) (push x car) (push x cdr))) |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
79 (cons (nreverse car) (nreverse cdr)))) |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
80 |
34407
bcedf6eef407
Minor doc/comment changes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
34304
diff
changeset
|
81 ;;; |
bcedf6eef407
Minor doc/comment changes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
34304
diff
changeset
|
82 ;;; frame, window, buffer handling |
bcedf6eef407
Minor doc/comment changes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
34304
diff
changeset
|
83 ;;; |
28088
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
84 |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
85 (defun cvs-pop-to-buffer-same-frame (buf) |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
86 "Pop to BUF like `pop-to-buffer' but staying on the same frame. |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
87 If `pop-to-buffer' would have opened a new frame, this function would |
34407
bcedf6eef407
Minor doc/comment changes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
34304
diff
changeset
|
88 try to split a new window instead." |
28088
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
89 (let ((pop-up-windows (or pop-up-windows pop-up-frames)) |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
90 (pop-up-frames nil)) |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
91 (or (let ((buf (get-buffer-window buf))) (and buf (select-window buf))) |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
92 (and pop-up-windows |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
93 (ignore-errors (select-window (split-window-vertically))) |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
94 (switch-to-buffer buf)) |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
95 (pop-to-buffer (current-buffer))))) |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
96 |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
97 (defun cvs-bury-buffer (buf &optional mainbuf) |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
98 "Hide the buffer BUF that was temporarily popped up. |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
99 BUF is assumed to be a temporary buffer used from the buffer MAINBUF." |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
100 (interactive (list (current-buffer))) |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
101 (save-current-buffer |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
102 (let ((win (if (eq buf (window-buffer (selected-window))) (selected-window) |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
103 (get-buffer-window buf t)))) |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
104 (when win |
94133
b41935af6fe9
(cvs-bury-buffer): Use quit-window instead of the
Sam Steingold <sds@gnu.org>
parents:
93821
diff
changeset
|
105 (quit-window nil win))) |
28088
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
106 (when mainbuf |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
107 (let ((mainwin (or (get-buffer-window mainbuf) |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
108 (get-buffer-window mainbuf 'visible)))) |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
109 (when mainwin (select-window mainwin)))))) |
49597
e88404e8f2cf
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
42205
diff
changeset
|
110 |
28088
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
111 (defun cvs-get-buffer-create (name &optional noreuse) |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
112 "Create a buffer NAME unless such a buffer already exists. |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
113 If the NAME looks like an absolute file name, the buffer will be created |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
114 with `create-file-buffer' and will probably get another name than NAME. |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
115 In such a case, the search for another buffer with the same name doesn't |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
116 use the buffer name but the buffer's `list-buffers-directory' variable. |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
117 If NOREUSE is non-nil, always return a new buffer." |
72244
63a604af4b8e
(cvs-get-buffer-create): Obey `noreuse' even if `name'
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
70292
diff
changeset
|
118 (or (and (not (file-name-absolute-p name)) |
63a604af4b8e
(cvs-get-buffer-create): Obey `noreuse' even if `name'
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
70292
diff
changeset
|
119 (if noreuse (generate-new-buffer name) |
63a604af4b8e
(cvs-get-buffer-create): Obey `noreuse' even if `name'
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
70292
diff
changeset
|
120 (get-buffer-create name))) |
28088
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
121 (unless noreuse |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
122 (dolist (buf (buffer-list)) |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
123 (with-current-buffer buf |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
124 (when (equal name list-buffers-directory) |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
125 (return buf))))) |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
126 (with-current-buffer (create-file-buffer name) |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
127 (set (make-local-variable 'list-buffers-directory) name) |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
128 (current-buffer)))) |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
129 |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
130 ;;;; |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
131 ;;;; string processing |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
132 ;;;; |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
133 |
33229
c76308387eec
(cvs-butlast, cvs-nbutlast): New (copied from CL).
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
30618
diff
changeset
|
134 (defun cvs-insert-strings (strings) |
c76308387eec
(cvs-butlast, cvs-nbutlast): New (copied from CL).
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
30618
diff
changeset
|
135 "Insert a list of STRINGS into the current buffer. |
c76308387eec
(cvs-butlast, cvs-nbutlast): New (copied from CL).
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
30618
diff
changeset
|
136 Uses columns to keep the listing readable but compact." |
c76308387eec
(cvs-butlast, cvs-nbutlast): New (copied from CL).
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
30618
diff
changeset
|
137 (when (consp strings) |
c76308387eec
(cvs-butlast, cvs-nbutlast): New (copied from CL).
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
30618
diff
changeset
|
138 (let* ((length (apply 'max (mapcar 'length strings))) |
c76308387eec
(cvs-butlast, cvs-nbutlast): New (copied from CL).
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
30618
diff
changeset
|
139 (wwidth (1- (window-width))) |
c76308387eec
(cvs-butlast, cvs-nbutlast): New (copied from CL).
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
30618
diff
changeset
|
140 (columns (min |
c76308387eec
(cvs-butlast, cvs-nbutlast): New (copied from CL).
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
30618
diff
changeset
|
141 ;; At least 2 columns; at least 2 spaces between columns. |
c76308387eec
(cvs-butlast, cvs-nbutlast): New (copied from CL).
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
30618
diff
changeset
|
142 (max 2 (/ wwidth (+ 2 length))) |
c76308387eec
(cvs-butlast, cvs-nbutlast): New (copied from CL).
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
30618
diff
changeset
|
143 ;; Don't allocate more columns than we can fill. |
37338 | 144 ;; Windows can't show less than 3 lines anyway. |
33229
c76308387eec
(cvs-butlast, cvs-nbutlast): New (copied from CL).
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
30618
diff
changeset
|
145 (max 1 (/ (length strings) 2)))) |
c76308387eec
(cvs-butlast, cvs-nbutlast): New (copied from CL).
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
30618
diff
changeset
|
146 (colwidth (/ wwidth columns))) |
37338 | 147 ;; Use tab-width rather than indent-to. |
33229
c76308387eec
(cvs-butlast, cvs-nbutlast): New (copied from CL).
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
30618
diff
changeset
|
148 (setq tab-width colwidth) |
c76308387eec
(cvs-butlast, cvs-nbutlast): New (copied from CL).
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
30618
diff
changeset
|
149 ;; The insertion should be "sensible" no matter what choices were made. |
c76308387eec
(cvs-butlast, cvs-nbutlast): New (copied from CL).
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
30618
diff
changeset
|
150 (dolist (str strings) |
69746
768d198de598
(cvs-insert-strings): Fix bug with strings longer than wwidth.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
68651
diff
changeset
|
151 (unless (bolp) |
768d198de598
(cvs-insert-strings): Fix bug with strings longer than wwidth.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
68651
diff
changeset
|
152 (insert " \t") |
768d198de598
(cvs-insert-strings): Fix bug with strings longer than wwidth.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
68651
diff
changeset
|
153 (when (< wwidth (+ (max colwidth (length str)) (current-column))) |
768d198de598
(cvs-insert-strings): Fix bug with strings longer than wwidth.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
68651
diff
changeset
|
154 (delete-char -2) (insert "\n"))) |
768d198de598
(cvs-insert-strings): Fix bug with strings longer than wwidth.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
68651
diff
changeset
|
155 (insert str))))) |
33229
c76308387eec
(cvs-butlast, cvs-nbutlast): New (copied from CL).
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
30618
diff
changeset
|
156 |
c76308387eec
(cvs-butlast, cvs-nbutlast): New (copied from CL).
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
30618
diff
changeset
|
157 |
28088
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
158 (defun cvs-file-to-string (file &optional oneline args) |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
159 "Read the content of FILE and return it as a string. |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
160 If ONELINE is t, only the first line (no \\n) will be returned. |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
161 If ARGS is non-nil, the file will be executed with ARGS as its |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
162 arguments. If ARGS is not a list, no argument will be passed." |
41780
fd46c3fb8ae5
(cvs-file-to-string): Move condition-case outside.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
41174
diff
changeset
|
163 (condition-case nil |
fd46c3fb8ae5
(cvs-file-to-string): Move condition-case outside.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
41174
diff
changeset
|
164 (with-temp-buffer |
fd46c3fb8ae5
(cvs-file-to-string): Move condition-case outside.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
41174
diff
changeset
|
165 (if args |
fd46c3fb8ae5
(cvs-file-to-string): Move condition-case outside.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
41174
diff
changeset
|
166 (apply 'call-process |
fd46c3fb8ae5
(cvs-file-to-string): Move condition-case outside.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
41174
diff
changeset
|
167 file nil t nil (when (listp args) args)) |
fd46c3fb8ae5
(cvs-file-to-string): Move condition-case outside.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
41174
diff
changeset
|
168 (insert-file-contents file)) |
fd46c3fb8ae5
(cvs-file-to-string): Move condition-case outside.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
41174
diff
changeset
|
169 (goto-char (point-min)) |
fd46c3fb8ae5
(cvs-file-to-string): Move condition-case outside.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
41174
diff
changeset
|
170 (buffer-substring (point) |
fd46c3fb8ae5
(cvs-file-to-string): Move condition-case outside.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
41174
diff
changeset
|
171 (if oneline (line-end-position) (point-max)))) |
fd46c3fb8ae5
(cvs-file-to-string): Move condition-case outside.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
41174
diff
changeset
|
172 (file-error nil))) |
28088
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
173 |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
174 (defun cvs-string-prefix-p (str1 str2) |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
175 "Tell whether STR1 is a prefix of STR2." |
56956
14b1949ce3d4
(cvs-string-prefix-p): Use compare-strings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
55791
diff
changeset
|
176 (eq t (compare-strings str2 nil (length str1) str1 nil nil))) |
28088
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
177 |
49597
e88404e8f2cf
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
42205
diff
changeset
|
178 ;;;; |
28088
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
179 ;;;; file names |
49597
e88404e8f2cf
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
42205
diff
changeset
|
180 ;;;; |
28088
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
181 |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
182 (defsubst cvs-expand-dir-name (d) |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
183 (file-name-as-directory (expand-file-name d))) |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
184 |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
185 ;;;; |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
186 ;;;; (interactive <foo>) support function |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
187 ;;;; |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
188 |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
189 (defstruct (cvs-qtypedesc |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
190 (:constructor nil) (:copier nil) |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
191 (:constructor cvs-qtypedesc-create |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
192 (str2obj obj2str &optional complete hist-sym require))) |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
193 str2obj |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
194 obj2str |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
195 hist-sym |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
196 complete |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
197 require) |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
198 |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
199 |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
200 (defconst cvs-qtypedesc-string1 (cvs-qtypedesc-create 'identity 'identity t)) |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
201 (defconst cvs-qtypedesc-string (cvs-qtypedesc-create 'identity 'identity)) |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
202 (defconst cvs-qtypedesc-strings |
78531
c2b062cb5942
(cvs-qtypedesc-strings): Use new names
Richard M. Stallman <rms@gnu.org>
parents:
78236
diff
changeset
|
203 (cvs-qtypedesc-create 'split-string-and-unquote |
c2b062cb5942
(cvs-qtypedesc-strings): Use new names
Richard M. Stallman <rms@gnu.org>
parents:
78236
diff
changeset
|
204 'combine-and-quote-strings nil)) |
28088
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
205 |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
206 (defun cvs-query-read (default prompt qtypedesc &optional hist-sym) |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
207 (let* ((qtypedesc (or qtypedesc cvs-qtypedesc-strings)) |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
208 (hist-sym (or hist-sym (cvs-qtypedesc-hist-sym qtypedesc))) |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
209 (complete (cvs-qtypedesc-complete qtypedesc)) |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
210 (completions (and (functionp complete) (funcall complete))) |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
211 (initval (funcall (cvs-qtypedesc-obj2str qtypedesc) default))) |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
212 (funcall (cvs-qtypedesc-str2obj qtypedesc) |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
213 (cond |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
214 ((null complete) (read-string prompt initval hist-sym)) |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
215 ((functionp complete) |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
216 (completing-read prompt completions |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
217 nil (cvs-qtypedesc-require qtypedesc) |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
218 initval hist-sym)) |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
219 (t initval))))) |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
220 |
49597
e88404e8f2cf
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
42205
diff
changeset
|
221 ;;;; |
28088
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
222 ;;;; Flags handling |
49597
e88404e8f2cf
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
42205
diff
changeset
|
223 ;;;; |
28088
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
224 |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
225 (defstruct (cvs-flags |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
226 (:constructor nil) |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
227 (:constructor -cvs-flags-make |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
228 (desc defaults &optional qtypedesc hist-sym))) |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
229 defaults persist desc qtypedesc hist-sym) |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
230 |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
231 (defmacro cvs-flags-define (sym defaults |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
232 &optional desc qtypedesc hist-sym docstring) |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
233 `(defconst ,sym |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
234 (let ((bound (boundp ',sym))) |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
235 (if (and bound (cvs-flags-p ,sym)) ,sym |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
236 (let ((defaults ,defaults)) |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
237 (-cvs-flags-make ,desc |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
238 (if bound (cons ,sym (cdr defaults)) defaults) |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
239 ,qtypedesc ,hist-sym)))) |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
240 ,docstring)) |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
241 |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
242 (defun cvs-flags-query (sym &optional desc arg) |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
243 "Query flags based on SYM. |
64545
f227dc7508ad
(cvs-flags-query, cvs-strings->string, cvs-prefix-get): Fix typos in docstrings.
Juanma Barranquero <lekktu@gmail.com>
parents:
64091
diff
changeset
|
244 Optional argument DESC will be used for the prompt. |
28088
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
245 If ARG (or a prefix argument) is nil, just use the 0th default. |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
246 If it is a non-negative integer, use the corresponding default. |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
247 If it is a negative integer query for a new value of the corresponding |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
248 default and return that new value. |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
249 If it is \\[universal-argument], just query and return a value without |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
250 altering the defaults. |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
251 If it is \\[universal-argument] \\[universal-argument], behave just |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
252 as if a negative zero was provided." |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
253 (let* ((flags (symbol-value sym)) |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
254 (desc (or desc (cvs-flags-desc flags))) |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
255 (qtypedesc (cvs-flags-qtypedesc flags)) |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
256 (hist-sym (cvs-flags-hist-sym flags)) |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
257 (arg (if (eq arg 'noquery) 0 (or arg current-prefix-arg 0))) |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
258 (numarg (prefix-numeric-value arg)) |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
259 (defaults (cvs-flags-defaults flags)) |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
260 (permstr (if (< numarg 0) (format " (%sth default)" (- numarg))))) |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
261 ;; special case for universal-argument |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
262 (when (consp arg) |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
263 (setq permstr (if (> numarg 4) " (permanent)" "")) |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
264 (setq numarg 0)) |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
265 |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
266 ;; sanity check |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
267 (unless (< (abs numarg) (length defaults)) |
38422
7a94f1c588c4
Some fixes to follow coding conventions.
Pavel Janík <Pavel@Janik.cz>
parents:
37338
diff
changeset
|
268 (error "There is no %sth default" (abs numarg))) |
28088
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
269 |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
270 (if permstr |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
271 (let* ((prompt (format "%s%s: " desc permstr)) |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
272 (fs (cvs-query-read (nth (- numarg) (cvs-flags-defaults flags)) |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
273 prompt qtypedesc hist-sym))) |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
274 (when (not (equal permstr "")) |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
275 (setf (nth (- numarg) (cvs-flags-defaults flags)) fs)) |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
276 fs) |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
277 (nth numarg defaults)))) |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
278 |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
279 (defsubst cvs-flags-set (sym index value) |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
280 "Set SYM's INDEX'th setting to VALUE." |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
281 (setf (nth index (cvs-flags-defaults (symbol-value sym))) value)) |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
282 |
49597
e88404e8f2cf
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
42205
diff
changeset
|
283 ;;;; |
28088
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
284 ;;;; Prefix keys |
49597
e88404e8f2cf
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
42205
diff
changeset
|
285 ;;;; |
28088
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
286 |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
287 (defconst cvs-prefix-number 10) |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
288 |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
289 (defsubst cvs-prefix-sym (sym) (intern (concat (symbol-name sym) "-cps"))) |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
290 |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
291 (defmacro cvs-prefix-define (sym docstring desc defaults |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
292 &optional qtypedesc hist-sym) |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
293 (let ((cps (cvs-prefix-sym sym))) |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
294 `(progn |
39542
48d3de634dc8
(cvs-prefix-define): Typo cons->concat.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38422
diff
changeset
|
295 (defvar ,sym nil ,(concat (or docstring "") " |
28088
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
296 See `cvs-prefix-set' for further description of the behavior.")) |
41174
6f2dcaad706b
(cvs-prefix-define): Don't defconst a variable.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
39542
diff
changeset
|
297 (defvar ,cps |
28088
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
298 (let ((defaults ,defaults)) |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
299 ;; sanity ensurance |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
300 (unless (>= (length defaults) cvs-prefix-number) |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
301 (setq defaults (append defaults |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
302 (make-list (1- cvs-prefix-number) |
30618
9dd1a6504bdd
Use `nth' instead of `first', `second', and `third'.
Gerd Moellmann <gerd@gnu.org>
parents:
28256
diff
changeset
|
303 (nth 0 defaults))))) |
28088
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
304 (-cvs-flags-make ,desc defaults ,qtypedesc ,hist-sym)))))) |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
305 |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
306 (defun cvs-prefix-make-local (sym) |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
307 (let ((cps (cvs-prefix-sym sym))) |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
308 (make-local-variable sym) |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
309 (set (make-local-variable cps) (copy-cvs-flags (symbol-value cps))))) |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
310 |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
311 (defun cvs-prefix-set (sym arg) |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
312 ;; we could distinguish between numeric and non-numeric prefix args instead of |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
313 ;; relying on that magic `4'. |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
314 "Set the cvs-prefix contained in SYM. |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
315 If ARG is between 0 and 9, it selects the corresponding default. |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
316 If ARG is negative (or \\[universal-argument] which corresponds to negative 0), |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
317 it queries the user and sets the -ARG'th default. |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
318 If ARG is greater than 9 (or \\[universal-argument] \\[universal-argument]), |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
319 the (ARG mod 10)'th prefix is made persistent. |
42205 | 320 If ARG is nil toggle the PREFIX's value between its 0th default and nil |
28088
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
321 and reset the persistence." |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
322 (let* ((prefix (symbol-value (cvs-prefix-sym sym))) |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
323 (numarg (if (integerp arg) arg 0)) |
69746
768d198de598
(cvs-insert-strings): Fix bug with strings longer than wwidth.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
68651
diff
changeset
|
324 ;; (defs (cvs-flags-defaults prefix)) |
768d198de598
(cvs-insert-strings): Fix bug with strings longer than wwidth.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
68651
diff
changeset
|
325 ) |
28088
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
326 |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
327 ;; set persistence if requested |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
328 (when (> (prefix-numeric-value arg) 9) |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
329 (setf (cvs-flags-persist prefix) t) |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
330 (setq numarg (mod numarg 10))) |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
331 |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
332 ;; set the value |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
333 (set sym |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
334 (cond |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
335 ((null arg) |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
336 (setf (cvs-flags-persist prefix) nil) |
30618
9dd1a6504bdd
Use `nth' instead of `first', `second', and `third'.
Gerd Moellmann <gerd@gnu.org>
parents:
28256
diff
changeset
|
337 (unless (symbol-value sym) (nth 0 (cvs-flags-defaults prefix)))) |
28088
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
338 |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
339 ((or (consp arg) (< numarg 0)) |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
340 (setf (nth (- numarg) (cvs-flags-defaults prefix)) |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
341 (cvs-query-read (nth (- numarg) (cvs-flags-defaults prefix)) |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
342 (format "%s: " (cvs-flags-desc prefix)) |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
343 (cvs-flags-qtypedesc prefix) |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
344 (cvs-flags-hist-sym prefix)))) |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
345 (t (nth numarg (cvs-flags-defaults prefix))))) |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
346 (force-mode-line-update))) |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
347 |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
348 (defun cvs-prefix-get (sym &optional read-only) |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
349 "Return the current value of the prefix SYM. |
64545
f227dc7508ad
(cvs-flags-query, cvs-strings->string, cvs-prefix-get): Fix typos in docstrings.
Juanma Barranquero <lekktu@gmail.com>
parents:
64091
diff
changeset
|
350 And reset it unless READ-ONLY is non-nil." |
28088
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
351 (prog1 (symbol-value sym) |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
352 (unless (or read-only |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
353 (cvs-flags-persist (symbol-value (cvs-prefix-sym sym)))) |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
354 (set sym nil) |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
355 (force-mode-line-update)))) |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
356 |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
357 (provide 'pcvs-util) |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
358 |
56956
14b1949ce3d4
(cvs-string-prefix-p): Use compare-strings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
55791
diff
changeset
|
359 ;; arch-tag: 3b2588bb-2ae3-4f1f-bf5b-dea91b1f8a59 |
38422
7a94f1c588c4
Some fixes to follow coding conventions.
Pavel Janík <Pavel@Janik.cz>
parents:
37338
diff
changeset
|
360 ;;; pcvs-util.el ends here |