Emacs - Clojure function highlighting (i.e. map, reduce, println, get, etc.) - emacs

I am currently using emacs24 with clojure-mode as my clojure IDE. I use the zenburn theme.
As far as I can tell, clojure-mode only provides syntax-highlighting for macros. Is there a way to add syntax highlighting for all clojure native functions?
I've googled a bit and it seems like I'm either the only one who wants this, or the only one that doesn't have it for some strange reason. I don't think my .emacs file is a necessary addition to this question but I'll add it if someone wants to take a look.
Thank you.

You need to explicitly enable font locking for these functions with clojure-mode-extra-font-locking. Install this package from MELPA, and add the following to your init.el:
(eval-after-load 'clojure-mode '(require 'clojure-mode-extra-font-locking))

Related

Syntax highlighting mode for SLIME in emacs

How do I enable the syntax highlighting mode for SLIME in emacs?
I guess that by SLIME you mean the SLIME REPL. It uses repl major mode and you cannot just enable font-locking for it, since there is one enabled already and it's simply different from that in lisp-mode and clojure-mode for instance. Your best bet might be to play around with the font-lock faces for repl-mode. This article might prove helpful.

Emacs ECB Alternative

I've been using Emacs as a PHP IDE for quite some time now (with emacs-starter-kit, ECB, & Geben). With each new release for emacs-starter-kit or Emacs 24, ECB introduces new errors & window issues. It doesn't seem well-maintained anymore (last release was 2009).
Wondering if there's a project-manager / IDE emacs plugin that's today's defacto? Something that does file-browsing (like sr-speedbar), method list, possibly even auto ctags?
The answer is that unfortunately no such thing exists. emacs-nav offer a file browser similar to the one in ECB and you can use something like helm to jump to various stuff in your project (like files, tags, imenu entries, etc). Small utils like projectile might also be helpful to you.
All in all using heavyweight tools like ECB is not the Emacs way and I guess this is the reason while its development has stagnated - few Emacs users would use a tool like that given there a smaller more flexible alternatives.
I'm use sr-speedbar to file browser
http://emacswiki.org/emacs/SrSpeedbar
I'm using ecb on emacs-24 with no problems. the only thing I had to add to my .emacs was:
(setq stack-trace-on-error t)
it prevents from throwing errors on ecb startup. What kind of window issues do you experience?

Ocaml - Emacs tuareg mode

I just started to use the tuareg mode in emacs for ocaml programming. So can someone tell me what are the main advantages of using it? Can someone suggest me any tutorial for that?
Tuareg-mode is good because it can parse code and calculate indentation & font-lock basing on this information. Plus it provides pretty good possibilities to interactive work with code.
Regarding tutorial - I don't think that such exists (although I planned to write it long time ago). All information for installation is in README file, and you can learn about available commands by visiting file with OCaml source code, and pressing C-h m to get description of mode, or by getting description of tuareg-mode function (if tuareg.el is loaded already).
Useful addition to these descriptions is Tuareg mode refcard that lists all (or almost) available commands.
Tuareg is really nice for:
Highlighting your code
Indenting your code correctly
Easily sending portions of code to a REPL
Easily compiling your code
Syntax highlight, indentation, as (almost) all language modes.
Compile or evaluate in a top level from a single buffer (you no longer need to open a ocaml toplevel in a command line to test some crap functions)
Caml-types minor mode : after a successful or partial compilation, you can easily point a variable and get the type the compiler inferred for it.

How to do automatic expansion or autocomplete of functions and variables in a Clojure repl

Is there a way to expand the current command at the Clojure repl like I'd be able to do in Common Lisp?
For example say I have typed:
Math/
I would like the tab key to expand to all the available variables and functions in that namespace.
I'm using Clojure as inferior-lisp would like to know how to do this from the plain vanilla repl in Clojure, and through swank slime.
Another vote in favour of clojure-mode and slime under Emacs. In particular, if you set up auto-complete, then you can use my ac-slime package to get context-aware tab completion in a dropdown list. Here's a screencast showing it in action.
And, further to technomancy's comment about hippie-expand, here's how to tie slime completion into hippie-expand.
Update: as of 2012, nrepl, nrepl.el and ac-nrepl are replacing slime and ac-slime; same functionality, smaller and cleaner codebase.
Update2: as of Oct 2013 nrepl.el is renamed to cider and it and ac-nrepl have moved to the clojure-emacs organisation on github. nrepl remains as the server component
Have you tried Clojure mode for Emacs? It has autocomplete (suggestions are shown in new window, and if there's only one possible option, it is used to expand name), highlighting and many other nice features (not more then for CL, but not less too).
It is available via ELPA. After installing ELPA type M-x package-list-packages, set cursor near needed package and press i (already installed packages are in red). You'll need packages clojure-mode, slime, slime-repl and swank-clojure. When you're done with i-marks, press x to complete installation. Finally, press M-x slime - Emacs will tell, that Clojure is not installed and propose to download and use latest version. Just agree.
You can also integrate Emacs with Leiningen.
The vanilla repl in Clojure is pretty crippled; it doesn't even have history. Avoid it for anything but the most primitive of tasks. I don't think you can get this in inferior-lisp, but in the slime repl you can just use TAB to complete things like this. In clojure-mode buffers with slime activated it's M-TAB, or you can tie it into your hippie-expand functions.

How to quickly get started at using and learning Emacs [closed]

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 10 years ago.
Improve this question
There are all sorts of advantages to using Emacs, but for someone comfortable with the usual Win32 applications it comes with a wall-like learning curve. With most other editors it’s possible to just start using them and then learn about their other features and enhancements as you go along.
How to just get on with using Emacs straight away, with the aim of reaching that point where you actually prefer to use Emacs over other editors or applications?
Edit - To try and clarify the question: I’ve done the tutorial, read some docs, etc. then soon after when I’ve wanted to quickly edit some text it’s been easier to just use another editor, that I already know. What do I need to do so that not only I don’t just go for another easier editor, but that I actually prefer to use Emacs, and how to get here as quickly as possible? What if any are the training wheels for Emacs?
The biggest thing about learning how to use Emacs is ... (drumroll please) learning how to use Emacs.
Okay, okay, okay. It's a silly answer, and it's a tautology, but it's true. If you start up Emacs, and think to yourself "How could I find every instance of the word 'foobar' in my source tree?" the worst thing you could do is hit Alt + Tab and visit Google.
Seriously.
Learning the help system and how it works is the best thing you can do. It's so nice to just hit C-h a find, and suddenly get all the information you need, right at your fingertips.
The next best thing you could do is install a wonderful little package called Icicles which has some seriously groovy completion functions. After you get it installed, just know that anytime the minibuffer is asking for some kind of input, you can now use regular expressions.
How would this apply to finding every file in your source tree? Well, you'd hit M-x, and then type "find". After that, you could hit (for instance) Shift + Tab and Icicles would kick in, finding every command that prefixes with "find". Alternatively, you could do M-x .find. and it would give you any command with find in it.
Build a cheat sheet. Just keep a saved buffer somewhere that has all of the keyboard shortcuts you use frequently in it. Remove the ones that you know off by heart, and pick up new ones. In most cases when you do a M-x command, the message buffer will tell you what the keyboard shortcut was for that command (if there was one).
Learn. Keyboard. Macros.
Learn. Emacs. Lisp.
Steven Huwig's idea of using some killer applications is a good one. Emacs is easier to use when you want to use it. For me, it was Planner Mode. (I've just moved to Org-mode, and it's even better.)
spend 20 minutes running the tutorial
ctrl-h t
That will get you to the point where you can be productive (and that "meta" key that you will read about is probably either Escape or alt).
I think it is easiest to find a "killer app" or two that just works best in Emacs. For me, it was the SQL editing and interaction mode for Oracle. Once you're already using Emacs for this killer app, then it will be more attractive to just open up other documents in Emacs rather than another editor.
Potential killer apps:
SQL editing and interaction modes
nxml-mode
AUCTeX
CPerl mode (best Perl mode there is)
PCL-CVS
SLIME
js2-mode (Javascript)
Learning to use Emacs effectively is inherently a slow process, but it's worth it.
Set up a .emacs file right away. You'll want to customize it quite a bit. It sounds silly, but having some kind of source control on that file will help, too.
To make it easier to find out about Emacs' innards, add to your .emacs:
(defalias 'ap 'apropos)
Then when you want to see if there's a command to do "something", type "[Alt-x] ap [enter] something [enter]". Emacs has its own name for stuff, so it can be hard to find things sometimes ("yank"? Seriously? Call it "cut" like everyone else!)
"[Ctrl-h f] function-name [enter]" looks up the help for that function.
"[Ctrl-h m]" shows you details about the current mode, like the keybindings specific to that mode.
Learn to use Ctrl-s and Ctrl-r for incremental search. All text editors need to come with this feature.
Add keybindings to your .emacs like:
(define-key global-map (kbd "M-z") 'redo)
(define-key global-map (kbd "C-z") 'undo)
Get the redo.el package to make Emacs' redo suck less.
iswitchb-mode is invaluable. It lets you have dozens of buffers open at once and switch between them in a blink of an eye. Set up iswitchb and add to your .emacs:
(iswitchb-mode)
(define-key global-map (kbd "M-RET") 'iswitchb-buffer)
To evaluate an emacs-lisp expression, type the expression into a buffer, put the cursor just after it, and type "[Ctrl-x Ctrl-e]". This lets you experiment with different customizations easily.
Remember, you don't have to let go of ctrl when typing a sequence like that.
See where a string occurs in a buffer with the "occur" function. Here are some handy functions and keybindings for that:
(defun word-at-point ()
(thing-at-point 'word)
)
(defun word-at-point-or-selection ()
(if mark-active
(regexp-quote (buffer-substring (mark) (point)))
(concat "\\")
)
)
(defun find-word-at-point ()
(interactive)
(occur (word-at-point-or-selection))
)
(define-key global-map (kbd "C-o") 'find-word-at-point)
(define-key isearch-mode-map (kbd "C-o")
(lambda ()
(interactive)
(let ((case-fold-search isearch-case-fold-search))
(occur (if isearch-regexp isearch-string
(regexp-quote isearch-string))))))
My ideas on how to come up to speed faster:
Find another Emacs user and watch them a few minutes every day
Have the Emacs user watch you (and provide feedback)
Find more Emacs users and repeat steps 1&2
Subscribe to the planet emacsen feed to see what other Emacs folks are learning
Follow the emacs tip of the day twitter
Try to answer folks Emacs questions on SO
I've been using Emacs for 15+ years and I learn a new thing every day by doing the things above.
Like #Claudiu said, just use it. Just bumble through and let your needs drive your learning curve.
Eventually you will get to a point where you "know enough to be dangerous", while not really mastering the environment. That's OK. Because at this point you'll likely be quite productive. You'll have the basic skills and tools.
In time, you'll run in to things that you do every day that you're simply sick enough of to try and take the time to find a "better way". Normally, your base skill set is enough to get by, enough that the (potentially unknown) time invested in to some alternate path isn't worth the cost, especially for something rare.
But, you may have free time, or the task might be big enough to justify looking deeper.
At these points you'll become more of an expert Emacs person than a journeyman user.
While I personally no longer use Emacs (instead relying on an IDE), I will say that while Emacs is quite complex, you need only know a small subset to make it useful and fun. I will also say that I've never "screamed at Emacs", whereas I scream at my IDE all the time. Yes, Emacs was doing less than what my IDE was doing, but I am seriously getting to the point that it might be worth my time to go back to it, and stop the screaming.
I just get this sense that Emacs is more "deterministic" than my IDE which likes to go traipsing off in to lala land every now and then, or require a restart, or whatever.
I've never personally crashed Emacs (which some will say means I'm not using it hard enough...)
Basic text editing with emacs is no more complicated than doing the same with Notepad. Just use it like it's notepad, but as you explore the menus, take note of the keyboard shortucts. Slowly you'll start to pick up things. When you want to do something and you don't know how, there's help available as a pulldown from menus, just like with other editors.
I guess the only "trick" I'd suggest is that after you open up a file for editing, try ctrl-h m to pull up a list of the keyboard bindings that work in that buffer's mode.
My advice is:
Learn the very basics (how to type, save a document, turn on syntax highlighting, maybe copy and paste). You can look up how to do these online (google "emacs tutorial" maybe)
Start using it.
Whenever you wish you knew how to do something, then look up how to do it. You might have to look the same thing up 3-4 times before you get it, but then you will learn it.
Keep doing this. It'll be annoying at first, but then you'll get used to it, and then you might even enjoy using it!
(DISCLAIMER: Personally I just use another editor).
Turn on icomplete-mode and you will often see functions that look useful when poking around.
(icomplete-mode t)
In your .emacs file.
C-h f will let you look up the docstring for a function, and C-h v will do the same for a variable. With icomplete, this is great for exploring.
As you learn basics like key commands, make your own cheat sheet. Of course find and plunder existing cheat sheets, but be sure to make your own and categorise the shortcuts / key bindings to groups that make sense to you. This will help you learn the basics and retain the memory.
Aim to customize Emacs into the editor you want, this is the single biggest advantage to using Emacs, and it will help you learn about all it's features and how it's extended.
Be glad that, relatively speaking, learning Emacs is much easier thanks to the community here on SO and other places like EmacsWiki. :)
Work from this point onward... a) Key bindings and customize. b) Macros and the macro editor. c) Elisp and your own custom libraries.
It's also worth noting that setting Emacs up to work like a more modern App, can be painful, you will need to do things like run the emacs server, and use the emacs client.
Thankfully (re: 3) there is a lot of help available on the net, but if you have direct access to a seasoned Emacs user, consider yourself lucky.