Репозиторий ALT Linux backports/2.4
Последнее обновление: 9 июля 2008 | Пакетов: 497 | Посещений: 1585073
 поиск   регистрация   авторизация 
 
Группа :: Редакторы
Пакет: emacs22

 Главная   Изменения   Спек   Патчи   Загрузить   Bugs and FR 

Патч: emacs-22.0.50-pc-select-private-mark.patch


In pc-selection-mode the mark is kept acive only while
the selection is being extended with special S- keys;
other movement keys (including the simple arrows) 
deactivate the mark and make the selection disappear.
This doesn't fit well with using the original style of 
selecting, e.g. C-space, then move with the simple arrow
keys to select: in pc-selection-mode, the mark is deactivated 
immediately after the first movement. Perhaps, there are
other original behaviours of Emacs concerning the mark and
the selection that are spoilt in pc-selection-mode.
The simple solution to the problem would be: don't use pc-select!
Fortunately, it has got easy to switch it off/on with last version
of pc-select.el from the HEAD of Emacs source.
I suggest another one -- a tweak to pc-select not interfere
into other behaviours which use mark activation/deactivation,
so that those who use them don't notice pc-selction-mode is active:
only if one starts selecting in the pc-select style (by holding Shift
and moving), the mark can be deactivated by pc-select functions. To sum
up, a mark can be deactivated by a pc-select function only if it has been
activated by a pc-select function.
The implementation is not complex:
Every time (ensure-mark) is called, remember the mark position
which was ensured to be active.
Add function ensure-nomark (in a sense, inverse to ensure-mark): it
deactivates the mark only if the currently active mark is the one 
remembered by the last call to (ensure-mark).
Replace all direct (setq mark-active nil) by a call to (ensure-nomark).
As a good side effect, (deactivate-mark) macro is now used instaed of the
(setq ...) expression: it handles the hook correctly.
The patch is against revision 1.23 of pc-select.el from GNU Emacs CVS.
imz@altliux.ru, Nov 2002.
--- emacs/lisp/emulation/pc-select.el	2005-09-03 01:24:02 +0600
+++ emacs/lisp/emulation/pc-select.el.private-mark	2005-09-03 02:11:18 +0600
@@ -255,6 +255,26 @@
 association.")
 
 ;;;;
+;; non-interactive
+;;;;
+(defvar ensured-mark nil)
+(defun ensure-mark()
+  ;; make sure mark is active
+  ;; test if it is active, if it isn't, set it and activate it
+  (or mark-active (set-mark-command nil))
+  (setq ensured-mark (mark)))
+(defun ensure-nomark()
+  ;; make sure mark is inactive; 
+  ;; try not to interfere with other behaviours using mark.
+  ;; test if it is active, if it is and is equal to the last one (ensure-mark)
+  ;; handled, deactivate it
+  (or (not mark-active)
+      (if (and ensured-mark (eq ensured-mark (mark)))
+	  (progn
+	    (deactivate-mark)
+	    (setq ensured-mark nil)))))
+
+;;;;
 ;; misc
 ;;;;
 
@@ -269,22 +289,14 @@
 and `transient-mark-mode'."
  (interactive "r")
  (copy-region-as-kill beg end)
- (setq mark-active nil)
+ (ensure-nomark)
  (message "Region saved"))
 
 (defun exchange-point-and-mark-nomark  ()
   "Like `exchange-point-and-mark' but without activating the mark."
   (interactive)
   (exchange-point-and-mark)
-  (setq mark-active nil))
-
-;;;;
-;; non-interactive
-;;;;
-(defun ensure-mark()
-  ;; make sure mark is active
-  ;; test if it is active, if it isn't, set it and activate it
-  (or mark-active (set-mark-command nil)))
+  (ensure-nomark))
 
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;
 ;;;;; forward and mark
@@ -427,7 +439,7 @@
   "Deactivate mark; move point right ARG characters \(left if ARG negative).
 On reaching end of buffer, stop and signal error."
   (interactive "p")
