emacs org-mode: completing a multi-line task - emacs

I am new to org-mode (using it under evil) and been using it as a very nice ASCII-based TODO with scheduled times and completion dates. I have a simple question - and in my case, I think an image is worth 1000 words...
Look at the image below, in the line that starts with "Merge button: ...." - i.e the one that I've split to two lines - with the continuation line starting with "click after..."
After hitting TAB to open the action tree node, the continuation line is colored in grey - as if it's not a part of the task in question:
This is further verified if I mark the task as DONE (shift-rightCursor): The DONE marker is placed below my task line, not below my continuation line - as if the continuation line is on its own:
I am probably missing something obvious - any help will be most appreciated.

In a word, it's the Design.
You could think like this:
The headline (first line) is the title of a task, the rest are contents/description or sub tasks.

The text at issue in the question of the original poster is what I generally refer to as the notes section of a task. By design, org-mode does not assign a particular highlighting of the notes section -- i.e., the default font for text will be used.
However, all is not lost. It is possible to change the default font for a particular buffer using the face-remapping-alist and setting it as a local variable. The following example uses a cyan foreground color, but it can be just about anything: http://www.gnu.org/software/emacs/manual/html_node/elisp/Face-Attributes.html I'm not certain when setq-local was introduced, but it is available in a current version of Emacs Trunk and may be available in earlier versions of Emacs.
(defun my-org-notes-face-function ()
(interactive)
(setq-local face-remapping-alist '(
(default (:foreground "cyan")))))
(add-hook 'org-mode-hook 'my-org-notes-face-function)

Related

Key binding to change the face of a character

I'm curious as to whether or not there's a simple way to edit the face of a block of text using a function.
Specifically, I'm working on a calendar major mode that I created, and I want to define a function that will be bound to a keystroke within this major mode. I want to be able to mark a group of text, and then change its face using this keybinding to mark it as "done", etc.
I did some research and wasn't able to find this exact issue. Also, I know I can basically do this exact thing in org-mode, but I really want to create my own mode to enable more flexibility on my end.
If you are using the 3-month mini-calendar as a basis to create your major-mode, then there is already a facility to do this. To see how this looks like, type M-x calendar and then M-x calendar-mark-holidays. To see how this works, you can type M-x find-function RET calendar-mark-holidays RET and see that it uses the function calendar-mark-visible-date -- so there you have it, that is your function of interest. Drew Adams has a fancier calendar mark date that has some additional options: https://www.emacswiki.org/emacs/calendar%2B.el . These markings are overlays and can be controlled with priorities to have one supersede another so that it is not actually necessary to remove a color unless you want to.
Here is a quick example of a keyboard shortcut/function that uses the F5 key: (define-key calendar-mode-map [f5] (lambda () (interactive) (calendar-mark-visible-date (calendar-cursor-to-date 'signal-error) '(:background "yellow" :foreground "black"))))
Sounds like ad hoc, not syntax, highlighting: You want to manually choose specific arbitrary text to highlight, and you want to choose the highlighting face to use for this or that chosen bit of text.
You can use library Highlight (highlight.el) to do that.
Command hlt-choose-default-face chooses the face to use for subsequent highlighting (it reads a face name or a color name, with completion).
Another way to choose the highlighting face is to use command
hlt-next-face or hlt-previous-face. These cycle among a
smaller set of faces and background colors, the elements in the
list value of option hlt-auto-face-backgrounds. You can use a
numeric prefix argument with these commands to choose any of the
elements by its absolute position in the list.
There are commands (e.g., hlt-highlight) to highlight or unhighlight the active region, or you can drag the mouse to highlight (or unhighlight). By default they use the last default face you chose.
For persistent highlighting, see Temporary or Permanent Highlighting.

How to disable Emacs auto moving command to right?

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.

Can we make an Emacs buffer to be static/pinned?

I use an Org file to keep track of my activities, because it's often that I am loosing track of what actually I am aiming to do :)
Now, I would like to reserved a top buffer window with only 5 lines tall and show the narrowed todo from that org file. All other window/buffer activites will not touch that static/pinned buffer.
Is there a way to achieve that result???
Thanks!
EDITED : Can we make that certain buffer to have different background Color? I pressume it's not, because all we have is set-background-color... I hope I am wrong..
Maybe setting the variable special-display-buffer-names will set you in the right direction.
(setq special-display-buffer-names
'(("magic buffer" (width . 70)
(height . 7)
(background-color . "green"))
))
to test certainly made a buffer called "magic buffer" turn up in a small and very very green frame. (For real-life use, of course do go through the customize mechanism by all means.)
ETA: And then, there's also this question which might apply here.
If you clock in to the Org TODO item, that task will be displayed in the modeline of the current buffer; you might also find that helpful as a reminder of what you're working on.
The original part of the question is a duplicate. See How do I make this Emacs frame keep its buffer and not get resized? (which is slightly enhanced over the earlier Pin Emacs buffers to windows (for cscope)), and the set-window-dedicated-p function.
YOu can use org-todo-list to show TODO items and org-agenda will show you useful choices such as "M" that filters your TODO items by keyword.
I struggled with the same problem for a while. The best solution I came up with was creating a small Emacs frame (size: 80x13) for my Org-mode agenda and placing it in an always-visible portion of my screen. (Use "C-x 5 2" to create a new frame.)

