view lisp/emulation/cua-gmrk.el @ 49612:407d6516031a

2003-02-05 Kai Gro?ohann <kai.grossjohann@uni-duisburg.de> Version 2.0.29 released. * net/tramp.el (tramp-send-region): Protect against tramp-chunksize being nil. 2003-02-04 Michael Albinus <Michael.Albinus@alcatel.de> * net/tramp.el (tramp-handle-directory-file-name): Handle the case PATH is "". (tramp-completion-handle-file-name-all-completions): Define `tramp-current-user' locally. See `tramp-parse-passwd'. (tramp-parse-passwd): For su-alike methods it would be desirable to return "root@localhost" as default. Unfortunately, we have no information whether any user name has been typed already. So we (mis-)use tramp-current-user as indication, assuming it is set in `tramp-completion-handle-file-name-all-completions'. (tramp-send-region): Handle the case `tramp-chunksize' is equal 0. I did it accidently. Infinite loop ... * net/tramp-ftp.el (top-level): eval-after-load "ange-ftp" '(tramp-disable-ange-ftp). Suggested by Kai. (tramp-ftp-file-name-handler): `tramp-disable-ange-ftp' not needed any longer. * net/tramp-smb.el (tramp-smb-file-name-handler-alist): Apply `tramp-handle-directory-file-name' in order to profit from Kai's yesterday changes. 2003-02-03 Kai Gro?ohann <kai.grossjohann@uni-duisburg.de> * net/tramp.el (tramp-chunksize): Set default to 500 as workaround for some ssh connections. (tramp-handle-directory-file-name): New implementation. Not sure if it works. 2003-01-28 Michael Albinus <Michael.Albinus@alcatel.de> * net/tramp.el (tramp-get-device): `tramp-make-tramp-file-name' must not be called with NIL path. It fails in case of multi-method. 2003-01-27 Michael Albinus <Michael.Albinus@alcatel.de> * net/tramp.el (tramp-file-name-for-operation): Apply `expand-file-name' for relative file names only. Otherwise there might be problems if the default directory is another Tramp directory as the directory the file is based on. (tramp-find-foreign-file-name-handler): Check whether FILENAME is a Tramp file name. It isn't if it comes from an expanded file name (like "/xx:yy//zz"). 2003-01-25 Michael Albinus <Michael.Albinus@alcatel.de> * net/tramp.el (tramp-devices): New variable. Keeps virtual device numbers. Devices must distinguish physical file systems. The device numbers provided by "lstat" aren't unique, because we operate on different hosts. So we use virtual device numbers, generated by `tramp-get-device'. Both Ange-FTP and EFS use device number -1. In order to be different, we use device number (-1 x), whereby "x" is unique for a given (multi-method method user host). Suggested by Kai. (tramp-perl-file-attributes): Always return device number -1. There will be a virtual device number set in `tramp-handle-file-attributes', which replaces this one. (tramp-handle-file-attributes): Set virtual device number. (tramp-get-device): New function. Returns the virtual device number. If it doesn't exist, generate a new one. (tramp-handle-file-regular-p): Use Emacs file name primitives instead of calling tramp-handle-* equivalents directly. Needed for tramp-smb. * net/tramp-smb.el (tramp-smb-devices, tramp-smb-get-device): Removed. Functionality moved to tramp.el. (tramp-smb-handle-file-attributes): Apply `tramp-get-device'. ATIME and CTIME are (0 0) now (= "don't know"), which is more honest. (tramp-smb-handle-make-directory): Use Emacs file name primitives instead of calling tramp-smb-handle-* equivalents directly. (tramp-smb-read-file-entry): Return size as a number but a string. 2003-01-24 Michael Albinus <Michael.Albinus@alcatel.de> * net/tramp.el (tramp-completion-function-alist-ssh): Add parsing of "/etc/ssh_config" and "~/.ssh/config". Suggested by Kai. (tramp-completion-function-alist, tramp-set-completion-function): Doc string update. (tramp-parse-sconfig, tramp-parse-sconfig-group): New functions. Provide parsing of "~/.ssh/config" style files. 2003-01-21 Michael Albinus <Michael.Albinus@alcatel.de> * net/tramp.el (tramp-completion-handle-expand-file-name): Apply `tramp-drop-volume-letter'. Otherwise, there are problems on W32 systems. 2003-01-21 Michael Albinus <Michael.Albinus@alcatel.de> * net/tramp-smb.el (tramp-smb-get-device, tramp-smb-get-inode): New functions. Device number and inode number don't exist for SMB files. Therefore we must generate virtual ones. (tramp-smb-devices, tramp-smb-inodes): New variables. Keep generated virtual device numbers and inodes numbers for SMB files. (tramp-smb-handle-file-attributes): Apply them. 2003-01-14 Kai Gro?ohann <kai.grossjohann@uni-duisburg.de> * net/tramp.el (tramp-md5-function): Require md5 before checking function md5. If using md5-encode, put wrapper around it that converts vector of bytes to ascii text. 2003-01-13 Michael Albinus <Michael.Albinus@alcatel.de> * net/tramp.el (tramp-completion-mode): Perform check (integerp last-input-event) before (event-modifiers last-input-event) - there might be problems if `last-input-event' is a mouse event. 2003-01-12 Michael Albinus <Michael.Albinus@alcatel.de> * net/tramp.el (tramp-parse-rhosts, tramp-parse-shosts) (tramp-parse-hosts, tramp-parse-passwd, tramp-parse-netrc): Use `file-readable-p' instead of `file-exists-p'. Otherwise these functions might block. Reported by <kin@neoscale.com>. 2003-01-02 Michael Albinus <Michael.Albinus@alcatel.de> * net/tramp-ftp.el (top-level): Defaults for `tramp-default-method-alist' must be a list. * net/tramp-smb.el (top-level): Defaults for `tramp-default-method-alist' must be a list. 2003-01-02 Kai Gro?ohann <kai.grossjohann@uni-duisburg.de> * net/tramp.el (top-level): Avoid byte-compiler warnings of unused variables if the byte-compiler supports this. This is for the with-parsed-tramp-file-name macro which is wont to produce such stuff.
author Kai Großjohann <kgrossjo@eu.uu.net>
date Wed, 05 Feb 2003 21:03:36 +0000
parents 0d8b17d428b5
children 695cf19ef79e d7ddb3e565de
line wrap: on
line source

