disable cedet/semantic code completion for lisp mode - emacs

I've set up cedet/semantic code completion for my c++ projects (using this tutorial: http://alexott.net/en/writings/emacs-devenv/EmacsCedet.html) but do not want the or all the helpers it (automagically it seems to me) offers in lisp mode.
So, my question is how to disable them in lisp-mode or have them enabled in c++-mode only.
Thanks,
Rene.

I think, that you need to slightly change config that is in the article - there are many global modes are used there, for example:
(global-srecode-minor-mode 1)
(global-semantic-mru-bookmark-mode 1)
etc. you can enable corresponding semantic-mru-bookmark-mode, srecode-minor-mode, etc. in the common C mode hook, like:
(defun my-c-mode-cedet-hook ()
(semantic-mru-bookmark-mode 1)
;; .....
)
(add-hook 'c-mode-common-hook 'my-c-mode-cedet-hook)
Or disable these modes for Lisp only... The other modes include semantic-auto-parse-mode, semantic-idle-summary-mode, semantic-idle-scheduler-mode - you can get this list using M-x apropos semantic.*mode
And the main thing here - you need to use semantic-load-enable-minimum-features in your config to enable minimal number of features by default, and enable other necessary features only in C/C++ mode hook...

Related

Emacs org mode 9.x refile not working with ido

