From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Newsgroups: gmane.emacs.help Subject: Re: Emacs lisp question Date: Mon, 18 Apr 2016 21:50:57 +0200 Message-ID: <20160418195057.GA24139@tuxteam.de> References: NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; x-action=pgp-signed Content-Transfer-Encoding: 8bit X-Trace: ger.gmane.org 1461009093 7817 80.91.229.3 (18 Apr 2016 19:51:33 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Mon, 18 Apr 2016 19:51:33 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Mon Apr 18 21:51:29 2016 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1asFCi-0003SX-Ox for geh-help-gnu-emacs@m.gmane.org; Mon, 18 Apr 2016 21:51:28 +0200 Original-Received: from localhost ([::1]:44475 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1asFCe-0005hg-UX for geh-help-gnu-emacs@m.gmane.org; Mon, 18 Apr 2016 15:51:24 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:52718) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1asFCS-0005es-P6 for help-gnu-emacs@gnu.org; Mon, 18 Apr 2016 15:51:13 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1asFCN-00026z-Q6 for help-gnu-emacs@gnu.org; Mon, 18 Apr 2016 15:51:12 -0400 Original-Received: from mail.tuxteam.de ([5.199.139.25]:38563 helo=tomasium.tuxteam.de) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1asFCN-00023Q-KL for help-gnu-emacs@gnu.org; Mon, 18 Apr 2016 15:51:07 -0400 Original-Received: from tomas by tomasium.tuxteam.de with local (Exim 4.80) (envelope-from ) id 1asFCE-0006L1-0H for help-gnu-emacs@gnu.org; Mon, 18 Apr 2016 21:50:58 +0200 In-Reply-To: User-Agent: Mutt/1.5.21 (2010-09-15) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 5.199.139.25 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Original-Sender: "help-gnu-emacs" Xref: news.gmane.org gmane.emacs.help:109791 Archived-At: -----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-----