Similar to this question except I want this as ideally a per-document setting or mode line. The ideal would be something like:
#+STARTUP: showlevels 3
Or if needed as a mode line:
# -*- org-showlevels: 3 -*-
And be equivalent to running C-3 S-tab when loading the file.
This does not appear to be directly supported in the initial visibility settings in the org-mode manual: https://orgmode.org/manual/Initial-visibility.html
New startup options for this are available in Emacs Org mode master since today.
The implementation is slightly different than your suggestion Elliott, since startup keywords cannot have argument (to the best of my knowledge). But the following will now work if you are using Org mode master:
#+STARTUP: show3levels
(3 can be changed to any of 2,3,4,5)
You can replicate what C-3 S-tab does with the org-content command:
# -*- eval:(org-content 3) -*-
From the docstring:
Show all headlines in the buffer, like a table of contents. With
numerical argument N, show content up to level N.
Related
Each time when I edit bash script I type a command M-x shell-script-mode. And then I get nice shell code higlighting. How to get it automatically each time I start emacs so I do not have to type the command. When I added (shell-script-mode) to init.el it did not help.
You can set the default major mode to be whatever you want by adding
(setq-default major-mode 'shell-script-mode)
to your init file. That will ensure that any newly created buffer will be in shell-script-mode unless its mode is specified otherwise (e.g. through auto-mode-alist). Whether it's a good idea or not, I don't know: I probably would not want that to be my default setting - but to each her/his own.
One of the simplest ways to have Emacs set the desired mode for a buffer editing a file is to include a special comment in the first line of that file, e.g. for a shell script your first line might be:
# -*-sh-*-
For scripts it is also common, or and often even required, to have an interpreter file comment on the very first line of the file, which of course would preclude having an Emacs mode comment, so Emacs also looks for interpreter file comments and associates those with a major mode, so the first line of your shell script might be:
#!/bin/sh
There are a number of other ways to tell Emacs how to set the buffer mode when visiting a file. See, for example, Emacs Manual: Choosing File Modes
I am writing a table in org-mode that is broader than the screen. Visual-line minor mode is enabled per default, which is useful in most situations. However, visual-line mode wraps my broad table at the edge of the screen, which makes it unreadable. Therefore I would like to turn off visual line mode for this particular file.
The way I would preferably like to implement this is via a file header. Is this possible?
I don't think setting the file-local visual-line-mode variable will work. Typically (these days, at any rate) you need to use the eval pseudo-variable to enable or disable minor modes that way.
You can do this in the header:
# -*- eval: (visual-line-mode 0); -*-
or in a comment block at (generally) the end of the file:
# Local Variables:
# eval: (visual-line-mode 0)
# End:
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.
I have a file open called test.scss, and when I press RET on a line, emacs will add 2 spaces to the current line and 4 extra spaces to the next line.
I've highlighted what the file looks like with whitespace-mode.
before pressing RET
after pressing RET
You can see that the .my-element row was auto-indented by 2 spaces, and the new line is indented by 4 spaces too many.
I want the output to look like this instead
desired output
What can I do to make emacs produce my desired output?
Here is the output of describe-mode:
Enabled minor modes: Auto-Composition Auto-Compression Auto-Encryption
Electric-Indent File-Name-Shadow Font-Lock Global-Eldoc
Global-Font-Lock Line-Number Menu-Bar Tooltip Whitespace
(Information about these minor modes follows the major mode info.)
SCSS mode defined in `css-mode.el':
Major mode to edit "Sassy CSS" files.
In addition to any hooks its parent mode `css-mode' might have run,
this mode runs the hook `scss-mode-hook', as the final step
during initialization.
Although in this case I'm in scss-mode, I see similar behavior with most of the other modes I use, such as ruby-mode, sgml-mode, js.el mode and others. I'd like to make the behavior match the desired output shown above.
Each mode can handle indentation in its own way, and you may have to look for mode-specific settings to get two-space indentation working everywhere.
For starters, you can set css-indent-offset, which should cover css-mode and scss-mode:
(setq css-indent-offset 2)
You can set the basic indenting of many other modes similarly. ruby-mode seems to use ruby-indent-level, sgml-mode uses sgml-basic-offset, and js-mode uses js-indent-level.
I use emacs for editing my sql code. I work 99% of time on postgresql plpgsql code. All my files with extension .sql contain postgresql. I'm curious is there a way to set sql-highlight-postgres-keywords SQL highlighting default instead of ANSI SQL, because it's pretty annoying to switch mode every time I open a file.
If you need to work with different databases, rather than using a hook to always switch to PostgreSQL highlighting when you open a .sql file, you can use Emacs' file variables feature to set the product on a file-by-file basis.
For example, if the first line of your .sql file is
-- -*- mode: sql; sql-product: postgres; -*-
sql-mode will automatically use PostgreSQL highlighting.
Full details on Emacs file variables here (you can also set them in a block anywhere in the file), and the list of product names is probably eaiest found by doing M-x sql-set-product, backspacing the ansi default, and hitting TAB to see the completion list. Examples are "mysql", "oracle", "sqlite", etc (about a dozen in my install).
Usually in emacs, if you want to change the settings every time some mode is opened, you use a hook. Something similar to this should work:
(add-to-list 'auto-mode-alist
'("\\.psql$" . (lambda ()
(sql-mode)
(sql-highlight-postgres-keywords))))