How to change emacs config in Lisp In A Box - emacs

I have been a programmer for a decade now, but I believe this is the first time I've ever asked a question on a forum. I just can't figure this out and can't find the answer already online.
I am trying to turn on CUA mode so that emacs is more bearable for a windows user (normal copy paste functions). I am running Windows 7 and installed emacs through the Lisp In A Box package. I understand that I need to add a line to my .emacs file or init.el file. I'm not sure which, but I can't find either in my Lip In A Box install directory. The emacs package install also did not come with any tutorials or help files, so its really hard to pick this up.
I am stuck, any help is greatly appreciated!

The .emacs can be found by looking at the answers to this similar question.
Regarding documentation and tutorials, it looks like the link you provided for "Lisp in a Box" says:
If you are new to Emacs, it is
recommended that you read the Emacs
Tutorial which you can access from
with Emacs by going to the Help menu,
or by typing Control-h, letting go,
and hitting t. A more extensive manual
is also available from the Help menu,
or on the web at
http://www.gnu.org/software/emacs/manual/.
Which makes it sound like the manual is there, and certainly the tutorial (I made bold the directions to get to the tutorial).
As far as other places to get information, there is a collection of screencasts on the wiki.
Your question doesn't specify whether or not you what to add to your .emacs to activate CUA mode. You can check out the CUA mode documentation on the wiki (which has links to the manual). The minimal installation is just adding this to your .emacs: (cua-mode t).

For GNU/Emacs, you can choose to use any one of the following three file names as the start-up configuration file:
${HOME}/.emacs
${HOME}/.emacs.el
${HOME}/.emacs.d/init.el
It would probably be a good idea to decide on one of the three options and then stick to it - the first one seems to be the most widely used one. In any case, ${HOME} stands for your home directory -- which is likely to be different from the Lisp In A Box install directory!
Coming from a Unix tradition, Emacs understands ~ (tilde) as an abbreviation for your home directory, so you can visit the .emacs file by typing:
C-x C-f ~/.emacs [ENTER]
(Note that the capital C is Emacs standard notation for a combination of the CTRL key and a second key, i.e. here you press CTRL-x CTRL-f which stands for "find-file" and will then ask you for a file name in the bottom part of the Frame (aka mini-buffer).)
If these are your first customizations, you will just see an empty buffer. Enter
;; start CUA mode every time Emacs starts
(cua-mode t)
and save the buffer with C-x C-s.
Next time you start Emacs, CUA mode should be turned on automatically.

What the others have told you is true: Simply adding (cua-mode t) to your dotfile would be sufficient. HOWEVER: Lisp in a box' Emacs doesn't load this file by default.
Therefore, be sure to edit the shortcut so that it does load the dotfile. This is important, because otherwise you would get weird behavior, where you would add the correct line to the dotfile, start emacs, and then not get cua mode. That would suck.
The reason it does this is to ensure that it starts a vanilla emacs everytime, instead of finding, say C:/_emacs and loading that instead, giving you another user's customizations and confusing you.
The flag for not loading an init file is -q or --no-init-file. Also make sure that --no-site-file is not there.
(I realize that this is an old post, but I found this while looking for something related, and I don't want people walking away frustrated over something that doesn't work.)

Related

Every time I type a comment in emacs, tramp freezes it

Every time I type a comment in emacs, tramp freezes it.
it says:Tramp: waiting for prompts from remote shell
This happens for any file I open. It freezes for a minute whenever I type /, and repeats for all characters typed until whitespace.
I found a few other questions like this, but they all seemed to be asked by people who use tramp. I do not use tramp. Had it not been freezing emacs, I would not have known what it is.
Can anyone tell me how to make it stop?
.emacs
Does it happen in every file? Only for octave related files?
Have you tried with "emacs -Q"?. If you are free of the problem with "emacs -Q", then check with "emacs -q", if not, post your emacs version and OS.
If with "emacs -q" you are free of the problem, the problem is in your .emacs. Your .emacs is tiny, so a binary search of what is the offending part should be quick.
By default, auto-complete suggests file names when you type //, and this invokes tramp to get the file name list. To turn of this behaviour, make sure ac-source-filename is not in your ac-sources list. An easy way to do this globally is to edit your auto-complete-config.el to comment out the line
(add-hook 'auto-complete-mode-hook 'ac-common-setup)

Automatically opening a file in emacs by specifying the file name

