emacs orgmode do not insert line between headers? - emacs

In emacs org-mode, when I make a new sub-heading,(org-insert-subheading), sometimes it adds a blank line, sometimes it doesn't based on some pattern in text above.
Can I force emacs to never insert a line break?
I.e,
* Heading 1
** Heading 2 #no line breaks.

This is controlled by the variable org-blank-before-new-entry:
Should `org-insert-heading' leave a blank line before new heading/item?
The value is an alist, with `heading' and `plain-list-item' as CAR, and a boolean flag as CDR. The cdr may also be the symbol `auto', in which case Org will look at the surrounding headings/items and try to make an intelligent decision whether to insert a blank line or not.
On my version of emacs, the default for both items is auto. To never insert blank lines, set both to nil:
(setf org-blank-before-new-entry '((heading . nil) (plain-list-item . nil)))

I think this is controlled by the variable org-blank-before-new-entry. As per the Org documentation:
Should org-insert-heading leave a blank line before new heading/item?
The value is an alist, with heading and plain-list-item as CAR,
and a boolean flag as CDR. The cdr may also be the symbol `auto', in
which case Org will look at the surrounding headings/items and try to
make an intelligent decision whether to insert a blank line or not.
For plain lists, if org-list-empty-line-terminates-plain-lists is set,
the setting here is ignored and no empty line is inserted to avoid breaking
the list structure.
The default value is '((heading . auto) (plain-list-item . auto)), so it normally will insert a newline before a heading (the auto part in the heading). You can specify Never when you customize the variable, and it will not insert a newline.

Related

Is there a way in Emacs to fill a paragraph containing some read-only characters?

In Emacs I am using cm-mode with markdown buffers. cm-mode inserts a few read-only characters to indicate document changes. When I issue fill-paragraph the fill is aborted with the message read-only Text.
Is there a way to fill a paragraph containing a few read-only characters? (I.e. after the fill the read-only characters should be read-only again.)
Bind or temporarily set inhibit-read-only to non-nil. C-h v tells us:
inhibit-read-only is a variable defined in C source code.
Its value is nil
Documentation:
Non-nil means disregard read-only status of buffers or characters.
If the value is t, disregard buffer-read-only and all read-only
text properties. If the value is a list, disregard buffer-read-only
and disregard a read-only text property if the property value
is a member of the list.

org-mode folding considers whitespace as content

Disclaimer: I am new to org-mode.
In org-mode, I sometimes add extra empty lines to make the separation between different tasks clearer when they are expanded. Like so:
** Task 1
*** Subtask 1.1
text text
*** Subtask 1.2
** Task 2
The problem is that when I fold 'Task 1' (by pressing C-tab while on its line) the subtasks and their contents are folded correctly, but the content of 'Subtask 1.2' is also folded (namely, the new line under it).
If I press C-tab while on the line of 'Subtask 1.2', the message 'SUBTREE (NO CHILDREN)' is printed and 'Subtask 1.2' is correctly not folded.
Is this normal? Can I somehow correct this behaviour so that empty content is not folded?
Use (setq org-cycle-separator-lines -1) in your config file.
This will fix it.
Documentation:
Number of empty lines needed to keep an empty line between collapsed trees.
If you leave an empty line between the end of a subtree and the following
headline, this empty line is hidden when the subtree is folded.
Org mode will leave (exactly) one empty line visible if the number of
empty lines is equal or larger to the number given in this variable.
So the default 2 means at least 2 empty lines after the end of a subtree
are needed to produce free space between a collapsed subtree and the
following headline.
If the number is negative, and the number of empty lines is at least -N,
all empty lines are shown.

Emacs lisp, skeleton-mode: Prevent trailing newline

I am using this code for inserting \emph{..} blocks into latex:
(define-skeleton mylatex-emph-skeleton "\emph{_}"
nil "\\emph{" _ "}")
As an undired side effect however, it also inserts a newline at the end of the skeleton. E.g. if I select emphasized in
This is emphasized text.
and press my hotkey, I end up with
This is \emph{emphasized}
text.
instead of
This is \emph{emphasized} text.
Can I prevent this? Note that the newline only gets inserted, there is text after the insertion point, so it is not as easy as deleting the character after the closing }.
Set skeleton-end-newline to nil to change the behavior of all skeletons.
Modify skeleton-end-hook to check which skeleton is being expanded and inserting newline as desired if you want to change the behavior of a specific skeleton.