;;; cua-gmrk.el --- CUA unified global mark support

;; Copyright (C) 1997-2002 Free Software Foundation, Inc.

;; Author: Kim F. Storm <storm@cua.dk>
;; Keywords: keyboard emulations convenience cua mark

;; This file is part of GNU Emacs.

;; GNU Emacs is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation; either version 2, or (at your option)
;; any later version.

;; GNU Emacs is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;; GNU General Public License for more details.

;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs; see the file COPYING.  If not, write to the
;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
;; Boston, MA 02111-1307, USA.

;;; Commentary:

;;; Code:

(provide 'cua-gmrk)

(eval-when-compile
  (require 'cua-base)
  (require 'cua-rect)
  )

;;; Global Marker

;; Non-nil when global marker is active.
(defvar cua--global-mark-active nil)

;; Global mark position marker.
(defvar cua--global-mark-marker nil)

;; Overlay for global mark position.
(defvar cua--global-mark-overlay nil)

;; Initialize global mark things once...
(defvar cua--global-mark-initialized nil)

;; Saved configured blink-cursor-interval
(defvar cua--orig-blink-cursor-interval nil)

(defun cua--deactivate-global-mark (&optional msg)
  (when cua--global-mark-overlay
    (delete-overlay cua--global-mark-overlay)
    (setq cua--global-mark-overlay nil))
  (if (markerp cua--global-mark-marker)
      (move-marker cua--global-mark-marker nil))
  (if cua--orig-blink-cursor-interval
      (setq blink-cursor-interval cua--orig-blink-cursor-interval
	    cua--orig-blink-cursor-interval nil))
  (setq cua--global-mark-active nil)
  (if msg
      (message "Global Mark Cleared")))

(defun cua--activate-global-mark (&optional msg)
  (if (not (markerp cua--global-mark-marker))
      (setq cua--global-mark-marker (make-marker)))
  (when (eobp)
    (insert " ")
    (backward-char 1))
  (move-marker cua--global-mark-marker (point))
  (if (overlayp cua--global-mark-overlay)
      (move-overlay cua--global-mark-overlay (point) (1+ (point)))
    (setq cua--global-mark-overlay
	  (make-overlay (point) (1+ (point))))
    (overlay-put cua--global-mark-overlay 'face 'cua-global-mark-face))
  (if (and cua-global-mark-blink-cursor-interval
	   (not cua--orig-blink-cursor-interval))
      (setq cua--orig-blink-cursor-interval blink-cursor-interval
	    blink-cursor-interval cua-global-mark-blink-cursor-interval))
  (setq cua--global-mark-active t)
  (if msg
      (message "Global Mark Set")))

(defun cua--global-mark-active ()
  (if cua--global-mark-active
      (or (and (markerp cua--global-mark-marker)
	       (marker-buffer cua--global-mark-marker))
	  (and (cua--deactivate-global-mark nil)
	       nil))))

(defun cua-toggle-global-mark (stay)
  "Set or cancel the global marker.
When the global marker is set, CUA cut and copy commands will automatically
insert the deleted or copied text before the global marker, even when the
global marker is in another buffer.
If the global marker isn't set, set the global marker at point in the current
buffer. Otherwise jump to the global marker position and cancel it.
With prefix argument, don't jump to global mark when cancelling it."
  (interactive "P")
  (unless cua--global-mark-initialized
    (cua--init-global-mark))
  (if (not (cua--global-mark-active))
      (if (not buffer-read-only)
	  (cua--activate-global-mark t)
	(ding)
	(message "Cannot set global mark in read-only buffer."))
    (when (not stay)
      (pop-to-buffer (marker-buffer cua--global-mark-marker))
      (goto-char cua--global-mark-marker))
    (cua--deactivate-global-mark t)))

(defun cua--insert-at-global-mark (str &optional msg)
  ;; Insert string at global marker and move marker
  (save-excursion
    (set-buffer (marker-buffer cua--global-mark-marker))
    (goto-char (marker-position cua--global-mark-marker))
    (insert-for-yank str)
    (cua--activate-global-mark))
  (if msg
      (message "%s %d to global mark in %s:%d" msg
	       (length str)
	       (buffer-name (marker-buffer cua--global-mark-marker))
	       (marker-position cua--global-mark-marker))))

(defun cua--delete-at-global-mark (arg &optional msg)
  ;; Delete chars at global marker
  (save-excursion
    (set-buffer (marker-buffer cua--global-mark-marker))
    (goto-char (marker-position cua--global-mark-marker))
    (delete-char arg))
  (if msg
      (message "%s %d chars at global mark in %s:%d" msg arg
	       (buffer-name (marker-buffer cua--global-mark-marker))
	       (marker-position cua--global-mark-marker))))

(defun cua-copy-region-to-global-mark (start end)
  "Copy region to global mark buffer/position."
  (interactive "r")
  (if (cua--global-mark-active)
      (let ((src-buf (current-buffer)))
	(save-excursion
	  (if (equal (marker-buffer cua--global-mark-marker) src-buf)
	      (let ((text (buffer-substring-no-properties start end)))
		(goto-char (marker-position cua--global-mark-marker))
		(insert text))
	    (set-buffer (marker-buffer cua--global-mark-marker))
	    (goto-char (marker-position cua--global-mark-marker))
	    (insert-buffer-substring-as-yank src-buf start end))
	  (cua--activate-global-mark)
	  (message "Copied %d to global mark in %s:%d"
		   (abs (- end start))
		   (buffer-name (marker-buffer cua--global-mark-marker))
		   (marker-position cua--global-mark-marker))))
    (cua--deactivate-global-mark)
    (message "No Global Mark")))

(defun cua-cut-region-to-global-mark (start end)
  "Move region to global buffer/position."
  (interactive "r")
  (if (cua--global-mark-active)
      (let ((src-buf (current-buffer)))
	(save-excursion
	  (if (equal (marker-buffer cua--global-mark-marker) src-buf)
	      (if (and (< start (marker-position cua--global-mark-marker))
		       (< (marker-position cua--global-mark-marker) end))
		  (message "Can't move region into itself.")
		(let ((text (buffer-substring-no-properties start end))
		      (p1 (copy-marker start))
		      (p2 (copy-marker end)))
		  (goto-char (marker-position cua--global-mark-marker))
		  (insert text)
		  (cua--activate-global-mark)
		  (delete-region (marker-position p1) (marker-position p2))
		  (move-marker p1 nil)
		  (move-marker p2 nil)))
	    (set-buffer (marker-buffer cua--global-mark-marker))
	    (goto-char (marker-position cua--global-mark-marker))
	    (insert-buffer-substring src-buf start end)
	    (message "Moved %d to global mark in %s:%d"
		     (abs (- end start))
		     (buffer-name (marker-buffer cua--global-mark-marker))
		     (marker-position cua--global-mark-marker))
	    (cua--activate-global-mark)
	    (set-buffer src-buf)
	    (delete-region start end))))
    (cua--deactivate-global-mark)
    (message "No Global Mark")))

(defun cua--copy-rectangle-to-global-mark (as-text)
  ;; Copy rectangle to global mark buffer/position.
  (if (cua--global-mark-active)
      (let ((src-buf (current-buffer))
	    (text (cua--extract-rectangle)))
	(save-excursion
	  (set-buffer (marker-buffer cua--global-mark-marker))
	  (goto-char (marker-position cua--global-mark-marker))
	  (if as-text
	      (while text
		(insert-for-yank (car text))
		(if (setq text (cdr text))
		    (insert "\n")))
	    (cua--insert-rectangle text 'auto))
	  (cua--activate-global-mark)
	  (message "Copied rectangle to global mark in %s:%d"
		   (buffer-name (marker-buffer cua--global-mark-marker))
		   (marker-position cua--global-mark-marker))))
    (cua--deactivate-global-mark)
    (message "No Global Mark")))

(defun cua--cut-rectangle-to-global-mark (as-text)
  ;; Move rectangle to global buffer/position.
  (if (cua--global-mark-active)
      (let ((src-buf (current-buffer)))
	(save-excursion
	  (if (equal (marker-buffer cua--global-mark-marker) src-buf)
	      (let ((olist (overlays-at (marker-position cua--global-mark-marker)))
		    in-rect)
		(while olist
		  (if (eq (overlay-get (car olist) 'face) 'cua-rectangle-face)
		      (setq in-rect t olist nil)
		    (setq olist (cdr olist))))
		(if in-rect
		    (message "Can't move rectangle into itself.")
		  (let ((text (cua--extract-rectangle)))
		    (cua--delete-rectangle)
		    (goto-char (marker-position cua--global-mark-marker))
		    (if as-text
			(while text
			  (insert-for-yank (car text))
			  (if (setq text (cdr text))
			      (insert "\n")))
		      (cua--insert-rectangle text 'auto))
		    (cua--activate-global-mark))))
	    (let ((text (cua--extract-rectangle)))
	      (cua--delete-rectangle)
	      (set-buffer (marker-buffer cua--global-mark-marker))
	      (goto-char (marker-position cua--global-mark-marker))
	      (cua--insert-rectangle text 'auto))
	    (message "Moved rectangle to global mark in %s:%d"
		     (buffer-name (marker-buffer cua--global-mark-marker))
		     (marker-position cua--global-mark-marker))
	    (cua--activate-global-mark))))
    (cua--deactivate-global-mark)
    (message "No Global Mark")))

(defun cua-copy-to-global-mark ()
  "Copy active region/rectangle to global mark buffer/position."
  (interactive)
  (setq cua--last-killed-rectangle nil)
  (if cua--rectangle
      (cua--copy-rectangle-to-global-mark nil)
    (let ((start (mark)) (end (point)))
      (or (<= start end)
	  (setq start (prog1 end (setq end start))))
      (cua-copy-region-to-global-mark start end))))

(defun cua-copy-next-to-global-mark (n)
  "Copy the following N characters in buffer to global mark buffer/position."
  (interactive "p")
  (setq cua--last-killed-rectangle nil)
  (or (eobp)
      (let ((p (point)))
	(goto-char (+ p n))
	(cua-copy-region-to-global-mark p (point)))))

(defun cua-cut-to-global-mark ()
  "Move active region/rectangle to global mark buffer/position."
  (interactive)
  (if buffer-read-only
      (cua-copy-to-global-mark)
    (setq cua--last-killed-rectangle nil)
    (if cua--rectangle
	(cua--cut-rectangle-to-global-mark nil)
      (let ((start (mark)) (end (point)))
	(or (<= start end)
	    (setq start (prog1 end (setq end start))))
	(cua-cut-region-to-global-mark start end)))))

(defun cua-cut-next-to-global-mark (n)
  "Move the following N characters in buffer to global mark buffer/position."
  (interactive "p")
  (setq cua--last-killed-rectangle nil)
  (or (eobp)
      (let ((p (point)))
	(goto-char (+ p n))
	(cua-cut-region-to-global-mark p (point)))))

(defun cua-delete-char-at-global-mark (arg)
  "Delete character following the global mark position."
  (interactive "p")
  (cua--delete-at-global-mark arg "Deleted"))

(defun cua-delete-backward-char-at-global-mark (arg)
  "Delete character before the global mark position."
  (interactive "p")
  (cua--delete-at-global-mark (- arg) "Deleted backward"))

(defun cua-insert-char-at-global-mark ()
  "Insert the character you type at the global mark position."
  (interactive)
  (cua--insert-at-global-mark (char-to-string (aref (this-single-command-keys) 0)) "Inserted"))

(defun cua-insert-newline-at-global-mark ()
  "Insert a newline at the global mark position."
  (interactive)
  (cua--insert-at-global-mark "\n"))

(defun cua-indent-to-global-mark-column ()
  "Indent current line or rectangle to global mark column."
  (interactive "*")
  (if (cua--global-mark-active)
      (let (col)
	(save-excursion
	  (set-buffer (marker-buffer cua--global-mark-marker))
	  (goto-char (marker-position cua--global-mark-marker))
	  (setq col (current-column)))
	(if cua--rectangle
	    (cua--indent-rectangle nil col t)
	  (indent-to col))
	(if (eq (current-buffer) (marker-buffer cua--global-mark-marker))
	    (save-excursion
	      (goto-char (marker-position cua--global-mark-marker))
	      (move-to-column col)
	      (move-marker cua--global-mark-marker (point))
	      (move-overlay cua--global-mark-overlay (point) (1+ (point))))))))


(defun cua-cancel-global-mark ()
  "Cancel the global mark."
  (interactive)
  (if mark-active
      (cua-cancel)
    (if (cua--global-mark-active)
	(cua--deactivate-global-mark t)))
  (cua--fallback))

;;; Post-command hook for global mark.

(defun cua--global-mark-post-command ()
  (when (and (cua--global-mark-active) ;; Updates cua--global-mark-active variable
	     cua-global-mark-keep-visible)
    ;; keep global mark position visible
    (sit-for 0)
    (if (or (not (eq (current-buffer) (marker-buffer cua--global-mark-marker)))
	    (not (pos-visible-in-window-p (marker-position cua--global-mark-marker))))
	(let ((w (selected-window)) (p (point)) h)
	  ;; The following code is an attempt to keep the global mark visible in
	  ;; other window -- but it doesn't work.
	  (switch-to-buffer-other-window (marker-buffer cua--global-mark-marker) t)
	  (goto-char (marker-position cua--global-mark-marker))
	  (if (not (pos-visible-in-window-p (marker-position cua--global-mark-marker)))
	      (recenter (if (> (setq h (- (window-height) 4)) 1) h '(4))))
	  (select-window w)
	  (goto-char p)))))

;;; Initialization

(defun cua--init-global-mark ()
  (unless (face-background 'cua-global-mark-face)
    (copy-face 'region 'cua-global-mark-face)
    (set-face-foreground 'cua-global-mark-face "black")
    (set-face-background 'cua-global-mark-face "cyan"))

  (define-key cua--global-mark-keymap [remap copy-region-as-kill]	'cua-copy-to-global-mark)
  (define-key cua--global-mark-keymap [remap kill-ring-save]		'cua-copy-to-global-mark)
  (define-key cua--global-mark-keymap [remap kill-region]		'cua-cut-to-global-mark)
  (define-key cua--global-mark-keymap [remap yank]			'cua-copy-next-to-global-mark)

  (define-key cua--global-mark-keymap [remap keyboard-escape-quit]	'cua-cancel-global-mark)
  (define-key cua--global-mark-keymap [remap keyboard-quit]		'cua-cancel-global-mark)

  (define-key cua--global-mark-keymap [(control ?d)]			'cua-cut-next-to-global-mark)
  (define-key cua--global-mark-keymap [remap delete-backward-char]	'cua-delete-backward-char-at-global-mark)
  (define-key cua--global-mark-keymap [remap backward-delete-char]	'cua-delete-backward-char-at-global-mark)
  (define-key cua--global-mark-keymap [remap backward-delete-char-untabify] 'cua-delete-backward-char-at-global-mark)
  (define-key cua--global-mark-keymap [remap self-insert-command]	'cua-insert-char-at-global-mark)
  (define-key cua--global-mark-keymap [remap self-insert-iso]		'cua-insert-char-at-global-mark)

  ;; Catch self-inserting characters which are "stolen" by other modes
  (define-key cua--global-mark-keymap [t]
    '(menu-item "sic" cua-insert-char-at-global-mark :filter cua--self-insert-char-p))

  (define-key cua--global-mark-keymap [remap newline]			'cua-insert-newline-at-global-mark)
  (define-key cua--global-mark-keymap [remap newline-and-indent]	'cua-insert-newline-at-global-mark)
  (define-key cua--global-mark-keymap "\r"				'cua-insert-newline-at-global-mark)

  (define-key cua--global-mark-keymap "\t"				'cua-indent-to-global-mark-column)

  (setq cua--global-mark-initialized t))

;;; cua-gmrk.el ends here