annotate lisp/tl/filename.el @ 32:e04119814345 r19-15b99

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