Emacs hide/show (hs-minor-mode) for imports/includes - eclipse

hs-minor-mode in Emacs makes it possible to hide the cumbersome initial comment block so that one can get quickly to the code.
Is there a way to duplicate in Emacs what Eclipse (and other) IDEs do to the initial import blocks? A solution that works for C++ includes as well as for Java imports would be nice.

Have a look at the various folding modes and HideShow mode in Emacs. The original Emacs folding-mode has the downside that it requires you to add some additional markers to the code, which I find cumbersome and they don't really help with readability IMHO.
CEDET has a semantic folding mode that will probably be able to do what you want (I haven't looked at it for a while but CEDET/semantic is pretty good at this sort of functionality).

Related

Is there an emacs game for practicing cursor control?

So I was wondering if there's a game out there that lets me practice my emacs cursor skills. I just started using emacs and thought that a game letting me control the player with the standard emacs bindings would be an awesome way to get going. When searching for one I stumbled upon this for VIM.
Does anyone know of something similar for emacs?
This is not a game, but I'd suggest installing hardcore-mode (available on Melpa too), and configure it to your liking (here's my configuration if interested). That package when enabled globally will force you to not use the arrow keys and use the C-f, C-b, C-n, C-p bindings instead. So much so that now using those bindings has become a second nature to me.
PS: There's an emacs-dedicated stackexchange site in case you didn't know.
One idea: Have a game mode that shows two buffers, and the goal is to transform the first into the second buffer with the least amount of keystrokes.

What is the correct way to show menu / help screens in Emacs?

When using tools like Org-mode and Magit the mode will sometimes show help menus. For instance, org-mode export will show a nice menu that accept single keys and then executes some command. In Magit, when looking at the status view it will accept tabs to expand the staged and commit areas.
These areas, for both Git and Org, are nicely placed to take up some portion of the emacs frame that is mostly convenient. How does emacs do choose this?
Additionally, these views are read-only, up until the user presses tab in the case of Magit and the status view. Is there a best practice when creating these views which control editing, but allows the mode to edit the file and present alternative text?
Perhaps the answer is take a look at these function A, B, and C. Which is fine, I'm just learning and experimenting on my own.
Magit in particular is not the simplest introduction to popup buffers in Emacs, but it certainly is sophisticated and a good read. Find magit-popup.el on your machine, for example M-x find-function RET magit-popup-mode-setup. To me, that function looks like a good candidate to start reading that file. You can see the macro magit-define-popup in use for example in magit-push-popup in the file magit-remote.el
In the end, it boils down to opening a new buffer in a new window and give it a dedicated major mode which has all the key-bindings.
Another good candidate is the family of temp-buffer-* functions.
Hope, that gives some pointers to start reading.
An easy way to show menus/help screens à la Magit and org-mode is with Hydras:
http://wikemacs.org/wiki/Discoverability#Hydra
https://github.com/abo-abo/hydra/
https://github.com/abo-abo/hydra/wiki
It's a short elisp method to write and it will give you a menu like org-mode. For example:
(defhydra hydra-zoom (global-map "<f2>")
"zoom"
("g" text-scale-increase "in")
("l" text-scale-decrease "out"))
ps: it's not what org-mode and magit use. Magit's system wasn't re-usable until recently and I don't know how it compares with Hydra. A nice feature of Hydras is that you can tell it to not disappear after a keypress, so than you can press many keys in a row.

Emacs Live linum-mode messed up when switching buffers

I am using Emacs Live (https://github.com/overtone/emacs-live) and I have global linum-mode enabled. However when I switch from a buffer to another, and then back to the original buffer, the line numbers are all messed up like so. Thanks.
Before digging further into it, you may want to try out nlinum-mode (available from GNU ELPA), which provides similar functionality, but using an implementation technique that tends to be more reliable.

Racket Emacs mode for mimicking Scribble or HTDP sample code examples?

I really like the syntax highlighting and coloring of the code samples throughout How to Design Programs. For example:
http://www.htdp.org/2003-09-26/Book/curriculum-Z-H-9.html#node_sec_6.5
Does anyone have something like this as a jumping off point for an Emacs major mode for editing source code?
Neil Van Dyke created an Emacs major mode for editing Scribble documents. It doesn't color the source code, unfortunately. But it's the best way to edit documents with embedded Racket code in Emacs.
In the realm of non-Emacs editors, DrRacket does highlight both code and text correctly in Scribble documents.
Is it possible you're looking for a Emacs major mode with source highlighting support? If you are, take a look at http://docs.racket-lang.org/guide/Emacs.html, which describes several of the Emacs major modes that support Racket and come with source highlighting.

Mac OS X Emacs Does Not Highlight Comments Correctly

I'm pretty old school sometimes and I like working with Emacs in my terminal. (I work with IDEs all the time. But sometimes, when in the privacy of my own home, I just like a text editor a terminal and a beer)
However, the default Emacs that comes with OS X does not seem to highlight the comments in font-lock-mode. I've seen this behavior in both Python and C mode.
I've already searched some forums and I found one post where the person was having the same problem as me:
http://forums.macosxhints.com/showthread.php?p=512361
Is is there any way to fix this problem?
I had this exact same problem. The solution is to change the color used for the comment face as follows:
(set-face-foreground 'font-lock-comment-face "red")
Or, if you only want to do this for certain modes:
;;; Only do this for the common C mode (C, C++, Objective-C)
(add-hook 'c-mode-common-hook #'(lambda () (set-face-foreground 'font-lock-comment-face "red")))
For more information on faces, see http://www.gnu.org/software/emacs/manual/html_node/emacs/Faces.html.
I'm not sure exactly how to fix it, but I'm fairly certain there's something you can put in the .emacs file. In fact, I think I've done that before. I'll look for my file and let you know what I can find.
I'll try and get you my .emacs file when I get home from work tonight.
[edit] I've looked and looked, and can't find a .emacs file on either system that I use, and on my OS X install (Leopard default), it looks like it does it correctly by default. I did some research here, and it looks like the default installations no longer use .emacs files, because there's folks like me that mess around with them and break things, and they got tired of having to help us fix it. But, there is a set of menus that will let you tweak things. Start by typing "M-x customize RET", where M is the meta character (on my OSX install, this is the esc key. Don't hold it down, just type it like a regular character. That'll get you into a menu of stuff you can change. I didn't poke around too much, so I'm not sure where in the menu you'll find what you're looking for. Sorry I couldn't be more help.
In my experience this is usually related to a unpaired quote (single-, double-, or otherwise) somewhere in an existing comment.
Hunt those occurences down and eradicate them in your source code (or if you are more ambitious, see if you can update the fontlock code in your major modes' emacs source code)
When I have encountered this in editting Perl in emacs, I often switch major modes to cperl-mode as it typically handles parsing the perl better than the default perl-mode.