diff options
author | Stefan Monnier <monnier@iro.umontreal.ca> | 2000-11-06 06:54:16 +0000 |
---|---|---|
committer | Stefan Monnier <monnier@iro.umontreal.ca> | 2000-11-06 06:54:16 +0000 |
commit | 80786c0aba66c68f43da9a90c154c00508d1b46f (patch) | |
tree | aa530bbfb8b1431870f2c9f9926212e02b363d5f /lisp | |
parent | 937b28770e225ab7222c1c7ae7a2521a6a91a088 (diff) | |
download | emacs-80786c0aba66c68f43da9a90c154c00508d1b46f.tar.gz emacs-80786c0aba66c68f43da9a90c154c00508d1b46f.tar.bz2 emacs-80786c0aba66c68f43da9a90c154c00508d1b46f.zip |
(cvs-butlast, cvs-nbutlast): New (copied from CL).
(cvs-insert-strings): New function.
Diffstat (limited to 'lisp')
-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 @@ ;; Author: Stefan Monnier <monnier@cs.yale.edu> ;; Keywords: pcl-cvs ;; Version: $Name: $ -;; Revision: $Id: pcvs-util.el,v 1.1 2000/08/05 19:33:53 gerd Exp gerd $ +;; Revision: $Id: pcvs-util.el,v 1.4 2000/08/06 09:18:02 gerd Exp $ ;; This file is part of GNU Emacs. @@ -33,7 +33,7 @@ ;;;; ;;;; list processing -;;;l +;;;; (defsubst cvs-car (x) (if (consp x) (car x) x)) (defalias 'cvs-cdr 'cdr-safe) @@ -78,6 +78,22 @@ the other elements. The ordering among elements is maintained." (if (funcall p x) (push x car) (push x cdr))) (cons (nreverse car) (nreverse cdr)))) +;; Copied from CL ;-( + +(defun cvs-butlast (x &optional n) + "Returns a copy of LIST with the last N elements removed." + (if (and n (<= n 0)) x + (cvs-nbutlast (copy-sequence x) n))) + +(defun cvs-nbutlast (x &optional n) + "Modifies LIST to remove the last N elements." + (let ((m (length x))) + (or n (setq n 1)) + (and (< n m) + (progn + (if (> n 0) (setcdr (nthcdr (- (1- m) n) x) nil)) + x)))) + ;;;; ;;;; frame, window, buffer handling ;;;; @@ -138,6 +154,27 @@ If NOREUSE is non-nil, always return a new buffer." ;;;; string processing ;;;; +(defun cvs-insert-strings (strings) + "Insert a list of STRINGS into the current buffer. +Uses columns to keep the listing readable but compact." + (when (consp strings) + (let* ((length (apply 'max (mapcar 'length strings))) + (wwidth (1- (window-width))) + (columns (min + ;; At least 2 columns; at least 2 spaces between columns. + (max 2 (/ wwidth (+ 2 length))) + ;; Don't allocate more columns than we can fill. + (max 1 (/ (length strings) 2)))) + (colwidth (/ wwidth columns))) + (setq tab-width colwidth) + ;; The insertion should be "sensible" no matter what choices were made. + (dolist (str strings) + (unless (bolp) (insert " \t")) + (when (< wwidth (+ (max colwidth (length str)) (current-column))) + (delete-char -2) (insert "\n")) + (insert str))))) + + (defun cvs-file-to-string (file &optional oneline args) "Read the content of FILE and return it as a string. If ONELINE is t, only the first line (no \\n) will be returned. |