mirror of
git://git.sv.gnu.org/emacs.git
synced 2026-02-16 17:24:23 +00:00
Add files somehow forgotten by bzr git-apply.
This commit is contained in:
parent
efc3dd3ccc
commit
f701ab72dd
4 changed files with 388 additions and 0 deletions
130
lisp/w32-common-fns.el
Normal file
130
lisp/w32-common-fns.el
Normal file
|
|
@ -0,0 +1,130 @@
|
|||
;;; w32-common-fns.el --- Lisp routines for Windows and Cygwin-w32
|
||||
|
||||
;; Copyright (C) 1994, 2001-2012 Free Software Foundation, Inc.
|
||||
|
||||
;; 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 3 of the License, 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. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
;;; Commentary:
|
||||
;;;
|
||||
;;; This file contains functions that are used by both native NT Emacs
|
||||
;;; and Cygwin Emacs compiled to use the native Windows widget
|
||||
;;; library.
|
||||
|
||||
(defun w32-version ()
|
||||
"Return the MS-Windows version numbers.
|
||||
The value is a list of three integers: the major and minor version
|
||||
numbers, and the build number."
|
||||
(x-server-version))
|
||||
|
||||
(defun w32-using-nt ()
|
||||
"Return non-nil if running on a Windows NT descendant.
|
||||
That includes all Windows systems except for 9X/Me."
|
||||
(getenv "SystemRoot"))
|
||||
|
||||
(declare-function w32-get-clipboard-data "w32select.c")
|
||||
(declare-function w32-set-clipboard-data "w32select.c")
|
||||
(declare-function x-server-version "w32fns.c" (&optional display))
|
||||
|
||||
;;; Fix interface to (X-specific) mouse.el
|
||||
(defun x-set-selection (type data)
|
||||
"Make an X selection of type TYPE and value DATA.
|
||||
The argument TYPE (nil means `PRIMARY') says which selection, and
|
||||
DATA specifies the contents. TYPE must be a symbol. \(It can also
|
||||
be a string, which stands for the symbol with that name, but this
|
||||
is considered obsolete.) DATA may be a string, a symbol, an
|
||||
integer (or a cons of two integers or list of two integers).
|
||||
|
||||
The selection may also be a cons of two markers pointing to the same buffer,
|
||||
or an overlay. In these cases, the selection is considered to be the text
|
||||
between the markers *at whatever time the selection is examined*.
|
||||
Thus, editing done in the buffer after you specify the selection
|
||||
can alter the effective value of the selection.
|
||||
|
||||
The data may also be a vector of valid non-vector selection values.
|
||||
|
||||
The return value is DATA.
|
||||
|
||||
Interactively, this command sets the primary selection. Without
|
||||
prefix argument, it reads the selection in the minibuffer. With
|
||||
prefix argument, it uses the text of the region as the selection value.
|
||||
|
||||
Note that on MS-Windows, primary and secondary selections set by Emacs
|
||||
are not available to other programs."
|
||||
(put 'x-selections (or type 'PRIMARY) data))
|
||||
|
||||
(defun x-get-selection (&optional type _data-type)
|
||||
"Return the value of an X Windows selection.
|
||||
The argument TYPE (default `PRIMARY') says which selection,
|
||||
and the argument DATA-TYPE (default `STRING') says
|
||||
how to convert the data.
|
||||
|
||||
TYPE may be any symbol \(but nil stands for `PRIMARY'). However,
|
||||
only a few symbols are commonly used. They conventionally have
|
||||
all upper-case names. The most often used ones, in addition to
|
||||
`PRIMARY', are `SECONDARY' and `CLIPBOARD'.
|
||||
|
||||
DATA-TYPE is usually `STRING', but can also be one of the symbols
|
||||
in `selection-converter-alist', which see."
|
||||
(get 'x-selections (or type 'PRIMARY)))
|
||||
|
||||
;; x-selection-owner-p is used in simple.el
|
||||
(defun x-selection-owner-p (&optional type)
|
||||
(and (memq type '(nil PRIMARY SECONDARY))
|
||||
(get 'x-selections (or type 'PRIMARY))))
|
||||
|
||||
;; The "Windows" keys on newer keyboards bring up the Start menu
|
||||
;; whether you want it or not - make Emacs ignore these keystrokes
|
||||
;; rather than beep.
|
||||
(global-set-key [lwindow] 'ignore)
|
||||
(global-set-key [rwindow] 'ignore)
|
||||
|
||||
(defvar w32-charset-info-alist) ; w32font.c
|
||||
|
||||
|
||||
;;;; Selections
|
||||
|
||||
;; We keep track of the last text selected here, so we can check the
|
||||
;; current selection against it, and avoid passing back our own text
|
||||
;; from x-selection-value.
|
||||
(defvar x-last-selected-text nil)
|
||||
|
||||
(defun x-get-selection-value ()
|
||||
"Return the value of the current selection.
|
||||
Consult the selection. Treat empty strings as if they were unset."
|
||||
(if x-select-enable-clipboard
|
||||
(let (text)
|
||||
;; Don't die if x-get-selection signals an error.
|
||||
(condition-case c
|
||||
(setq text (w32-get-clipboard-data))
|
||||
(error (message "w32-get-clipboard-data:%s" c)))
|
||||
(if (string= text "") (setq text nil))
|
||||
(cond
|
||||
((not text) nil)
|
||||
((eq text x-last-selected-text) nil)
|
||||
((string= text x-last-selected-text)
|
||||
;; Record the newer string, so subsequent calls can use the 'eq' test.
|
||||
(setq x-last-selected-text text)
|
||||
nil)
|
||||
(t
|
||||
(setq x-last-selected-text text))))))
|
||||
|
||||
(defalias 'x-selection-value 'x-get-selection-value)
|
||||
|
||||
;; Arrange for the kill and yank functions to set and check the clipboard.
|
||||
(setq interprogram-cut-function 'x-select-text)
|
||||
(setq interprogram-paste-function 'x-get-selection-value)
|
||||
|
||||
(provide 'w32-common-fns)
|
||||
169
src/cygw32.c
Normal file
169
src/cygw32.c
Normal file
|
|
@ -0,0 +1,169 @@
|
|||
/* Cygwin support routines.
|
||||
Copyright (C) 2011 Free Software Foundation, Inc.
|
||||
|
||||
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 3 of the License, 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. If not, see <http://www.gnu.org/licenses/>. */
|
||||
|
||||
|
||||
#include "cygw32.h"
|
||||
#include "character.h"
|
||||
#include "buffer.h"
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
static Lisp_Object Qutf_16_le;
|
||||
|
||||
static Lisp_Object
|
||||
fchdir_unwind (Lisp_Object dir_fd)
|
||||
{
|
||||
(void) fchdir (XFASTINT (dir_fd));
|
||||
(void) close (XFASTINT (dir_fd));
|
||||
return Qnil;
|
||||
}
|
||||
|
||||
static void
|
||||
chdir_to_default_directory ()
|
||||
{
|
||||
Lisp_Object new_cwd;
|
||||
int old_cwd_fd = open (".", O_RDONLY | O_DIRECTORY);
|
||||
|
||||
if (old_cwd_fd == -1)
|
||||
error ("could not open current directory: %s", strerror (errno));
|
||||
|
||||
record_unwind_protect (fchdir_unwind, make_number (old_cwd_fd));
|
||||
|
||||
new_cwd = Funhandled_file_name_directory (
|
||||
Fexpand_file_name (build_string ("."), Qnil));
|
||||
if (!STRINGP (new_cwd))
|
||||
new_cwd = build_string ("/");
|
||||
|
||||
if (chdir (SDATA (ENCODE_FILE (new_cwd))))
|
||||
error ("could not chdir: %s", strerror (errno));
|
||||
}
|
||||
|
||||
static Lisp_Object
|
||||
conv_filename_to_w32_unicode (Lisp_Object in, int absolute_p)
|
||||
{
|
||||
ssize_t converted_len;
|
||||
Lisp_Object converted;
|
||||
unsigned flags;
|
||||
int count = SPECPDL_INDEX ();
|
||||
|
||||
chdir_to_default_directory ();
|
||||
|
||||
flags = CCP_POSIX_TO_WIN_W;
|
||||
if (!absolute_p) {
|
||||
flags |= CCP_RELATIVE;
|
||||
}
|
||||
|
||||
in = ENCODE_FILE (in);
|
||||
|
||||
converted_len = cygwin_conv_path (flags, SDATA (in), NULL, 0);
|
||||
if (converted_len < 2)
|
||||
error ("cygwin_conv_path: %s", strerror (errno));
|
||||
|
||||
converted = make_uninit_string (converted_len - 1);
|
||||
if (cygwin_conv_path (flags, SDATA (in),
|
||||
SDATA (converted), converted_len))
|
||||
error ("cygwin_conv_path: %s", strerror (errno));
|
||||
|
||||
return unbind_to (count, converted);
|
||||
}
|
||||
|
||||
static Lisp_Object
|
||||
conv_filename_from_w32_unicode (const wchar_t* in, int absolute_p)
|
||||
{
|
||||
ssize_t converted_len;
|
||||
Lisp_Object converted;
|
||||
unsigned flags;
|
||||
int count = SPECPDL_INDEX ();
|
||||
|
||||
chdir_to_default_directory ();
|
||||
|
||||
flags = CCP_WIN_W_TO_POSIX;
|
||||
if (!absolute_p) {
|
||||
flags |= CCP_RELATIVE;
|
||||
}
|
||||
|
||||
converted_len = cygwin_conv_path (flags, in, NULL, 0);
|
||||
if (converted_len < 1)
|
||||
error ("cygwin_conv_path: %s", strerror (errno));
|
||||
|
||||
converted = make_uninit_string (converted_len - 1 /*subtract terminator*/);
|
||||
if (cygwin_conv_path (flags, in, SDATA (converted), converted_len))
|
||||
error ("cygwin_conv_path: %s", strerror (errno));
|
||||
|
||||
return unbind_to (count, DECODE_FILE (converted));
|
||||
}
|
||||
|
||||
Lisp_Object
|
||||
from_unicode (Lisp_Object str)
|
||||
{
|
||||
CHECK_STRING (str);
|
||||
if (!STRING_MULTIBYTE (str) &&
|
||||
SBYTES (str) & 1)
|
||||
{
|
||||
str = Fsubstring (str, make_number (0), make_number (-1));
|
||||
}
|
||||
|
||||
return code_convert_string_norecord (str, Qutf_16_le, 0);
|
||||
}
|
||||
|
||||
wchar_t *
|
||||
to_unicode (Lisp_Object str, Lisp_Object *buf)
|
||||
{
|
||||
*buf = code_convert_string_norecord (str, Qutf_16_le, 1);
|
||||
/* We need to make a another copy (in addition to the one made by
|
||||
code_convert_string_norecord) to ensure that the final string is
|
||||
_doubly_ zero terminated --- that is, that the string is
|
||||
terminated by two zero bytes and one utf-16le null character.
|
||||
Because strings are already terminated with a single zero byte,
|
||||
we just add one additional zero. */
|
||||
str = make_uninit_string (SBYTES (*buf) + 1);
|
||||
memcpy (SDATA (str), SDATA (*buf), SBYTES (*buf));
|
||||
SDATA (str) [SBYTES (*buf)] = '\0';
|
||||
*buf = str;
|
||||
return WCSDATA (*buf);
|
||||
}
|
||||
|
||||
DEFUN ("cygwin-convert-path-to-windows",
|
||||
Fcygwin_convert_path_to_windows, Scygwin_convert_path_to_windows,
|
||||
1, 2, 0,
|
||||
doc: /* Convert PATH to a Windows path. If ABSOLUTE-P if
|
||||
non-nil, return an absolute path.*/)
|
||||
(Lisp_Object path, Lisp_Object absolute_p)
|
||||
{
|
||||
return from_unicode (
|
||||
conv_filename_to_w32_unicode (path, absolute_p == Qnil ? 0 : 1));
|
||||
}
|
||||
|
||||
DEFUN ("cygwin-convert-path-from-windows",
|
||||
Fcygwin_convert_path_from_windows, Scygwin_convert_path_from_windows,
|
||||
1, 2, 0,
|
||||
doc: /* Convert a Windows path to a Cygwin path. If ABSOLUTE-P
|
||||
if non-nil, return an absolute path.*/)
|
||||
(Lisp_Object path, Lisp_Object absolute_p)
|
||||
{
|
||||
return conv_filename_from_w32_unicode (to_unicode (path, &path),
|
||||
absolute_p == Qnil ? 0 : 1);
|
||||
}
|
||||
|
||||
void
|
||||
syms_of_cygw32 (void)
|
||||
{
|
||||
/* No, not utf-16-le: that one has a BOM. */
|
||||
DEFSYM (Qutf_16_le, "utf-16le");
|
||||
defsubr (&Scygwin_convert_path_from_windows);
|
||||
defsubr (&Scygwin_convert_path_to_windows);
|
||||
}
|
||||
59
src/cygw32.h
Normal file
59
src/cygw32.h
Normal file
|
|
@ -0,0 +1,59 @@
|
|||
/* Header for Cygwin support routines.
|
||||
Copyright (C) 2011 Free Software Foundation, Inc.
|
||||
|
||||
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 3 of the License, 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. If not, see <http://www.gnu.org/licenses/>. */
|
||||
|
||||
#ifndef CYGW32_H
|
||||
#define CYGW32_H
|
||||
#include <config.h>
|
||||
#include <windef.h>
|
||||
#include <sys/cygwin.h>
|
||||
#include <wchar.h>
|
||||
|
||||
#include <signal.h>
|
||||
#include <stdio.h>
|
||||
#include <limits.h>
|
||||
#include <errno.h>
|
||||
#include <math.h>
|
||||
#include <setjmp.h>
|
||||
|
||||
#include "lisp.h"
|
||||
#include "coding.h"
|
||||
|
||||
/* *** Character conversion *** */
|
||||
|
||||
/* Access the wide-character string stored in a Lisp string object. */
|
||||
#define WCSDATA(x) ((wchar_t *) SDATA (x))
|
||||
|
||||
/* Convert the Emacs string in STR to UTF-16LE and store a new string
|
||||
containing the encoded version of STR into *BUF. BUF may safely
|
||||
point to STR on entry. */
|
||||
extern wchar_t *to_unicode (Lisp_Object str, Lisp_Object *buf);
|
||||
|
||||
/* Convert STR, a UTF-16LE encoded string embedded in an Emacs string
|
||||
object, to a normal Emacs string and return it. */
|
||||
extern Lisp_Object from_unicode (Lisp_Object str);
|
||||
|
||||
/* *** Path conversion. *** */
|
||||
|
||||
EXFUN (Fcygwin_convert_path_to_windows, 2);
|
||||
EXFUN (Fcygwin_convert_path_from_windows, 2);
|
||||
|
||||
/* *** Misc *** */
|
||||
extern void syms_of_cygw32 (void);
|
||||
extern char * w32_strerror (int error_no);
|
||||
|
||||
#endif /* CYGW32_H */
|
||||
30
src/w32select.h
Normal file
30
src/w32select.h
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
/* Selection processing for Emacs on the Microsoft W32 API.
|
||||
|
||||
Copyright (C) 1993-1994, 2001-2011 Free Software Foundation, Inc.
|
||||
|
||||
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 3 of the License, 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. If not, see <http://www.gnu.org/licenses/>. */
|
||||
|
||||
#ifndef W32SELECT_H
|
||||
#define W32SELECT_H
|
||||
#include <windows.h>
|
||||
|
||||
#define HAVE_W32SELECT 1
|
||||
|
||||
extern void syms_of_w32select (void);
|
||||
extern void globals_of_w32select (void);
|
||||
extern void term_w32select (void);
|
||||
|
||||
#endif
|
||||
Loading…
Reference in a new issue