annotate lisp/tl/filename.el @ 147:e186c2b7192d xemacs-20-2

Added tag r20-2p1 for changeset 2af401a6ecca
author cvs
date Mon, 13 Aug 2007 09:34:48 +0200
parents fe104dbd9147
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
74
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents:
diff changeset
1 ;;; filename.el --- file name filter
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents:
diff changeset
2
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents:
diff changeset
3 ;; Copyright (C) 1996 MORIOKA Tomohiko
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents:
diff changeset
4
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents:
diff changeset
5 ;; Author: MORIOKA Tomohiko <morioka@jaist.ac.jp>
110
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 76
diff changeset
6 ;; Version: $Id: filename.el,v 1.3 1997/03/16 03:05:44 steve Exp $
74
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents:
diff changeset
7 ;; Keywords: string, file name
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents:
diff changeset
8
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents:
diff changeset
9 ;; This file is part of tl (Tiny Library).
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents:
diff changeset
10
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents:
diff changeset
11 ;; This program is free software; you can redistribute it and/or
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents:
diff changeset
12 ;; modify it under the terms of the GNU General Public License as
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents:
diff changeset
13 ;; published by the Free Software Foundation; either version 2, or (at
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents:
diff changeset
14 ;; your option) any later version.
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents:
diff changeset
15
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents:
diff changeset
16 ;; This program is distributed in the hope that it will be useful, but
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents:
diff changeset
17 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents:
diff changeset
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents:
diff changeset
19 ;; General Public License for more details.
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents:
diff changeset
20
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents:
diff changeset
21 ;; You should have received a copy of the GNU General Public License
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents:
diff changeset
22 ;; along with GNU Emacs; see the file COPYING. If not, write to the
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents:
diff changeset
23 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents:
diff changeset
24 ;; Boston, MA 02111-1307, USA.
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents:
diff changeset
25
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents:
diff changeset
26 ;;; Code:
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents:
diff changeset
27
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents:
diff changeset
28 (require 'tl-list)
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents:
diff changeset
29 (require 'tl-str)
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents:
diff changeset
30
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents:
diff changeset
31
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents:
diff changeset
32 ;;; @ variables
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents:
diff changeset
33 ;;;
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents:
diff changeset
34
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents:
diff changeset
35 (defvar filename-limit-length 21)
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents:
diff changeset
36
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents:
diff changeset
37 (defvar filename-replacement-alist
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents:
diff changeset
38 (list
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents:
diff changeset
39 (cons (string-to-char-list " \t") "_")
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents:
diff changeset
40 (cons (string-to-char-list (expand-char-ranges "!-*,/:;<>?[-^`{-~")) "_")
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents:
diff changeset
41 '(filename-control-p . "")
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents:
diff changeset
42 ))
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents:
diff changeset
43
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents:
diff changeset
44 (defvar filename-filters
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents:
diff changeset
45 (nconc
110
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 76
diff changeset
46 (and (exec-installed-p "kakasi")
74
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents:
diff changeset
47 '(filename-japanese-to-roman-string)
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents:
diff changeset
48 )
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents:
diff changeset
49 '(filename-special-filter
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents:
diff changeset
50 filename-eliminate-top-low-lines
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents:
diff changeset
51 filename-canonicalize-low-lines
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents:
diff changeset
52 filename-maybe-truncate-by-size
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents:
diff changeset
53 filename-eliminate-bottom-low-lines
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents:
diff changeset
54 )))
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents:
diff changeset
55
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents:
diff changeset
56
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents:
diff changeset
57 ;;; @ filters
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents:
diff changeset
58 ;;;
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents:
diff changeset
59
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents:
diff changeset
60 (defun filename-japanese-to-roman-string (str)
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents:
diff changeset
61 (save-excursion
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents:
diff changeset
62 (set-buffer (get-buffer-create " *temp kakasi*"))
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents:
diff changeset
63 (erase-buffer)
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents:
diff changeset
64 (insert str)
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents:
diff changeset
65 (call-process-region (point-min)(point-max) "kakasi" t t t
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents:
diff changeset
66 "-Ha" "-Ka" "-Ja" "-Ea" "-ka")
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents:
diff changeset
67 (buffer-string)
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents:
diff changeset
68 ))
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents:
diff changeset
69
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents:
diff changeset
70 (defun filename-control-p (character)
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents:
diff changeset
71 (let ((code (char-int character)))
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents:
diff changeset
72 (or (< code 32)(= code 127))
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents:
diff changeset
73 ))
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents:
diff changeset
74
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents:
diff changeset
75 (defun filename-special-filter (string)
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents:
diff changeset
76 (let (dest
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents:
diff changeset
77 (i 0)
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents:
diff changeset
78 (len (length string))
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents:
diff changeset
79 (b 0)
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents:
diff changeset
80 )
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents:
diff changeset
81 (while (< i len)
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents:
diff changeset
82 (let* ((chr (sref string i))
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents:
diff changeset
83 (ret (ASSOC chr filename-replacement-alist
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents:
diff changeset
84 :test (function
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents:
diff changeset
85 (lambda (chr key)
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents:
diff changeset
86 (if (functionp key)
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents:
diff changeset
87 (funcall key chr)
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents:
diff changeset
88 (memq chr key)
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents:
diff changeset
89 )
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents:
diff changeset
90 ))))
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents:
diff changeset
91 )
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents:
diff changeset
92 (if ret
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents:
diff changeset
93 (setq dest (concat dest (substring string b i)(cdr ret))
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents:
diff changeset
94 i (+ i (char-length chr))
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents:
diff changeset
95 b i)
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents:
diff changeset
96 (setq i (+ i (char-length chr)))
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents:
diff changeset
97 )))
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents:
diff changeset
98 (concat dest (substring string b))
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents:
diff changeset
99 ))
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents:
diff changeset
100
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents:
diff changeset
101 (defun filename-eliminate-top-low-lines (string)
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents:
diff changeset
102 (if (string-match "^_+" string)
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents:
diff changeset
103 (substring string (match-end 0))
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents:
diff changeset
104 string))
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents:
diff changeset
105
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents:
diff changeset
106 (defun filename-canonicalize-low-lines (string)
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents:
diff changeset
107 (let (dest)
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents:
diff changeset
108 (while (string-match "__+" string)
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents:
diff changeset
109 (setq dest (concat dest (substring string 0 (1+ (match-beginning 0)))))
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents:
diff changeset
110 (setq string (substring string (match-end 0)))
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents:
diff changeset
111 )
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents:
diff changeset
112 (concat dest string)
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents:
diff changeset
113 ))
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents:
diff changeset
114
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents:
diff changeset
115 (defun filename-maybe-truncate-by-size (string)
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents:
diff changeset
116 (if (and (> (length string) filename-limit-length)
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents:
diff changeset
117 (string-match "_" string filename-limit-length)
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents:
diff changeset
118 )
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents:
diff changeset
119 (substring string 0 (match-beginning 0))
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents:
diff changeset
120 string))
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents:
diff changeset
121
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents:
diff changeset
122 (defun filename-eliminate-bottom-low-lines (string)
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents:
diff changeset
123 (if (string-match "_+$" string)
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents:
diff changeset
124 (substring string 0 (match-beginning 0))
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents:
diff changeset
125 string))
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents:
diff changeset
126
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents:
diff changeset
127
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents:
diff changeset
128 ;;; @ interface
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents:
diff changeset
129 ;;;
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents:
diff changeset
130
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents:
diff changeset
131 (defun replace-as-filename (string)
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents:
diff changeset
132 "Return safety filename from STRING. [filename.el]"
76
c0c698873ce1 Import from CVS: tag r20-0b33
cvs
parents: 74
diff changeset
133 (and string
c0c698873ce1 Import from CVS: tag r20-0b33
cvs
parents: 74
diff changeset
134 (poly-funcall filename-filters string)
c0c698873ce1 Import from CVS: tag r20-0b33
cvs
parents: 74
diff changeset
135 ))
74
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents:
diff changeset
136
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents:
diff changeset
137
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents:
diff changeset
138 ;;; @ end
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents:
diff changeset
139 ;;;
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents:
diff changeset
140
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents:
diff changeset
141 (provide 'filename)
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents:
diff changeset
142
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents:
diff changeset
143 ;;; filename.el ends here