1 ;;; filename.el --- file name filter
3 ;; Copyright (C) 1996 MORIOKA Tomohiko
5 ;; Author: MORIOKA Tomohiko <morioka@jaist.ac.jp>
6 ;; Version: $Id: filename.el,v 1.3 1997/03/10 13:09:34 morioka Exp $
7 ;; Keywords: string, file name
9 ;; This file is part of tl (Tiny 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.
35 (defvar filename-limit-length 21)
37 (defvar filename-replacement-alist
39 (cons (string-to-char-list " \t") "_")
40 (cons (string-to-char-list (expand-char-ranges "!-*,/:;<>?[-^`{-~")) "_")
41 '(filename-control-p . "")
44 (defvar filename-filters
46 (and (exec-installed-p "kakasi")
47 '(filename-japanese-to-roman-string)
49 '(filename-special-filter
50 filename-eliminate-top-low-lines
51 filename-canonicalize-low-lines
52 filename-maybe-truncate-by-size
53 filename-eliminate-bottom-low-lines
60 (defun filename-japanese-to-roman-string (str)
62 (set-buffer (get-buffer-create " *temp kakasi*"))
65 (call-process-region (point-min)(point-max) "kakasi" t t t
66 "-Ha" "-Ka" "-Ja" "-Ea" "-ka")
70 (defun filename-control-p (character)
71 (let ((code (char-int character)))
72 (or (< code 32)(= code 127))
75 (defun filename-special-filter (string)
82 (let* ((chr (sref string i))
83 (ret (ASSOC chr filename-replacement-alist
93 (setq dest (concat dest (substring string b i)(cdr ret))
94 i (+ i (char-length chr))
96 (setq i (+ i (char-length chr)))
98 (concat dest (substring string b))
101 (defun filename-eliminate-top-low-lines (string)
102 (if (string-match "^_+" string)
103 (substring string (match-end 0))
106 (defun filename-canonicalize-low-lines (string)
108 (while (string-match "__+" string)
109 (setq dest (concat dest (substring string 0 (1+ (match-beginning 0)))))
110 (setq string (substring string (match-end 0)))
115 (defun filename-maybe-truncate-by-size (string)
116 (if (and (> (length string) filename-limit-length)
117 (string-match "_" string filename-limit-length)
119 (substring string 0 (match-beginning 0))
122 (defun filename-eliminate-bottom-low-lines (string)
123 (if (string-match "_+$" string)
124 (substring string 0 (match-beginning 0))
131 (defun replace-as-filename (string)
132 "Return safety filename from STRING. [filename.el]"
134 (poly-funcall filename-filters string)
143 ;;; filename.el ends here