diff options
| author | Stefan Monnier | 2000-11-06 06:54:16 +0000 |
|---|---|---|
| committer | Stefan Monnier | 2000-11-06 06:54:16 +0000 |
| commit | 80786c0aba66c68f43da9a90c154c00508d1b46f (patch) | |
| tree | aa530bbfb8b1431870f2c9f9926212e02b363d5f | |
| parent | 937b28770e225ab7222c1c7ae7a2521a6a91a088 (diff) | |
| download | emacs-80786c0aba66c68f43da9a90c154c00508d1b46f.tar.gz emacs-80786c0aba66c68f43da9a90c154c00508d1b46f.zip | |
(cvs-butlast, cvs-nbutlast): New (copied from CL).
(cvs-insert-strings): New function.
| -rw-r--r-- | lisp/pcvs-util.el | 41 |
1 files changed, 39 insertions, 2 deletions
diff --git a/lisp/pcvs-util.el b/lisp/pcvs-util.el index 06a07583482..8310ea87c69 100644 --- a/lisp/pcvs-util.el +++ b/lisp/pcvs-util.el | |||
| @@ -5,7 +5,7 @@ | |||
| 5 | ;; Author: Stefan Monnier <monnier@cs.yale.edu> | 5 | ;; Author: Stefan Monnier <monnier@cs.yale.edu> |
| 6 | ;; Keywords: pcl-cvs | 6 | ;; Keywords: pcl-cvs |
| 7 | ;; Version: $Name: $ | 7 | ;; Version: $Name: $ |
| 8 | ;; Revision: $Id: pcvs-util.el,v 1.1 2000/08/05 19:33:53 gerd Exp gerd $ | 8 | ;; Revision: $Id: pcvs-util.el,v 1.4 2000/08/06 09:18:02 gerd Exp $ |
| 9 | 9 | ||
| 10 | ;; This file is part of GNU Emacs. | 10 | ;; This file is part of GNU Emacs. |
| 11 | 11 | ||
| @@ -33,7 +33,7 @@ | |||
| 33 | 33 | ||
| 34 | ;;;; | 34 | ;;;; |
| 35 | ;;;; list processing | 35 | ;;;; list processing |
| 36 | ;;;l | 36 | ;;;; |
| 37 | 37 | ||
| 38 | (defsubst cvs-car (x) (if (consp x) (car x) x)) | 38 | (defsubst cvs-car (x) (if (consp x) (car x) x)) |
| 39 | (defalias 'cvs-cdr 'cdr-safe) | 39 | (defalias 'cvs-cdr 'cdr-safe) |
| @@ -78,6 +78,22 @@ the other elements. The ordering among elements is maintained." | |||
| 78 | (if (funcall p x) (push x car) (push x cdr))) | 78 | (if (funcall p x) (push x car) (push x cdr))) |
| 79 | (cons (nreverse car) (nreverse cdr)))) | 79 | (cons (nreverse car) (nreverse cdr)))) |
| 80 | 80 | ||
| 81 | ;; Copied from CL ;-( | ||
| 82 | |||
| 83 | (defun cvs-butlast (x &optional n) | ||
| 84 | "Returns a copy of LIST with the last N elements removed." | ||
| 85 | (if (and n (<= n 0)) x | ||
| 86 | (cvs-nbutlast (copy-sequence x) n))) | ||
| 87 | |||
| 88 | (defun cvs-nbutlast (x &optional n) | ||
| 89 | "Modifies LIST to remove the last N elements." | ||
| 90 | (let ((m (length x))) | ||
| 91 | (or n (setq n 1)) | ||
| 92 | (and (< n m) | ||
| 93 | (progn | ||
| 94 | (if (> n 0) (setcdr (nthcdr (- (1- m) n) x) nil)) | ||
| 95 | x)))) | ||
| 96 | |||
| 81 | ;;;; | 97 | ;;;; |
| 82 | ;;;; frame, window, buffer handling | 98 | ;;;; frame, window, buffer handling |
| 83 | ;;;; | 99 | ;;;; |
| @@ -138,6 +154,27 @@ If NOREUSE is non-nil, always return a new buffer." | |||
| 138 | ;;;; string processing | 154 | ;;;; string processing |
| 139 | ;;;; | 155 | ;;;; |
| 140 | 156 | ||
| 157 | (defun cvs-insert-strings (strings) | ||
| 158 | "Insert a list of STRINGS into the current buffer. | ||
| 159 | Uses columns to keep the listing readable but compact." | ||
| 160 | (when (consp strings) | ||
| 161 | (let* ((length (apply 'max (mapcar 'length strings))) | ||
| 162 | (wwidth (1- (window-width))) | ||
| 163 | (columns (min | ||
| 164 | ;; At least 2 columns; at least 2 spaces between columns. | ||
| 165 | (max 2 (/ wwidth (+ 2 length))) | ||
| 166 | ;; Don't allocate more columns than we can fill. | ||
| 167 | (max 1 (/ (length strings) 2)))) | ||
| 168 | (colwidth (/ wwidth columns))) | ||
| 169 | (setq tab-width colwidth) | ||
| 170 | ;; The insertion should be "sensible" no matter what choices were made. | ||
| 171 | (dolist (str strings) | ||
| 172 | (unless (bolp) (insert " \t")) | ||
| 173 | (when (< wwidth (+ (max colwidth (length str)) (current-column))) | ||
| 174 | (delete-char -2) (insert "\n")) | ||
| 175 | (insert str))))) | ||
| 176 | |||
| 177 | |||
| 141 | (defun cvs-file-to-string (file &optional oneline args) | 178 | (defun cvs-file-to-string (file &optional oneline args) |
| 142 | "Read the content of FILE and return it as a string. | 179 | "Read the content of FILE and return it as a string. |
| 143 | If ONELINE is t, only the first line (no \\n) will be returned. | 180 | If ONELINE is t, only the first line (no \\n) will be returned. |