The coding format style that is used at my work is as follows:
public:
TraceIndent(int i = 0) : _i(i)
{
if (_i)
{
nesting++;
}
}
Tabs are three spaces but no indentation after braces. Is it possible to achieve such style of formatting for c-mode in emacs?
Seems like I solved my problem. After researching a bit, I found that this kind of style is know as "whitesmith". I put these lines in my emacs init.el, which solved the issue. Hopefully, it will be helpful to someone.
(setq c-default-style "whitesmith"
c-basic-offset 3)
You could add this to init.el and enjoy manual formatting
(add-to-list 'c++-mode-hook
(lambda () (setq c-syntactic-indentation nil)))
Related
I’ve just started writing Go programs in Emacs. How can I turn off tabs highlighting in go-mode buffers? I use «whitespace» for whitespace chars highlighting. Go btw is the only mode where I don’t want tabs highlighted since tabs are standard formatting in Go.
Sincerely, Pavel.
To be clear, you're doing something like
(require 'whitespace)
(global-whitespace-mode t)
right? You can disable whitespace-mode for go-mode with
(setq whitespace-global-modes '(not go-mode))
There is a related question on emacs stack exchange.
I found that this
(add-hook 'go-mode-hook
(lambda ()
(add-hook 'before-save-hook 'gofmt-before-save)
(setq whitespace-style '(face empty trailing lines-tail))
(setq tab-width 4)
(setq indent-tabs-mode 1)))
Worked a bit better for me. Leaves whitespace-mode on but doesn't highlight tabs. Also runs go fmt before save and sets tab width to 4. I'm using prelude.
Add this line
(whitespace-toggle-options '(tabs)))
To your go-mode hook e.g
(use-package go-mode
:preface
(defun go-mode-config ()
(whitespace-toggle-options '(tabs)))
:config
(add-hook 'go-mode-hook (lambda ()
(go-mode-config))))
Taken from prelue go config
I would like to change the indentation style when I edit C++ files in my .emacs to 4-spaces instead of what seems to be the default current 2-spaces. I don't want the style to change for other languages, only for C++. How can I define this in my .emacs configuration?
Use this:
(add-hook 'c++-mode-hook
(lambda ()
(setq c-basic-offset 4)))
I installed SML Mode in Emacs and the indentation is messed up. I disabled all my .emacs customizations, but that didn't make any difference. At the end of each line in the code below, I used C-j, which is mapped to newline-and-indent.
If I highlight everything and reindent (C-M-\), the result makes more sense:
I'm using Emacs 24.1.1 and SML Mode 6.2 on Ubuntu 12.10. What should I do?
Don't use newline-and-indent.
You can use reindent-then-new-and-indent or electric-indent-mode instead.
try in the .emacs file:
(setq default-tab-width 4);
(setq-default indent-tabs-mode nil);
(global-set-key (kbd "TAB") 'self-insert-command);
I'm no wizard but that worked for me.
http://www.pement.org/emacs_tabs.htm
Following up on Stefan's (now 4 year old...) suggestion, you can auto-enable the minor mode electric-indent-mode for sml-mode by putting this:
(push (lambda () electric-indent-local-mode 1) sml-mode-hook)
somewhere in your emacs initialization code.
Or, you might prefer:
(use-package sml-mode
:config
(push (lambda () electric-indent-local-mode 1) sml-mode-hook))
This seems to me to produce reasonably sane behavior for indenting code in sml-mode.
When I am using emacs to edit a latex document the paragraph fill (Esc-q) does not do what I want. For example, something like:
The component \vn{%vec} is not similar to
When I use fill I get:
The component \vn{%vec} is not
% similar to
That is, emacs is taking "%" to be a comment character and filling the paragraph accordingly. However, "\vn" is a macro of mine that sets text in texttt mode and here "%" is simply a regular printable character so the paragraph fill has done things incorrectly.
So what I want is for paragraph fill to be the same it is as in text-mode. That is, no indentation and no adding extra characters. But I don't want to have to toggle between text-mode and latex-mode every time I want to paragraph fill. Is there any way to do this?
Thanks for the help. -- David
PS: Yes, I do know that if there are real comments at the end of lines then the test-mode fill will not do things correctly. But I never put comments at the end of lines so this will never bother me.
I found the solution. I put this in my init.el file:
(add-hook 'latex-mode-hook '(lambda() (setq comment-start nil)))
(add-hook 'tex-mode-hook '(lambda() (setq comment-start nil)))
(add-hook 'latex-mode-hook '(lambda() (setq fill-indent-according-to-mode nil)))
(add-hook 'tex-mode-hook '(lambda() (setq fill-indent-according-to-mode nil)))
I love emacs but the documentation (or lack thereof) can sometimes drive me crazy... :).
You can try:
(setq comment-start nil)
to handle this specific case.
What you're trying to fix is a symptom of the real problem -- latex-mode is
naively marking code after "%" as comment.
Does installing auctex-mode fix your problem?
Is there an Emacs minor-mode (or piece of elisp code) that lets you selectively hide/show environments while in Sweave (Sweave = R + LaTeX)?
For instance, I would like to move to the beginning of a code block (<<>>), hit a keystroke, and have the contents of the environment hidden from view.
Is this possible? I just tried hs-minor-mode, allout-mode, and outline-minor-mode, but most of them don't recognize R environments.
I also tryed org-mode that works great for folding/unfolding but, do not support the LaTeX highlighting code for expression like: \cite{}; \ref{}; \ce{} ...
Best
Riccardo
--EDIT--
I tried for some day to use emacs-folding-mode but, because I work on a very long code (more than 2000 rows), folding mode "goes crazy" and for example misunderstand the mining of some special character (i.e. $), that has very different use both in R than LaTeX. I think the problem is intrinsic to Sweave, because in the same buffer I have R code and LaTeX code together.
So, now I'm testing emacs outline minor mode. But when I move through R from LaTeX (and vice versa) all the outlined part were unfolded despite I write in my .emacs:
(defun turn-on-outline-minor-mode ()
(outline-minor-mode 1))
(add-hook 'ess-mode-hook 'turn-on-outline-minor-mode)
(add-hook 'LaTeX-mode-hook 'turn-on-outline-minor-mode)
(add-hook 'latex-mode-hook 'turn-on-outline-minor-mode)
(setq outline-minor-mode-prefix "\C-c\C-o")
Do you have any suggestions??
Regards
--EDIT 2--
It seems to work:
(load "folding" 'nomessage 'noerror)
(folding-mode-add-find-file-hook)
(add-hook 'LaTeX-mode-hook 'folding-mode)
(add-hook 'ess-mode-hook 'folding-mode)
(folding-add-to-marks-list 'ess-mode "#{{{ " "#}}}" " ")
I don't know if is right that, when you leave the chunk, it is automatically unfolded.
There's a generic folding mode here: http://www.emacswiki.org/emacs/FoldingMode
I have had very good results with the hideshow hs-minor-mode, these are the lines I basically use in my ~/.emacs.d/init.el:
(add-hook 'ess-mode-hook 'hs-minor-mode)
(eval-after-load 'hideshow
'(progn
(global-set-key (kbd "C-+") 'hs-toggle-hiding)))