Share your knowledge at the LQ Wiki.
Go Back > Forums > Linux Forums > Linux - Software
User Name
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.


  Search this Thread
Old 10-24-2004, 08:36 PM   #1
LQ Newbie
Registered: Oct 2004
Posts: 6

Rep: Reputation: 0
Lisp/Emacs: How to do a macro on a buffer-name with another extension

Hi! :-)

I am learning to use emacs, and really like it!

I edit latex texts, and I programmed a macro to make "pdflatex" quickly; this are the lines in my .emacs:

(defun pdflatex () 
  "Run <pdflatex> on the current buffer's file." 
     (let ((cb (current-buffer))) 
        (set-buffer (get-buffer-create "*TEMP*")) 
        (call-process "pdflatex" nil t nil (buffer-file-name cb) ) 
(global-set-key [(meta p)] 'pdflatex)
(in fact, I copied it from a tutorial and simply made some minor and necessary changes).

My problem now is this: I would like to do a macro that runs "acrobat reader", but on a file whose name is the same of the buffer-name, but with another extension (".pdf"). I hope I made myself clear...

Thank you! :-)
Old 10-24-2004, 09:53 PM   #2
Senior Member
Registered: Jun 2004
Posts: 2,553

Rep: Reputation: 53
i think i know what you mean
to return current buffername + ".pdf"

(concat (buffer-file-name (current-buffer)) ".pdf" )

i think that will work

when you need to see what an expression will be like this one
will get you an eval: prompt
then just middle click the expression in there and hit return
and it will tell you what it sees the expression as

you like using emacs LISP how cool -- bookmark this
Old 10-24-2004, 10:05 PM   #3
LQ Newbie
Registered: Oct 2004
Posts: 6

Original Poster
Rep: Reputation: 0
Thank you very much for your reply!

I wasn't clear enough: I need the ".pdf" extension, but without the ".tex" extension of the file name. I mean, the buffer's name is: "foo.tex", so I want to get "foo.pdf". If I use your advice, I get "foo.tex.pdf".
Old 10-25-2004, 09:26 PM   #4
LQ Newbie
Registered: Oct 2004
Posts: 6

Original Poster
Rep: Reputation: 0

Finally, I found a solution (at least, it works for me... )

I use the function "substring":

(call-process "/usr/local/Acrobat5/bin/acroread" nil t nil (concat (substring (buffer-file-name cb) 0 -4) ".pdf" ))
It works because the files I want to apply this macro always end with ".tex"


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Learning Lisp helpful for using Emacs? dr_zayus69 Programming 1 06-15-2005 12:44 PM
Syntax Highlighting in Emacs with Lisp question 95se Programming 2 02-25-2005 09:04 PM
emacs and lisp jonathanz1980 Linux - Software 4 09-24-2004 10:00 AM
emacs and lisp jonathanz1980 Programming 4 09-24-2004 09:30 AM
Lisp, emacs-lisp aizkorri Programming 1 09-04-2002 06:16 PM > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 02:08 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration