]> code.delx.au - gnu-emacs/blobdiff - lisp/textmodes/two-column.el
Merge.
[gnu-emacs] / lisp / textmodes / two-column.el
index 0ab2ebb98b079d2d4a4f9afcc97426aa7765b86b..de9ac10d0e94784d2edd601ed88a4901f2a22419 100644 (file)
@@ -1,7 +1,6 @@
 ;;; two-column.el --- minor mode for editing of two-column text
 
-;; Copyright (C) 1992, 1993, 1994, 1995, 2001, 2002, 2003, 2004,
-;;   2005, 2006, 2007, 2008 Free Software Foundation, Inc.
+;; Copyright (C) 1992-1995, 2001-2011 Free Software Foundation, Inc.
 
 ;; Author: Daniel Pfeiffer <occitan@esperanto.org>
 ;; Adapted-By: ESR, Daniel Pfeiffer
 (defcustom 2C-mode-line-format
        '("-%*- %15b --"  (-3 . "%p")  "--%[("  mode-name
          minor-mode-alist  "%n"  mode-line-process  ")%]%-")
-  "*Value of `mode-line-format' for a buffer in two-column minor mode."
+  "Value of `mode-line-format' for a buffer in two-column minor mode."
   :type 'sexp
   :group 'two-column)
 
 
 (defcustom 2C-other-buffer-hook 'text-mode
-  "*Hook run in new buffer when it is associated with current one."
+  "Hook run in new buffer when it is associated with current one."
   :type 'function
   :group 'two-column)
 
 
 (defcustom 2C-separator ""
-  "*A string inserted between the two columns when merging.
+  "A string inserted between the two columns when merging.
 This gets set locally by \\[2C-split]."
   :type 'string
   :group 'two-column)
@@ -230,7 +229,7 @@ This gets set locally by \\[2C-split]."
 
 
 (defcustom 2C-window-width 40
-  "*The width of the first column.  (Must be at least `window-min-width')
+  "The width of the first column.  (Must be at least `window-min-width')
 This value is local for every buffer that sets it."
   :type 'integer
   :group 'two-column)
@@ -240,7 +239,7 @@ This value is local for every buffer that sets it."
 
 
 (defcustom 2C-beyond-fill-column 4
-  "*Base for calculating `fill-column' for a buffer in two-column minor mode.
+  "Base for calculating `fill-column' for a buffer in two-column minor mode.
 The value of `fill-column' becomes `2C-window-width' for this buffer
 minus this value."
   :type 'integer
@@ -334,7 +333,7 @@ first and the associated buffer to its right."
   ;; first go to full width, so that we can certainly split into two windows
   (unless (window-full-width-p)
     (enlarge-window 99999 t))
-  (split-window-horizontally
+  (split-window-right
    (max window-min-width (min 2C-window-width
                              (- (frame-width) window-min-width))))
   (if (2C-other)
@@ -407,14 +406,13 @@ First column's text    sSs  Second column's text
        (if (y-or-n-p (concat "Overwrite associated buffer `"
                             (buffer-name (2C-other))
                             "'? "))
-          (save-excursion
-            (set-buffer (2C-other))
+          (with-current-buffer (2C-other)
             (erase-buffer))
         (signal 'quit nil)))
   (let ((point (point))
-       ; make next-line always come back to same column
-       (goal-column (current-column))
-       ; a counter for empty lines in other buffer
+       ;; make next-line always come back to same column
+       (column (current-column))
+       ;; a counter for empty lines in other buffer
        (n (1- (count-lines (point-min) (point))))
        chars other)
     (save-excursion
@@ -423,13 +421,17 @@ First column's text    sSs  Second column's text
       (skip-chars-forward " \t" point)
       (make-local-variable '2C-separator)
       (setq 2C-separator (buffer-substring (point) point)
-           2C-window-width (current-column)))
+           2C-window-width (+ (fringe-columns 'left)
+                              (fringe-columns 'right)
+                              (scroll-bar-columns 'left)
+                              (scroll-bar-columns 'right)
+                              (current-column))))
     (2C-two-columns)
     (setq other (2C-other))
-    ; now we're ready to actually split
+    ;; now we're ready to actually split
     (save-excursion
       (while (not (eobp))
-       (if (not (and (= (current-column) goal-column)
+       (if (not (and (= (current-column) column)
                      (string= chars
                               (buffer-substring (point)
                                                 (save-excursion
@@ -448,7 +450,8 @@ First column's text    sSs  Second column's text
                                                 (1+ (point)))))
          (delete-region point (point))
          (setq n 0))
-       (forward-line 1)))))
+       (forward-line 1)
+       (move-to-column column)))))
 
 
 
@@ -532,7 +535,8 @@ off trailing spaces with \\[delete-trailing-whitespace]."
     (if (get-buffer-window (2C-other t))
        (select-window (get-buffer-window (2C-other)))
       (switch-to-buffer (2C-other)))
-    (newline (goto-line line))
+    (goto-char (point-min))
+    (newline (forward-line (1- line)))
     (if col
        (move-to-column col)
       (end-of-line 1))))
@@ -580,10 +584,10 @@ on, this also realigns the two buffers."
       ;; catch a mouse scroll on non-selected scrollbar
       (select-window
        (prog1 (selected-window)
-        (and (consp last-command-char)
+        (and (consp last-command-event)
              (not (eq (selected-window)
-                      (car (car (cdr last-command-char)))))
-             (select-window (car (car (cdr last-command-char)))))
+                      (car (car (cdr last-command-event)))))
+             (select-window (car (car (cdr last-command-event)))))
         ;; In some cases scrolling causes an error, but post-command-hook
         ;; shouldn't, and should always stay in the original window
         (condition-case ()
@@ -627,5 +631,4 @@ on, this also realigns the two buffers."
 
 (provide 'two-column)
 
-;; arch-tag: 2021b5ab-d3a4-4a8c-a21c-1936b0f9e6b1
 ;;; two-column.el ends here