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

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

Патч: emacs-21.2-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.
--- 21.2/lisp/emulation/pc-select.el.private-mark	2002-11-17 00:30:12 +0300
+++ 21.2/lisp/emulation/pc-select.el	2002-11-17 00:31:21 +0300
@@ -254,6 +254,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
 ;;;;
 
@@ -268,22 +288,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
@@ -426,7 +438,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)
@@ -435,13 +447,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)
 )
@@ -451,7 +463,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)
@@ -463,7 +475,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)
@@ -482,7 +494,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))
 
@@ -491,14 +503,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))
@@ -511,7 +523,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)))))
@@ -527,7 +539,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)
@@ -662,14 +674,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)
@@ -677,7 +689,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)
@@ -692,7 +704,7 @@
 
 See `forward-paragraph' for more information."
   (interactive "p")
-  (setq mark-active nil)
+  (ensure-nomark)
   (backward-paragraph arg))
 
 (defun previous-line-nomark (&optional arg)
@@ -705,7 +717,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))
 
@@ -714,7 +726,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)
@@ -723,7 +735,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)))))
@@ -739,7 +751,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