automatically align properties and in-buffer settings

How is automatic alignment of properties, in-buffer settings and similar things enabled?
I always end up with something like this and then have to align manually.
#+STARTUP: indent
#+PRIORITIES: A C B
#+COLUMNS: %ITEM %foo %bar
* section
:PROPERTIES:
:foo: foo
:barbaz: barbaz
:END:
However I found some signs alignment should happen automatically. E.g. there is this:
(defcustom org-property-format "%-10s %s"
"How property key/value pairs should be formatted by `indent-line'.
When `indent-line' hits a property definition, it will format the line
according to this format, mainly to make sure that the values are
lined-up with respect to each other."
:group 'org-properties
:type 'string)
Is there a command that will fixup a property to respect that? Shouldn't a property inserted with org-set-property follow that format? M-x org-indent-line doesn't do anything for me and indent-line doesn't exist.
org-indent-line did not do the right thing when the property keyword was right at the beginning of the line. It does now.
Also, from a fresh git pull, using C-M-\ on the region will indent the region.
To format the options header you can select the region you want to align and do
M-x align-regexp RET <space> RET

How to make part of a word bold in org-mode

How can I make org-mode markup work for a part of a word? For example, I'd like it to work for cases like this:
=Class=es
and this:
/Method/s
Based on my tests it seems like org-mode markup syntax works on complete words only.
These days, there is a way to do this (without using quoted HTML tags):
(setcar org-emphasis-regexp-components " \t('\"{[:alpha:]")
(setcar (nthcdr 1 org-emphasis-regexp-components) "[:alpha:]- \t.,:!?;'\")}\\")
(org-set-emph-re 'org-emphasis-regexp-components org-emphasis-regexp-components)
Explanation
The manual says that org-emphasis-regexp-components can be used to
fine tune what characters are allowed before and after the markup characters [...].
It is a list containing five entries. The first entry lists characters that are allowed to immediately precede markup characters, and the second entry lists characters that are allowed to follow markup characters. By default, letters are not included in either one of these entries. So in order to successfully apply formatting to strings immediately preceded or followed by a letter, we have to add [:alpha:] (which matches any letter) to both entries.
This is what the calls to setcar do. The purpose of the third line is to rebuild the regular expression for emphasis based on the modified version of org-emphasis-regexp-components.
I don't think you can do it so that it shows up in the buffer as bold. If you just need it so that it appears bold when you export it to html, you can use:
th#<b>is is ha#</b>lf bold
See Quoting HTML tags
No, you can't do that. I searched for the same solution before and found nothing. A (very) bad hack is to do something like *Class* es (with a whitespace).
Perhaps you can write a short message to the creator, Carsten Dominik (Homepage), and ask him for a solution. He seems to be a nice guy.
A solution that has not been mentioned is to use a unicode zero width space (U+200B) in between the desired bolded and unbolded parts of a word.
To get the desired bolding of the word "Classes":
Type 'Class*es' in the buffer (without quotes).
Move the cursor between the '*' and 'e' characters.
Press C-x 8 RET (to execute the insert-char command).
Type 'zero width space' (without quotes) and press RET.
Move the cursor to the beginning of the word and insert a '*' character.
The word "Classes" should now have the desired appearance.
Note that there is the possibility that this will cause problems when exporting.
src_latex{\textbf{Class}es and \textit{Method}s}
Building up on the previous excellent answer
I had to modify it a bit in order to make it work with spacemacs. Indeed, from the spacamacs org-layer documentation, available here, we can read
Because of autoloading, calling to org functions will trigger the
loading up of the org shipped with emacs which will induce conflicts.
One way to avoid conflict is to wrap your org config code in a
with-eval-after-load block [...]
So, I put the following lines inside my dotspacemacs/user-config ()
(eval-after-load "org"
'(progn
(setcar org-emphasis-regexp-components " \t('\"{[:alpha:]")
(setcar (nthcdr 1 org-emphasis-regexp-components) "[:alpha:]- \t.,:!?;'\")}\\")
(org-set-emph-re 'org-emphasis-regexp-components org-emphasis-regexp-components)
))