Reference: rust-cpp
Can emacs/spacemacs support nested mode in major mode? I'm used to vim and new to emacs/spacemacs.
General information
You have access to a wiki listing some solutions to run several major modes at once:
mmm-mode
polymode
multi-mode
In your case, you will need to run 2 major modes in order to recognize C++ and Rust in the same buffer:
c++-mode (available by default)
rust-mode
A practical example with mmm-mode
I suppose your Rust environment is already configured in your Emacs. The following will add c++-mode while the Rust major mode is running. In your Emacs configuration file, add the following snippet:
(require 'mmm-mode)
(setq mmm-global-mode 'maybe)
(mmm-add-classes
'((rust-cpp ; Name of the mmm class
:submode c++-mode ; Additional major mode, here it is C++
:front "^cpp! {[\n\r]+" ; Start tag for c++-mode
:back "^}$"))) ; Stop tag for c++-mode
(mmm-add-mode-ext-class 'rust-mode nil 'rust-cpp)
In your Rust code, c++-mode will be activated when the following pattern is present:
cpp! {
// your C++ code...
}
I'll let you fine-tune the regular expression since I do not know the rules of rust-cpp when mixing Rust and C++.
Related
After installing pdf-tools the dired mode opens the pdf file with PDFView mode as major mode.
(use-package pdf-tools
:ensure t
:config
(pdf-tools-install t))
How does the pdf-tools package be able to accomplish this?
The Help for RET key in dried buffer says it is bound to dired-find-file
RET (translated from ) runs the command dired-find-file (found
in dired-mode-map), which is an interactive compiled Lisp function.
I searched for dired-find-file in pdf-tools installed elisp files and could not find any advice-add's?
Also please explain how can one go about finding arbitrary key bindings like this one?
What it modified is not directly related to dired, but to how Emacs decides to open files in general. The part of the code that is responsible for that is in pdf-tools-install-noverify, itself called by pdf-tools-install. The first two lines of the function are:
(add-to-list 'auto-mode-alist pdf-tools-auto-mode-alist-entry)
(add-to-list 'magic-mode-alist pdf-tools-magic-mode-alist-entry)
the relevant variables pdf-tools-<auto/magic>-mode-alist-entry being constants defined earlier in the file pdf-tools.el.
You can check the relevant documentation for auto-mode-alist and magic-mode-alist, but to sum up, the former is a mapping from "filenames" (or more precisely, file patterns -- typically, regexps matching file extensions) to major modes, and the latter is a mapping from "beginning of a buffer" to a major mode (see also this wikipedia page on magic numbers/file signatures).
As to how one can determine that: because it is not directly related to key bindings/advices/redefinition of functions, the only "general" option is to explore the "call stack" ! The package tells you to put (pdf-tools-install) somewhere in your init file to activate the package, so you can try to see what this function actually does -- and going a bit further, you see that it is essentially a wrapper around pdf-tools-install-noverify, which does the real job of setting everything up.
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.
I am searching for a list of symbols which are highlighted per default in slime. Where can I find it?
Are these symbols derived from emacs lisp mode or are they defined in slime? Or are they implementation specific?
Based on which rules are certain symbols highlighted and certain not?
Thank you
Matus
You should check out slime-fontifying-fu.el in SLIME distribution, as well as the contents of lisp-mode.el that comes with your Emacs distribution. In the beginning of slime-fontifying-fu.el it read as follows:
(:on-load
(font-lock-add-keywords
'lisp-mode slime-additional-font-lock-keywords)
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...
Emacs has poor handling of auto-indentation in Flex and Bison. In fact, it seems to have no support for flex mode. So, how does an emacs user cope with these? I like VIm but I would prefer not to switch because I am much faster and more comfortable in Emacs.
I had a third party elisp module for Bison a few months ago but when its indentation broke, it would never get fixed. In short, it was a bad hack.
Or is there a way I can turn off auto indentation for .l and .y files (so pressing would do one indent)? How would I also change this elisp setting for just emacs?
A nice and concise guide for elisp would be very helpful too. I wouldn't mind spending a few days to write my own flex and bison modes if I had the right documentation.
Emacs chooses the major mode mainly based on the file name extension. .l is a contended extension: some people use it for lex, others for lisp (and there are a few other rarer uses). Emacs associates .l with lisp, and .lex with lex (for which it uses C mode).
If the .l files you work with are more often lex than lisp, you can change what .l files are associated with the following line in your .emacs:
(add-to-list 'auto-mode-alist '("\\.l\\'" . c-mode))
You can also declare inside a file what mode you want Emacs to use when it opens the file. Put the following snippet on the first line of the file (typically in a comment):
-*-mode: c-mode-*-
This is a more general feature, offering other syntaxes and other possibilities; see “File Variables” in the Emacs manual for more information.
If you would like to get started with Emacs Lisp, read the Emacs Lisp intro (which may be included in your Emacs or OS distribution). Once you've played around with the basics of the language a bit, you can turn to the chapter on modes in the Emacs Lisp reference manual.
Additional tip: You might decide that what you want is Emacs' generic behavior -- what it uses when it doesn't have any special mode for a file format. That's called Fundamental mode in emacs lingo: so you can request it on the fly with M-x fundamental-mode, or put -*- mode: fundamental -*- on the first line of the file, or customize auto-mode-alist like so:
(add-to-list 'auto-mode-alist '("\\.l\\'" . fundamental-mode))
Another thing to try might be indented-text-mode (probably with auto-fill disabled).