I use emacs edit js files, when I enter a ;, it will auto jump a new line.
like this:
function test() {
var x = 1;
// <----- cursor auto in here !!!
}
How to disable it ?
It sounds like you are using electric-mode and have the auto-newline enabled.
Try evaluating this in a js buffer and see if it makes a difference (type M-: to eval):
(c-toggle-auto-newline 0)
If it does, just disable the electric mode in your setup or add that line to your js2-mode hook.
Related
I'm trying to create a highlight for trailing spaces and tabs for all windows in NeoVim, but I'm having problems to handle exceptions. Basically I want to set it for all windows except terminal windows (which I use the plugin toggleterm) and the help page.
From reading the docs I realised that the WinNew or WinEnter events are fired before the filetype is set, so it basically inherits the filetype from the current window. Because of that my check never works properly. Is there a way to make this check work? I thought of using buffer events, but then I'd be executing this many times unnecessarily since the match applies for the window and not for the buffer.
vim.cmd('highlight ExtraWhitespace ctermbg=lightyellow guibg=lightyellow')
vim.api.nvim_create_autocmd({ 'VimEnter', 'WinNew' }, {
desc = 'Highlight all tabs and trailing whitespaces',
pattern = '*',
callback = function()
-- TODO: implement blacklist
if vim.bo.filetype ~= 'toggleterm' or vim.bo.filetype ~= 'help' then
vim.fn.matchadd('ExtraWhitespace', '\\s\\+$\\|\\t')
end
end,
})
Terminal can be opened in any existing window, and so you can't tell this beforehand and can't blacklist anything.
Instead, remove the match after terminal has been opened.
augroup mystuff | au!
autocmd VimEnter,WinNew 2match Todo /\s\+$\|\t/
autocmd TermOpen,TerminalWinOpen * 2match none
" ^-- Nvim ^-- Vim
augroup end
In emacs, when I type this:
if(true)
{
I get this:
if(true)
{
So then I have to press the left arrow to move back one space, then delete the two extra spaces to get the expected result. Any ideas on how to fix this?
Check what the RET key is bound to in the current mode. Bind it to something else, such as newline.
Or just turn off electric-indent-mode, by putting this in your init file:
(electric-indent-mode -1)
That turns off having RET (the Enter key) automatically indent, in most programming modes.
I'm using the most recent version of Emacs on Windows 7. Let's say I type the following code in my .emacs:
;test|
| means the cursor position. Now if I press Enter, the text will be moved to the right and it will look like:
;test
How to disable this feature?
This is done in accordance with the Emacs Lisp style guide:
Comments that start with a single semicolon, ';', should all be aligned to the same column on the right of the source code. Such comments usually explain how the code on that line does its job. For example:
(setq base-version-list ; There was a base
(assoc (substring fn 0 start-vn) ; version to which
file-version-assoc-list)) ; this looks like
; a subversion.
If you use two or more semicolons you will see other behaviour:
Comments that start with two semicolons, ';;', should be aligned to the same level of indentation as the code. Such comments usually describe the purpose of the following lines or the state of the program at that point.
...
Comments that start with three semicolons, ';;;', should start at the left margin. We use them for comments which should be considered a “heading” by Outline minor mode.
...
Comments that start with four semicolons, ';;;;', should be aligned to the left margin and are used for headings of major sections of a program.
The automatic indentation is done by electric-indent-mode. If you wish to disable it entirely, put something like
(electric-indent-mode -1)
in your init file. You could also disable it for specific modes using something like
(electric-indent-local-mode -1)
in the appropriate init hooks.
Simply using two semi-colons as suggested by the style guide should also prevent the behaviour, which will let you benefit from electric-indent-mode on other code.
Hi i have the following issue with my emacs:
When typing a long line, sometimes, when I type a space at the end of a line the line automatically gets split into multiple lines.
e.g. Line I am typing emacs: 'This is my line 1. This is my line 2. This is my line 3'%space%
emacs automatically formats this to:
'This is my line 1. %emacs adds new line%
This is my line 2. %emacs adds new line%
This is my line 3 %space%
Please help me fix this annoyance :)
What you are seeing is a feature (grin). "Auto Fill" mode is a buffer-local minor mode in
which lines are broken automatically when they become too wide. "Minor mode" means it is additional functionality which is associated with a buffer.
If you look at the emacs mode line, it will say "Auto Fill" if this is active. To turn it off for that buffer, M-x auto-fill-mode.
If for a particular major mode you would always like it on, you can turn it on by modifying the hook for that. For example, if every time you edit a text file, you would like auto-fill on, you can customize the variable text-mode-hook to turn it on.
M-x customize-variable
when prompted for the variable, say:text-mode-hook. You can use the same mechanism to turn it on (or off) for other modes.
Turn off auto-fill-mode: Put this in your init file, or do it for a particular mode on the mode hook: (auto-fill-mode).
I'd like to have the function name displayed next to the buffer name
on the mode-line if the point is inside a function (maybe with some reasonable truncation if necessary).
Is ther a simple way to achieve this? (via imenu? defuns?)
Example: in test.py if my cursor is inside def myfunction, I'd like my mode-line say:
test.py: myfunction
Could be also interesting for org mode (displaying the inside-most header)
Which Function Mode should help you :
WhichFuncMode (also known as WhichFunctionMode) is a minor mode, that when activated displays the current function name in the mode line. It works under certain major modes, like CcMode or PerlMode.
To activate this minor mode : M-x which-function-mode RET
An interesting effect of this mode is by middle-clicking on the current function name : it can narrow the display to the current function.
OK... I found it: the mode is built in and can be globally activated by:
(which-function-mode 1)
Change colors and add major modes (e.g. org-mode is not enabled by default) with:
M-x customize-group and selecting which-func