pcl-cvs / pcl-cvs-util.el

Diff from to

File pcl-cvs-util.el

 ;;;; list processing
 (defsubst cvs-car (x) (if (consp x) (car x) x))
 (defalias 'cvs-cdr 'cdr-safe)
 (defun cvs-pop-to-buffer-same-frame (buf)
   "Pop to BUF like `pop-to-buffer' but staying on the same frame.
 If `pop-to-buffer' would have opened a new frame, this function would
-try to split the a new window instead."
+try to split a new window instead."
   (let ((pop-up-windows (or pop-up-windows pop-up-frames))
 	(pop-up-frames nil))
     (or (let ((buf (get-buffer-window buf))) (and buf (select-window buf)))
 		(delete-window win)
 	      (error (iconify-frame (window-frame win))))
 	  (if (and mainbuf (get-buffer-window mainbuf))
-	      (delete-window win)))))
+	      ;; FIXME: if the buffer popped into a pre-existing window,
+	      ;; we don't want to delete that window.
+	      t ;;(delete-window win)
+	      ))))
     (with-current-buffer buf
       (bury-buffer (unless (and (eq buf (window-buffer (selected-window)))
 				(not (window-dedicated-p (selected-window))))
 ;;;; 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.
+		     ;; Windows can't show less than 3 lines anyway.
+		     (max 1 (/ (length strings) 2))))
+	   (colwidth (/ wwidth columns)))
+      ;; Use tab-width rather than indent-to.
+      (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.
   it queries the user and sets the -ARG'th default.
 If ARG is greater than 9 (or \\[universal-argument] \\[universal-argument]),
   the (ARG mod 10)'th prefix is made persistent.
-If ARG is NIL toggle the PREFIX's value between its 0th default and NIL
+If ARG is nil toggle the PREFIX's value between its 0th default and nil
   and reset the persistence."
   (let* ((prefix (symbol-value (cvs-prefix-sym sym)))
 	 (numarg (if (integerp arg) arg 0))