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

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

Re: Emacs lisp question


From: tomas
Subject: Re: Emacs lisp question
Date: Mon, 18 Apr 2016 21:50:57 +0200
User-agent: Mutt/1.5.21 (2010-09-15)

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On Mon, Apr 18, 2016 at 04:27:50PM +0200, Matthias Pfeifer wrote:
> Hi there,
> 
> My emacs version is 25.0.91.1 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$" . [ "template.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 ""
>                (reverse
>                 (split-string
>                  (file-name-directory (buffer-file-name))
>                  "\\/")))))
>     (concat (nth 0 components) "." (nth 1 components) "." (nth 2
> components))))

[...]

Replace-match, by default, keeps the case of the match. So you need to
set the second argument of replace-match to false, like so:

  (replace-match package-name nil)

HTH
- -- tomás
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.12 (GNU/Linux)

iEYEARECAAYFAlcVOqEACgkQBcgs9XrR2kbrRwCeIm2/D77KAEKqQfsLFKMOExhM
3mIAmgNoXAAtkInK3XhDhm2dYT9NsGEM
=9oMa
-----END PGP SIGNATURE-----



reply via email to

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