;; Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001 ;; David J. Biesack ;; This file is not 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: ;; some functions to deal with Windows file name atrocities. ;; ;; Author: David Biesack (David.Biesack@sas.com or biesack@mindspring.com ;; Last Modified By: biesack@mindspring.com ;; Last Modified: Thu May 31 20:05:16 2001 (defun w32-convert-clipboard () "Convert / in the Windows clipboard to \\ or vise versa" ;; I bind this to a Windows shortcut key C-M-\ in Start Menu/Programs/Emacs/Convert clipboard slashes ;; gnudoitw "(w32-convert-clipboard)" (with-temp-buffer (let ((in (current-kill 0)) out) (insert in) (subst-char-in-region (point-min) (point-max) ?/ ?\\) (setq out (buffer-substring-no-properties (point-min) (point-max))) ;; If that did not change anything, try changing \ to / (cond ((string-equal in out) (subst-char-in-region (point-min) (point-max) ?\\ ?/) (setq out (buffer-substring-no-properties (point-min) (point-max))))) (kill-new out))) t) (defun change-character-in-region (from to start end) (interactive "*cChange character: \ncTo character: \nr") (subst-char-in-region start end from to)) (defun change-character-in-buffer (from to) (interactive "cChange character: \ncTo character: \n") (change-character-in-region from to (point-min) (point-max))) (defalias '// 'change-character-in-region) (defun /\\-buffer () "Change all / to \\ in the buffer." (interactive) (change-character-in-buffer ?/ ?\\)) (defun /\\-region (start end) "Change all / to \\ for the rest of the buffer." (interactive "r") (change-character-in-region ?/ ?\\ start end)) (defalias '/\\ '/\\-region) (defun \\/-buffer () "Change all \\ to / in the buffer." (interactive) (change-character-in-buffer ?\\ ?/)) (defun \\/-region (start end) "Change all \\ to / for the region START to END." (interactive "r") (change-character-in-region ?\\ ?/ start end)) (defun /.-region (start end) "Change all / to . for the region START to END." (interactive "r") (change-character-in-region ?/ ?. start end)) (defun \./-region (start end) "Change all . to / for the region START to END." (interactive "r") (change-character-in-region ?. ?/ start end)) (defalias '\\/ '\\/-region) (defalias '\./ '\./-region) (defalias '/. '/.-region) ;; Following two contributed by: "Nascif Abousalh-Neto" (defun \,\.-region (start end) "Change all , to . for the region START to END." (interactive "r") (change-character-in-region ?, ?. start end)) (defun \.\,-region (start end) "Change all . to , for the region START to END." (interactive "r") (change-character-in-region ?. ?, start end)) (defalias '\,\. '\,\.-region) (defalias '\.\, '\.\,-region) (defun ^m () "Remove all ^M's from the buffer." (interactive) (^m-region (point-min) (point-max))) (defalias '^M '^m) (defalias '^M '6m) (defun ^m-buffer () "Remove all ^M's from the buffer." (interactive) (^m-region (point-min) (point-max))) (defalias '^m '^m-buffer) (defalias '^M '^m-buffer) (defun ^m-region (min max) "Remove all ^M's from the region." (interactive "r") (save-excursion (goto-char max) (while (re-search-backward "\C-m$" min t) (delete-char 1)))) (defun :/-region (start end) "Convert a path in the region START to END from Windows format to CygWin32 format, using cygpath" (interactive "r") (shell-command-on-region start end (concat "cygpath --unix '" (buffer-substring-no-properties start end) "'") t t) (goto-char (mark)) (backward-delete-char-untabify 1) ) (defalias ':/ ':/-region) (defun /:-region (start end) "Convert a path in the region START to END from CygWin32 format to Windows format, using cygpath" (interactive "r") (shell-command-on-region start end (concat "cygpath --windows '" (buffer-substring-no-properties start end) "'") t t) (goto-char (mark)) (backward-delete-char-untabify 1) ) (defalias ':/ ':/-region) (defun cygpath-region (start end) "Convert a path in the region START to END from CygWin32 format to Windows format, or from Windows format to CygWin32 format." (interactive "r") (save-excursion (goto-char start) (cond ((looking-at "/") (/:-region start end)) ((looking-at "[a-zA-Z]:") (:/-region start end)) ((looking-at "\\") (insert (substring default-directory 0 2)) (backward-char 2) (:/-region start end)))))