gnu-emacs-sources
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

aliator.el 1.1


From: Andreas Roehler
Subject: aliator.el 1.1
Date: Sat, 15 Jul 2006 14:09:51 +0200
User-agent: KNode/0.9.2

;;; aliator.el --- 

;; Version: 1.1

;; Copyright (C) 2006  Andreas Roehler

;; Author: Andreas Roehler <address@hidden>
;; Keywords: convenience

;; This file 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 2, or (at your option)
;; any later version.

;; This file 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 GNU Emacs; see the file COPYING.  If not, write to
;; the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
;; Boston, MA 02110-1301, USA.


;; Changes: Now with customize facility, minor changes
;; in code also

;;; Commentary:

;; Defines aliases from given command praefix names, in
;; order to enable listing of the (now) expanded names
;; together with the others, already beginning with the
;; mode-name.

;; Example for the created list of aliases: 
;;
;;  (defalias 'outline-hide-entry' hide-entry) 
;;  (defalias 'outline-show-entry' show-entry)

;; Edit `aliator-list-1' and/or
;; `aliator-list-4' according to your needs

; you may specfiy further aliator-list-n
;; to call with numeric prefix args


;; To acticate these new aliases evaluate the
;; output-buffer.

;; ToDo: aliator-report-consum

;;; Code:

(defcustom aliator-list-1
  '(  ("/usr/local/share/emacs/22.0.50/lisp/outline.el" "outline" "" "")
    )
  "A list of lists specifying filenames and the way to get aliases from.

Add or remove lists, whose elements are:

 \"file to process\" \"praefix\" \"no-alias\" \"replace-praefix\"

where

`praefix' indicates the new name-praefix wherefrom expansion will work, 

`no-alias' the exception, where no alias should be defined - i.e. functions 
start with `html-' in sgml-mode.el - and 

`replace-praefix' cases where it seems appropriate to provide an `alias' 
replacing the first part of the function-name, as `xml-' instead of `sgml-'; 
might also be the empty string

Each list must specify four strings, the latter two might be
empty.
"
  :type '(alist :value-type (repeat string))
;;  :options '

  )

(defcustom aliator-list-4
  '(("~/emacs/lisp/textmodes/sgml-mode.el" "xml" "html" "sgml" "")
    ("~/emacs/lisp/abbrev.el" "abbrev" "" "" "")
    ("~/emacs/lisp/find-dired.el" "dired" "" "" ""))

  "A list of files to process in order to get aliases.
See `aliator-list-1' for documentation"

  :type '(alist :value-type (repeat string)))

(defcustom aliator-report-consum  nil 
 "Report the amount of memory and conses consumed due defined new aliases" 

:type 'boolean
:initialize 'custom-initialize-default
:group 'convenience)

(defun aliator (&optional arg) 
  "Provides `alias'-defs following a PREFIX and specifications.
Works at function names not starting already with that praefix.
Normalizes command names to that `M-x mode-name- TAB' - now lists
all functions available, even if they don't start with that
PREFIX originally.  See the default `aliator-list-1' for
documentation how to edit that list.
With arg: use `aliator-list-4' to process
When calling from a programm, use
"
  (interactive "p")
  (set-buffer (get-buffer-create "neualias"))
  (erase-buffer)
  (let* ((argument (if arg
                       (prefix-numeric-value arg) 1))
         (newalias-list
          (cond ((eq 1 argument)
                 aliator-list-1)
                ((eq 4 argument)
                 aliator-list-4))))
                ;; you may specfiy more aliator-list-n
                ;; to call here with numeric prefix
                ;; args
    (while newalias-list
      (let (
            (file
             (caar newalias-list))
            (praefix
             (cadr (car newalias-list)))
            (no-alias
             (car (nthcdr 2 (car newalias-list))))
            (replace-praefix 
             (car (nthcdr 3 (car newalias-list))))
            (suffix 
             (car (nthcdr 4 (car newalias-list)))))
        (aliator-intern file praefix no-alias replace-praefix suffix))
      (setq newalias-list (cdr newalias-list)))
    (switch-to-buffer "neualias")
    (if (eq 0 (buffer-size))
        (error "Nothing to do? Can't make a proposal to define new aliases.")
      (message "%s" "`M-x eval-buffer' to install these aliases"))))

 
(defun aliator-intern (file praefix no-alias replace-praefix suffix)
  "To call from a programm, also usable directly"
  (if (file-readable-p file)
      (find-file file))
  (message "Processing %s " (buffer-name))
  (goto-char (point-min))
  (save-excursion 
    (eval-buffer)
    (while (and
            newalias-list
            (re-search-forward "^(defun \\([A-Za-z0-9\-]+\\)" (point-max) t 1))
      (let ((akt-fn (match-string 1))
            (fn-first-part (substring (match-string 1) 0 (string-match "-" 
(match-string 1)))))
        ;; if the function name already starts with the
        ;; wished name or `no-alias' is set, do nothing
        (unless (or (string= fn-first-part praefix)
                    (string= fn-first-part no-alias))
          (if (string= fn-first-part replace-praefix)
              (progn (setq neualias (concat praefix (substring akt-fn 
(string-match "-" akt-fn))))
                     (aliator-ausgabe neualias))
            (let*
                ((alt-alias (split-string akt-fn "-"))
                 (alias-ohne-neualias (remove praefix alt-alias))
                 (alias-ohne-suffix (remove suffix alt-alias))
                 ;; avoid repeats in names as dired-look-dired
                 (alias-ohne-doppel (delete-dups alias-ohne-suffix))
                 alias-verkettet)
              (dolist (teil alias-ohne-doppel)
                (setq alias-verkettet (concat alias-verkettet "-"(format "%s" 
teil))))
              (if (< 0 (length praefix))
                  (setq neualias (concat praefix alias-verkettet))
                (setq neualias (substring alias-verkettet 1)))
              (when (< 0 (length suffix))
                (setq neualias (concat neualias"-"suffix)))
              (aliator-ausgabe neualias)))))))
  (kill-buffer (current-buffer)))

(defun aliator-ausgabe (neualias)
  (if (functionp neualias)
      (message " %s" "Function already exists")
    (save-excursion
      (set-buffer "neualias")
      (switch-to-buffer (current-buffer))
      (insert "(defalias '"neualias "\t'"akt-fn")""\n"))))

(provide 'aliator)
;;; aliator.el ends here



reply via email to

[Prev in Thread] Current Thread [Next in Thread]