[Top][All Lists]

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

Emacs lisp question

From: Matthias Pfeifer
Subject: Emacs lisp question
Date: Mon, 18 Apr 2016 16:27:50 +0200

Hi there,

My emacs version is and it's running on Windows 7. I have this
piece of Emacs lisp that does insert a template file in a fresh java-mode
buffer and start my "pre-processor"

(add-to-list 'auto-insert-alist '(".*\\.java$" . [ ""
mp:java-preprocessor] ))

pre-processor looks like this:

(defun mp:java-preprocessor()
  (let ((classname (file-name-sans-extension (buffer-name)))
    (packagename (mp:predict-package-name-for-current-buffer)))
    (while (search-forward "CLASSNAME" nil t)
      (replace-match classname))
    (goto-char (point-min))
    (while (search-forward "PACKAGE" nil t)
      (replace-match packagename) ) ) )

(defun mp:predict-package-name-for-current-buffer ()
  "Simply take two parent directories and concat with . inbetween."
  (let* ((components (remq ""
                 (file-name-directory (buffer-file-name))
    (concat (nth 0 components) "." (nth 1 components) "." (nth 2

The problem is that the class-name and package-name are actually inserted
in capital letters while all file-names involved are writtn with lower-case
letters. So for a file with this path "c:/a/b/c/d/. The predict method
actually inserts: C.D.

Calling it outside the auto-insert environment eg by pressing C-x C-e
behind the closing paren belonging to the form in the
mp:predict-package-name-for-current-buffer function results into a lower
case letters package name.

Sorry for the bit lengthy question. I hope the question is clear: Why is
the result in capital letters in one case and in the case of the filename
letters in the other case?


reply via email to

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