I created a TAGS file for emacs in my django project using the following command on my Linux machine
ctags -eR *
I can now jump to a symbol definition using M-. and specifying the symbol name.In my project i have py,html and css files so is there also a way i can make emacs automatically open a file, if i specify the file name ?.
Thank You
I think you are looking for project management. There are few packages to manage project directory in emacs. The best one may be ede. but Its not easy to setup. It does have some learning curve and its limitations.
Thankfully there are many easy ones. like eproject. https://github.com/jrockway/eproject/wiki
anyway you can also check out emacswiki page for more details. http://www.emacswiki.org/ProjectSettings
http://www.emacswiki.org/emacs/find-file-in-tags.el
IDO (Interactive Do) mode does this. If you activate it, C-x C-f searches for files matching what you are typing, interactively. Beware though, it may take some time to get used to it.
[edit] The search is based on files or directories you've recently visited, and you can use M-s to force a search.
From the comments, I figured that you are looking for has nothing to do with tags, you just want a better find-file that makes good automatic guesses for the path given only the file name.
For this, I use the entirely awesome ido-mode: http://emacswiki.org/emacs/InteractivelyDoThings

Emacs inside of gedit?

After years of experimentation with editors, the fact is I prefer them as minimal as possible. I never use fancy features and the full-feature IDE's become bloated, heavy, and slow. Of course, when I do something that pretty much requires a specific IDE (like Android dev and Eclipse) I have no problems using it. But most of the time, I use gedit for programming.
However, I like many Emacs commands, and I want to use them occasionally. Is there a way to embed Emacs inside of gedit? For instance, I envision pressing alt-q (or whatever combo) and Emacs mode is enabled, and from then on all my key presses in the current tab do Emacs commands. I press alt-q again, and it turns off. This would allow me the best of both worlds. Anything like this exist, or do I need to write this plugin myself?
No.
I've seen discussion of embedding of Emacs in other applications in the past, and the consensus is that even that's not feasible, let alone what you're suggesting.
You'd be better off identifying what gedit does that makes you want to use it instead of Emacs, and extending Emacs to make it do that, too. (There can't be that much --- gedit doesn't do much.) The extra features can just sit there and wait for you, and you'll find it easier to locate and use them if you're comfortable in Emacs-mode already.
(On top of all the other advantages of Emacs, you gain the ability to use the same editor you use in a windowed environment on the terminal --- a huge advantage.)
Or maybe yes . . .
You can use the External Tools plugin of gedit (look for it in Preferences). Add a new command, bind it to the key you want, and use this script:
#!/bin/sh
FILE_NAME=$GEDIT_CURRENT_DOCUMENT_PATH
emacs $FILE_NAME
If you want it to open in the currently-running Emacs, replace emacs with emacsclient, and add the following to your .emacs:
(server-start)
This is kind of backward. Why don't you just use Emacs and stay away from all the extra bells and whistles? It'd probably be easier to coax emacs to emulate gedit than the other way around.
If gedit (a) can be scripted to launch another application with the current file as an argument, and (b) will notice if the file is modified on disk and offer to reload it, then you would have a workaround.

Change the initial directory on emacs, and also some tips for a starter

How can I change the initial directory on emacs? I started using it today and there are a lot of things to learn!
Right now I'm using M-X cd and then I change the directory that I use for C-x C-f, but in a daily work I'm going to heavily use one particular directory so I need to make the change permanent.
Also if you have some tips for a starter it will be nice.
To set a default directory, simply put
(cd "/default/path/")
in your ~/.emacs file.
Emacs has a steep learning curve, but with constant use the most common commands will soon become second nature. As you discover more, emacs may become your favorite text editor, file manager, and email reader :)
To learn emacs, I'd start by pressing C-h t to start plowing through the excellent tutorial. Have a pad of paper beside you and write down the commands as you learn them. You'll use the crib sheet at first, but after a while, as I mentioned before, your fingers will learn the key combinations without your brain conciously intervening.
Good luck and have fun!
Default directory is determined by:
(setq default-directory "~/")
in this case, set to the users home dir, but it could be somewhere else.
If this variable is not set, the initial load point for find-file will be the directory where the emacs executable lives.
EDIT: on windows, a global HOME environment variable can be defined (HOME=c:\path\to\user\home\directory), ensuring that Emacs translates ~ to the correct value. This makes the Emacs settings usable across platforms.
Start up emacs only after changing to that "initial directory", effectively setting the current directory for emacs.
This is a solution specific to Windows.
Create a shortcut to emacs.exe" called GNU Emacs
Open Properties on the GNU Emacs shortcut
Set Start in to %USERPROFILE%\Documents
This solution works for multi-user workstations whether they are on or off Active Directory.
This shortcut will start Emacs in the current user's Documents folder.
Print out the Gnu Emacs Reference card and keep it by the desk.

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.