Emacs org mode 9.x refile not working with ido - emacs

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.

Related

How to enable org-indent-mode by default?

I am using Emacs 25.1.50.2
When I am using Org-mode, the org-indent-mode is off by default. So I have to enable it using M-x org-indent-mode everytime.
I put the lisp below into my config file ~/.emecs.d/init.el with no effect.
;; Enable org-indent mode by default
(org-indent mode 1)
;; Above line really should be (org-indent-mode 1)
Thanks for your time :)
You can use the mode hook for the major mode to enable this buffer-local minor mode in org-mode buffers.
For Emacs 24+ you can simply write:
(add-hook 'org-mode-hook 'org-indent-mode)
In earlier Emacs versions you should instead use a custom function to explicitly enable the minor mode by calling (org-indent-mode 1), and then add that custom function to the hook variable.
In 2021 current version of org, you can do this:
(setq org-startup-indented t)

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.

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.

disable cedet/semantic code completion for lisp mode

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...

In Emacs, how to automatically enable a minor mode based on buffer name?

I have a Emacs extension that creates a buffer named *erl-output*. This buffer gets created with only fundamental-mode by default. Is there any way to automatically enable compilation-minor-mode on that buffer?
To automatically change major modes you can add the following to your .emacs file:
(add-to-list 'auto-mode-alist '("^\\*erl-output\\*$" . my-major-mode))
This won't work for you; it's for major mode selection and you're after minor mode selection.
Instead you could try a Hook. The manual says:
A hook is a Lisp variable which holds a list of functions, to be called on some well-defined occasion.
So you should be able to write a function which sets the minor mode when required. Looking at the List of Standard Hooks I think you should be trying temp-buffer-setup-hook or temp-buffer-show-hook.
You'll have to write a function which checks the buffer name and sets the mode if required, and add it to the hook using something like the following in your .emacs:
(add-hook 'temp-buffer-setup-hook 'my-func-to-set-mode)
Since your extension is creating the buffer, why not just add:
(compilation-mode)
(or (compilation-minor-mode) if you're really set on the minor mode idea) in the code that's creating the *erl-output* buffer. You can edit the source for the mode, or use advice around the creation routine...