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

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)

Related

emacs scratch not interactive mode

I updated a lot of packages that I had directly from github to the MELPA packages. Nonetheless something really weird happened to my *scratch* buffer. The default message is not appearing (the buffer is completely empty), and also the interactive elisp mode is not set (let's say I write (+ 2 2) and then hit C-j and it tells me invalid function). I have no idea why. I don't even know how to debug it to check where the error is. Any ideas?
Finally the problem was generated by flycheck-add-next-checker, for some reason, using the MELPA repositories is generating this error. I just commented the following part of my configuration file.
(eval-after-load 'flycheck
'(progn
;; Add Google C++ Style checker.
;; In default, syntax checked by Clang and Cppcheck.
(flycheck-add-next-checker 'c/c++-clang
'(warnings-only . c/c++-googlelint))))

What happened to the ido-imenu in ruby-mode function in Emacs24?

Emacs 23.2 in emacs-starter-kit v1 has C-x C-i (or ido-imenu) (similar to Sublime Text's Cmd+R). Emacs24 in emacs-starter-kit v2 lacks this function. I found this github issue and a fix, which try to recreate the functionality. While this ido-imenu works in elisp-mode, it stopped working in ruby-mode. I get:
imenu--make-index-alist: No items suitable for an index found in this buffer
Has anyone figured out how to get this to work?
Why was this taken out of Emacs24?
Is there a new replacement for this function?
Since the function is part of ESK (as opposed to something budled with Emacs) you'd probably do best to report the bug upstream. On a related note ESK main competitor Emacs Prelude offers the same functionality (bound to C-c i by default) and it seems to be working fine with ruby-mode in Emacs 24. Here you can find more on ido-imenu.
So I finally figured it out, after reading the Defining an Imenu Menu for a Mode section on emacs-wiki again.
Short answer: you need to add this bit to your customization. Feel free to add more types to the list (I am happy with just methods).
(add-hook 'ruby-mode-hook
(lambda ()
(set (make-local-variable imenu-generic-expression)
'(("Methods" "^\\( *\\(def\\) +.+\\)" 1)
))))
Longer answer: I first tried to define a ruby-imenu-generic-expression function and set that to imenu-generic-expression by using the ruby-mode-hook:
(defvar ruby-imenu-generic-expression
'(("Methods" "^\\( *\\(def\\) +.+\\)" 1))
"The imenu regex to parse an outline of the ruby file")
(defun ruby-set-imenu-generic-expression ()
(make-local-variable 'imenu-generic-expression)
(make-local-variable 'imenu-create-index-function)
(setq imenu-create-index-function 'imenu-default-create-index-function)
(setq imenu-generic-expression ruby-imenu-generic-expression))
(add-hook 'ruby-mode-hook 'ruby-set-imenu-generic-expression)
This however did not work (I would get the same error as before). More reading of the Defining an Imenu Menu for a Mode section showed me the way. Now, I'm not an elisp expert, so here's my hypothesis: basically, the above method works for modes where the
major mode supports a buffer local copy of the “real” variable, ‘imenu-generic-expression’. If your mode doesn’t do it, you will have to rely on a hook.
The example for foo-mode made it clear how to do it for ruby-mode. So it appears that ruby-mode does not have a buffer-local copy of the real imenu-generic-expression variable. I still can't explain why it worked in Emacs 23.2 (with ESK v1) but does not on Emacs24, but hey at least I found a working solution.

Warning when I revert from desktop session. Emacs

Yesterday I found desktop mode from EmacsWiki, and then I configure it for my Emacs 24:
;; Desktop
(require 'desktop)
;; save the desktop file automatically if it already exists
(desktop-save-mode 1)
;; use only one desktop
(setq desktop-path '("~/.emacs.d/tmp/"))
(setq desktop-dirname "~/.emacs.d/tmp/")
(setq desktop-base-file-name "desktop.cache")
But I got a warning in *Compile-Log* buffer when I restart Emacs:
Warning: ad-Orig-kill-region called with 3 arguments, but accepts only 2
Anyone else encounter this warning when use desktop? Or, any add-ons else better than desktop-mode?
The ad-Orig- prefix is telling you that the function kill-region is advised. Possibly that advice is causing issues?
C-hf kill-region RET should tell you the name of the advice; chances are good that it's something in your own config, so I would look for it there firstly.
See if disabling the advice resolves the problem.
I do note an oddity with this function in Emacs 24; the source code for kill-region clearly takes an optional third argument, but that *Help* screen mentions only the two required args.
I checked in Emacs 23, and the help there mentions all three arguments.
Perhaps there's a bug in Emacs 24 which is responsible for both the discrepancy in the help output, and the error you're seeing?

clicking on emacs blows away x selection

Much of the time when I use the mouse to click on an emacs window, the x selection which I hope to paste into the buffer is blown away. This seems to be caused by the slight shift of the hand as I apply the left click causing an inadvertant "drag copy." I do not believe I will be able to break this particular habit.
One solution I have found to prevent this is to set:
(setq mouse-drag-copy-region nil)
however this has the unfortunate side effect of preventing me from using the mouse drag functionality at all in emacs. Is there a way to control mouse drag behavior so that a click is ignored unless it spands two or more characters within the buffer?
I am coding on Centos 5.x + GNOME 2 with GNU emacs 23.3.1 in case it makes a difference.
This appears to be a GTK/X issue; I can produce similar behavior with other apps.
The easiest solution to this is to modify the function mouse-drag-track, which can be found in mouse.el. To find the function definition, M-x find-function mouse-drag-track RET.
Copy that into your .emacs file and make one small change. Find the and statement that looks like:
(and mouse-drag-copy-region
do-mouse-drag-region-post-process
(let (deactivate-mark)
(copy-region-as-kill region-commencement
region-termination)))
And modify it to have the check to ensure the region is at least 2 characters. I've made this check to be 10 characters for easier testing:
(and mouse-drag-copy-region
(>= (abs (- region-commencement region-termination)) 10) ;; THIS IS NEW
do-mouse-drag-region-post-process
(let (deactivate-mark)
(copy-region-as-kill region-commencement
region-termination)))
I don't see a clean way to do this via advice or hooks or variable settings.
Be sure to have a (require 'mouse) before your definition of mouse-drag-track to ensure you override the built-in definition, as opposed to it overriding yours. You also might want to add a check to your .emacs right above the re-definition to remind you to check for new versions of the library/function you're overwriting:
(unless (eq emacs-major-version 23)
(error "check for new mouse-drag-track"))
This is a bug in emacs that was introduced into the source code history in 2001. I have posted a patch that can be applied to local installations. Hopefully the emacs maintainers will investigate further.
Here is my patch and discussion:
http://lists.gnu.org/archive/html/emacs-devel/2011-08/msg00818.html

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

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.