how to warn against deleting folded subtree in org-mode? - emacs

I'm editing content in emacs org-mode and using the header structure in both folded and unfolded modes. In editing, though, I'm worried I will accidentally delete a folded subtree containing content.
Is there a way to get org-mode to warn me before deleting a folded subtree containing hidden content?

See the following variables to protect hidden trees under some circumstances:
org-catch-invisible-edits
org-ctrl-k-protect-subtree
Note however that those will not protect hidden trees from being killed by, e.g., C-w (kill-region).

Related

Inserting or removing line(s) inside a folded region causes it to unfold

When I have the same document open in two different editors, if I fold a region inside one editor and insert or remove a line in the folded region with the other editor, it causes the folded region in the first editor to unfold. Other changes do not seem to cause the unfold.
Same problem in monaco editor and can't find an option to disable it.
How do I prevent it?

Emacs highlighting: how to deal with highlighting messed up by unusual usage of special characters?

Problem:
In Emacs configuration modes (e.g. conf-xdefaults-mode or conf-space-mode), some special characters are used in unusual ways, for instance when they define keybindings. This messes up the highlighting for the rest of the buffer.
Example:
The ranger rc.conf file uses conf-space-mode which greatly helps its readability. But lines such as:
map # console shell -p%space
map "<any> tag_toggle tag=%any
mess up the highlighting since # usually defines a comment and is followed by font-lock-comment-face until the end of the line and " defines the beginning of a string and is followed by font-lock-string-face until it encounters a closing quote.
Escaping those characters is not an option because it would prevent them from defining the keybindings.
Possible solution:
The best solution I can think of is to fiddle with font lock settings for those configuration modes to remove the highlighting after those special characters. But I will then loose the proper highlighting after those characters when it is suitable.
A compromise could be to keep highlighting after # since this only messes up one line and there are a lot of comments in those configuration files, while removing the highlighting after single and double quotes since those mess up the entire rest of the buffer and strings are not so common in configuration files.
Question:
What is the proper way to deal with these situations?
Is there a way to reset the highlighting at a point in the buffer? or to insert a character which would affect the highlighting (to fix it) without affecting the code? or is there a way to "escape" some characters for the highlighting only without affecting the code?
The easy way
It's probably easiest to just live with it but keep things constrained. Here, I took ranger's default rc.conf and re-arranged some of the font-lock errors.
Let's ignore the blue "map" for now. We have two visible font-lock errors. The map #... is font-locking as a comment, and the map "... font-locking as a string to the end of the buffer. The first error is self-constrained. Comments end at the end of the line. The second error we constrain by adding a comment. (I don't know if ranger would accept comments in the middle of the line, so I'm only using beginning-of-line comments here.)
The second error is now constrained to one line, but a couple more errors have popped up. Quickly adjusting these we get.
This is something that I could live with, as I'm not in conf files all day long (as opposed to say, source code.) It would be even neater if our new "comments" could be included on the same line.
The hard way
You'll want to use Emacs font-lock-add-keywords. Let's get back to that blue map in the first image. It's rendering blue because conf-space-mode thinks that a string, followed by any amount of whitespace, followed by an opening brace should be rendered in font-lock-type-face (the actually regexp that triggers this is ^[_space__tab_]*\\(.+?\\)[_space__tab_\n]*{[^{}]*?$ where _space_ and _tab_ are actual space and tab characters.)
We can override this in a simple fashion by evaluating
(font-lock-remove-keywords
'conf-space-mode
'(("^\\<\\(map\\)\\>" 1 font-lock-variable-name-face)))
and reloading the buffer with C-x C-v RET. Now, every time that the word "map" appears at the beginning of a line it's rendered as font-lock-variable-name-face (yellow in our example.)
You can make this change permanent by adding a hook to your init file.
(add-hook 'conf-space-mode-hook (lambda ()
(font-lock-remove-keywords
nil
'(("^\\<\\(map\\)\\>" 1 font-lock-variable-name-face)))))
This method doesn't appear to work for your comment (#) and string (' ") delimiters as they're defined in the syntax table. Modifying the syntax table to provide special cases is probably more effort than it's worth.

In org-mode, how to include archived headings in the agenda text search

How do I include items that have the ARCHIVE tag in the org agenda search C-c a s?
I know archive files are included in this search by
(setq org-agenda-text-search-extra-files (quote (agenda-archives))) but I want to search archived entries within my agenda files, too.
You can either set org-agenda-skip-archived-trees to nil or use v in the agenda to toggle the display of archived entries. From the org-agenda-skip-archived-trees manual:
Non-nil means the agenda will skip any items located in archived trees.
An archived tree is a tree marked with the tag ARCHIVE. The use of this
variable is no longer recommended, you should leave it at the value t.
Instead, use the key ā€˜vā€™ to cycle the archives-mode in the agenda.

emacs preview duplicate lines before removing

Context: I'm working with a large text file that is almost excel-like and I'm adding/editing entries. It is a shared file so others can have already edited the file.
I'm working with emacs and I found that they added the command delete-duplicate-lines. This command seems great for pruning extra entries, but it would be nice to know which lines were duplicates (i.e. already existed in the file) so that I would know which entries had already been added. Is there a command that is similar to delete-duplicate-lines, but only points out which lines are duplicates without removing them?
You can use command hlt-highlight-line-dups-region from the Highlight library, to highlight all sets of duplicate lines in the region or (if no active region) in the buffer.
By default, leading and trailing whitespace are ignored
when checking for duplicates, but this is controlled by option
hlt-line-dups-ignore-regexp. And with a prefix arg the behavior
effectively acts opposite to the value of that option. So if the
option says not to ignore whitespace and you use a prefix arg then
whitespace is ignored, and vice versa.
You can also control the colors/faces used to highlight each set of duplicates.

lazy loading of only the first N lines in emacs org-mode

Is there a way to tell org-mode to load only the first N lines of a long text file? I would like to keep the whole file open to be able to search through it, but have org-mode display on the first N lines of my file, which is where I edit new content.
If you have a structured outline in org-mode, you can set the global file visibility with the #+STARTUP markup, or the visibility of any heading with the VISIBILITY property, see Visibility Cycling for details. The benefit of using the built-in org-mode properties is that it's easy to have a file open up in exactly the state you want.
I have my journal file set up to accomplish something similar what I think you're asking for using these org-mode properties. The "Today" section is opened so I can see everything, but older archives are collapsed.
I'm not sure the title really fits the description?
I think you just want use buffer narrowing, which lets you hide everything outside of the specified region for as long as necessary.
You can manually narrow the buffer by marking the region and typing C-xnn
Widen the display back to the full buffer with C-xnw
I guess you could use an eval Local Variable to automate this to a pre-defined region, if you really wanted to.
There's also narrow-to-defun (C-xnd) and narrow-to-page (C-xnp). If you throw a page break into your org file (C-qC-l), the latter might prove handy.