-  (setq mark-active nil)
+  (ensure-nomark)
   (forward-char arg))
 
 (defun forward-word-nomark (&optional arg)
@@ -436,13 +448,13 @@
 If an edge of the buffer is reached, point is left there
 and nil is returned."
   (interactive "p")
-  (setq mark-active nil)
+  (ensure-nomark)
   (forward-word arg))
 
 (defun forward-line-nomark (&optional arg)
   "Deactivate mark; move cursor vertically down ARG lines."
   (interactive "p")
-  (setq mark-active nil)
+  (ensure-nomark)
   (forward-line arg)
   (setq this-command 'forward-line)
 )
@@ -452,7 +464,7 @@
 With argument, do it that many times.  Negative arg -N means
 move backward across N balanced expressions."
   (interactive "p")
-  (setq mark-active nil)
+  (ensure-nomark)
   (forward-sexp arg))
 
 (defun forward-paragraph-nomark (&optional arg)
@@ -464,7 +476,7 @@
 A paragraph end is the beginning of a line which is not part of the paragraph
 to which the end of the previous line belongs, or the end of the buffer."
   (interactive "p")
-  (setq mark-active nil)
+  (ensure-nomark)
   (forward-paragraph arg))
 
 (defun next-line-nomark (&optional arg)
@@ -483,7 +495,7 @@
 Then it does not try to move vertically.  This goal column is stored
 in `goal-column', which is nil when there is none."
   (interactive "p")
-  (setq mark-active nil)
+  (ensure-nomark)
   (next-line arg)
   (setq this-command 'next-line))
 
@@ -492,14 +504,14 @@
 With argument ARG not nil or 1, move forward ARG - 1 lines first.
 If scan reaches end of buffer, stop there without error."
   (interactive "p")
-  (setq mark-active nil)
+  (ensure-nomark)
   (end-of-line arg)
   (setq this-command 'end-of-line))
 
 (defun backward-line-nomark (&optional arg)
   "Deactivate mark; move cursor vertically up ARG lines."
   (interactive "p")
-  (setq mark-active nil)
+  (ensure-nomark)
   (if (null arg)
       (setq arg 1))
   (forward-line (- arg))
@@ -512,7 +524,7 @@
 Negative ARG means scroll upward.
 When calling from a program, supply a number as argument or nil."
   (interactive "P")
-  (setq mark-active nil)
+  (ensure-nomark)
   (cond (pc-select-override-scroll-error
 	 (condition-case nil (scroll-down arg)
 	   (beginning-of-buffer (goto-char (point-min)))))
@@ -528,7 +540,7 @@
 Don't use this command in Lisp programs!
 \(goto-char (point-max)) is faster and avoids clobbering the mark."
   (interactive "P")
-  (setq mark-active nil)
+  (ensure-nomark)
   (let ((size (- (point-max) (point-min))))
     (goto-char (if arg
 		   (- (point-max)
@@ -663,14 +675,14 @@
   "Deactivate mark; move point left ARG characters (right if ARG negative).
 On attempt to pass beginning or end of buffer, stop and signal error."
   (interactive "p")
-  (setq mark-active nil)
+  (ensure-nomark)
   (backward-char arg))
 
 (defun backward-word-nomark (&optional arg)
   "Deactivate mark; move backward until encountering the end of a word.
 With argument, do this that many times."
   (interactive "p")
-  (setq mark-active nil)
+  (ensure-nomark)
   (backward-word arg))
 
 (defun backward-sexp-nomark (&optional arg)
@@ -678,7 +690,7 @@
 With argument, do it that many times.  Negative arg -N means
 move forward across N balanced expressions."
   (interactive "p")
-  (setq mark-active nil)
+  (ensure-nomark)
   (backward-sexp arg))
 
 (defun backward-paragraph-nomark (&optional arg)
@@ -693,7 +705,7 @@
 
 See `forward-paragraph' for more information."
   (interactive "p")
-  (setq mark-active nil)
+  (ensure-nomark)
   (backward-paragraph arg))
 
 (defun previous-line-nomark (&optional arg)
@@ -706,7 +718,7 @@
 a semipermanent goal column to which this command always moves.
 Then it does not try to move vertically."
   (interactive "p")
-  (setq mark-active nil)
+  (ensure-nomark)
   (previous-line arg)
   (setq this-command 'previous-line))
 
@@ -715,7 +727,7 @@
 With argument ARG not nil or 1, move forward ARG - 1 lines first.
 If scan reaches end of buffer, stop there without error."
   (interactive "p")
-  (setq mark-active nil)
+  (ensure-nomark)
   (beginning-of-line arg))
 
 (defun scroll-up-nomark (&optional arg)
@@ -724,7 +736,7 @@
 Negative ARG means scroll downward.
 When calling from a program, supply a number as argument or nil."
   (interactive "P")
-  (setq mark-active nil)
+  (ensure-nomark)
   (cond (pc-select-override-scroll-error
 	 (condition-case nil (scroll-up arg)
 	   (end-of-buffer (goto-char (point-max)))))
@@ -740,7 +752,7 @@
 Don't use this command in Lisp programs!
 \(goto-char (point-min)) is faster and avoids clobbering the mark."
   (interactive "P")
-  (setq mark-active nil)
+  (ensure-nomark)
   (let ((size (- (point-max) (point-min))))
     (goto-char (if arg
 		   (+ (point-min)
 
design & coding: Vladimir Lettiev aka crux © 2004-2005