LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices



Reply
 
Search this Thread
Old 09-28-2006, 01:47 AM   #1
jantman
Member
 
Registered: Nov 2005
Location: New Jersey, USA
Distribution: SuSE
Posts: 492

Rep: Reputation: 31
Emacs LISP - function and keymap?


I'm relatively new to Emacs and LISP. I was wondering if someone could give me a hand with some LISP:

I want a function mapped to F11.

The purpose of the function will be to open a new window in shell mode and type a string at the prompt but not execute it.

Also, how would I go about accessing the name of a buffer open in a certain frame (not this frame)?

The end result that I want is:
if there are 2 frames open, switch to the other frame. If not, make a new vertical frame. Start shell mode, and:

F10) if the active buffer in the first frame is <filename>.java, run javac <filename>.java.

F11) if the active buffer in the first frame is named as above, run java <filename> (without the extension)

I can handle the small stuff, but I'm a bit overwhelmed with LISP. If someone could give me a good direction to start, and some general comments on how this is done, it would be appreciated.

Thanks,
Jason
 
Old 09-28-2006, 10:00 AM   #2
indienick
Senior Member
 
Registered: Dec 2005
Location: London, ON, Canada
Distribution: Arch, Ubuntu, Slackware, OpenBSD, FreeBSD
Posts: 1,853

Rep: Reputation: 65
If you're relatively new to Emacs <i>AND</i> Lisp, I would suggest reading through any Emacs and Emacs Lisp manuals. I'm learning Lisp, and from what I understand, Emacs Lisp is just a pared down implementation of Lisp or Common Lisp.
I apologize, because I haven't yet learned how to work with key-bindings in Common Lisp, so I'm no help to you there, but here are some links that may provide:
http://www.gnu.org/software/emacs/emacs-lisp-intro/
http://en.wikipedia.org/wiki/Emacs_Lisp
 
Old 09-28-2006, 10:32 AM   #3
m0rg
Member
 
Registered: Jun 2003
Location: France
Distribution: slackware 11.0
Posts: 80

Rep: Reputation: 15
As indienick says emacs lisp is just common-lisp with a lot of function added for emacs (buffer, text processing etc etc).

You can define a keymap like this:

Code:
;;Here we define Ctrl-C-C as a shortcut for the compile command
(define-key global-map "\C-cc" 'compile)
Since this is just lisp I guess you can start from this and define the keymap you need, for example if you want to remap Ctrl-Z key to print hello world into the current buffer, I think this should do the job:

Code:
(defun hello()
  (insert-string "HELLO WORLD"))

(define-key global-map "F11" 'hello)
Hope this helps...

Note: I haven't tested the code and most of the time I'm just writing regular common lisp, you should really read some manuals concerning emacs and e-lisp to do what you need.
 
Old 09-28-2006, 10:49 AM   #4
indienick
Senior Member
 
Registered: Dec 2005
Location: London, ON, Canada
Distribution: Arch, Ubuntu, Slackware, OpenBSD, FreeBSD
Posts: 1,853

Rep: Reputation: 65
Well, I guess I now know how to bind keys to functions/commands.

hee hee.

thanks m0rg. I love how easy Lisp makes everything.
 
Old 09-28-2006, 11:14 AM   #5
jantman
Member
 
Registered: Nov 2005
Location: New Jersey, USA
Distribution: SuSE
Posts: 492

Original Poster
Rep: Reputation: 31
Thanks. I figured out the keymapping later last night, but I'll use that function as a starting place.

How do I add multiple lines to the function?

For the text parsing, I'll look through some of the tutorials online.
 
Old 09-28-2006, 12:59 PM   #6
ntubski
Senior Member
 
Registered: Nov 2005
Distribution: Debian
Posts: 2,542

Rep: Reputation: 879Reputation: 879Reputation: 879Reputation: 879Reputation: 879Reputation: 879Reputation: 879
Quote:
Originally Posted by jantman
How do I add multiple lines to the function?
Whitespace like newline is not significant in lisp, so for instance the hello function m0rg needs to be interactive if you want to bind it:
Code:
(defun hello()
  (interactive)
  (insert-string "HELLO WORLD"))
;or put it all on 1 line
(defun hello() (interactive) (insert-string "HELLO WORLD"))
btw, it should be [f11], or (kbd "<f11>") instead of "F11"
 
  


Reply


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 01:44 PM
Lisp/Emacs: How to do a macro on a buffer-name with another extension LuisG Linux - Software 3 10-25-2004 10:26 PM
emacs and lisp jonathanz1980 Linux - Software 4 09-24-2004 11:00 AM
emacs and lisp jonathanz1980 Programming 4 09-24-2004 10:30 AM
Lisp, emacs-lisp aizkorri Programming 1 09-04-2002 07:16 PM


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

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