Since I upgraded orgmode to 9.x, refile is no longer working with ido. According to http://orgmode.org/Changes.html, all options related to ido and iswitchb have been removed. It also mentions "Instead Org uses regular functions, e.g., completion-read so as to let those libraries operate."
However, being a recent vim-user-turned-emacs, I can't find how to setup ido (including ido-vertical) to work in orgmode 9.x the way it used to work in 8.x
Any suggestion welcome.
Thanks in advance.
Cheers /jerome
I think the only way to do this is to re-define or wrap the stock emacs completion functions. ido-completing-read+ is a package that wraps the stock completion functions to use ido wherever possible (including in org-refile), and you can configure exceptions.
That package is a bit aggressive in that it tries to enable IDO everywhere. If you don't want that, you can set the completing read function to IDO's completing read function in org mode only by adding a function to the org mode hook:
(defun bl/completion-use-ido ()
"Set the current buffer's completing read engine to IDO."
(setq-local completing-read-function #'ido-completing-read))
(add-hook 'org-mode-hook 'bl/completion-use-ido)
That will enable IDO completion for only org-mode buffers.

start emacs sr-speedbar in buffers mode on loading

I use sr-speedbar in emacs. On loading, it starts in file mode. I then manually change it to buffers mode. Since I almost always use buffers mode, I would prefer to start it in that. However, I cannot find any way after googling and wondering if someone with Lisp expertise has inputs on how to resolve this
The variable speedbar-initial-expansion-list-name controls the initial view of speedbar. The default value is "files". The other two possibilities are "quick buffers" or "buffers" -- either of the following could be placed in the .emacs file after a (require 'speedbar) statement:
(setq speedbar-initial-expansion-list-name "quick buffers")
or
(setq speedbar-initial-expansion-list-name "buffers")
The sr-speedbar is a package built on speedbar, so you need to consider customizing speedbar itself as well. There is no existing customization option for what you want but you can implement youself by using Hook, in your case, speedbar-mode-hook.
The following should do what you want
(add-hook 'speedbar-mode-hook
(lambda ()
(speedbar-change-initial-expansion-list "quick buffers")))
I copy it from https://stackoverflow.com/a/24291661/2999892 and I've test it by using both speedbar and sr-speedbar.

Inspecting / modifying Emacs hooks for minor modes

I use the following to enable linum-mode for Python buffers:
(defun my-python-mode-hook ()
(linum-mode 1))
(add-hook 'python-mode-hook 'my-python-mode-hook)
However, my understanding of hooks is still quite limited. As far as I understand, the code above adds a function to python-mode-hook so I assume this hook has already been defined, and may even have some code in it already. With this:
Does Emacs define a hook of the form <minor_mode_name>-hook for all minor modes? Or do the modes themshelves define them?
How can I look up the code added to a hook already?
How can I change elements of that hook?
This question is partly motivated by this GitHub issue for elpy where elpy-mode seems to have left a hook for python-mode that doesn't go away after uninstalling elpy.
(1) Emacs does not define a minor mode hook automatically, but you can define one with the :after-hook keyword (as per manual page for defining minor mode). (UPDATE: as per Legoscia's last comment, the minor-mode hook gets defined automatically as of emacs version 24.3.90. Thanks, Legoscia!)
(2) hooks are just variables, so you can inspect them as you would any other variable (e.g., C-h v or M-x describe-variable RET some-hook).
(3) you can use add-hook and remove-hook to change elements of the hook (see the manual on setting hooks), eg:
(add-hook 'python-mode-hook 'my-python-mode-hook)
(remove-hook 'python-mode-hook 'my-python-mode-hook)
(Note, by the way, that it's preferable to use named functions in your hooks rather than anonymous lambdas because you can use remove-hook on your named functions.)

How to enable a non-global minor mode by default, on emacs startup?

I want to enable rainbow-mode everytime I start emacs, rather than having to use M-x rainbow-mode.
I guess there is some command I put in my .emacs file.
I tried all of the following, but none of them worked:
(require 'rainbow-mode)
(rainbow-mode initialize)
(global-rainbow-mode)
More generally, how do I load any mode/package automatically on startup?
rainbow-mode isn't a global minor mode, so it needs to be enabled on a per-buffer basis.
I only use it for CSS, so I have:
(add-hook 'css-mode-hook 'my-css-mode-hook)
(defun my-css-mode-hook ()
(rainbow-mode 1))
If you genuinely want it to be global, everywhere, you can easily define a global minor mode yourself:
(define-globalized-minor-mode my-global-rainbow-mode rainbow-mode
(lambda () (rainbow-mode 1)))
(my-global-rainbow-mode 1)
You can add any arbitrary logic to that (lambda () (rainbow-mode 1)) function (which will be evaluated in every buffer) in order to decide whether or not to actually call (rainbow-mode 1) for a given buffer, so if you're comfortable with elisp then you can easily extend this approach to cover your specific requirements for the mode in question.
More generally, how do I load any mode/package automatically on startup?
It can vary, but the approaches I've shown would suffice for most minor modes: Either you want them enabled whenever MODE is enabled (being some specific other mode name), in which case you can use the MODE-hook variable (which will always be available) as per the css-mode-hook example; or else you want the mode enabled permanently, in which case a global minor mode is a good approach (because you can toggle it on and off globally). Some minor modes are global by default (or provide global variants), but you can create your own if necessary, as per the my-global-rainbow-mode example.
Also be aware that modes can be derived from other modes, in which case all relevant MODE-hook hooks will be run (for details see https://stackoverflow.com/a/19295380/324105). A common use-case is to use prog-mode-hook to enable functionality wanted for all the programming modes which are derived from it (which is most programming modes).
Remember that many (hopefully most) libraries and packages will provide usage instructions. If you can't find documentation, be sure to try M-x find-library to visit the library file, and then read through the comments at the top. There is often a very informative "Commentary" section, and sometimes this is the primary source of end-user documentation, and explain how to enable its functionality.

How to minify .emacs configuration file?

I was wondering if anyone can provide me with some help on minifying my .emacs file.
Currently I have it set up where each language I use have a custom tab, for example, if I have a hook for Java, it would look like this.
;; Java Hook
(defun e-java-mode-hook ()
(setq tab-width 4)
(setq indent-tabs-mode t)
(define-key java-mode-map (kbd "") 'java-insert-tab))
(defun java-insert-tab (&optional arg)
(interactive "P")
(insert-tab arg))
(add-hook 'java-mode-hook 'e-java-mode-hook)
And if I were to add another language like CSS or JavaScript, I would add another hook for CSS and another hook for JavaScript. So I was wondering if there's a global way of setting it so it would apply to any and all language?
I am currently running GNU Emacs 23.2.1 on Windows 7.
I agree with Tyler; although it's a bit complicated, you would be better off in the long run if you try to understand and customize the default indentation features. The Emacs Wiki has good resources, and there are other relevant Q&As here on Stack Overflow.
Binding the tab key to insert-tab means you completely lose the benefit of the likes of indent-region, and any other intelligent behaviour that a major mode might offer.
To address your specific questions regardless, however:
1) If you are defining (java-insert-tab) and (css-insert-tab) and (javascript-insert-tab) etc, and they all do exactly the same thing... well, hopefully you can see that you don't actually need more than one of those functions. Just give it a more generic name, and re-use it.
2) (local-set-key ...) does the same thing as (define-key (current-local-map) ...), which means you can also have a single generic function to override the tab keybinding, regardless of the major mode.
(defun my-coding-config ()
(setq tab-width 4)
(setq indent-tabs-mode t)
(local-set-key (kbd "<tab>") 'my-insert-tab))
(defun my-insert-tab (&optional arg)
(interactive "P")
(insert-tab arg))
Then you just need to add my-coding-config to each applicable mode hook variable. If there are a lot of them, you might wrap it up in a list like this:
;; Use my coding hook for all programming modes
(mapcar
(lambda (language-mode-hook)
(add-hook language-mode-hook 'my-coding-config))
'(java-mode-hook
javascript-mode-hook
css-mode-hook
...))
3) If you look at C-h v tab-width RET and likewise for indent-tabs-mode, you'll notice that they both say "Automatically becomes buffer-local when set in any fashion."
As an alternative to the customize interface already mentioned, you can use (set-default 'indent-tabs-mode t) to establish the default value for such variables. In the absence of code which sets a buffer-local value, all of your buffers will use the default, which might help you to avoid writing unnecessary mode hooks.
I'm not sure what you're trying to do. If you want to set the tab-width to 4 spaces globally, then you can do that using the customize command:
M-x customize-variable tab-width <ret>
Any changes you make to tab-width in customize will be applied globally. So you won't need to set it individually for each mode with hooks.
If you have different settings you want to apply to different modes, you will necessarily have to have code specific for each mode in your .emacs.
More generally, it looks like you're trying to build your own custom tab insertion commands - does the built-in indentation not do what you need? I think it will be easier to customize the indentation settings in Emacs than to manually insert tabs where you want them.
If you haven't already, take a look at the manual section on indentation and see if you might be able to do what you need without a lot of extra hooks:
C-h r m Indentation
(that is: h-elp, r-ead the manual, m-enu item Indentation)
or:
(info "(emacs)Indentation")
espect.el is doing exactly what you want.
From the docs:
This mode makes it easy to configure settings for individual
buffers with a concice and extensible mini-language. It abstracts
away common configuration selection tasks, like checking the mode
or filename, into a simple declarative syntax. Declare conditions;
run a function when the new buffer matches them. This makes it
easy to do things like turn on flyspell-prog-mode for your favorite
programming languages, or make all text-mode buffers ending in .mkn
have special properties.