LinuxQuestions.org
Latest LQ Deal: Linux Power User Bundle
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 03-01-2013, 04:24 PM   #1
stateless
Member
 
Registered: Jan 2013
Distribution: Debian
Posts: 166
Blog Entries: 1

Rep: Reputation: 4
emacs lisp: define function to be used inside emacs


Hi. I'm going to be reading through the whole Emacs lisp manual, but I already know a bit of common lisp, and was hoping to get enough "working knowledge" quickly to play around with making functions I can call and use within Emacs. For example, how would I define a function which would allow me to enter

Code:
M-x negate <RET> -2 <RET>
and see "2" displayed in the minibuffer.
 
Old 03-01-2013, 06:04 PM   #2
ntubski
Senior Member
 
Registered: Nov 2005
Distribution: Debian, Arch
Posts: 3,387

Rep: Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553
You could start with a non-interactive version of the function, which will look the same as the Common Lisp version:
Code:
(defun negate (n)
  (- n)) ; put the point (cursor) on the definition and hit C-M-x
         ; (Ctrl+Alt+X) to define the function

(negate -2) ; C-M-x here to test it
Then make it interactive by using the interactive form, and using the message function instead of returning the value:
Code:
(defun negate (n)
  (interactive "NEnter a number: ")
  (message "%d" (- n)))
 
1 members found this post helpful.
  


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
emacs + auctex - opening output PDF inside emacs buffer coenvh Linux - Newbie 1 04-29-2010 06:52 AM
Emacs LISP - function and keymap? jantman Programming 5 09-28-2006 12:59 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

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 07:55 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration