In Emacs, how do I figure out which package is loading tramp? - emacs

I have a strange interaction with tramp and cygwin-mount (I think: Emacs: Tab completion of file name appends an extra i:\cygwin). Because of this, I want to disable tramp. I'm unable to find anything in my .emacs which is loading tramp explicitly. I can see "Loading tramp..." when I hit a tab in the find-file minibuffer. I'd like to figure out what package is causing the loading of tramp and disable that. How do I go about doing this? I tried searching for (require 'tramp) but couldn't find anything interesting. The only other option I can think of is to comment out bits of my .emacs one-by-one and see which one works - but this is so brute-force, I'd like a cleverer (and easier) way.

What a great question! If only because I was not aware of the function (eval-after-load file form) which will enable you to write code like the following and put it in your .emacs file:
(eval-after-load "tramp"
'(debug))
Which will, in brute force form, vomit a backtrace in your window and reveal the offending library.

I think you'll find that tramp is turned on by default. If you do:
M-x customize-apropos
Customize (regexp): tramp
('Customize (regexp):' is the prompt from emacs) you'll see two variables listed (at least I do in emacs 23), something like:
If you set tramp-mode to 'off', save for future sessions, and restart emacs tramp should no longer be loaded. I believe you can just turning it off in the current session should allow you to test this, but this doesn't always work with customize variables, although it should do with something like tramp that is part of the standard emacs distribution.
I don't have emacs 22 installed any more, but something similar should work for that too.

I had a similar problem with tramp, when one day I found
"/C:\...\debuglog.txt" on my system.
Because of that file, auto-complete was invoking tramp each time
I entered "/". And tramp was of course giving an error.
auto-complete was calling
(expand-file-name ...)
which, because of the current file-name-handler-alist, was calling tramp.
My solution was:
(delete-if
(lambda (x)
(or (eq (cdr x) 'tramp-completion-file-name-handler)
(eq (cdr x) 'tramp-file-name-handler)))
file-name-handler-alist)

Instrument find-file for debugging and/or instrument your init file for debugging. Then you can step through the loading and see where the tramp stuff is loaded.

Related

ac-auto-start (auto-complete mode) would not get set no matter what

I'm facing a very bizarre behaviour. No matter how I set ac-auto-start, be it through customization, by evaluating (setq ac-auto-start 2), (setq-default ac-auto-start 2) or (setq-local ac-auto-start 2) immediately after I do it, the variable is set to nil.
I've looked through the source of auto-complete mode and the ac-slime in my case, but none of these does nothing to this variable. I am at a loss as to how to deal with this.
The effective consequences of this malfunction is that completion combobox doesn't appear on its own, unless I force it to by doing M-x auto-complete. This behaviour is consistent in all modes where auto-complete minor mode is enabled.
EDIT
This seems to be an issue with latest Emacs. Now it fails to modify variables values, no matter what variable it is. So, say, after running it with -Q I've now discovered that I can't evaluate the code that uses (setq ...) forms as it has no effect. :/ So, please, hold on, I'll try to investigate this...
This was due to the typo, but the original problem is still there.
Emacs version is 24.3.50.1 pulled from trunk about a week ago.
auto-complete is version 1.4 installed from MELPA.
I'm setting the variable by moving the point to the REPL buffer, then M-:. I check its value in the same way.
EDIT2
OK, I finally found the reason: I had enzyme package installed, and it had an earlier version of auto-complete inside of it, for some reason parts of the auto-complete code were loaded from there and other parts from the one installed from MELPA. After disabling enzyme it all works well now.
EDIT3
This still happens after I run (auto-complete-mode 1) in the REPL buffer. The variable will become impossible to set. I've searched through various autocomplete timers that may be setting something, but no luck so far.
There is indeed something strange going on with the setting of auto-complete-mode.
(I'm using the ELPA version in a GNU Emacs 24.3.1)
This is set up by customize-group RET auto-complete :
'(ac-auto-show-menu t)
'(ac-auto-start t)
At this point if you M-x auto-complete-mode you get a [no match] right in the minibuffer. Only after you try to M-x auto-complete, yelding a "auto-complete-mode is not enabled" weird error, will you be able to M-x auto-complete-mode (but without command completion... Hm) and then be in the mode.
If you put this in your init file (.emacs)
(require 'auto-complete)
(auto-complete-mode t)
It will be effective only if you re-eval it after startup (?!?).
The same with something like
(if (auto-complete)
(auto-complete-mode t))
The only way that I found to get auto-complete-mode to load at startup is to :
(eval-and-compile
(require 'auto-complete nil 'noerror))
(The above customize options are now effective)

emacs command-t behavior

I'm a total emacs newbie. I watched a video which shows ido in emacs working similar to command-t in textmate:
(video is: http://vimeo.com/1013263)
The issue is I don't get this behavior when I'm in emacs with ido mode. Here is my init.el:
(require 'ido)
(ido-mode t)
(setq ido-enable-flex-matching t)
I have no idea what t means, this is just what I found online.
When I search for a file (C-x C-f) it doesn't find files in sub directories. So if I have a file test/core.clj and I search for tc (for test core) it has no match.
On thing I notice is that he has 'Project file:' in the screenshot, where I get 'Find file:'. I installed 'find-file-in-project' to see if that was the missing behavior but it doesn't work either. It only does matching on the filename, not the directories containing the file.
ido 'learns' what files you've visited and maintains a history cache. I believe that's what you're seeing in the screenshot above.(sometimes you'll want to clear the cache with ido-wash-history).
Usually once you've been in a project for a while it'll work in the way you're expecting.
If you're new to emacs, customize is the best way to experiment with the various features. e.g. you can M-x customize-group <RET> ido <RET> and see all the options for ido
There are other options, like find-file-in-project, are you sure you're actually invoking it? Just installing it isn't enough, that won't re-bind C-x C-f for you.
Try M-x find-file-in-project and see if that's the behaviour you desire.
There's also find-file-in-repository if you always work in source controlled dir.
('t' means true btw).
I would take a look at find-file-in-project.el.
http://www.emacswiki.org/cgi-bin/wiki/FindFileInProject
It will search for all files within the .git tree. I have this mapped to C-c f.
the "t" just means non-nil or true. You could use "a", "w", or "t" and it would mean the same thing. People just use t by convention.
Enabling
If you want to enable something you would have in your .emacs (ido-mode t)
Disabling
If you want to disable something you would have in your .emacs (ido-mode nil)

perltidy-mode autorun in Emacs

I have a perltidy-mode.el lisp file, which is being loaded - I can call it manually by M-x perltidy-mode.
What would be the proper way to run it automatically after a file is opened (or emacs is loaded)?
(defalias 'perl-mode 'cperl-mode)
(defalias 'perl-mode 'perltidy-mode)
doesn't seem to work.
It seems I've forgotten a lot of lisp/emacs
If you would like to activate it for every opened perl file, you can add it to a hook:
(defun my-perl-hook ()
(perltidy-mode 1))
(add-hook 'perl-mode-hook 'my-perl-hook)
Note: I know nothing about this mode, or about the different perl modes, so you might to add your function to other hooks as well.

Emacs on-the-fly mode changing

When writing shell scripts (which to my knowledge usually don't have .* suffix), I usually do something like the following
1) emacs foo
2) Type in #!/bin/sh
3) Close and reopen emacs so that the shell-script major mode is enabled
Is there any nice way so that I don't have to do step (3)? I could bind M-x shell-script-mode to some key combination, but is there some general way to make emacs re-evaluate the mode using its standard set of rules?
The general way to do it would be M-x normal-mode
Add this to you .emacs:
(add-hook 'after-save-hook
'(lambda ()
(if (not (executable-make-buffer-file-executable-if-script-p))
(normal-mode))))
The first bit executable-make-buffer-file-executable-if-script-p was not part of your question but is also useful: it makes the file executable if it wasn't already (if it looks like a script). If we end up flipping the execut bit, then we also set the mode.

Trying to edit init.el to customize emacs

So I'm relatively new in trying to customize emacs. But I really need to customize is asap. Tabs are a pain in emacs as they are two spaces, and the text is all messed up when it is opened with any other editor after that.
Currently, I only have few lines in my ~/emacs.d/init.el file:
(setq load-path (concat (getenv "HOME") "/.emacs.d/"))
(set-scroll-bar-mode 'right)
(require 'linum)
(global-linum-mode t)
I get an error while starting up emacs:
Loading encoded-kb...done
An error has occurred while loading `/Users/mycomp/.emacs.d/init.el':
Symbol's function definition is void: set-scroll-bar-mode
To ensure normal operation, you should investigate and remove the
cause of the error in your initialization file. Start Emacs with
the `--debug-init' option to view a complete error backtrace.
I tried srtating it with the --debug-init option, but my lisp knowledge is not enough to help me figure out what's wrong. Any help on how to get this working or redirecting me to some GOOD tutorials on editing init.el files will be really helpful (yes i did google tutorials on editing the initialization file, but every one of them was terrible).
I'm assuming my code for getting line numbers on the left is also wrong. Could someone please help me with this? Thanks a lot.
I think this line may be the problem:
(setq load-path (concat (getenv "HOME") "/.emacs.d/"))
First of all, I don't think this is required to load ~/emacs.d/init.el. Secondly, if you do want to add a directory to your load-path, you should probably be doing it like this instead:
(add-to-list 'load-path "~/.emacs.d/")
This code adds the directory to the load-path, your code just clobbers it with the single directory.
Use 'M-x apropos' and 'M-x customize-apropos'. For now, those will make your life much easier when you want to customize things.
For instance, to customize things to do with scrolling, 'M-x customize-apropos RET scroll RET' will give you a list of all things that you can customize that have 'scroll' in them. You can look around and find the things that you want by searching the buffer. If you find a particular thing that you want, there's usually a group that it belongs to. You can click on that, and just customize those particular values. Make sure you save the settings.
It might take you a while to figure out what things are called. If you've got an idea, try the apropos search. If that doesn't turn up anything, google can probably sort it out for you.
For now, don't worry about hacking the elisp. This method will write values to your startup file (probably the .emacs?) and you can look and check the syntax later if you're really interested. I customize most of my stuff this way; I only bother actually modifying the file by hand when I'm trying to write my own hooks or functions.