1 ;;; filename.el --- file name filter
3 ;; Copyright (C) 1996,1997 MORIOKA Tomohiko
5 ;; Author: MORIOKA Tomohiko <morioka@jaist.ac.jp>
6 ;; Version: $Id: filename.el,v 1.4 1997/03/10 13:53:38 morioka Exp $
7 ;; Keywords: file name, string
9 ;; This file is part of APEL (A Portable Emacs Library).
11 ;; This program is free software; you can redistribute it and/or
12 ;; modify it under the terms of the GNU General Public License as
13 ;; published by the Free Software Foundation; either version 2, or (at
14 ;; your option) any later version.
16 ;; This program is distributed in the hope that it will be useful, but
17 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 ;; General Public License for more details.
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs; see the file COPYING. If not, write to the
23 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
24 ;; Boston, MA 02111-1307, USA.
30 (require 'file-detect)
32 (defsubst poly-funcall (functions arg)
34 (setq arg (funcall (car functions) arg)
35 functions (cdr functions))
43 (defvar filename-limit-length 21)
45 (defvar filename-replacement-alist
47 ((?! ?\" ?# ?$ ?% ?& ?' ?\( ?\) ?* ?/
48 ?: ?; ?< ?> ?? ?\[ ?\\ ?\] ?` ?{ ?| ?}) . "_")
49 (filename-control-p . "")
52 (defvar filename-filters
54 (and (exec-installed-p "kakasi")
55 '(filename-japanese-to-roman-string)
57 '(filename-special-filter
58 filename-eliminate-top-low-lines
59 filename-canonicalize-low-lines
60 filename-maybe-truncate-by-size
61 filename-eliminate-bottom-low-lines
68 (defun filename-japanese-to-roman-string (str)
70 (set-buffer (get-buffer-create " *temp kakasi*"))
73 (call-process-region (point-min)(point-max) "kakasi" t t t
74 "-Ha" "-Ka" "-Ja" "-Ea" "-ka")
78 (defun filename-control-p (character)
79 (let ((code (char-int character)))
80 (or (< code 32)(= code 127))
83 (defun filename-special-filter (string)
90 (let* ((chr (sref string i))
91 (ret (assoc-if (function
97 filename-replacement-alist))
100 (setq dest (concat dest (substring string b i)(cdr ret))
101 i (+ i (char-length chr))
103 (setq i (+ i (char-length chr)))
105 (concat dest (substring string b))
108 (defun filename-eliminate-top-low-lines (string)
109 (if (string-match "^_+" string)
110 (substring string (match-end 0))
113 (defun filename-canonicalize-low-lines (string)
115 (while (string-match "__+" string)
116 (setq dest (concat dest (substring string 0 (1+ (match-beginning 0)))))
117 (setq string (substring string (match-end 0)))
122 (defun filename-maybe-truncate-by-size (string)
123 (if (and (> (length string) filename-limit-length)
124 (string-match "_" string filename-limit-length)
126 (substring string 0 (match-beginning 0))
129 (defun filename-eliminate-bottom-low-lines (string)
130 (if (string-match "_+$" string)
131 (substring string 0 (match-beginning 0))
138 (defun replace-as-filename (string)
139 "Return safety filename from STRING. [filename.el]"
141 (poly-funcall filename-filters string)
150 ;;; filename.el ends here