-
Notifications
You must be signed in to change notification settings - Fork 0
/
cygwinize.el
executable file
·94 lines (71 loc) · 3.24 KB
/
cygwinize.el
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
;;; cygwinize.el --- Extra compat utils for Cygwin -*- lexical-binding: t; -*-
;; Copyright (C) 2016 Aaron Harris
;; Author: Aaron Harris <[email protected]>
;; Keywords: os w32 cygwin
;; Dependencies: `vizier'
;; This program 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.
;; This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
;;; Commentary:
;; This module contains some extra compatability utilities that are
;; useful for interacting with Cygwin, and with Windows in general.
;;; Code:
(require 'vizier)
;;;; Filename Compatability
;;=========================
(defun cygwinize-convert-file-name-to-hybrid-windows
(file &optional absolute-p)
"As `cygwin-convert-file-name-to-windows', with forward slashes."
(replace-regexp-in-string "\\\\" "/"
(cygwin-convert-file-name-to-windows
file absolute-p)))
(defun cygwinize--advice (orig-fn &rest args)
"Generic advice to \"cygwinize\" a function.
Within the advised function, calls to `buffer-file-name' return
Windows-style filenames (but with forward slashes, as in
`cygwinize-convert-file-name-to-hybrid-windows'). This may be
used to provide a compatability layer when Emacs is dealing with
processes from outside the Cygwin ecosystem.
This advice should be installed as :around advice, and it is safe
to do so even on non-Cygwin systems, as the advice checks
`system-type' before proceeding."
(vizier-with-advice-if (eq system-type 'cygwin)
((buffer-file-name
:filter-return
(lambda (return)
(when return
(require 'cygwinize)
(cygwinize-convert-file-name-to-hybrid-windows return)))))
(apply orig-fn args)))
(defun cygwinize (symbol)
"Install advice to Cygwinize SYMBOL (a function name).
In all subsequent calls to the function named by SYMBOL, the
function `buffer-file-name' will return Windows-style
filenames (but with forward slshes, as in
`cygwinize-convert-file-name-to-hybrid-windows'). This may be
used to provide a compatability layer when Emacs is dealing with
processes from outside the Cygwin ecosystem.
If the current system is not Cygwin, do nothing."
(when (eq system-type 'cygwin)
(advice-add symbol :around #'cygwinize--advice)))
(defun cygwinize-remove (symbol)
"Remove advice installed on SYMBOL with `cygwinize'."
(advice-remove symbol #'cygwinize--advice))
;;;; DOS line endings
;;===================
;; From Johan Bockgård via
;; http://stackoverflow.com/questions/730751/hiding-m-in-emacs
(defun cygwinize-hide-dos-eol ()
"Do not show ^M in files containing mixed UNIX and DOS line endings."
(interactive)
(setq buffer-display-table (make-display-table))
(aset buffer-display-table ?\^M []))
(provide 'cygwinize)
;;; cygwinize.el ends here