Emacs remember text selection

I decided that I was ready to try something new, after a few years of using gEdit for most of my coding needs, and try to learn using Emacs. I knew this would be difficult, as I have heard how complex Emacs can be, but I was lured by its power. The hardest thing has been getting used to writing ELisp in the .emacs file to change things about the editor. I can't currently do it myself, but I have found a few helpful snippets here and there to change some options.
One thing I have been having a lot of problems with is getting Emacs to remember the text I have selected after a command. For instance, I commonly highlight a section of code to mass indent it. However, if I do this in Emacs, it will move the selected text only once before unselecting all of the text. Does anyone know a way around this?
Anyway, I apologize for what seems to me to be an easy question, but after an hour of Google searching and looking around here on SO, I thought it was worth asking. I have a few more questions about Emacs, but I will save them and ask separately after I get this straightened out. Thanks!
UPDATE
A few people have asked about what mod I am using and what type of text I am entering. While I don't know much about Emacs modes, I am editing a pure text file at the moment. Something like this:
Hello, I am a simple text file
that is made up of three separate
lines.
If I highlight all three lines and hit TAB, I get this:
Hello, I am a simple text file
that is made up of three separate
lines.
This is great, however, if I use C-x C-x like some suggest below to reselect the text and hit TAB again, I get this:
Hello, I am a simple text file
that is made up of three separate
lines.
I hope this helps!
FWIW, here is the reason for the behaviour of your newly-added example. (I'm not 'solving' the issue here, but I'm posting it to demystify what you're seeing.)
This was determined with emacs -q which disables my customisations, so the following is default behaviour for emacs 23.2.
You are in text-mode. You should see (Text) or similar in the mode line at the bottom of the screen, and C-h m will tell you (under the list of minor modes) "Text mode: Major mode for editing text written for humans to read." Emacs decides (by way of the auto-mode-alist variable) that it should switch to text-mode if you visit a filename matching certain extensions (such as .txt).
In text-mode pressing TAB with a region highlighted causes indent-according-to-mode to be called on each line of the region in sequence. The slightly convoluted path to finding this out starts at C-h k TAB, which tells us that TAB is bound to indent-for-tab-command, which in this instance calls indent-region -- that function name is not stated explicitly in the help, but can be seen in the code -- which checks the buffer-local indent-region-function variable, which is nil, and: "A value of nil means really run indent-according-to-mode on each line."
indent-according-to-mode checks the indent-line-function variable, which has the buffer-local value indent-relative.
Use C-h f indent-relative RET to see the help for this function. (Read this).
Although you probably won't yet have had the experience to know how to check all that (or necessarily even want to!), and fully understand everything it tells you, this is an example of how the self-documenting aspect of Emacs enables a user to figure out what is going on (which then makes it feasible to change things). I essentially just used C-h k (describe-key), C-h f (describe-function), and C-h v (describe-variable) to follow the documentation. Looking at the source code for indent-for-tab-command was as simple as clicking the file name shown as part of its help page.
I suggest doing the following to help see what is happening when indent-relative runs on each line:
M-x set-variable x-stretch-cursor t
M-x set-variable ruler-mode-show-tab-stops t
M-x ruler-mode
Now for each line in turn, put the cursor at the very start of the line and press TAB. You'll end up with all three lines indented to the first tab-stop ('T' in the ruler).
Now repeat this -- again, ensure you are at the very start of each line, in front of the existing indentation.
The first character of the first line (which is currently a tab) is once again indented to the first tab-stop, as there is no preceding line for it to examine.
Next, the first character of the second line is indented to match the position of the first non-white-space character of the preceding line. Because the first character of the second line is also a tab, the actual text of the second line is pushed one tab further along.
The third line follows suit. Its first tab character is lined up with the first non-white-space character of the second line, with the same relative effect as before, giving you the final state in your example.
To emphasise, note what happens if you now put enter the line "a b c" above the existing lines, then move back to the start of the next line (what was previously the first line) and press TAB. The first tab character will now be indented in line with the 'b'. Provided that the indent-tabs-mode variable is true (meaning you have actual tab characters), then this will have no practical effect on the position of the words in the line, as 'indenting' a tab with spaces will not have an effect until the number of spaces exceeds the width of the tab (but that's another kettle of fish entirely!)
All this really means is that text-mode in Emacs doesn't behave the way you'd like it to in this situation. Other major modes can do completely different things when you press TAB, of course.
As is invariably the case with Emacs, things you don't like can be changed or circumvented with elisp. Some searching (especially at the Emacs Wiki) will frequently turn up useful solutions to problems you encounter.
Try typing C-x C-x after Emacs unselects it.
Then, instead of hitting tab (I never knew that tab does what you said! That's totally whacked.), do M-8 C-x C-i. Pity it's so many keys, but it ought to do what you want -- namely, shove everything over 8 columns. Obviously replace the M-8 with something else if you want some other number of columns.
What I usually do is simply type C-x C-x (exchange-point-and-mark) after a command that deactives the region.
How are you indenting, and in which mode?
The indentation rules in any programming mode should generally just get it right. (If they don't, that's probably more indicative that you want to configure the rules for that mode differently, but I suspect that's a different question which has been asked already).
If you're in text-mode or similar and just using TAB, then I can see the problem.
Note that if you're using indent-rigidly (C-x C-i, or C-x TAB which is the same thing) then you can repeatedly indent the same region simply by repeating the command, even if the highlighting has disappeared from view.
You can also use a prefix arg to indent-rigidly to make it indent many times. e.g. C-u C-u C-x C-i (easier to type than it looks) will indent 16 spaces (4 x 4, as the prefix arg defaults to 4, and it multiplies on each repeat). Similarly, M-8 C-x C-i indents 8 spaces. This is fine in some circumstances, and way too cumbersome in others.
Personally I suggest putting (cua-selection-mode 1) into your .emacs and using that for rigid indentation. Trey Jackson made a handy blog about it. With this, you can C-RET to start rectangle selection, down as many lines as you need, TAB repeatedly to indent the lines, and C-RET to exit the mode.
While the rectangle is active, RET cycles through the corners. For left-hand corners, typing inserts in front. For right-hand corners, typing inserts after. For the single-column rectangle, bottom counts as 'left' and top counts as 'right' for this purpose.
Trey's blog lists all the available features (or look in the source file: cua-base.el)
Be warned that indentation in Emacs is generally an unexpectedly complicated topic.
You can do this with something like the following:
(add-hook 'text-mode-hook (lambda ()
(set (make-local-variable 'indent-region-function)
(lambda (s e)
(indent-rigidly s e tab-width)))))
Then selecting a region and hitting TAB. will indent the region by a tab-width. You can then exchange point and mark with C-x C-x and hit TAB again to repeat.
I do, however, agree with the previous answers that suggest using indent-rigidly directly.

Why might my Emacs use spaces instead of tabs?

I am trying to diagnose this problem. TAB creates 4 spaces instead of a 4 col TAB like I want. But I don't think it should because C-h v indent-tabs-mode on the buffer in question says it is set to t. When I check my keybindings, TAB is set to c-indent-line-or-region. Does this function ignore my tabs-mode?
Tabs and indentation in Emacs is a considerably more complex subject than most people anticipate. I highly recommend spending some time reading about it -- it will almost certainly save you some confusion in the long run.
The following page at the Emacs Wiki groups together most of the relevant discussion:
http://www.emacswiki.org/emacs/CategoryIndentation
There's quite a lot there, but it's worth looking through.
One or other of the TabsAreEvil and SmartTabs configurations is quite likely to be appealing to you, btw, depending on your personal opinions on the subject!
Make sure you read the page on the tab-stop-list variable. It's tucked away near the bottom of that list of links, but it's critical to understanding the behaviour of tabs in the absence of automated-indentation rules, along with things like 'tabify'.
ruler-mode is useful here as well. I enable it automatically with text-mode:
;; Use ruler in text-mode
(add-hook 'text-mode-hook
(function (lambda ()
(setq ruler-mode-show-tab-stops t)
(ruler-mode 1))))
I figured out the problem. It was inserting a tab character after all. It turns out I thought it wasn't because when I hit backspace that key is bound to c-electric-backspace, which looks at the variable c-backspace-function which was set to backward-delete-char-untabify, which IMO defeats the purpose of having tabs.
Check tab-width variable. If it is 8 (the default), then Emacs of course has to insert four spaces since a tab would be "too much".
Check of the file for Emacs "File Local Variables". These specially formatted lines can override your settings when that file is loaded.
Here is an example from the bottom of a bit of Ruby code, forcing indent to 2 spaces, and tabs converted to spaces:
# Local Variables:
# tab-width: 2
# ruby-indent-level: 2
# indent-tabs-mode: nil
# End:
Be sure to take a look at the first line of the file as well. If you see something like
// -- tab-width: 4; Mode: C++; c-basic-offset: 4; indent-tabs-mode: nil --
This line will override any global or mode settings.