DummyHead

  • Home

  • Tags30

  • Categories16

  • Archives32

5.Orgmode TODO Items

Posted on 2019-05-21 | In linux - emacs - orgmode | Comments:

Org mode does not maintain TODO lists as separate documents37. Instead, TODO items are an integral part of the notes file, because TODO items usually come up while taking notes! With Org mode, simply mark any entry in a tree as being a TODO item. In this way, information is not duplicated, and the entire context from which the TODO item emerged is always present.

说得真好, to do items usually come up while taking notes. scatter

Of course, this technique for managing TODO items scatters them throughout your notes file. Org mode compensates for this by providing methods to give you an overview of all the things that you have to do.

• TODO Basics: Marking and displaying TODO entries.
• TODO Extensions: Workflow and assignments.
• Progress Logging: Dates and notes for progress.
• Priorities: Some things are more important than others.
• Breaking Down Tasks: Splitting a task into manageable pieces.
• Checkboxes: Tick-off lists.

5.1 Basic TODO Functionality

没啥东西, 略过.
Any headline becomes a TODO item when it starts with the word ‘TODO’, for example:

1
*** TODO Write letter to Sam Fortune

The most important commands to work with TODO entries are:

  • C-c C-t (org-todo)

    Rotate the TODO state of the current item among,-> (unmarked) -> TODO -> DONE --. '--------------------------------'If TODO keywords have fast access keys (see Fast access to TODO states), prompt for a TODO keyword through the fast selection interface; this is the default behavior when org-use-fast-todo-selection is non-nil.The same rotation can also be done “remotely” from the agenda buffer with the t command key (see Agenda Commands).

  • C-u C-c C-t

    When TODO keywords have no selection keys, select a specific keyword using completion; otherwise force cycling through TODO states with no prompt. When org-use-fast-todo-selection is set to prefix, use the fast selection interface.

  • S-RIGHT S-LEFT

    Select the following/preceding TODO state, similar to cycling. Useful mostly if more than two TODO states are possible (see TODO Extensions). See also Conflicts, for a discussion of the interaction with shift-selection-mode. See also the variable org-treat-S-cursor-todo-selection-as-state-change.

  • C-c / t (org-show-todo-tree)

    View TODO items in a sparse tree (see Sparse Trees). Folds the entire buffer, but shows all TODO items—with not-DONE state—and the headings hierarchy above them. With a prefix argument, or by using C-c / T, search for a specific TODO. You are prompted for the keyword, and you can also give a list of keywords like ‘KWD1|KWD2|…’ to list entries that match any one of these keywords. With a numeric prefix argument N, show the tree for the Nth keyword in the variable org-todo-keywords. With two prefix arguments, find all TODO states, both un-done and done.

  • M-x org-agenda t (org-todo-list)

    Show the global TODO list. Collects the TODO items (with not-DONE states) from all agenda files (see Agenda Views) into a single buffer. The new buffer is in Org Agenda mode, which provides commands to examine and manipulate the TODO entries from the new buffer (see Agenda Commands). See Global TODO list, for more information.

  • S-M-RET (org-insert-todo-heading)

    Insert a new TODO entry below the current one.

Changing a TODO state can also trigger tag changes. See the docstring of the option org-todo-state-tags-triggers for details.

5.2 Extended Use of TODO Keywords

todo list的多种状态.

By default, marked TODO entries have one of only two states: TODO and DONE. Org mode allows you to classify TODO items in more complex ways with TODO keywords (stored in org-todo-keywords). With special setup, the TODO keyword system can work differently in different files.

Note that tags are another way to classify headlines in general and TODO items in particular (see Tags).

• Workflow states: From TODO to DONE in steps.
• TODO types: I do this, Fred does the rest.
• Multiple sets in one file: Mixing it all, still finding your way.
• Fast access to TODO states: Single letter selection of state.
• Per-file keywords: Different files, different requirements.
• Faces for TODO keywords: Highlighting states.
• TODO dependencies: When one task needs to wait for others.

从2.1到2.7说来说去, 就只有一件事情:更多的关键词,采纳默认设置即可,不必要浪费时间。
总结前面这两章, 核心思想便是从note中写todo。

5.2.1 TODO keywords as workflow states

You can use TODO keywords to indicate different sequential states in the process of working on an item, for example38:

1
2
3
4
5
6
7
(setq org-todo-keywords
'((sequence "TODO" "FEEDBACK" "VERIFY" "|" "DONE" "DELEGATED")))

Its value is
((sequence "TODO(t)" "NEXT(n)" "|" "DONE(d!/!)")
(sequence "PROJECT(p)" "|" "DONE(d!/!)" "CANCELLED(c@/!)")
(sequence "WAITING(w@/!)" "DELEGATED(e!)" "HOLD(h)" "|" "CANCELLED(c@/!)"))

The vertical bar separates the TODO keywords (states that need action) from the DONE states (which need no further action). If you do not provide the separator bar, the last state is used as the DONE state.

With this setup, the command C-c C-t cycles an entry from ‘TODO’ to ‘FEEDBACK’, then to ‘VERIFY’, and finally to ‘DONE’ and ‘DELEGATED’. You may also use a numeric prefix argument to quickly select a specific state. For example C-3 C-c C-t changes the state immediately to ‘VERIFY’. Or you can use S-LEFT to go backward through the sequence. If you define many keywords, you can use in-buffer completion (see Completion) or even a special one-key selection scheme (see Fast access to TODO states) to insert these words into the buffer. Changing a TODO state can be logged with a timestamp, see Tracking TODO state changes, for more information.

5.2.2 TODO keywords as types

The second possibility is to use TODO keywords to indicate different types of action items. For example, you might want to indicate that items are for “work” or “home”. Or, when you work with several people on a single project, you might want to assign action items directly to persons, by using their names as TODO keywords. This would be set up like this:

1
(setq org-todo-keywords '((type "Fred" "Sara" "Lucy" "|" "DONE")))

In this case, different keywords do not indicate a sequence, but rather different types. So the normal work flow would be to assign a task to a person, and later to mark it DONE. Org mode supports this style by adapting the workings of the command C-c C-t39. When used several times in succession, it still cycles through all names, in order to first select the right type for a task. But when you return to the item after some time and execute C-c C-t again, it will switch from any name directly to ‘DONE’. Use prefix arguments or completion to quickly select a specific name. You can also review the items of a specific TODO type in a sparse tree by using a numeric prefix to C-c / t. For example, to see all things Lucy has to do, you would use C-3 C-c / t. To collect Lucy’s items from all agenda files into a single buffer, you would use the numeric prefix argument as well when creating the global TODO list: C-3 M-x org-agenda t.

5.2.3 Multiple keyword sets in one file

Sometimes you may want to use different sets of TODO keywords in parallel. For example, you may want to have the basic TODO/DONE, but also a workflow for bug fixing, and a separate state indicating that an item has been canceled—so it is not DONE, but also does not require action. Your setup would then look like this:

1
2
3
4
(setq org-todo-keywords
'((sequence "TODO" "|" "DONE")
(sequence "REPORT" "BUG" "KNOWNCAUSE" "|" "FIXED")
(sequence "|" "CANCELED")))

The keywords should all be different, this helps Org mode keep track of which subsequence should be used for a given entry. In this setup, C-c C-t only operates within a sub-sequence, so it switches from ‘DONE’ to (nothing) to ‘TODO’, and from ‘FIXED’ to (nothing) to ‘REPORT’. Therefore you need a mechanism to initially select the correct sequence. In addition to typing a keyword or using completion (see Completion), you may also apply the following commands:

  • C-u C-u C-c C-t

  • C-S-RIGHT

  • C-S-LEFT

    These keys jump from one TODO sub-sequence to the next. In the above example, C-u C-u C-c C-t or C-S-RIGHT would jump from ‘TODO’ or ‘DONE’ to ‘REPORT’, and any of the words in the second row to ‘CANCELED’. Note that the C-S- key binding conflict with shift-selection-mode (see Conflicts).

  • S-RIGHT

  • S-LEFT

    S-LEFT and S-RIGHT walk through all keywords from all sub-sequences, so for example S-RIGHT would switch from ‘DONE’ to ‘REPORT’ in the example above. For a discussion of the interaction with shift-selection-mode, see Conflicts.

5.2.4 Fast access to TODO states

If you would like to quickly change an entry to an arbitrary TODO state instead of cycling through the states, you can set up keys for single-letter access to the states. This is done by adding the selection character after each keyword, in parentheses40. For example:

1
2
3
4
(setq org-todo-keywords
'((sequence "TODO(t)" "|" "DONE(d)")
(sequence "REPORT(r)" "BUG(b)" "KNOWNCAUSE(k)" "|" "FIXED(f)")
(sequence "|" "CANCELED(c)")))

If you then press C-c C-t followed by the selection key, the entry is switched to this state. SPC can be used to remove any TODO keyword from an entry41.

5.2.5 Setting up keywords for individual files

本节目前用不着.

It can be very useful to use different aspects of the TODO mechanism in different files. For file-local settings, you need to add special lines to the file which set the keywords and interpretation for that file only. For example, to set one of the two examples discussed above, you need one of the following lines, starting in column zero anywhere in the file:

1
#+TODO: TODO FEEDBACK VERIFY | DONE CANCELED

You may also write ‘#+SEQ_TODO’ to be explicit about the interpretation, but it means the same as ‘#+TODO’, or

1
#+TYP_TODO: Fred Sara Lucy Mike | DONE

A setup for using several sets in parallel would be:

1
2
3
#+TODO: TODO | DONE
#+TODO: REPORT BUG KNOWNCAUSE | FIXED
#+TODO: | CANCELED

To make sure you are using the correct keyword, type ‘#+’ into the buffer and then use M-TAB to complete it (see Completion).

Remember that the keywords after the vertical bar—or the last keyword if no bar is there—must always mean that the item is DONE, although you may use a different word. After changing one of these lines, use C-c C-c with point still in the line to make the changes known to Org mode42.

5.2.6 Faces for TODO keywords

Org mode highlights TODO keywords with special faces: org-todo for keywords indicating that an item still has to be acted upon, and org-done for keywords indicating that an item is finished. If you are using more than two different states, you might want to use special faces for some of them. This can be done using the variable org-todo-keyword-faces. For example:

1
2
3
(setq org-todo-keyword-faces
'(("TODO" . org-warning) ("STARTED" . "yellow")
("CANCELED" . (:foreground "blue" :weight bold))))

While using a list with face properties as shown for ‘CANCELED’ should work, this does not always seem to be the case. If necessary, define a special face and use that. A string is interpreted as a color. The variable org-faces-easy-properties determines if that color is interpreted as a foreground or a background color.

5.2.7 TODO dependencies

The structure of Org files—hierarchy and lists—makes it easy to define TODO dependencies. Usually, a parent TODO task should not be marked DONE until all TODO subtasks, or children tasks, are marked as DONE. Sometimes there is a logical sequence to (sub)tasks, so that one subtask cannot be acted upon before all siblings above it have been marked DONE. If you customize the variable org-enforce-todo-dependencies, Org blocks entries from changing state to DONE while they have TODO children that are not DONE. Furthermore, if an entry has a property ‘ORDERED’, each of its TODO children is blocked until all earlier siblings are marked DONE. Here is an example:

1
2
3
4
5
6
7
8
9
10
11
* TODO Blocked until (two) is done
** DONE one
** TODO two

* Parent
:PROPERTIES:
:ORDERED: t
:END:
** TODO a
** TODO b, needs to wait for (a)
** TODO c, needs to wait for (a) and (b)

You can ensure an entry is never blocked by using the ‘NOBLOCKING’ property (see Properties and Columns):

1
2
3
4
* This entry is never blocked
:PROPERTIES:
:NOBLOCKING: t
:END:
  • C-c C-x o (org-toggle-ordered-property)

    Toggle the ‘ORDERED’ property of the current entry. A property is used for this behavior because this should be local to the current entry, not inherited from entries above like a tag (see Tags). However, if you would like to track the value of this property with a tag for better visibility, customize the variable org-track-ordered-property-with-tag.

  • C-u C-u C-u C-c C-t

    Change TODO state, regardless of any state blocking.

If you set the variable org-agenda-dim-blocked-tasks, TODO entries that cannot be marked DONE because of unmarked children are shown in a dimmed font or even made invisible in agenda views (see Agenda Views).

You can also block changes of TODO states by using checkboxes (see Checkboxes). If you set the variable org-enforce-todo-checkbox-dependencies, an entry that has unchecked checkboxes is blocked from switching to DONE.

If you need more complex dependency structures, for example dependencies between entries in different trees or files, check out the contributed module ‘org-depend.el’.

5.3 Progress Logging

不需要阅读就会应用的章节。 是todo最重要的部分。

Org mode can automatically record a timestamp and optionally a note when you mark a TODO item as DONE, or even each time you change the state of a TODO item. This system is highly configurable, settings can be on a per-keyword basis and can be localized to a file or even a subtree. For information on how to clock working time for a task, see Clocking Work Time.

• Closing items: When was this entry marked DONE?
• Tracking TODO state changes: When did the status change?
• Tracking your habits: How consistent have you been?

只有一句话, 有habit这个property.

5.3.1 Closing items

The most basic logging is to keep track of when a certain TODO item was marked DONE. This can be achieved with43

1
(setq org-log-done 'time)

Then each time you turn an entry from a TODO (not-done) state into any of the DONE states, a line ‘CLOSED: [timestamp]’ is inserted just after the headline. If you turn the entry back into a TODO item through further state cycling, that line is removed again. If you turn the entry back to a non-TODO state (by pressing C-c C-t SPC for example), that line is also removed, unless you set org-closed-keep-when-no-todo to non-nil. If you want to record a note along with the timestamp, use44

1
(setq org-log-done 'note)

You are then be prompted for a note, and that note is stored below the entry with a ‘Closing Note’ heading.

5.3.2 Tracking TODO state changes

目前我用不着.

When TODO keywords are used as workflow states (see *Workflow states), you might want to keep track of when a state change occurred and maybe take a note about this change. You can either record just a timestamp, or a time-stamped note. These records are inserted after the headline as an itemized list, newest first45. When taking a lot of notes, you might want to get the notes out of the way into a drawer (see Drawers). Customize the variable org-log-into-drawer to get this behavior—the recommended drawer for this is called ‘LOGBOOK’46. You can also overrule the setting of this variable for a subtree by setting a ‘LOG_INTO_DRAWER’ property.

Since it is normally too much to record a note for every state, Org mode expects configuration on a per-keyword basis for this. This is achieved by adding special markers ‘!’ (for a timestamp) or ‘@’ (for a note with timestamp) in parentheses after each keyword. For example, with the setting

1
2
(setq org-todo-keywords
'((sequence "TODO(t)" "WAIT(w@/!)" "|" "DONE(d!)" "CANCELED(c@)")))

to record a timestamp without a note for TODO keywords configured with ‘@’, just type C-c C-c to enter a blank note when prompted.

You not only define global TODO keywords and fast access keys, but also request that a time is recorded when the entry is set to ‘DONE’, and that a note is recorded when switching to ‘WAIT’ or ‘CANCELED’47. The setting for ‘WAIT’ is even more special: the ‘!’ after the slash means that in addition to the note taken when entering the state, a timestamp should be recorded when leaving the ‘WAIT’ state, if and only if the target state does not configure logging for entering it. So it has no effect when switching from ‘WAIT’ to ‘DONE’, because ‘DONE’ is configured to record a timestamp only. But when switching from ‘WAIT’ back to ‘TODO’, the ‘/!’ in the ‘WAIT’ setting now triggers a timestamp even though ‘TODO’ has no logging configured.

You can use the exact same syntax for setting logging preferences local to a buffer:

1
#+TODO: TODO(t) WAIT(w@/!) | DONE(d!) CANCELED(c@)

In order to define logging settings that are local to a subtree or a single item, define a ‘LOGGING’ property in this entry. Any non-empty ‘LOGGING’ property resets all logging settings to nil. You may then turn on logging for this specific tree using ‘STARTUP’ keywords like ‘lognotedone’ or ‘logrepeat’, as well as adding state specific settings like ‘TODO(!)’. For example:

1
2
3
4
5
6
7
8
9
10
11
12
* TODO Log each state with only a time
:PROPERTIES:
:LOGGING: TODO(!) WAIT(!) DONE(!) CANCELED(!)
:END:
* TODO Only log when switching to WAIT, and when repeating
:PROPERTIES:
:LOGGING: WAIT(@) logrepeat
:END:
* TODO No logging at all
:PROPERTIES:
:LOGGING: nil
:END:

5.3.3 Tracking your habits

了解到有habit这个property即可, 使用heading处理更方便.

Org has the ability to track the consistency of a special category of TODO, called “habits.” To use habits, you have to enable the habits module by customizing the variable org-modules.

A habit has the following properties:

  1. The habit is a TODO item, with a TODO keyword representing an open state.
  2. The property ‘STYLE’ is set to the value ‘habit’ (see Properties and Columns).
  3. The TODO has a scheduled date, usually with a ‘.+’ style repeat interval. A ‘++’ style may be appropriate for habits with time constraints, e.g., must be done on weekends, or a ‘+’ style for an unusual habit that can have a backlog, e.g., weekly reports.
  4. The TODO may also have minimum and maximum ranges specified by using the syntax ‘.+2d/3d’, which says that you want to do the task at least every three days, but at most every two days.
  5. State logging for the DONE state is enabled (see Tracking TODO state changes), in order for historical data to be represented in the consistency graph. If it is not enabled it is not an error, but the consistency graphs are largely meaningless.

To give you an idea of what the above rules look like in action, here’s an actual habit with some history:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
** TODO Shave
SCHEDULED: <2009-10-17 Sat .+2d/4d>
:PROPERTIES:
:STYLE: habit
:LAST_REPEAT: [2009-10-19 Mon 00:36]
:END:
- State "DONE" from "TODO" [2009-10-15 Thu]
- State "DONE" from "TODO" [2009-10-12 Mon]
- State "DONE" from "TODO" [2009-10-10 Sat]
- State "DONE" from "TODO" [2009-10-04 Sun]
- State "DONE" from "TODO" [2009-10-02 Fri]
- State "DONE" from "TODO" [2009-09-29 Tue]
- State "DONE" from "TODO" [2009-09-25 Fri]
- State "DONE" from "TODO" [2009-09-19 Sat]
- State "DONE" from "TODO" [2009-09-16 Wed]
- State "DONE" from "TODO" [2009-09-12 Sat]

What this habit says is: I want to shave at most every 2 days—given by the ‘SCHEDULED’ date and repeat interval—and at least every 4 days. If today is the 15th, then the habit first appears in the agenda (see Agenda Views) on Oct 17, after the minimum of 2 days has elapsed, and will appear overdue on Oct 19, after four days have elapsed.

What’s really useful about habits is that they are displayed along with a consistency graph, to show how consistent you’ve been at getting that task done in the past. This graph shows every day that the task was done over the past three weeks, with colors for each day. The colors used are:

  • Blue

    If the task was not to be done yet on that day.

  • Green

    If the task could have been done on that day.

  • Yellow

    If the task was going to be overdue the next day.

  • Red

    If the task was overdue on that day.

In addition to coloring each day, the day is also marked with an asterisk if the task was actually done that day, and an exclamation mark to show where the current day falls in the graph.

There are several configuration variables that can be used to change the way habits are displayed in the agenda.

  • org-habit-graph-column

    The buffer column at which the consistency graph should be drawn. This overwrites any text in that column, so it is a good idea to keep your habits’ titles brief and to the point.

  • org-habit-preceding-days

    The amount of history, in days before today, to appear in consistency graphs.

  • org-habit-following-days

    The number of days after today that appear in consistency graphs.

  • org-habit-show-habits-only-for-today

    If non-nil, only show habits in today’s agenda view. The default value is t.

Lastly, pressing K in the agenda buffer causes habits to temporarily be disabled and do not appear at all. Press K again to bring them back. They are also subject to tag filtering, if you have habits which should only be done in certain contexts, for example.

5.4 Priorities

可以用作四象限时间管理.

If you use Org mode extensively, you may end up with enough TODO items that it starts to make sense to prioritize them. Prioritizing can be done by placing a priority cookie into the headline of a TODO item, like this

1
*** TODO [#A] Write letter to Sam Fortune

By default, Org mode supports three priorities: ‘A’, ‘B’, and ‘C’. ‘A’ is the highest priority. An entry without a cookie is treated as equivalent if it had priority ‘B’. Priorities make a difference only for sorting in the agenda (see Weekly/daily agenda); outside the agenda, they have no inherent meaning to Org mode. The cookies are displayed with the face defined by the variable org-priority-faces, which can be customized.

Priorities can be attached to any outline node; they do not need to be TODO items.

  • C-c , (org-priority)

    Set the priority of the current headline. The command prompts for a priority character ‘A’, ‘B’ or ‘C’. When you press SPC instead, the priority cookie, if one is set, is removed from the headline. The priorities can also be changed “remotely” from the agenda buffer with the , command (see Agenda Commands).

  • S-UP (org-priority-up)

  • S-DOWN (org-priority-down)

    Increase/decrease the priority of the current headline48. Note that these keys are also used to modify timestamps (see Creating Timestamps). See also Conflicts, for a discussion of the interaction with shift-selection-mode.

You can change the range of allowed priorities by setting the variables org-highest-priority, org-lowest-priority, and org-default-priority. For an individual buffer, you may set these values (highest, lowest, default) like this (please make sure that the highest priority is earlier in the alphabet than the lowest priority):

1
#+PRIORITIES: A C B

5.5 Breaking Down Tasks into Subtasks

需要记住的属性,cookie data

It is often advisable to break down large tasks into smaller, manageable subtasks. You can do this by creating an outline tree below a TODO item, with detailed subtasks on the tree49. To keep an overview of the fraction of subtasks that have already been marked DONE, insert either ‘[/]’ or ‘[%]’ anywhere in the headline. These cookies are updated each time the TODO status of a child changes, or when pressing C-c C-c on the cookie. For example:

1
2
3
4
5
6
* Organize Party [33%]
** TODO Call people [1/2]
*** TODO Peter
*** DONE Sarah
** TODO Buy food
** DONE Talk to neighbor

If a heading has both checkboxes and TODO children below it, the meaning of the statistics cookie become ambiguous. Set the property ‘COOKIE_DATA’ to either ‘checkbox’ or ‘todo’ to resolve this issue.

这里的含义是如果不设置则二者都会自动显示出来. 

If you would like to have the statistics cookie count any TODO entries in the subtree (not just direct children), configure the variable org-hierarchical-todo-statistics. To do this for a single subtree, include the word ‘recursive’ into the value of the ‘COOKIE_DATA’ property.

1
2
3
4
5
#修改为recursive这一点很不错. 
* Parent capturing statistics [2/20]
:PROPERTIES:
:COOKIE_DATA: todo recursive
:END:

If you would like a TODO entry to automatically change to DONE when all children are done, you can use the following setup:

1
2
3
4
5
6
(defun org-summary-todo (n-done n-not-done)
"Switch entry to DONE when all subentries are done, to TODO otherwise."
(let (org-log-done org-log-states) ; turn off logging
(org-todo (if (= n-not-done 0) "DONE" "TODO"))))

(add-hook 'org-after-todo-statistics-hook 'org-summary-todo)

Another possibility is the use of checkboxes to identify (a hierarchy of) a large number of subtasks (see Checkboxes).

5.6 Checkboxes

应用分数表示, 并且随时更新.
键入checkbox即可.

Every item in a plain list50 (see Plain Lists) can be made into a checkbox by starting it with the string ‘[ ]’. This feature is similar to TODO items (see TODO Items), but is more lightweight. Checkboxes are not included into the global TODO list, so they are often great to split a task into a number of simple steps. Or you can use them in a shopping list. To toggle a checkbox, use C-c C-c, or use the mouse (thanks to Piotr Zielinski’s ‘org-mouse.el’).

Here is an example of a checkbox list.

1
2
3
4
5
6
7
8
* TODO Organize party [2/4]
- [-] call people [1/3]
- [ ] Peter
- [X] Sarah
- [ ] Sam
- [X] order food
- [ ] think about what music to play
- [X] talk to the neighbors

Checkboxes work hierarchically, so if a checkbox item has children that are checkboxes, toggling one of the children checkboxes makes the parent checkbox reflect if none, some, or all of the children are checked.

The ‘[2/4]’ and ‘[1/3]’ in the first and second line are cookies indicating how many checkboxes present in this entry have been checked off, and the total number of checkboxes present. This can give you an idea on how many checkboxes remain, even without opening a folded entry. The cookies can be placed into a headline or into (the first line of) a plain list item. Each cookie covers checkboxes of direct children structurally below the headline/item on which the cookie appears51. You have to insert the cookie yourself by typing either ‘[/]’ or ‘[%]’. With ‘[/]’ you get an ‘n out of m’ result, as in the examples above. With ‘[%]’ you get information about the percentage of checkboxes checked (in the above example, this would be ‘[50%]’ and ‘[33%]’, respectively). In a headline, a cookie can count either checkboxes below the heading or TODO states of children, and it displays whatever was changed last. Set the property ‘COOKIE_DATA’ to either ‘checkbox’ or ‘todo’ to resolve this issue.

If the current outline node has an ‘ORDERED’ property, checkboxes must be checked off in sequence, and an error is thrown if you try to check off a box while there are unchecked boxes above it.

The following commands work with checkboxes:

  • C-c C-c (org-toggle-checkbox)

    Toggle checkbox status or—with prefix argument—checkbox presence at point. With a single prefix argument, add an empty checkbox or remove the current one52. With a double prefix argument, set it to ‘[-]’, which is considered to be an intermediate state.

  • C-c C-x C-b (org-toggle-checkbox) 快捷键的含义是checkbox

    Toggle checkbox status or—with prefix argument—checkbox presence at point. With double prefix argument, set it to ‘[-]’, which is considered to be an intermediate state.If there is an active region, toggle the first checkbox in the region and set all remaining boxes to the same status as the first. With a prefix argument, add or remove the checkbox for all items in the region.If point is in a headline, toggle checkboxes in the region between this headline and the next—so not the entire subtree.If there is no active region, just toggle the checkbox at point.

  • M-S-RET (org-insert-todo-heading)

    Insert a new item with a checkbox. This works only if point is already in a plain list item (see Plain Lists).

  • C-c C-x o (org-toggle-ordered-property)

    Toggle the ‘ORDERED’ property of the entry, to toggle if checkboxes must be checked off in sequence. A property is used for this behavior because this should be local to the current entry, not inherited like a tag. However, if you would like to track the value of this property with a tag for better visibility, customize org-track-ordered-property-with-tag.

  • C-c # (org-update-statistics-cookies)

    Update the statistics cookie in the current outline entry. When called with a C-u prefix, update the entire file. Checkbox statistic cookies are updated automatically if you toggle checkboxes with C-c C-c and make new ones with M-S-RET. TODO statistics cookies update when changing TODO states. If you delete boxes/entries or add/change them by hand, use this command to get things back into sync.

总结

两个要点: 一是breakdown 二是priority,
Logging的部分放在clock那里
特殊的的property是cookie-data, 用的时候再来查询.
其余内容无需关注.

使用Termux把Android手机变成SSH服务器

Posted on 2019-05-20 | Edited on 2019-06-02 | In networking - ssh | Comments:

概要

Termux是一款能够为Android手机提供Linux环境的应用。它最大的特点就是无需root,而且自带pkg包管理软件,可以很方便的其他linux应用。

  • Termux
  • Termux

手机安装Termux

可以在Google Play Store或F-Droid上搜索Termux来安装,目前的版本是0.47。

安装sshd

打开 Termux 会出现一个类似Linux终端的界面。

由于sshd是包含在openssh包中的,因此我们首先需要在Termux中安装openssh

1
pkg install openssh

安装好之后,我们需要手工启动 sshd

1
2
sshd
#当链接不上的时候, 也需要手工启动sshd

需要指出的是, sshd 监听的是8022端口而不是22号端口,因此可以使用下面命令来验证ssh服务是否开启
这里是需要特别注意的一点.

1
2
3
ssh localhost -p 8022 #助记, 80是http端口, 22是ssh端口
#提示输入密码
passwd#设置密码
  • Password to ssh connec to termux - Android Enthusiasts Stack Exchange

若要查看sshd的日志,则可以在Termux上执行

1
logcat -s 'syslog:*'

添加Public key

Termux的sshd只能通过密钥登陆,因此你需要在linux客户机上生成密钥对

1
ssh-keygen

把linux客户机上的公钥加到Termux中的 .ssh/authorized_keys,这一步比较麻烦

因为你无法使用 ssh-copy-id,只能先把 id_rsa.pub 拷贝到手机上,再在手机上打开该文件,拷贝文件内容后在Termux中用 vi 打开 authorized_keys,并复制内容进去.

不过如果linux客户机上本身也开启了ssh服务的话,则会简单很多,可以在Termux上执行,

1
2
3
$ scp -P 8022 /home/me/.ssh/id_rsa.pub  192.168.1.204:~ 
me@192.168.1.204's password:
id_rsa.pub

就行了,其中linux_clinet为linux客户机的地址,user为登陆用户

客户端登陆

在客户端上执行

1
ssh 192.4.4.9 -p 8022

将这里的 192.4.4.9 修改为手机的ip,就能登陆到Termux中了。

手机ip可以通过在 Termux 中运行 ifconfig -a 来查看。

需要说明的是,使用ssh登陆Termux时无需带上用户名,因为Termux是单用户系统。即使你登陆时带上了用户名,Termux也会忽略该用户名

为了方便,我们可以配置一下ssh client的配置文件,将下面内容加入到 ~/.ssh/config 文件中

1
2
3
Host termux
HostName 192.4.4.9
Port 8022

这样只需要执行 ssh termux 就能登陆termx了.

Emacs时间管理之Datetime与Clock工具

Posted on 2019-05-18 | Edited on 2019-06-01 | In linux - emacs - orgmode | Comments:

前文概要:

时间管理的三件工具
(clock, datetime, calendar)

时间变量的顺序与时间表示的格式
(%a %b-d %H:%M %Y)

Emacs中的时间格式与任务的时间属性

时间管理的三件工具: 钟表, 日历, 以及二者结合的便利工具datetime.

The Org Manual: Dates and Times主要应用datetime和clock两个工具管理时间.

  • 时间戳的格式 (Datetime)

    • datetime格式 <2019-05-18 sat 09:52> C-u C-c . 6个时间变量 %Y-%m-%d %a %H:%M

    • date格式 <2019-05-18 sat> C-c . 4个时间变量

Datetime时间戳与任务的时间属性

  • 时间(戳)到底什么?
    时间戳从概念上辨析为两个类别 1) appointment 2) schedule.
    可以将主动安排的时间理解为schedule, 被动参与的时间为appointment

  • 事件(任务)的四个时间属性

    • Repeater
      三种repeater,
      1) standard 时间戳后面 +1w day, week, month, year
      2) 过期后只需要补上一次, ++1w(比如每周给父母打电话)
      3) 以档次完成时间为下一个interval的开始点,比如3个周理一次发. 理发 .+3w; 任何时间点上理完发,自动从该时间点上启动下一轮repeat.

    • Time Span
      会议的时间
      <2019-05-18 sat 10:04>–<2019-05-18 sat 10:05>

    • Scheduled
      任务的开始时间,
      SCHEDULED: <2019-05-18 sat>

    • Deadline
      任务的截止时间
      DEADLINE: <2019-05-18 sat>

  • 任务的监控与跟踪 Check
    整合管理deadline与schedule.
    • org-check-deadlines, C-7 C-c / d #7天内将要截止的任务.变量org-deadline-warning-days
    • org-check-before-date, given-date前的schedule and appointments
    • org-check-after-date, given-date后的schedule and appointments.

Clock计时与中断处理

  1. 基本计时功能,
    org-clock-in, org-clock-out
    可以手动修改计时, 然后调用org-evaluate-time-range或者update-maybe

  2. 任务的第五个属性, efforts
    总结任务的5个属性,1)schedule 2) deadline 3)repeater 4)time span 5)预测的time span(efforts).
    efforts是核心参数,逐步提高对时间和任务的掌控.

  1. Resolve idle time and continuous clocking
    中断计时的问题,调出来org-resolve-clocks重新设置.k(keep), s(substract),只用keep便可.
    总结:
    1) 计时与计算 2) 任务的5个时间属性 3)idle中断计时的处理.

Date and Time in Emacs

Posted on 2019-05-18 | Edited on 2019-06-02 | In linux - emacs - orgmode | Comments:

8.1 Timestamps, Deadlines and Scheduling

A timestamp is a specification of a date (possibly with a time or a range of times) in a special format, either ‘<2003-09-16 tue>’ or ‘<2003-09-16 tue 09:39>’ or ‘<2003-09-16 tue 12:00-12:30>’[^1] A timestamp can appear anywhere in the headline or body of an Org tree entry. Its presence causes entries to be shown on specific dates in the agenda (see Weekly/daily agenda). We distinguish:

timestamp, 几个基本概念与变量,
时间戳的顺序,appointment(schedule),  repeater, 还有time range.
所以此处是时间戳, appointment(scheduel)

  1. Plain timestamp; Event; Appointment

    A simple timestamp just assigns a date/time to an item. This is just like writing down an appointment or event in a paper agenda. In the agenda display, the headline of an entry associated with a plain timestamp is shown exactly on that date.

    1
    2
    3
    <2006-11-01 Wed 19:15> 
    * Discussion on climate change
    <2006-11-02 Thu 20:00-22:00> `
    1. Tmestamp with repeater interval(repeater)

    A timestamp may contain a repeater interval, indicating that it applies not only on the given date, but again and again after a certain interval of N days (d), weeks (w), months (m), or years (y). The following shows up in the agenda every Wednesday:

    1
    2
    * Pick up Sam at school   
    <2007-05-16 Wed 12:30 +1w>q
  2. Diary-style sexp entries (这一项可以去掉)

    For more complex date specifications, Org mode supports using the special sexp diary entries implemented in the Emacs calendar/diary package. For example, with optional time:

​ <%%(diary-float t 4 2)>

  1. Time/Date range

    Two timestamps connected by ‘–’ denote a range. The headline is shown on the first and last day of the range, and on any dates that are displayed and fall in the range. Here is an example:

    1
    2
    ** Meeting in Amsterdam
    <2004-08-23 Mon>--<2004-08-26 Thu>
  2. Inactive timestamp

    Just like a plain timestamp, but with square brackets instead of angular ones. These timestamps are inactive in the sense that they do not trigger an entry to show up in the agenda.

    1
    2
    * Gillian comes late for the fifth time   
    [2006-11-01 Wed]

interval(range), repeater,

8.2 Creating Timestamps

For Org mode to recognize timestamps, they need to be in the specific format. All commands listed below produce timestamps in the correct format.

  • C-c . (org-time-stamp)

    Prompt for a date and insert a corresponding timestamp. When point is at an existing timestamp in the buffer, the command is used to modify this timestamp instead of inserting a new one. When this command is used twice in succession, a time range is inserted.When called with a prefix argument, use the alternative format which contains date and time. The default time can be rounded to multiples of 5 minutes. See the option org-time-stamp-rounding-minutes.With two prefix arguments, insert an active timestamp with the current time without prompting.

  • C-c > (org-goto-calendar)

    Access the Emacs calendar for the current date. If there is a timestamp in the current line, go to the corresponding date instead.

只有以上两个常用的快捷键,

<2019-05-16 thu> C-c C-.

<2019-05-16 thu 15:45> #C-u C-c C-.

<2019-05-16 thu 15:46>–<2019-05-16 thu 15:46> #Consecutive

另外还有两节无关紧要的内容.

8.2.1 The Org Manual: The date/time prompt

8.2.2 The Org Manual: Custom time format

q

8.3 Deadlines and Scheduling

A timestamp may be preceded by special keywords to facilitate planning. Both the timestamp and the keyword have to be positioned immediately after the task they refer to.

  • ‘DEADLINE’

    Meaning: the task (most likely a TODO item, though not necessarily) is supposed to be finished on that date.

    On the deadline date, the task is listed in the agenda. In addition, the agenda for today carries a warning about the approaching or missed deadline, starting org-deadline-warning-daysbefore the due date, and continuing until the entry is marked DONE. An example:

    1
    2
    3
    *** TODO write article about the Earth for the Guide
    DEADLINE: <2004-02-29 Sun>
    The editor in charge is [[bbdb:Ford Prefect]]

    You can specify a different lead time for warnings for a specific deadlines using the following syntax. Here is an example with a warning period of 5 days

    1
    DEADLINE: <2004-02-29 Sun -5d>

    宕开一笔, 这里的-5d与find中处理时间的思路是一致的.

    1
    2
    3
    4
    >      +n     for greater than n,
    > - n for less than n,
    > n for exactly n.
    >

    This warning is deactivated if the task gets scheduled and you set org-agenda-skip-deadline-prewarning-if-scheduled to t.

  • ‘SCHEDULED’

    Meaning: you are planning to start working on that task on the given date.

    The headline is listed under the given date66. In addition, a reminder that the scheduled date has passed is present in the compilation for today, until the entry is marked DONE, i.e., the task is automatically forwarded until completed.

    1
    2
    *** TODO Call Trillian for a date on New Years Eve.
    SCHEDULED: <2004-12-25 Sat>

    If you want to delay the display of this task in the agenda, use SCHEDULED: <2004-12-25 Sat -2d>: the task is still scheduled on the 25th but will appear two days later. In case the task contains a repeater, the delay is considered to affect all occurrences; if you want the delay to only affect the first scheduled occurrence of the task, use ‘–2d’ instead. See org-scheduled-delay-days and org-agenda-skip-scheduled-delay-if-deadline for details on how to control this globally or per agenda.

    Important:

    Setting a date for a meeting is just a simple appointment, you should mark this entry with a simple plain timestamp, to get this item shown on the date where it applies. This is a frequent misunderstanding by Org users. In Org mode, scheduling means setting a date when you want to start working on an action item.

    区别schedule and appointments.

You may use timestamps with repeaters in scheduling and deadline entries. Org mode issues early and late warnings based on the assumption that the timestamp represents the nearest instance of the repeater. However, the use of diary S-exp entries like

1
<%%(diary-float t 42)>

in scheduling and deadline timestamps is limited. Org mode does not know enough about the internals of each S-exp function to issue early and late warnings. However, it shows the item on each day where the S-exp entry matches.

总结
核心收获一是区别appointment and schedule, 二是对deadline和schedule的准确定义.

8.3.1 Inserting deadlines or schedules

The following commands allow you to quickly insert a deadline or to schedule an item:67

  • C-c C-d (org-deadline)

    Insert ‘DEADLINE’ keyword along with a stamp. The insertion happens in the line directly following the headline. Remove any ‘CLOSED’ timestamp . When called with a prefix argument, also remove any existing deadline from the entry. Depending on the variable org-log-redeadline, take a note when changing an existing deadline68.

  • C-c C-s (org-schedule)

    Insert ‘SCHEDULED’ keyword along with a stamp. The insertion happens in the line directly following the headline. Remove any ‘CLOSED’ timestamp. When called with a prefix argument, also remove the scheduling date from the entry. Depending on the variable org-log-reschedule, take a note when changing an existing scheduling time69.

  • C-c C-x C-k (org-mark-entry-for-agenda-action)

    Mark the current entry for agenda action. After you have marked the entry like this, you can open the agenda or the calendar to find an appropriate date. With point on the selected date, pressk s or k d to schedule the marked item.

  • C-c / d (org-check-deadlines)

    Create a sparse tree with all deadlines that are either past-due, or which will become due within org-deadline-warning-days. With C-u prefix, show all deadlines in the file. With a numeric prefix, check that many days. For example, C-1 C-c / d shows all deadlines due tomorrow.

  • C-c / b (org-check-before-date)

    Sparse tree for deadlines and scheduled items before a given date.

  • C-c / a (org-check-after-date)

    Sparse tree for deadlines and scheduled items after a given date.

Note that org-schedule and org-deadline supports setting the date by indicating a relative time e.g., ‘+1d’ sets the date to the next day after today, and ‘–1w’ sets the date to the previous week before any current timestamp.

注意事项, 在headline与schedule, deadline之间不要插入任何内容.Do not put any text between this line and the headline.

8.3.2 Repeated tasks

Some tasks need to be repeated again and again. Org mode helps to organize such tasks using a so-called repeater in a ‘DEADLINE’, ‘SCHEDULED’, or plain timestamps70. In the following example:

1
2
** TODO Pay the rent
DEADLINE: <2005-10-01 Sat +1m>

the ‘+1m’ is a repeater; the intended interpretation is that the task has a deadline on ‘<2005-10-01>’ and repeats itself every (one) month starting from that time. You can use yearly, monthly, weekly, daily and hourly repeat cookies by using the ‘y’, ‘w’, ‘m’, ‘d’ and ‘h’ letters. If you need both a repeater and a special warning period in a deadline entry, the repeater should come first and the warning period last

1
DEADLINE: <2005-10-01 Sat +1m -3d>

Deadlines and scheduled items produce entries in the agenda when they are over-due, so it is important to be able to mark such an entry as DONE once you have done so. When you mark a ‘DEADLINE’ or a ‘SCHEDULED’ with the TODO keyword ‘DONE’, it no longer produces entries in the agenda. The problem with this is, however, is that then also the next instance of the repeated entry will not be active. Org mode deals with this in the following way: when you try to mark such an entry DONE, using C-c C-t, it shifts the base date of the repeating timestamp by the repeater interval, and immediately sets the entry state back to TODO71. In the example above, setting the state to DONE would actually switch the date like this:

1
2
** TODO Pay the rent
DEADLINE: <2005-11-01 Tue +1m>

To mark a task with a repeater as DONE, use C– 1 C-c C-t, i.e., org-todo with a numeric prefix argument of ‘-1’

prefix argument是终极的done

A timestamp72 is added under the deadline, to keep a record that you actually acted on the previous instance of this deadline.

As a consequence of shifting the base date, this entry is no longer visible in the agenda when checking past dates, but all future instances will be visible.

With the ‘+1m’ cookie, the date shift is always exactly one month. So if you have not paid the rent for three months, marking this entry DONE still keeps it as an overdue deadline. Depending on the task, this may not be the best way to handle it. For example, if you forgot to call your father for 3 weeks, it does not make sense to call him 3 times in a single day to make up for it. Finally, there are tasks like changing batteries which should always repeat a certain time after the last time you did it. For these tasks, Org mode has special repeaters ‘++’ and ‘.+’. For example:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
** TODO Call Father
DEADLINE: <2008-02-10 Sun ++1w>
Marking this DONE shifts the date by at least one week, but also
by as many weeks as it takes to get this date into the future.
However, it stays on a Sunday, even if you called and marked it
done on Saturday.

** TODO Empty kitchen trash
DEADLINE: <2008-02-08 Fri 20:00 ++1d>
Marking this DONE shifts the date by at least one day, and also
by as many days as it takes to get the timestamp into the future.
Since there is a time in the timestamp, the next deadline in the
future will be on today's date if you complete the task before
20:00.

** TODO Check the batteries in the smoke detectors
DEADLINE: <2005-11-01 Tue .+1m>
Marking this DONE will shift the date to one month after today.

这里的两个选项好有意思呀.
还有一点只有appointment的meeting使用plain.

You may have both scheduling and deadline information for a specific task. If the repeater is set for the scheduling information only, you probably want the repeater to be ignored after the deadline. If so, set the variable org-agenda-skip-scheduled-if-deadline-is-shown to repeated-after-deadline. However, any scheduling information without a repeater is no longer relevant once the task is done, and thus, removed upon repeating the task. If you want both scheduling and deadline information to repeat after the same interval, set the same repeater for both timestamps.

An alternative to using a repeater is to create a number of copies of a task subtree, with dates shifted in each copy. The command C-c C-x c was created for this purpose; it is described inStructure Editing.

8.4 Clocking Work Time

Org mode allows you to clock the time you spend on specific tasks in a project. When you start working on an item, you can start the clock. When you stop working on that task, or when you mark the task done, the clock is stopped and the corresponding time interval is recorded. It also computes the total time spent on each subtree73 of a project. And it remembers a history or tasks recently clocked, to that you can jump quickly between a number of tasks absorbing your time.

To save the clock history across Emacs sessions, use:

1
2
(setq org-clock-persist 'history)
(org-clock-persistence-insinuate)

When you clock into a new task after resuming Emacs, the incomplete clock74 is retrieved (see Resolving idle time (1)) and you are prompted about what to do with it.

8.4.1 Clocking commands

  • C-c C-x C-i (org-clock-in)

    Start the clock on the current item (clock-in). This inserts the CLOCK keyword together with a timestamp. If this is not the first clocking of this item, the multiple CLOCK lines are wrapped into a ‘LOGBOOK’ drawer (see also the variable org-clock-into-drawer). You can also overrule the setting of this variable for a subtree by setting a ‘CLOCK_INTO_DRAWER’ or ‘LOG_INTO_DRAWER’ property. When called with a C-u prefix argument, select the task from a list of recently clocked tasks. With two C-u C-u prefixes, clock into the task at point and mark it as the default task; the default task is always be available with letter d when selecting a clocking task. With three C-u C-u C-u prefixes, force continuous clocking by starting the clock when the last clock stopped.While the clock is running, Org shows the current clocking time in the mode line, along with the title of the task. The clock time shown is all time ever clocked for this task and its children. If the task has an effort estimate (see Effort Estimates), the mode line displays the current clocking time against it75. If the task is a repeating one (see Repeated tasks), show only the time since the last reset of the task76. You can exercise more control over show time with the ‘CLOCK_MODELINE_TOTAL’ property. It may have the values ‘current’ to show only the current clocking instance, ‘today’ to show all time clocked on this tasks today—see also the variable org-extend-today-until, all to include all time, or auto which is the default77. Clicking with mouse-1 onto the mode line entry pops up a menu with clocking options.

  • C-c C-x C-o (org-clock-out)

    Stop the clock (clock-out). This inserts another timestamp at the same location where the clock was last started. It also directly computes the resulting time in inserts it after the time range as ‘=>HH:MM’. See the variable org-log-note-clock-out for the possibility to record an additional note together with the clock-out timestamp78.

  • C-c C-x C-x (org-clock-in-last)

    Re-clock the last clocked task. With one C-u prefix argument, select the task from the clock history. With two C-u prefixes, force continuous clocking by starting the clock when the last clock stopped.

  • C-c C-x C-e (org-clock-modify-effort-estimate)

    Update the effort estimate for the current clock task.

  • C-c C-c or C-c C-y (org-evaluate-time-range)

    Recompute the time interval after changing one of the timestamps. This is only necessary if you edit the timestamps directly. If you change them with S- keys, the update is automatic.

  • C-S-UP (org-clock-timestamps-up)

  • C-S-DOWN (org-clock-timestamps-down)

    On CLOCK log lines, increase/decrease both timestamps so that the clock duration keeps the same value.

  • S-M-UP (org-timestamp-up)

  • S-M-DOWN (org-timestamp-down)

    On ‘CLOCK’ log lines, increase/decrease the timestamp at point and the one of the previous, or the next, clock timestamp by the same duration. For example, if you hit S-M-UP to increase a clocked-out timestamp by five minutes, then the clocked-in timestamp of the next clock is increased by five minutes.

  • C-c C-t (org-todo)

    Changing the TODO state of an item to DONE automatically stops the clock if it is running in this same item.

  • C-c C-x C-q (org-clock-cancel)

    Cancel the current clock. This is useful if a clock was started by mistake, or if you ended up working on something else.

  • C-c C-x C-j (org-clock-goto)

    Jump to the headline of the currently clocked in task. With a C-u prefix argument, select the target task from a list of recently clocked tasks.

  • C-c C-x C-d (org-clock-display)

    Display time summaries for each subtree in the current buffer. This puts overlays at the end of each headline, showing the total time recorded under that heading, including the time of any subheadings. You can use visibility cycling to study the tree, but the overlays disappear when you change the buffer (see variable org-remove-highlights-with-change) or press C-c C-c.

The l key may be used in the agenda (see Weekly/daily agenda) to show which tasks have been worked on or closed during a day.

Important: note that both org-clock-out and org-clock-in-last can have a global keybinding and do not modify the window disposition.

这里的命令有点多, 只要先看clock-in和clock-out便可.

8.4.2 The clock table

这一章全部都是没用的,只有前面的三个命令有用.
org-clock-report, org-dbclok-update, C-u C-c C-x C-u全部更新.

Org mode can produce quite complex reports based on the time clocking information. Such a report is called a clock table, because it is formatted as one or several Org tables.

  • C-c C-x C-r (org-clock-report)
    Insert a dynamic block (see Dynamic Blocks) containing a clock report as an Org mode table into the current file. When point is at an existing clock table, just update it. When called with a prefix argument, jump to the first clock report in the current document and update it. The clock table includes archived trees.

  • C-c C-c or C-c C-x C-u (org-dblock-update)
    Update dynamic block at point. Point needs to be in the ‘BEGIN’ line of the dynamic block.

  • C-u C-c C-x C-u

    Update all dynamic blocks (see Dynamic Blocks). This is useful if you have several clock table blocks in a buffer.

  • S-LEFT

  • S-RIGHT (org-clocktable-try-shift)

    Shift the current ‘:block’ interval and update the table. Point needs to be in the ‘#+BEGIN: clocktable’ line for this command. If ‘:block’ is ‘today’, it is shifted to ‘today-1’, etc.

Here is an example of the frame for a clock table as it is inserted into the buffer with the C-c C-x C-r command:

1
2
#+BEGIN: clocktable :maxlevel 2 :emphasize nil :scope file
#+END: clocktable

The ‘#+BEGIN’ line and specify a number of options to define the scope, structure, and formatting of the report. Defaults for all these options can be configured in the variable org-clocktable-defaults.

First there are options that determine which clock entries are to be selected:

  • ‘:maxlevel’

    Maximum level depth to which times are listed in the table. Clocks at deeper levels are summed into the upper level.

  • ‘:scope’

    The scope to consider. This can be any of the following:‘nil’the current buffer or narrowed region‘file’the full current buffer‘subtree’the subtree where the clocktable is located‘treeN’the surrounding level N tree, for example ‘tree3’‘tree’the surrounding level 1 tree‘agenda’all agenda files‘(“file” …)’scan these files‘FUNCTION’scan files returned by calling FUNCTION with no argument‘file-with-archives’current file and its archives‘agenda-with-archives’all agenda files, including archives

  • ‘:block’

    The time block to consider. This block is specified either absolutely, or relative to the current time and may be any of these formats:‘2007-12-31’New year eve 2007‘2007-12’December 2007‘2007-W50’ISO-week 50 in 2007‘2007-Q2’2nd quarter in 2007‘2007’the year 2007‘today’, ‘yesterday’, ‘today-N’a relative day‘thisweek’, ‘lastweek’, ‘thisweek-N’a relative week‘thismonth’, ‘lastmonth’, ‘thismonth-N’a relative month‘thisyear’, ‘lastyear’, ‘thisyear-N’a relative year‘untilnow’79all clocked time everWhen this option is not set, Org falls back to the value in org-clock-display-default-range, which defaults to the current year.Use S-LEFT or S-RIGHT to shift the time interval.

  • ‘:tstart’

    A time string specifying when to start considering times. Relative times like ‘“<-2w>“’ can also be used. See Matching tags and properties for relative time syntax.

  • ‘:tend’

    A time string specifying when to stop considering times. Relative times like ‘““’ can also be used. See Matching tags and properties for relative time syntax.

  • ‘:wstart’

    The starting day of the week. The default is 1 for Monday.

  • ‘:mstart’

    The starting day of the month. The default is 1 for the first.

  • ‘:step’

    Set to week or day to split the table into chunks. To use this, :block or :tstart, :tend are needed.

  • ‘:stepskip0’

    When non-nil, do not show steps that have zero time.

  • ‘:fileskip0’

    When non-nil, do not show table sections from files which did not contribute.

  • ‘:match’

    A tags match to select entries that should contribute. See Matching tags and properties for the match syntax.

Then there are options that determine the formatting of the table. There options are interpreted by the function org-clocktable-write-default, but you can specify your own function using the ‘:formatter’ parameter.

  • ‘:emphasize’

    When non-nil, emphasize level one and level two items.

  • ‘:lang’

    Language80 to use for descriptive cells like “Task”.

  • ‘:link’

    Link the item headlines in the table to their origins.

  • ‘:narrow’

    An integer to limit the width of the headline column in the Org table. If you write it like ‘50!’, then the headline is also shortened in export.

  • ‘:indent’

    Indent each headline field according to its level.

  • ‘:tcolumns’

    Number of columns to be used for times. If this is smaller than ‘:maxlevel’, lower levels are lumped into one column.

  • ‘:level’

    Should a level number column be included?

  • ‘:sort’

    A cons cell containing the column to sort and a sorting type. E.g., ‘:sort (1 . ?a)’ sorts the first column alphabetically.

  • ‘:compact’

    Abbreviation for ‘:level nil :indent t :narrow 40! :tcolumns 1’. All are overwritten except if there is an explicit ‘:narrow’.

  • ‘:timestamp’

    A timestamp for the entry, when available. Look for ‘SCHEDULED’, ‘DEADLINE’, ‘TIMESTAMP’ and ‘TIMESTAMP_IA’ special properties (see Special Properties), in this order.

  • ‘:tags’

    When this flag is non-nil, show the headline’s tags.

  • ‘:properties’

    List of properties shown in the table. Each property gets its own column.

  • ‘:inherit-props’

    When this flag is non-nil, the values for ‘:properties’ are inherited.

  • ‘:formula’

    Content of a ‘TBLFM’ keyword to be added and evaluated. As a special case, ‘:formula %’ adds a column with % time. If you do not specify a formula here, any existing formula below the clock table survives updates and is evaluated.

  • ‘:formatter’

    A function to format clock data and insert it into the buffer.

To get a clock summary of the current level 1 tree, for the current day, you could write:

1
2
#+BEGIN: clocktable :maxlevel 2 :block today :scope tree1 :link t
#+END: clocktable

To use a specific time range you could write81

1
2
3
#+BEGIN: clocktable :tstart "<2006-08-10 Thu 10:00>"
:tend "<2006-08-10 Thu 12:00>"
#+END: clocktable

A range starting a week ago and ending right now could be written as

1
2
#+BEGIN: clocktable :tstart "<-1w>" :tend "<now>"
#+END: clocktable

A summary of the current subtree with % times would be

1
2
#+BEGIN: clocktable :scope subtree :link t :formula %
#+END: clocktable

A horizontally compact representation of everything clocked during last week would be

1
2
#+BEGIN: clocktable :scope agenda :block lastweek :compact t
#+END: clocktable

8.4.3 Resolving idle time and continuous clocking

Resolving idle time

本章中的有用信息是可以通过 M-x org-resolve-clocks调出来时间调整的页面.

If you clock in on a work item, and then walk away from your computer—perhaps to take a phone call—you often need to “resolve” the time you were away by either subtracting it from the current clock, or applying it to another one.

By customizing the variable org-clock-idle-time to some integer, such as 10 or 15, Emacs can alert you when you get back to your computer after being idle for that many minutes82, and ask what you want to do with the idle time. There will be a question waiting for you when you get back, indicating how much idle time has passed constantly updated with the current amount, as well as a set of choices to correct the discrepancy:

  • k

    To keep some or all of the minutes and stay clocked in, press k. Org asks how many of the minutes to keep. Press RET to keep them all, effectively changing nothing, or enter a number to keep that many minutes.

  • K

    If you use the shift key and press K, it keeps however many minutes you request and then immediately clock out of that task. If you keep all of the minutes, this is the same as just clocking out of the current task.

  • s

    To keep none of the minutes, use s to subtract all the away time from the clock, and then check back in from the moment you returned.

  • S

    To keep none of the minutes and just clock out at the start of the away time, use the shift key and press S. Remember that using shift always leave you clocked out, no matter which option you choose.

  • C

    To cancel the clock altogether, use C. Note that if instead of canceling you subtract the away time, and the resulting clock amount is less than a minute, the clock is still canceled rather than cluttering up the log with an empty entry.

What if you subtracted those away minutes from the current clock, and now want to apply them to a new clock? Simply clock in to any task immediately after the subtraction. Org will notice that you have subtracted time “on the books”, so to speak, and will ask if you want to apply those minutes to the next task you clock in on.

There is one other instance when this clock resolution magic occurs. Say you were clocked in and hacking away, and suddenly your cat chased a mouse who scared a hamster that crashed into your UPS’s power button! You suddenly lose all your buffers, but thanks to auto-save you still have your recent Org mode changes, including your last clock in.

If you restart Emacs and clock into any task, Org will notice that you have a dangling clock which was never clocked out from your last session. Using that clock’s starting time as the beginning of the unaccounted-for period, Org will ask how you want to resolve that time. The logic and behavior is identical to dealing with away time due to idleness; it is just happening due to a recovery event rather than a set amount of idle time.

You can also check all the files visited by your Org agenda for dangling clocks at any time using M-x org-resolve-clocks RET (or C-c C-x C-z).

Continuous clocking

You may want to start clocking from the time when you clocked out the previous task. To enable this systematically, set org-clock-continuously to non-nil. Each time you clock in, Org retrieves the clock-out time of the last clocked entry for this session, and start the new clock from there.

If you only want this from time to time, use three universal prefix arguments with org-clock-in and two C-u C-u with org-clock-in-last.

8.5 Effort Estimates

If you want to plan your work in a very detailed way, or if you need to produce offers with quotations of the estimated work effort, you may want to assign effort estimates to entries. If you are also clocking your work, you may later want to compare the planned effort with the actual working time, a great way to improve planning estimates. Effort estimates are stored in a special property ‘EFFORT’. You can set the effort for an entry with the following commands:

  • C-c C-x e (org-set-effort)

    Set the effort estimate for the current entry. With a prefix argument, set it to the next allowed value—see below. This command is also accessible from the agenda with the e key.

  • C-c C-x C-e (org-clock-modify-effort-estimate)

    Modify the effort estimate of the item currently being clocked.

Clearly the best way to work with effort estimates is through column view (see Column View). You should start by setting up discrete values for effort estimates, and a ‘COLUMNS’ format that displays these values together with clock sums—if you want to clock your time. For a specific buffer you can use:

1
2
#+PROPERTY: Effort_ALL 0 0:10 0:30 1:00 2:00 3:00 4:00 5:00 6:00 7:00
#+COLUMNS: %40ITEM(Task) %17Effort(Estimated Effort){:} %CLOCKSUM

or, even better, you can set up these values globally by customizing the variables org-global-properties and org-columns-default-format. In particular if you want to use this setup also in the agenda, a global setup may be advised.

The way to assign estimates to individual items is then to switch to column mode, and to use S-RIGHT and S-LEFT to change the value. The values you enter are immediately summed up in the hierarchy. In the column next to it, any clocked time is displayed.

If you switch to column view in the daily/weekly agenda, the effort column summarizes the estimated work effort for each day83, and you can use this to find space in your schedule. To get an overview of the entire part of the day that is committed, you can set the option org-agenda-columns-add-appointments-to-effort-sum. The appointments on a day that take place over a specified time interval are then also added to the load estimate of the day.

Effort estimates can be used in secondary agenda filtering that is triggered with the / key in the agenda (see Agenda Commands). If you have these estimates defined consistently, two or three key presses narrow down the list to stuff that fits into an available time slot.

参考资料

  • Formats: Working with Dates and Times Using the ISO 8601 Basic and Extended Notations - 9.2

find中的时间, atime, ctime, mtime (-n * 24hours)
amin, cmin, min (n minutes)

Emacs Agenda Views

Posted on 2019-05-17 | In linux - emacs - orgmode , timeManagement | Comments:

Due to the way Org works, TODO items, time-stamped items, and tagged headlines can be scattered throughout a file or even a number of files. To get an overview of open action items, or of events that are important for a particular date, this information must be collected, sorted and displayed in an organized way.

Org can select items based on various criteria and display them in a separate buffer. Six different view types are provided:

  • an agenda that is like a calendar and shows information for specific dates,
  • a TODO list that covers all unfinished action items,
  • a match view, showings headlines based on the tags, properties, and TODO state associated with them,
  • a text search view that shows all entries from multiple files that contain specified keywords,
  • a stuck projects view showing projects that currently do not move along, and
  • custom views that are special searches and combinations of different views.

The extracted information is displayed in a special agenda buffer. This buffer is read-only, but provides commands to visit the corresponding locations in the original Org files, and even to edit these files remotely.

By default, the report ignores commented (see Comment Lines) and archived (see Internal archiving) entries. You can override this by setting org-agenda-skip-comment-trees and org-agenda-skip-archived-trees to nil.

Two variables control how the agenda buffer is displayed and whether the window configuration is restored when the agenda exits: org-agenda-window-setup and org-agenda-restore-windows-after-quit.

Agenda Views
• Agenda Files: Files being searched for agenda information.
• Agenda Dispatcher: Keyboard access to agenda views.
• Built-in Agenda Views: What is available out of the box?
• Presentation and Sorting: How agenda items are prepared for display.
• Agenda Commands: Remote editing of Org trees.
• Custom Agenda Views: Defining special searches and views.
• Exporting Agenda Views: Writing a view to a file.
• Agenda Column View: Using column view for collected entries.

10.1 Agenda Files

概括:
可以将directory作为org-agenda-files
在agenda views中工作, 对org mode的所有应用对围绕agenda view展开.

The information to be shown is normally collected from all agenda files, the files listed in the variable org-agenda-files[^1]. If a directory is part of this list, all files with the extension ‘.org’ in this directory are part of the list.

Thus, even if you only work with a single Org file, that file should be put into the list[^2]. You can customize org-agenda-files, but the easiest way to maintain it is through the following commands

  • C-c [ (org-agenda-file-to-front)
    Add current file to the list of agenda files. The file is added to the front of the list. If it was already in the list, it is moved to the front. With a prefix argument, file is added/moved to the end.

  • C-c ] (org-remove-file)
    Remove current file from the list of agenda files.

  • C-‘ or

  • C-, (org-cycle-agenda-files)

    Cycle through agenda file list, visiting one file after the other.
    Command to use an iswitchb-like interface to switch to and between Org buffers.

The Org menu contains the current list of files and can be used to visit any of them.

If you would like to focus the agenda temporarily on a file not in this list, or on just one file in the list, or even on only a subtree in a file, then this can be done in different ways. For a single agenda command, you may press < once or several times in the dispatcher (see Agenda Dispatcher). To restrict the agenda scope for an extended period, use the following commands:

  • C-c C-x < (org-agenda-set-restriction-lock)
    Restrict the agenda to the current subtree. If there already is a restriction at point, remove it. When called with a universal prefix argument or with point before the first headline in a file, set the agenda scope to the entire file. This restriction remains in effect until removed with C-c C-x >, or by typing either < or > in the agenda dispatcher. If there is a window displaying an agenda view, the new restriction takes effect immediately.

  • C-c C-x > (org-agenda-remove-restriction-lock)
    Remove the restriction created by C-c C-x <.

When working with Speedbar, you can use the following commands in the Speedbar frame:

  • < (org-speedbar-set-agenda-restriction)
    Restrict the agenda to the item—either an Org file or a subtree in such a file—at point in the Speedbar frame. If agenda is already restricted there, remove the restriction. If there is a window displaying an agenda view, the new restriction takes effect immediately.

  • > (org-agenda-remove-restriction-lock)

    Remove the restriction.


Footnotes

  1. If the value of that variable is not a list, but a single file name, then the list of agenda files in maintained in that external file.
  2. When using the dispatcher, pressing < before selecting a command actually limits the command to the current file, and ignores org-agenda-files until the next dispatcher command.

10.2 The Agenda Dispatcher

dispatcher, a, t
第一个提示界面, 当下只需要关注前两个.
采纳动词dispatch协助思考.

The views are created through a dispatcher, accessible with M-x org-agenda, or, better, bound to a global key (see Activation). It displays a menu from which an additional letter is required to execute a command. The dispatcher offers the following default commands:

  • a
    Create the calendar-like agenda (see Weekly/daily agenda).

  • t or T
    Create a list of all TODO items (see Global TODO list).

  • m or M
    Create a list of headlines matching a given expression (see Matching tags and properties).

  • s
    Create a list of entries selected by a boolean expression of keywords and/or regular expressions that must or must not occur in the entry.

  • /
    Search for a regular expression in all agenda files and additionally in the files listed in org-agenda-text-search-extra-files. This uses the Emacs command multi-occur. A prefix argument can be used to specify the number of context lines for each match, default is

  • # or !
    Create a list of stuck projects (see Stuck projects).

    重点概念.

  • <
    Restrict an agenda command to the current buffer93. After pressing <, you still need to press the character selecting the command.

  • < <
    If there is an active region, restrict the following agenda command to the region. Otherwise, restrict it to the current subtree94. After pressing < <, you still need to press the character selecting the command.

  • *
    Toggle sticky agenda views. By default, Org maintains only a single agenda buffer and rebuilds it each time you change the view, to make sure everything is always up to date. If you switch between views often and the build time bothers you, you can turn on sticky agenda buffers (make this the default by customizing the variable org-agenda-sticky). With sticky agendas, the dispatcher only switches to the selected view, you need to update it by hand with r or g. You can toggle sticky agenda view any time with org-toggle-sticky-agenda.

You can also define custom commands that are accessible through the dispatcher, just like the default commands. This includes the possibility to create extended agenda buffers that contain several blocks together, for example the weekly agenda, the global TODO list and a number of special tags matches. See Custom Agenda Views.

Footnotes

  1. For backward compatibility, you can also press 1 to restrict to the current buffer.

  2. For backward compatibility, you can also press 0 to restrict to the current region/subtree.

10.3 The Built-in Agenda Views

In this section we describe the built-in views.

进入正题.

Agenda View
• Weekly/daily agenda: The calendar page with current tasks.
• Global TODO list: All unfinished action items.
• Matching tags and properties: Structured information with fine-tuned search.
• Search view: Find entries by searching for text.
• Stuck projects: Find projects you need to review.

10.3.1 Weekly/daily agenda

The default agenda-span 设置成两天, 提问如何设置成前后一天的模式.

The purpose of the weekly/daily agenda is to act like a page of a paper agenda, showing all the tasks for the current week or day.

  • M-x org-agenda a (org-agenda-list)

    Compile an agenda for the current week from a list of Org files. The agenda shows the entries for each day. With a numeric prefix argument[^1]—like C-u 2 1 M-x org-agenda a—you may set the number of days to be displayed.

The default number of days displayed in the agenda is set by the variable org-agenda-span. This variable can be set to any number of days you want to see by default in the agenda, or to a span name, such a day, week, month or year. For weekly agendas, the default is to start on the previous Monday (see org-agenda-start-on-weekday). You can also set the start date using a date shift: ‘(setq org-agenda-start-day “+10d”)’ starts the agenda ten days from today in the future.

Remote editing from the agenda buffer means, for example, that you can change the dates of deadlines and appointments from the agenda buffer. The commands available in the Agenda buffer are listed in Agenda Commands.

1. Calendar/Diary integration

Work with calendar, sunrise and sunset
calendar工具的应用, 增加三个自然规律的变量, sunrise, sunset and moon phase

Emacs contains the calendar and diary by Edward M. Reingold. The calendar displays a three-month calendar with holidays from different countries and cultures. The diary allows you to keep track of anniversaries, lunar phases, sunrise/set, recurrent appointments (weekly, monthly) and more. In this way, it is quite complementary to Org. It can be very useful to combine output from Org with the diary.

In order to include entries from the Emacs diary into Org mode’s agenda, you only need to customize the variable

1
(setq org-agenda-include-diary t)

After that, everything happens automatically. All diary entries including holidays, anniversaries, etc., are included in the agenda buffer created by Org mode. SPC, TAB, and RET can be used from the agenda buffer to jump to the diary file in order to edit existing diary entries. The i command to insert new entries for the current date works in the agenda buffer, as well as the commands S, M, and C to display Sunrise/Sunset times, show lunar phases and to convert to other calendars, respectively. c can be used to switch back and forth between calendar and agenda.

获取当前的坐标

Ubuntu Manpage: libgps - C service library for communicating with the GPS daemon
how to use/install gps python library - Stack Overflow

If you are using the diary only for S-exp entries and holidays, it is faster to not use the above setting, but instead to copy or even move the entries into an Org file. Org mode evaluates diary-style sexp entries, and does it faster because there is no overhead for first creating the diary display. Note that the sexp entries must start at the left margin, no whitespace is allowed before them, as seen in the following segment of an Org file:96

1
2
3
4
5
6
7
8
9
10
11
12
* Holidays
:PROPERTIES:
:CATEGORY: Holiday
:END:
%%(org-calendar-holiday) ; special function for holiday names

* Birthdays
:PROPERTIES:
:CATEGORY: Ann
:END:
%%(org-anniversary 1956 5 14) Arthur Dent is %d years old
%%(org-anniversary 1869 10 2) Mahatma Gandhi would be %d years old

2. Anniversaries from BBDB

If you are using the Insidious Big Brother Database to store your contacts, you very likely prefer to store anniversaries in BBDB rather than in a separate Org or diary file. Org supports this and can show BBDB anniversaries as part of the agenda. All you need to do is to add the following to one of your agenda files:

1
2
3
4
5
* Anniversaries
:PROPERTIES:
:CATEGORY: Anniv
:END:
%%(org-bbdb-anniversaries)
1
2
3
4
1973-06-22
06-22
1955-08-02 wedding
2008-04-14 %s released version 6.01 of Org mode, %d years ago

After a change to BBDB, or for the first agenda display during an Emacs session, the agenda display suffers a short delay as Org updates its hash with anniversaries. However, from then on things will be very fast, much faster in fact than a long list of ‘%%(diary-anniversary)’ entries in an Org or Diary file.

If you would like to see upcoming anniversaries with a bit of forewarning, you can use the following instead:

1
2
3
4
5
* Anniversaries
:PROPERTIES:
:CATEGORY: Anniv
:END:
%%(org-bbdb-anniversaries-future 3)

That will give you three days’ warning: on the anniversary date itself and the two days prior. The argument is optional: if omitted, it defaults to 7.

3. Appointment reminders

Org can interact with Emacs appointments notification facility. To add the appointments of your agenda files, use the command org-agenda-to-appt. This command lets you filter through the list of your appointments and add only those belonging to a specific category or matching a regular expression. It also reads a ‘APPT_WARNTIME’ property which overrides the value of appt-message-warning-time for this appointment. See the docstring for details.

Footnotes

  1. For backward compatibility, the universal prefix argument C-u causes all TODO entries to be listed before the agenda. This feature is deprecated, use the dedicated TODO list, or a block agenda instead (see Block agenda).
  2. The variable org-anniversary used in the example is just like diary-anniversary, but the argument order is always according to ISO and therefore independent of the value of calendar-date-style.

后续计划, 研究下agenda-view与diary的结合.

10.3.2 The global TODO list

The global TODO list contains all unfinished TODO items formatted and collected into a single place.

  • M-x org-agenda t (org-todo-list)

    Show the global TODO list. This collects the TODO items from all agenda files (see Agenda Views) into a single buffer. By default, this lists items with a state the is not a DONE state. The buffer is in agenda-mode, so there are commands to examine and manipulate the TODO entries directly from that buffer (see Agenda Commands).

  • M-x org-agenda T (org-todo-list)

    Like the above, but allows selection of a specific TODO keyword. You can also do this by specifying a prefix argument to t. You are prompted for a keyword, and you may also specify several keywords by separating them with ‘|’ as the boolean OR operator. With a numeric prefix, the Nth keyword in org-todo-keywords is selected.The r key in the agenda buffer regenerates it, and you can give a prefix argument to this command to change the selected TODO keyword, for example 3 r. If you often need a search for a specific keyword, define a custom command for it (see Agenda Dispatcher).Matching specific TODO keywords can also be done as part of a tags search (see Tag Searches).

Remote editing of TODO items means that you can change the state of a TODO entry with a single key press. The commands available in the TODO list are described in Agenda Commands.

Normally the global TODO list simply shows all headlines with TODO keywords. This list can become very long. There are two ways to keep it more compact:

  • Some people view a TODO item that has been scheduled for execution or have a deadline (see Timestamps) as no longer open. Configure the variables org-agenda-todo-ignore-scheduled, org-agenda-todo-ignore-deadlines, org-agenda-todo-ignore-timestamp and/or org-agenda-todo-ignore-with-date to exclude such items from the global TODO list.
  • TODO items may have sublevels to break up the task into subtasks. In such cases it may be enough to list only the highest level TODO headline and omit the sublevels from the global list. Configure the variable org-agenda-todo-list-sublevels to get this behavior.

todo的sublevel

10.3.3 Matching tags and properties

与编程相结合, 稍微了解一点.

If headlines in the agenda files are marked with tags (see Tags), or have properties (see Properties and Columns), you can select headlines based on this metadata and collect them into an agenda buffer. The match syntax described here also applies when creating sparse trees with C-c / m.

  • M-x org-agenda m (org-tags-view)

    Produce a list of all headlines that match a given set of tags. The command prompts for a selection criterion, which is a boolean logic expression with tags, like ‘+work+urgent-withboss’ or ‘work|home’ (see Tags). If you often need a specific search, define a custom command for it (see Agenda Dispatcher).

  • M-x org-agenda M (org-tags-view)

    Like m, but only select headlines that are also TODO items and force checking subitems (see the variable org-tags-match-list-sublevels). To exclude scheduled/deadline items, see the variable org-agenda-tags-todo-honor-ignore-options. Matching specific TODO keywords together with a tags match is also possible, see Tag Searches.

The commands available in the tags list are described in Agenda Commands.

A search string can use Boolean operators ‘&’ for AND and ‘|’ for OR. ‘&’ binds more strongly than ‘|’. Parentheses are currently not implemented. Each element in the search is either a tag, a regular expression matching tags, or an expression like ‘PROPERTY OPERATOR VALUE’ with a comparison operator, accessing a property value. Each element may be preceded by ‘-’ to select against it, and ‘+’ is syntactic sugar for positive selection. The AND operator ‘&’ is optional when ‘+’ or ‘-’ is present. Here are some examples, using only tags.

  • +work-boss
    Select headlines tagged ‘work’, but discard those also tagged ‘boss’.

  • work|laptop
    Selects lines tagged ‘work’ or ‘laptop’.

  • work|laptop+night
    Like before, but require the ‘laptop’ lines to be tagged also ‘night’.

Instead of a tag, you may also specify a regular expression enclosed in curly braces. For example, ‘work+{^boss.}’ matches headlines that contain the tag ‘:work:’ and any tag starting* with ‘boss’.

an amazing function.

Group tags (see Tag Hierarchy) are expanded as regular expressions. E.g., if ‘work’ is a group tag for the group ‘:work:lab:conf:’, then searching for ‘work’ also searches for ‘{(?:work|lab|conf)}’ and searching for ‘-work’ searches for all headlines but those with one of the tags in the group (i.e., ‘-{(?:work|lab|conf)}’).

You may also test for properties (see Properties and Columns) at the same time as matching tags. The properties may be real properties, or special properties that represent other metadata (see Special Properties). For example, the property ‘TODO’ represents the TODO keyword of the entry. Or, the property ‘LEVEL’ represents the level of an entry. So searching ‘+LEVEL=3+boss-TODO=”DONE”’ lists all level three headlines that have the tag ‘boss’ and are not marked with the TODO keyword ‘DONE’. In buffers with org-odd-levels-only set, ‘LEVEL’ does not count the number of stars, but ‘LEVEL=2’ corresponds to 3 stars etc.

Here are more examples:

  • ‘work+TODO=”WAITING”’
    Select ‘work’-tagged TODO lines with the specific TODO keyword ‘WAITING’.

  • ‘work+TODO=”WAITING”|home+TODO=”WAITING”’
    Waiting tasks both at work and at home.

When matching properties, a number of different operators can be used to test the value of a property. Here is a complex example:

1
2
+work-boss+PRIORITY="A"+Coffee="unlimited"+Effort<2
+With={Sarah|Denny}+SCHEDULED>="<2008-10-11>"

The type of comparison depends on how the comparison value is written:

  • If the comparison value is a plain number, a numerical comparison is done, and the allowed operators are ‘<’, ‘=’, ‘>’, ‘<=’, ‘>=’, and ‘<>’.
  • If the comparison value is enclosed in double-quotes, a string comparison is done, and the same operators are allowed.
  • If the comparison value is enclosed in double-quotes and angular brackets (like ‘DEADLINE<=”<2008-12-24 18:30>“’), both values are assumed to be date/time specifications in the standard Org way, and the comparison is done accordingly. Valid values also include ‘““’ for now (including time), ‘““’, and ‘““’ for these days at 0:00 hours, i.e., without a time specification. You can also use strings like ‘“<+5d>”’ or ‘“<-2m>“’ with units ‘d’, ‘w’, ‘m’, and ‘y’ for day, week, month, and year, respectively.
  • If the comparison value is enclosed in curly braces, a regexp match is performed, with ‘=’ meaning that the regexp matches the property value, and ‘<>’ meaning that it does not match.

So the search string in the example finds entries tagged ‘work’ but not ‘boss’, which also have a priority value ‘A’, a ‘Coffee’ property with the value ‘unlimited’, an ‘EFFORT’ property that is numerically smaller than 2, a ‘With’ property that is matched by the regular expression ‘Sarah|Denny’, and that are scheduled on or after October 11, 2008.

You can configure Org mode to use property inheritance during a search, but beware that this can slow down searches considerably. See Property Inheritance, for details.

For backward compatibility, and also for typing speed, there is also a different way to test TODO states in a search. For this, terminate the tags/property part of the search string (which may include several terms connected with ‘|’) with a ‘/’ and then specify a Boolean expression just for TODO keywords. The syntax is then similar to that for tags, but should be applied with care: for example, a positive selection on several TODO keywords cannot meaningfully be combined with boolean AND. However, negative selection combined with AND can be meaningful. To make sure that only lines are checked that actually have any TODO keyword (resulting in a speed-up), use M-x org-agenda M, or equivalently start the TODO part after the slash with ‘!’. Using M-x org-agenda M or ‘/!’ does not match TODO keywords in a DONE state. Examples:

  • ‘work/WAITING’
    Same as ‘work+TODO=”WAITING”’.

  • ‘work/!-WAITING-NEXT’
    Select ‘work’-tagged TODO lines that are neither ‘WAITING’ nor ‘NEXT’.

  • ‘work/!+WAITING|+NEXT’
    Select ‘work’-tagged TODO lines that are either ‘WAITING’ or ‘NEXT’.

这一部分过分复杂, 等以后再来看吧.

10.3.4 Search view

This agenda view is a general text search facility for Org mode entries. It is particularly useful to find notes.

  • M-x org-agenda s (org-search-view)

    This is a special search that lets you select entries by matching a substring or specific words using a boolean logic.

For example, the search string ‘computer equipment’ matches entries that contain ‘computer equipment’ as a substring, even if the two words are separated by more space or a line break.

Search view can also search for specific keywords in the entry, using Boolean logic. The search string ‘+computer +wifi -ethernet -{8.11[bg]}’ matches note entries that contain the keywords ‘computer’ and ‘wifi’, but not the keyword ‘ethernet’, and which are also not matched by the regular expression ‘8.11[bg]’, meaning to exclude both ‘8.11b’ and ‘8.11g’. The first ‘+’ is necessary to turn on boolean search, other ‘+’ characters are optional. For more details, see the docstring of the command org-search-view.

You can incrementally adjust a boolean search with the following keys

[ Add a positive search word
] Add a negative search word
{ Add a positive regular expression
} Add a negative regular expression

Note that in addition to the agenda files, this command also searches the files listed in org-agenda-text-search-extra-files.

10.3.5 Stuck projects

这是有用的一项.

If you are following a system like David Allen’s GTD to organize your work, one of the “duties” you have is a regular review to make sure that all projects move along. A stuck project is a project that has no defined next actions, so it never shows up in the TODO lists Org mode produces. During the review, you need to identify such projects and define next actions for them.

  • M-x org-agenda # (org-agenda-list-stuck-projects)

    List projects that are stuck.

  • M-x org-agenda !

    Customize the variable org-stuck-projects to define what a stuck project is and how to find it.

You almost certainly need to configure this view before it works for you. The built-in default assumes that all your projects are level-2 headlines, and that a project is not stuck if it has at least one entry marked with a TODO keyword ‘TODO’ or ‘NEXT’ or ‘NEXTACTION’.

Let’s assume that you, in your own way of using Org mode, identify projects with a tag ‘:PROJECT:’, and that you use a TODO keyword ‘MAYBE’ to indicate a project that should not be considered yet. Let’s further assume that the TODO keyword ‘DONE’ marks finished projects, and that ‘NEXT’ and ‘TODO’ indicate next actions. The tag ‘:@shop:’ indicates shopping and is a next action even without the NEXT tag. Finally, if the project contains the special word ‘IGNORE’ anywhere, it should not be listed either. In this case you would start by identifying eligible projects with a tags/TODO match (see Tag Searches) ‘+PROJECT/-MAYBE-DONE’, and then check for ‘TODO’, ‘NEXT’, ‘@shop’, and ‘IGNORE’ in the subtree to identify projects that are not stuck. The correct customization for this is:

1
2
3
(setq org-stuck-projects
'("+PROJECT/-MAYBE-DONE" ("NEXT" "TODO") ("@shop")
"\\<IGNORE\\>"))

Note that if a project is identified as non-stuck, the subtree of this entry is searched for stuck projects.

这个功能很有意思
org mode名副其实是写给人看的工具.

10.4 Presentation and Sorting

这一章里只有time specification有点用.
Sort并不重要, 只关注presentation
修改time grid.

Before displaying items in an agenda view, Org mode visually prepares the items and sorts them. Each item occupies a single line. The line starts with a prefix that contains the category (see Categories) of the item and other important information. You can customize in which column tags are displayed through org-agenda-tags-column. You can also customize the prefix using the option org-agenda-prefix-format. This prefix is followed by a cleaned-up version of the outline headline associated with the item.

Presentation and Sort
• Categories: Not all tasks are equal.
• Time-of-day specifications: How the agenda knows the time.
• Sorting of agenda items: The order of things.
• Filtering/limiting agenda times: Dynamically narrow the agenda.

10.4.1 Categories

The category is a broad label assigned to each agenda item. By default, the category is simply derived from the file name, but you can also specify it with a special line in the buffer, like this:

等日后用的时候再说.

1
#+CATEGORY: Thesis

If you would like to have a special category for a single entry or a (sub)tree, give the entry a ‘CATEGORY’ property with the special category you want to apply as the value.

The display in the agenda buffer looks best if the category is not longer than 10 characters.

You can set up icons for category by customizing the org-agenda-category-icon-alist variable.

10.4.2 Time-of-day specifications

本章的关键, 从这里修改time-grid

Org mode checks each agenda item for a time-of-day specification. The time can be part of the timestamp that triggered inclusion into the agenda, for example

1
<2005-05-10 Tue 19:00>

Time ranges can be specified with two timestamps:

1
<2005-05-10 Tue 20:30>--<2005-05-10 Tue 22:15>

In the headline of the entry itself, a time(range)—like ‘12:45’ or a ‘8:30-1pm’—may also appear as plain text[^1].
If the agenda integrates the Emacs diary (see Weekly/daily agenda), time specifications in diary entries are recognized as well.
For agenda display, Org mode extracts the time and displays it in a standard 24 hour format as part of the prefix. The example times in the previous paragraphs would end up in the agenda like this:

1
2
3
4
 8:30-13:00 Arthur Dent lies in front of the bulldozer
12:45...... Ford Prefect arrives and takes Arthur to the pub
19:00...... The Vogon reads his poem
20:30-22:15 Marvin escorts the Hitchhikers to the bridge

If the agenda is in single-day mode, or for the display of today, the timed entries are embedded in a time grid, like

1
2
3
4
5
6
7
8
9
10
11
 8:00...... ------------------
8:30-13:00 Arthur Dent lies in front of the bulldozer
10:00...... ------------------
12:00...... ------------------
12:45...... Ford Prefect arrives and takes Arthur to the pub
14:00...... ------------------
16:00...... ------------------
18:00...... ------------------
19:00...... The Vogon reads his poem
20:00...... ------------------
20:30-22:15 Marvin escorts the Hitchhikers to the bridge

The time grid can be turned on and off with the variable org-agenda-use-time-grid, and can be configured with org-agenda-time-grid.


Footnotes

  1. You can, however, disable this by setting org-agenda-search-headline-for-time variable to a nil value.

10.4.3 Sorting of agenda items

Before being inserted into a view, the items are sorted. How this is done depends on the type of view.

  • For the daily/weekly agenda, the items for each day are sorted. The default order is to first collect all items containing an explicit time-of-day specification. These entries are shown at the beginning of the list, as a schedule for the day. After that, items remain grouped in categories, in the sequence given by org-agenda-files. Within each category, items are sorted by priority (see Priorities), which is composed of the base priority (2000 for priority ‘A’, 1000 for ‘B’, and 0 for ‘C’), plus additional increments for overdue scheduled or deadline items.
  • For the TODO list, items remain in the order of categories, but within each category, sorting takes place according to priority (see Priorities). The priority used for sorting derives from the priority cookie, with additions depending on how close an item is to its due or scheduled date.
  • For tags matches, items are not sorted at all, but just appear in the sequence in which they are found in the agenda files.

Sorting can be customized using the variable org-agenda-sorting-strategy, and may also include criteria based on the estimated effort of an entry (see Effort Estimates).

并没有啥用.

10.4.4 Filtering/limiting agenda times

并没啥用.

Agenda built-in or customized commands are statically defined. Agenda filters and limits provide two ways of dynamically narrowing down the list of agenda entries: filters and limits. Filters only act on the display of the items, while limits take effect before the list of agenda entries is built. Filters are more often used interactively, while limits are mostly useful when defined as local variables within custom agenda commands.

1. Filtering in the agend

  • / (org-agenda-filter-by-tag)

    Filter the agenda view with respect to a tag and/or effort estimates. The difference between this and a custom agenda command is that filtering is very fast, so that you can switch quickly between different filters without having to recreate the agenda.98You are prompted for a tag selection letter; SPC means any tag at all. Pressing TAB at that prompt offers completion to select a tag, including any tags that do not have a selection character. The command then hides all entries that do not contain or inherit this tag. When called with prefix argument, remove the entries that do have the tag. A second / at the prompt turns off the filter and shows any hidden entries. Pressing + or - switches between filtering and excluding the next tag.Org also supports automatic, context-aware tag filtering. If the variable org-agenda-auto-exclude-function is set to a user-defined function, that function can decide which tags should be excluded from the agenda automatically. Once this is set, the / command then accepts RET as a sub-option key and runs the auto exclusion logic. For example, let’s say you use a ‘Net’ tag to identify tasks which need network access, an ‘Errand’ tag for errands in town, and a ‘Call’ tag for making phone calls. You could auto-exclude these tags based on the availability of the Internet, and outside of business hours, with something like this:(defun org-my-auto-exclude-function (tag) (and (cond ((string= tag "Net") (/= 0 (call-process "/sbin/ping" nil nil nil "-c1" "-q" "-t1" "mail.gnu.org"))) ((or (string= tag "Errand") (string= tag "Call")) (let ((hour (nth 2 (decode-time)))) (or (< hour 8) (> hour 21))))) (concat "-" tag))) (setq org-agenda-auto-exclude-function 'org-my-auto-exclude-function)

  • < (org-agenda-filter-by-category)
    Filter the current agenda view with respect to the category of the item at point. Pressing < another time removes this filter. When called with a prefix argument exclude the category of the item at point from the agenda.You can add a filter preset in custom agenda commands through the option org-agenda-category-filter-preset. See Setting options.

  • ^ (org-agenda-filter-by-top-headline)
    Filter the current agenda view and only display the siblings and the parent headline of the one at point.

  • = (org-agenda-filter-by-regexp)
    Filter the agenda view by a regular expression: only show agenda entries matching the regular expression the user entered. When called with a prefix argument, it filters out entries matching the regexp. Called in a regexp-filtered agenda view, remove the filter, unless there are two universal prefix arguments, in which case filters are cumulated.You can add a filter preset in custom agenda commands through the option org-agenda-regexp-filter-preset. See Setting options.

  • _ (org-agenda-filter-by-effort)
    Filter the agenda view with respect to effort estimates. You first need to set up allowed efforts globally, for example(setq org-global-properties '(("Effort_ALL". "0 0:10 0:30 1:00 2:00 3:00 4:00")))You can then filter for an effort by first typing an operator, one of <, > and =, and then the one-digit index of an effort estimate in your array of allowed values, where 0 means the 10th value. The filter then restricts to entries with effort smaller-or-equal, equal, or larger-or-equal than the selected value. For application of the operator, entries without a defined effort are treated according to the value of org-sort-agenda-noeffort-is-high.When called with a prefix argument, it removes entries matching the condition. With two universal prefix arguments, it clears effort filters, which can be accumulated.You can add a filter preset in custom agenda commands through the option org-agenda-effort-filter-preset. See Setting options.

  • | (org-agenda-filter-remove-all)

    Remove all filters in the current agenda view.

2. Setting limits for the agenda

Here is a list of options that you can set, either globally, or locally in your custom agenda views (see Custom Agenda Views).

  • org-agenda-max-entries

    Limit the number of entries.

  • org-agenda-max-effort

    Limit the duration of accumulated efforts (as minutes).

  • org-agenda-max-todos

    Limit the number of entries with TODO keywords.

  • org-agenda-max-tags

    Limit the number of tagged entries.

When set to a positive integer, each option excludes entries from other categories: for example, ‘(setq org-agenda-max-effort 100)’ limits the agenda to 100 minutes of effort and exclude any entry that has no effort property. If you want to include entries with no effort property, use a negative value for org-agenda-max-effort. One useful setup is to use org-agenda-max-entries locally in a custom command. For example, this custom command displays the next five entries with a ‘NEXT’ TODO keyword.

1
2
3
(setq org-agenda-custom-commands
'(("n" todo "NEXT"
((org-agenda-max-entries 5)))))

Once you mark one of these five entry as DONE, rebuilding the agenda will again the next five entries again, including the first entry that was excluded so far.

You can also dynamically set temporary limits, which are lost when rebuilding the agenda:

  • ~ (org-agenda-limit-interactively)

    This prompts for the type of limit to apply and its value.


Footnotes

  1. Custom commands can preset a filter by binding the variable org-agenda-tag-filter-preset as an option. This filter is then applied to the view and persists as a basic filter through refreshes and more secondary filtering. The filter is a global property of the entire agenda view—in a block agenda, you should only set this in the global options section, not in the section of an individual block.

10.5 Commands in the Agenda Buffer

没啥用.

Entries in the agenda buffer are linked back to the Org file or diary file where they originate. You are not allowed to edit the agenda buffer itself, but commands are provided to show and jump to the original entry location, and to edit the Org files “remotely” from the agenda buffer. In this way, all information is stored only once, removing the risk that your agenda and note files may diverge.

Some commands can be executed with mouse clicks on agenda lines. For the other commands, point needs to be in the desired line.

10.6 Custom Agenda Views

没啥用.

Custom agenda commands serve two purposes: to store and quickly access frequently used TODO and tags searches, and to create special composite agenda buffers. Custom agenda commands are accessible through the dispatcher (see Agenda Dispatcher), just like the default commands.

• Storing searches: Type once, use often.
• Block agenda: All the stuff you need in a single buffer.
• Setting options: Changing the rules.

10.7 Exporting Agenda Views

If you are away from your computer, it can be very useful to have a printed version of some agenda views to carry around. Org mode can export custom agenda views as plain text, HTML104, Postscript, PDF105, and iCalendar files. If you want to do this only occasionally, use the following command:

  • C-x C-w (org-agenda-write)

    Write the agenda view to a file.

If you need to export certain agenda views frequently, you can associate any custom agenda command with a list of output file names106. Here is an example that first defines custom commands for the agenda and the global TODO list, together with a number of files to which to export them. Then we define two block agenda commands and specify file names for them as well. File names can be relative to the current working directory, or absolute.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
(setq org-agenda-custom-commands
'(("X" agenda "" nil ("agenda.html" "agenda.ps"))
("Y" alltodo "" nil ("todo.html" "todo.txt" "todo.ps"))
("h" "Agenda and Home-related tasks"
((agenda "")
(tags-todo "home")
(tags "garden"))
nil
("~/views/home.html"))
("o" "Agenda and Office-related tasks"
((agenda)
(tags-todo "work")
(tags "office"))
nil
("~/views/office.ps" "~/calendars/office.ics"))))

The extension of the file name determines the type of export. If it is ‘.html’, Org mode uses the htmlize package to convert the buffer to HTML and save it to this file name. If the extension is ‘.ps’, ps-print-buffer-with-faces is used to produce Postscript output. If the extension is ‘.ics’, iCalendar export is run export over all files that were used to construct the agenda, and limit the export to entries listed in the agenda. Any other extension produces a plain ASCII file.

The export files are not created when you use one of those commands interactively because this might use too much overhead. Instead, there is a special command to produce all specified files in one step:

  • e (org-store-agenda-views)

    Export all agenda views that have export file names associated with them.

You can use the options section of the custom agenda commands to also set options for the export commands. For example:

1
2
3
4
5
6
7
8
(setq org-agenda-custom-commands
'(("X" agenda ""
((ps-number-of-columns 2)
(ps-landscape-mode t)
(org-agenda-prefix-format " [ ] ")
(org-agenda-with-colors nil)
(org-agenda-remove-tags t))
("theagenda.ps"))))

This command sets two options for the Postscript exporter, to make it print in two columns in landscape format—the resulting page can be cut in two and then used in a paper agenda. The remaining settings modify the agenda prefix to omit category and scheduling information, and instead include a checkbox to check off items. We also remove the tags to make the lines compact, and we do not want to use colors for the black-and-white printer. Settings specified in org-agenda-exporter-settings also apply, e.g.,

1
2
3
4
5
(setq org-agenda-exporter-settings
'((ps-number-of-columns 2)
(ps-landscape-mode t)
(org-agenda-add-entry-text-maxlines 5)
(htmlize-output-type 'css)))

but the settings in org-agenda-custom-commands take precedence.

From the command line you may also use:

1
emacs -eval (org-batch-store-agenda-views) -kill

or, if you need to modify some parameters107

1
2
3
4
5
6
emacs -eval '(org-batch-store-agenda-views                      \
org-agenda-span (quote month) \
org-agenda-start-day "2007-11-01" \
org-agenda-include-diary nil \
org-agenda-files (quote ("~/org/project.org")))' \
-kill

which creates the agenda views restricted to the file ‘~/org/project.org’, without diary entries and with a 30-day extent.

You can also extract agenda information in a way that allows further processing by other programs. See Extracting Agenda Information, for more information.

10.8 Using Column View in the Agenda

没啥用.

Column view (see Column View) is normally used to view and edit properties embedded in the hierarchical structure of an Org file. It can be quite useful to use column view also from the agenda, where entries are collected by certain criteria.

  • C-c C-x C-c (org-agenda-columns)

    Turn on column view in the agenda.

To understand how to use this properly, it is important to realize that the entries in the agenda are no longer in their proper outline environment. This causes the following issues:

  1. Org needs to make a decision which columns format to use. Since the entries in the agenda are collected from different files, and different files may have different columns formats, this is a non-trivial problem. Org first checks if the variable org-overriding-columns-format is currently set, and if so, takes the format from there. Otherwise it takes the format associated with the first item in the agenda, or, if that item does not have a specific format (defined in a property, or in its file), it uses org-columns-default-format.

  2. If any of the columns has a summary type defined (see

Column attributes

), turning on column view in the agenda visits all relevant agenda files and make sure that the computations of this property are up to date. This is also true for the special ‘

CLOCKSUM

’ property. Org then sums the values displayed in the agenda. In the daily/weekly agenda, the sums cover a single day; in all other views they cover the entire block.

It is important to realize that the agenda may show the same entry twice—for example as scheduled and as a deadline—and it may show two entries from the same hierarchy (for example a parent and its child). In these cases, the summation in the agenda leads to incorrect results because some values count double.

  1. When the column view in the agenda shows the ‘CLOCKSUM’ property, that is always the entire clocked time for this item. So even in the daily/weekly agenda, the clocksum listed in column view may originate from times outside the current view. This has the advantage that you can compare these values with a column listing the planned total effort for a task—one of the major applications for column view in the agenda. If you want information about clocked time in the displayed period use clock table mode (press R in the agenda).

  2. When the column view in the agenda shows the ‘CLOCKSUM_T’ property, that is always today’s clocked time for this item. So even in the weekly agenda, the clocksum listed in column view only originates from today. This lets you compare the time you spent on a task for today, with the time already spent—via ‘CLOCKSUM’—and with the planned total effort for it.

时间管理的三件工具

Posted on 2019-05-15 | Edited on 2019-06-03 | In linux - system - administration | Comments:

前情概要

时间变量的顺序与时间表示的格式 总结了时间的10个变量及其直觉解析的顺序 Weekday Hour:Minute Month-Day WeekNumber Year

时间的感知与分析 阐述对时间的认知方法论以奠定高效利用和有效掌控时间的基础。

“工欲善其事必先利其器”,接下来的问题便是时间管理的工具。

时间管理的三件工具

无论是手机的android系统还是Linux系统,都提供两项基本的时间管理工具日历(calendar) and 时钟(clock).
Calendar是date地图,提供全景式的鸟瞰图; clock是指南针,指导具体的每一步应该迈向何处。
二者的结合形成第三个工具datetime。

工具虽然简单,但如果不能抽象到认知的层面,则不能为己所用。试问,谁手机里没个日历,每个钟表呢。认知层面的结论是需要且仅需要这三件工具O(∩_∩)O。

  • 日历提供全景式鸟瞰

    1
    2
    3
    4
    5
    6
    7
    8
    9
    $ ncal -B 3  #ncal中的n竟然是new这个单词
    February 2019 March 2019 April 2019 May 2019
    Su 3 10 17 24 3 10 17 24 31 7 14 21 28 5 12 19 26
    Mo 4 11 18 25 4 11 18 25 1 8 15 22 29 6 13 20 27
    Tu 5 12 19 26 5 12 19 26 2 9 16 23 30 7 14 21 28
    We 6 13 20 27 6 13 20 27 3 10 17 24 1 8 15 22 29
    Th 7 14 21 28 7 14 21 28 4 11 18 25 2 9 16 23 30
    Fr 1 8 15 22 1 8 15 22 29 5 12 19 26 3 10 17 24 31
    Sa 2 9 16 23 2 9 16 23 30 6 13 20 27 4 11 18 25
  • 时钟实施具体的测量

    1
    2
    3
    4
    $ time sleep 10
    real 0m10.011s
    user 0m0.002s
    sys 0m0.001s
  • datetime整合二者,提供更加实用的功能

    1
    2
    3
    #贸易战倒计时
    $ TZ="America/New_York" date #美东夏季时间, 第十个变量时区。
    Thu May 9 20:04:30 EDT 2019 #Eatern Daylight Timer

Python中的时间管理

以calendar, clock(time),datetime与十个时间变量为基础,审视python的calendar, time, and datetime

1. Calender

calendar — General calendar-related functions
calendar — Work with Dates — PyMOTW 3

Python中的calendar十个无关紧要的工具,没有人会费力不讨好的到这里查看日期和规划日程。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
class TextCalendar(Calendar)
| TextCalendar(firstweekday=0)
In [326]: cal = calendar.TextCalendar(calendar.MONDAY) #周一作为一周的起始点
In [327]: cal.prmonth(2019, 5)
May 2019
Mo Tu We Th Fr Sa Su
1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30 31
In [328]: cal.pryear(2019)
2019
January February March
Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su
1 2 3 4 5 6 1 2 3 1 2 3
7 8 9 10 11 12 13 4 5 6 7 8 9 10 4 5 6 7 8 9 10
14 15 16 17 18 19 20 11 12 13 14 15 16 17 11 12 13 14 15 16 17
21 22 23 24 25 26 27 18 19 20 21 22 23 24 18 19 20 21 22 23 24
28 29 30 31 25 26 27 28 25 26 27 28 29 30 31
# 只了解下TextCalendar, pryear, prmonth

2. Time

time — Time access and conversions
calendar — Work with Dates — PyMOTW 3

  • 1.与epoch time的相互转换

    Use the following functions to convert between time representations:
    人以minutes计时, 机器以second计时。

From To Use
seconds since the epoch struct_time in UTC gmtime()
seconds since the epoch struct_time in local time localtime()
struct_time in UTC seconds since the epoch calendar.timegm()
struct_time in local time seconds since the epoch mktime()
1
2
3
4
5
6
7
8
9
10
11
12
13
14
#seconds to  timetuple
In [8]: time.localtime() #local time
Out[8]: time.struct_time(tm_year=2019, tm_mon=5, tm_mday=15, tm_hour=20, tm_min=4, tm_sec=17, tm_wday=2, tm_yday=135, tm_isdst=0)

In [9]: time.gmtime() #UTC time
Out[9]: time.struct_time(tm_year=2019, tm_mon=5, tm_mday=15, tm_hour=12, tm_min=4, tm_sec=31, tm_wday=2, tm_yday=135, tm_isdst=0)

In [11]: time.gmtime(100) #
Out[11]: time.struct_time(tm_year=1970, tm_mon=1, tm_mday=1, tm_hour=0, tm_min=1, tm_sec=40, tm_wday=3, tm_yday=1, tm_isdst=0)
#timetuple to seconds
In [17]: calendar.timegm(time.gmtime()) #UTC time
Out[17]: 1557922318
In [18]: time.mktime(time.localtime()) #Local time
Out[18]: 1557922368.0
  • 2.第十一个时间变量 tm_isdst daylight saving time夏季时间

    1
    2
    3
    gmtime(...) ->time.struct_time,  (strptime, localtime)
    gmtime([seconds]) -> (tm_year, tm_mon, tm_mday, tm_hour, tm_min,
    tm_sec, tm_wday, tm_yday, tm_isdst)
  • 3.Processor Time and Timer

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    time.process_time() #cpu time  of kernel and user-space
    time.process_time_ns() ->int #not inclue sleep time
    time.perf_counter() ->float
    time.perf_counter_ns() -> int
    time.thread_time() ->float
    time.thread_time_ns() ->int
    time.time()
    time.time_ns()
    time.sleep
    time.monotonic()
    time.monotonic_ns()
  • 4.Timezone Constants

    1
    2
    3
    4
    5
    6
    In [9]: time.daylight
    Out[9]: 0
    In [10]: time.tzname
    Out[10]: ('CST', 'CST')
    In [11]: time.altzone
    Out[11]: -28800
  • 5.两个最重要的methodss

    1
    2
    time.strptime(string, format)
    time.strftime(format)
  • 6.ctime

    1
    2
    3
    4
    In [20]: time.asctime(time.localtime())
    Out[20]: 'Wed May 15 21:05:27 2019'
    In [21]: time.ctime()
    Out[21]: 'Wed May 15 21:05:32 2019'

3. Datetime

复习calendar(date), clock(time)的逻辑,先看两个没用的函数。

datetime — Date and Time Value Manipulation — PyMOTW 3

  • 1.datetime.date()

    1
    2
    3
    4
    5
    6
    7
    8
    class date(builtins.object)  就是符号%x返回的内容
    | date(year, month, day) --> date object
    In [135]: datetime.date.today().year
    Out[135]: 2019
    In [136]: datetime.date.today().month
    Out[136]: 5
    In [137]: datetime.date.today().day
    Out[137]: 9
  • 2.datetime.time()

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    class time(builtins.object) 符号%X返回的内容
    | time([hour[, minute[, second[, microsecond[, tzinfo]]]]]) --> a time object
    #5个参数,由大到小排列
    In [104]: t = datetime.time(6, 15, 30, 999999, dateutil.tz.tzutc())
    In [105]: t.strftime("%f:%S:%M:%H %Z")
    Out[105]: '999999:30:15:06 UTC'
    In [106]: t.min
    Out[106]: datetime.time(0, 0)
    In [107]: t.max
    Out[107]: datetime.time(23, 59, 59, 999999)
    In 108]: t.resolution
    Out[108]: datetime.timedelta(microseconds=1) #精确度
  • 3.datetime.datetime()

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    #前面两个datetime.time and datetime.date没啥用.
    #这里的关键是第十个时间变量tzinfo
    class datetime(date)
    | datetime(year, month, day[, hour[, minute[, second[, microsecond[,tzinfo]]]]])
    Help on built-in function weekday:

    weekday(...) method of datetime.datetime instance
    Return the day of the week represented by the date.
    Monday == 0 ... Sunday == 6
    In [200]: dt = datetime.datetime.now().replace(tzinfo=dateutil.tz.gettz("Asia/Shanghai"))
    In [201]: dt
    Out[201]: datetime.datetime(2019, 5, 9, 17, 47, 10, 421561, tzinfo=tzfile('/usr/share/zoneinfo/Asia/Shanghai'))
    In [208]: datetime.datetime.utcnow().timetuple()
    Out[208]: time.struct_time(tm_year=2019, tm_mon=5, tm_mday=9, tm_hour=9, tm_min=49, tm_sec=24, tm_wday=3, tm_yday=129, tm_isdst=-1)
  • 4.datetime.timedelta and Arithmetic Opertions

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    class datetime.timedelta(days=0, seconds=0, microseconds=0, milliseconds=0, minutes=0, hours=0, weeks=0)
    In [219]: datetime.datetime.now() + datetime.timedelta(days=-1)
    Out[219]: datetime.datetime(2019, 5, 8, 17, 57, 40, 910880)
    In [220]: !date -d "1 days ago"
    Wed May 8 17:57:52 CST 2019
    #转换为seconds的另外一种写法
    In [25]: str(datetime.timedelta(seconds=100))
    Out[25]: '0:01:40'
    In [29]: time.strftime("%H:%M:%S", time.gmtime(3000))
    Out[29]: '00:50:00'

Shell的时间管理工具

1.Calendar

1
2
3
4
5
6
7
8
$ ncal -1
$ ncal -M #Monday as the first day
$ ncal -w #weeknumber
$ncal -y -m;
$ncal -d yyyy-mm
$ncal yyyy-mm-dd#highlight the current date
$ ncal -A3 -B4
#就只有这么多操作

2.Clock(Time)

  • hwclock

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    In [31]: !sudo hwclock
    2019-05-15 21:25:29.514803+08:00
    ---------------------------------------------------
    NAME
    hwclock - time clocks utility
    FILES
    /etc/adjtime
    The configuration and state file for hwclock.
    /etc/localtime
    The system timezone file
    /usr/share/zoneinfo/
    The system timezone database directory.
    Device files hwclock may try for Hardware Clock access:
    /dev/rtc0
    /dev/rtc
    /dev/misc/rtc
    /dev/efirtc
    /dev/misc/efirtc
  • time (processing profile)

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    $ time (tree  /usr/share/zoneinfo | grep -i "prc")
    │ ├── Chongqing -> ../PRC
    │ ├── Chungking -> ../PRC
    │ ├── Harbin -> ../PRC
    │ ├── Shanghai -> ../PRC
    │ │ ├── Chongqing -> ../../PRC
    │ │ ├── Chungking -> ../../PRC
    │ │ ├── Harbin -> ../../PRC
    │ │ ├── Shanghai -> ../../PRC
    │ ├── PRC -> ../PRC
    ├── PRC
    │ │ ├── Chongqing -> ../PRC
    │ │ ├── Chungking -> ../PRC
    │ │ ├── Harbin -> ../PRC
    │ │ ├── Shanghai -> ../PRC
    │ ├── PRC

    real 0m0.017s
    user 0m0.015s
    sys 0m0.004s

3.Datetime

  • timedatectl

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    #systemd的service
    $ timedatectl
    Local time: Thu 2019-05-09 21:30:27 CST
    Universal time: Thu 2019-05-09 13:30:27 UTC
    RTC time: Thu 2019-05-09 13:30:27
    Time zone: Asia/Shanghai (CST, +0800)
    System clock synchronized: yes
    NTP service: active

    - Check the current system clock time:
    timedatectl
    - Set the local time of the system clock directly:
    timedatectl set-time {{"yyyy-MM-dd hh:mm:ss"}}

    - List available timezones:
    timedatectl list-timezones

    - Set the system timezone:
    timedatectl set-timezone {{timezone}}

    - Enable Network Time Protocol (NTP) synchronization:
    timedatectl set-ntp on
  • date (最趁手的一个工具)

    日常应用date作为思考工具.

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    In [9]: time.time()                                                                            
    Out[9]: 1557406444.1336956
    In [10]: !date +%s
    1557406449
    $ date -d @$(date +%s) #date -d @1557406449
    Thu May 9 21:11:15 CST 2019

    #基本的操作
    $ date -u +"%Y-%m-%dT%H:%M:%SZ"
    2019-05-09T12:55:31Z

    #Future date and time
    $ date -d " two weeks"
    date: invalid date ‘ two weeks’
    $ date -d "2 weeks"
    Thu May 23 21:20:17 CST 2019
    $ date -d "next fri" #只有两个变量能够以文字表述 Month and Weekday
    Fri May 10 00:00:00 CST 2019

    #the elpased date and time
    $ date -d "last thursday"
    Thu May 2 00:00:00 CST 2019
    $ date -d "2 days ago"
    Tue May 7 21:22:28 CST 2019
    $ date -d "last month"
    Tue Apr 9 21:22:39 CST 2019

    #贸易战倒计时
    $ TZ="America/New_York" date
    Thu May 9 20:04:30 EDT 2019

Emacs中的时间管理

….

总结

时间管理的三个工具, time, datetime, calendar(从微观到宏观处理5, 8, 10个时间变量)

Our units of temporal measurement, from seconds on up to months, are so complicated, asymmetrical and disjunctive so as to make coherent mental reckoning in time all but impossible. Indeed, had some tyrannical god contrived to enslave our minds to time, to make it all but impossible for us to escape subjection to sodden routines and unpleasant surprises, he could hardly have done better than handing down our present system. It is like a set of trapezoidal building blocks, with no vertical or horizontal surfaces, like a language in which the simplest thought demands constructions, useless particles and lengthy circumlocutions. Unlike the more successful patterns of language and science, which enable us to face experience boldly or at least level-headedly, our system of temporal calculation silently and persistently encourages our terror of time.

… It is as though architects had to measure length in feet, width in meters and height in ells; as though basic instruction manuals demanded a knowledge of five different languages. It is no wonder then that we often look into our own immediate past or future, last Tuesday or a week from Sunday, with feelings of helpless confusion. …

—Robert Grudin, Time and the Art of Living.

哈哈哈~,神吐槽。因此需要将so complicated, asymmetrical and disjunctive 抽象为calender, time, datetime三个工具。

参考资料

GNU Coreutils: Date input formats

时间的感知与分析

Posted on 2019-05-15 | Edited on 2019-05-16 | In timeManagement | Comments:

在前文时间变量的顺序与时间表示的格式中分析得到感知时间的5个基本变量及其顺序.
Weekday Hour:Minute Month-Day 记作 %w %H:%M %d-%m

对时间流逝的测量分为两个维度:
一是仪器在微观层面上的的准确测量,比如钟表或者计算机
二是直觉在宏观层面上的粗略感知.

接下来的问题,如何有效的把握住一天的时间,如何对一天24小时有良好的感知.

宏观层面粗颗粒度的时间感知

一天有24小时,大脑的直觉系统(系统一)不能直接处理24这个复杂的数字,需要调动“系统二”理性的助攻.
“系统一”能处理3以内的数字,10以内的数字,比如列清单最好3项,最多七项,更多则聊胜于无.

因此应该分割24小时成10内的模块.

选项一: 二分,白天和黑夜
选项二: 四分, 象限图 (比如AM, PM, 黑夜, 凌晨)
选项三: 八分

二分与四分的颗粒度过大,八分是不错的选项, 以3个小时为一个模块,称为Phrase阶段.

参考维基百科的划分一日之时细分

No 时间段 维基命名 修正命名 理由
1 0时~3时 凌晨 深夜(deep night or good night) 后面详叙
2 3时~6时 拂晓 拂晓(或者破晓, dawn)
3 6时~9时 早晨 晨曦(or 晨曦,清晨 Morning) 将晨字放到前面
4 9时~12时 午前 午前(forenoon)
5 12时~15时 午后 午后(afternoon postnoon) 没有更好的英语词汇
6 15时~18时 傍晚 傍晚(evening, approach) 也没有更好的英语词汇
7 18时~21时 薄暮 薄暮(Dusk)
8 21时~24时 深夜 夜晚(Night) $

将”凌晨”修改为”深夜”的理由是, 看到”晨”这个字眼,将联想到’一天之计在于晨’,潜意识自动被调动起来,不利于晚间的休息和养成良好的作息习惯,取名深夜或者晚安.
时间段的命名,中文的表述更为精确,因此后续采用中文命名.

微观层面细颗粒度的时间感知

对时间的精确测量很简单,低头看一眼手表便可.难点在于如何引导直觉或者大脑的“系统一”感知到精确的时间.

具体的例子,如何认识“早上 6:30”这个时刻.

首先看Hour(6点), 盯着看半天,学着格物致知,并不能读到什么信息能在宏观层面上上辅助直觉的理解.
用点数学,可以借助'分数'辅助直觉.将6点读成6/24, 含义是一天的24小时中的6个小时已经流逝而去;
如此便将微观的时刻与宏观的一天,以进度条的方式关联起来.对大脑提供的直接信息是, 从一天这个整体概念中感知具体的时刻.

再看Minute(30分), 同理可以读成30/60, 将minute与hour关联起来.
以60分钟为底数,可以理解为时间感知的最小单位是10分钟,而选择60又比选择6好一点儿.

整体来看06:30这个时刻 06/24: 30/60

选择起始时刻

如上所述,早上6点,可以表示为6/24,单靠直觉便能感知到具体的时刻在一整天这个进度中的位置。

观察6/24,会发现一个问题,如果早晨6点起床, 那么在睁开眼醒来的一瞬间,这一天的24小中的6个小时就没了, 一天的的1/4就没了。这太让人沮丧, 真没有心情做事.
如果醒来却拥有完整无缺的24小时该有多么美妙, 那样会更加积极地投入到一天之中.

解决方案是选择早上6:00作为一天起始点. 该方案的优点,除了可以完整的获得24小时之外,还能奖励早起和辅助养成良好的作息习惯.

比如5点起床,意味着这一天多出了一个小时,仿佛是从时间之神Chrones手中偷得了一个小时,赢在起跑线上, 构筑起来很强的心理优势.

另外一个意外之喜则是可以鼓励早睡.

选择新的起始时刻后,重新审视一天的八分图.

No 时间段 维基命名 修正命名 理由
7 0时~3时 凌晨 深夜(deep night or good night) 后面详叙
8 3时~6时 拂晓 拂晓(或者破晓, dawn)
1 6时~9时 早晨 晨曦(or 晨曦,清晨 Morning) 将晨字放到前面
2 9时~12时 午前 午前(forenoon)
3 12时~15时 午后 午后(afternoon postnoon) 没有更好的英语词汇
4 15时~18时 傍晚 傍晚(evening, approach) 也没有更好的英语词汇
5 18时~21时 薄暮 薄暮(Dusk)
6 21时~24时 深夜 夜晚(Night) $

如上图,晚上12点并非一天的结束, 因此熬夜偷不到任何时间,也不会获得比别人多出来更多的时间的虚假心理满足感.相反,熬夜是障碍,导致不能早起,导致不能从chrones手中偷得额外时间.

小结:选择6点作为起始时刻

1)建立心理优势账户
2)从理性和感性两个方面否定熬夜
3)养成早起的好习惯。

将6:00理解成 00:00.

两个重要时间节点

以早晨6点作为时间感知的0点,有两个重要的时间节点里程碑:
一是中午12点,这是AM与 PM的划分点,是白昼的一半
二是下午6点,这是一整天的一半.

可以通过这两个时间节点下的进度和已完工作,粗略估算和预测.而且很重要的一点,假如在下午6点预估到不能按期完成任务,可以选择的方案是早起赶工而非熬夜赶工.(晚上12点非一天的结束,拂晓6点才是昨日之终和今日之始)

12小时制还是24小时制

首先来看12小时制,将一天分为白昼和黑夜两个部分,这一点很棒负,符合人的自然直觉。接下来分别针对白昼和黑夜进行计时。
白昼是从早上6点到晚上6点,黑夜是从晚上6点到早上6点。早上6点可以表示为 (6-6)/12, 白天的0/12.
这样划分的结果是以地平线作为昼夜分割线,与AM,PM将中午12点作为一天的分割线的标准相冲突。不仅需要做6-6的转换,还需要做AM, PM转换。

其次24小时制, 24小时保证了一天的连贯性,不论是5/24还是15/24,都在同一个尺度下比较。

综上,暂时选择24小时制。

认识具体时间的算法

在宏观层面的八分图与微观层面的分数表示的基础上,如何解析一个具体的时间呢?
比如一个比较古怪的14:39这个时间如何理解?

第一步, 先看Hour(14), 从粗略上感知, 14点是午后,这是从电脑或者手表等仪器上的数字读取的。 但是,午后这个时间概念,不需要借助仪器,可以从身体的疲惫状态,从窗外光线的强度,甚至从个人的生物钟便可以感知到(大体会有感觉一天过去了多久)。单单依靠感觉或许不能准确估量到小时这个单位,但是估摸到是午后,傍晚,夕阳西下还是旭日东升? 是黎明还是黄昏? 在3个小时的误差允许的范围内,应该是没有问题的。或许,长时间的训练还能提高个体的感受力,做仪器和工具的主人而非奴隶;

第二步, 所以第一步工作并非读14这个数字,而是调用直觉,调用人的动物本能去感受一下当前的时间,大概估算出是八分图的哪一个阶段。比如吃完午饭似乎有一段时间了,但是工作起来没精神,大概这个就是午后综合征。拿到“午后”这个概念之后,继续分析“午后”是什么意思?潜意识里如何理解“午后”呢。午后是白昼的一半时间已经过去了,现在处在白昼3/4的位置上,用八分图表示则是3/8的位置。模糊概念上“午后”等于准确测量的“3/8”。但是只需要停留在“午后”这个概念即可,不必显性的将3/8读出来,那是潜意识的工作

第三步,通过前两部得到“午后”这个时间段,并且通过调用感受力去判断出这个时间段的过程,潜意识里或许有了如3/8这样的数字。午后就是3/8,但午后这个文字描述更加亲切,不需要消耗脑力。
现在开始看表,一看是14:39, 14这个数字很亲切,因为与直觉感受到“午后”是相一致的。调用大脑的系统二读14点这个数字是14/24, 这个进度挺可怕,刚吃完午饭,一天的24小时里的14个小时已经没了, 着实使人沮丧。好消息是要从14里减去6, (14-6)/ 24 = 8/24, 减法算的太开心了。如此与模糊概念上的“午后”便对应起来。 在粗颗粒度下,当前处在大约一天中3/8的位置,而理性的细颗粒度下则是在8/24这个准确的位置上(一天还只过去了三分之一,还拥有三分之二的时间筹码在手上)e。

第四步, 读minutes, 39表示为39/60, 一个小时是最宝贵的资源,所有的工作都在一个一个的一个小时内展开。定性分析一个小时,可以将钟表盘想象成一个没有数字刻度的饼图, 粗略估算下饼图的切口在哪里, 39/60就是一半多一点点。定量分析则以10分钟为一个单位, 将饼图分为六个部分。

第五步, 实际的工作是在一个小时的范围内,读到39/60, 定性分析下,原计划一个小时内完成的工作能否如期交付, 定量分析下按照当前的进度大概需要几个小时?

总结, 前两部(2/5)从感觉上定性分析当前所处的时间段, 第三步和第四步调用理性定量读取时间, 第五步,有效利用最有价值的资源每一个一个小时。

估算时间段

分数有定性和定量, 串通理性与感性,宏观与微观的神奇作用。
具体的例子,比如有好看的综艺节目大概一个小时,用分数定性看一眼1/24,一天的二十四之一; 刷个手机半个小时 30/60,一个小时的一半没了,而一个小时是一天的二十四分之一。

分数的方法可以帮助explicitly珍惜时间。

总结

粗颗粒度下应用八分图辅助直觉粗略的感知一天内的时间,应用饼图粗略感知一个小时内的时间;
细颗粒度下应用分数15/24, 41/60,定性与定量相结合分析。
挥霍时间前,先用24这个数字定性审视感受一下。

17:31这个时间,
1) 傍晚,傍晚这个词太好了,傍->依傍,approach, 向晚。
2) 粗略感受下在八分图中的位置, 17点是个特殊的数字,距离之前定义的两个重要的时间节点中的18:00很近。
3) (17-6)/24 = 11/24, 马上就12/24,一天的一半即将结束。
4) 31/60 同时也从饼图上感受下这一个小时的流逝
5) 根据31/60定性和定量分析当前的工作。

综上,再来看具体的一天, 三个变量最重要,

1) 周几, 周三(3/7 )
2) 小时 (小时是一天的进度条)
3)分钟 (分钟是小时的进度条)

参考资料

  • 拂晓 - 维基百科,自由的百科全书
  • Day - Wikipedia
  • Sunrise - Wikipedia
  • Chronodex:时间饼的用法、研习、使用心得及灵感收集
  • Chronodex 一張圓錶圖完滿每一天,視覺系手帳行事曆上手教學
  • 《思考,快与慢》
  • 《金字塔原理》

Ubuntu 18.10安装ibus-rime输入法

Posted on 2019-05-14 | Edited on 2019-05-15 | In linux - fileManager | Comments:

照搬 Ubuntu 18.04 安装 ibus-rime 输入法

目的

安装rime输入法的初衷是解决搜狗输入法导致系统经常性崩溃的问题。

工具/原料

  • Ubuntu 18.10
  • RIME | 中州韻輸入法引擎
  • rime/librime: Rime Input Method Engine, the core library

方法与步骤

一、安装前的准备

1
2
sudo apt install ibus-rime(安装rime输入法)
sudo apt install librime-data-pinyin-simp (安装简体拼音库)

二、设置自定义文件

在 ~/.config/ibus/rime/ 下新建一个文件 default.custom.yaml (覆盖默认设置)

1
2
3
4
5
6
7
8
9
10
11
$ ls -lSh  ~/.config/ibus/rime | sed "s/$USER/me/g"
total 32K
drwxrwxr-x 2 me me 4.0K May 14 12:15 build
drwxr-xr-x 2 me me 4.0K May 14 12:45 luna_pinyin.userdb
drwxr-xr-x 2 me me 4.0K May 14 11:14 pinyin_simp.userdb
drwxrwxr-x 3 me me 4.0K May 14 08:59 sync
-rw-rw-r-- 1 me me 202 May 14 08:58 installation.yaml
-rw-r--r-- 1 me me 120 May 14 12:12 default.custom.yaml
-rw-r--r-- 1 me me 74 May 14 11:36 #default.custom.yaml#
-rw-rw-r-- 1 me me 34 May 14 12:15 user.yaml
-rw-r--r-- 1 me me 0 May 14 09:33 default.custom.yaml~

自定义文件的内容

1
2
3
4
5
6
7
$ cat ~/.config/ibus/rime/default.custom.yaml
patch:
style/horizontal: true #无效的设置
schema_list:
- schema: luna_pinyin_simp
style:
- horizontal: true #无效的设置

三、重启系统, 使安装生效

四、调出Chinese(Rime)

打开“setting(设置)”, “Region&Language(区域和语言)”,点+号, 添加输入法 Chinese(Rime) 。如果不用其它输入法,可以删除,其实也真不用其它输入法了.

五、部署

系统右上角选择输入法, 下拉部署

注意事项

  • 不必要做过多的设置,够用就行。

下一步的计划

大范围的应用的autokey

参考资料

  • Rime输入法—鼠须管(Squirrel)词库添加及配置 - 简书
  • ubuntu16.04 安装 rime输入法 - 简书
  • RimeWithIBus · rime/home Wiki
  • Ubuntu 18.04 安装 ibus-rime 输入法
  • Rime 输入法配置记录
  • 鼠须管,“神级” 输入法 | 爱范儿
  • Rime 输入法配置小结 - Havee’s Space
  • 「鼠须管」的调教笔记
  • Hot key to type today’s date? - Ask Ubuntu
  • autokey/autokey: AutoKey, a desktop automation utility for Linux and X11

时间变量的顺序与时间表示的格式

Posted on 2019-05-13 | Edited on 2019-05-15 | In linux - system | Comments:

时间的感知

直觉对时间的感知, 是按照怎么的顺序解析的呢?
从早晨起床这个场景中,分析大脑解析时间的顺序.

似乎理所当然的一点,Hour(时)排在最前面,Hour:Minute的组合是醒来后第一时间想要获得的信息,以判断上班是否迟到,是否有时间吃早餐?但是再想一层,上班是否迟到? 在处理Hour:Minute之前,潜意识已经先获取并处理完了一个信息:今天是周几?(Weekday).如果是周末的话,几点几分起床并不特别重要.
因此,最先处理的三个变量是Weekday Hour:Minutes

再看日期,Month-Day,哪个变量在前呢?
如果day在前,则是冗余信息,因为已经weekday在先.
解析日期,首先获取Month,以判断一年的进度,获得当前时间在一年中所处的位置,比如May的含义是一年已经将半.
日期的顺序是Month-Day

还有变量week number,是对一年进度的另外一种表示.

最后是Year

综上, 直觉解析时间的顺序为:
Weekday Hour:Minute Month-Day WeekNumber Year, 要事第一,最重要的信息是Weekday.
合计8个变量, 命名为intuitive time(or intelligent time)简写为itime

这也是CTIME时间格式的理念.

1
2
3
4
In [2]: time.ctime()    
Out[2]: 'Wed May 15 08:29:38 2019'
In [3]: !date
Wed May 15 08:31:45 CST 2019

ctime将weekday安排在最前面,然后遵循这个先处理日期的逻辑,May:15跟在后面提高日期的精确颗粒度.但是对大脑的瞬间思考而言,则是冗余信息.因此以itime作为基石,推导拓展到其他时间顺序.

Cron中时间变量的顺序

The sequence matters.
时间变量顺序的第一个应用场景是cron.

Cron的顺序是Minute:Hour Day:Month Weekday

1
2
3
4
5
6
7
8
9
# ┌───────────── minute (0 - 59)
# │ ┌───────────── hour (0 - 23)
# │ │ ┌───────────── day of the month (1 - 31)
# │ │ │ ┌───────────── month (1 - 12)
# │ │ │ │ ┌───────────── day of the week (0 - 6) (Sunday to Saturday;
# │ │ │ │ │ 7 is also Sunday on some systems)
# │ │ │ │ │
# │ │ │ │ │
# * * * * * command to execute

大脑长于处理模糊宏观的信息,而机器专于精确的信息,将最小的时间单位排在前面,是倒排的ctime.应用的时候也只需要将思考倒叙.

cron将minute作为最小单位和第一顺序是因为crond按分钟扫描,可见从性能经济性的角度考虑,对大脑和对机器, 秒都是可以忽略的,不然会浪费大量的资源.

接下来讨论一个问题:
在感知上, minutes:hours 与hours:minutes有何差异呢?

minutes:hours的顺序,是将精力关注到一个小时之内,比如六点十五15:06表达出来是,在从6点到7点这一个小时的时间段内,已经过去了15分钟,知道现在已经消费了一个小时的四分之一(1/4),接下来就会自然的发问,按照这个进度,等一个小时结束能完成多少工作.
而hours:minutes的顺序,是关注在一天之内,比如06:15表达的是,现在是早上时间(6/24),一天之计在于晨,后面的分钟15只是作为辅助.
总结:hour:minutes(6:15)关注的是一天之内,而minute:hour关注的是一个小时之内,以一个小时为单位做计划和考核产出.

在直觉上采用哪一个作为基础,等更多的应用总结后,再行确定.暂时采用Hour:Minute的格式,因为minute:hour消耗更多大脑内存和计算资源.

总结, cron是写给机器读的,对象是机器,因此将ctime倒叙.

需要记住时间顺序的另外一个应用场景是journalctl

1
journalctl --since  “YYYY-MM-DD HH:MM:SS” --until “YYYY-MM-DD HH:MM:SS”

从宏观到微观,从模糊到精确,这是写给人用的时间格式,也是ISO的标准时间格式.

引用一段话:

Your computer is not a lifeless piece of machinery. It is a dynamic tool that interacts with your very thought processes. Whenever you use a computer it becomes, for better or for worse, an extension of your mind.

This means that, whenever you use a Unix or Linux system, you are forging a mental relationship with some of the smartest, most accomplished (and satisfied) programmers and computer scientists who ever lived.
Such a partnership can’t help but have a positive effect on you.

As you do, your mind will change for the better, your thought processes will improve, and your way of looking at the world and at yourself will change.

时间的格式

以Cron的5个时间变量顺序为基础分析时间表示的格式,
前面加上second+(minute, hour day, month weekday)后面补充year and weeknumber.

时间的格式以C, python采用的unix strftime格式为准.

时间变量 1.second 2.minute 3.hour 4.day 5.month 6.weekday 7.week number 8.year
常规符号 %S 01 %M 01 %H 23 %d 01 %m 01 %w (0-6) %W %y 19
简单扩展 %I (12-hour), %p AM %Y 2019
文字描述 %b Oct, %BOctober %a Thu, %A Thursday
Obscure扩展 %f 微秒 % e 1~31 %j 366 %u(1~7) %V %U %G 2019

分析:

第一行, 钟表时间全部为大写, 日期时间全部为小写, WeekNumber大写%W与weekday %w相区分;
第二行, 简单扩展, %H是24小时制, H后面的字母是I,因此用%I表示12小时制,同时%p(postnoon)标注上下午; 大写的%Y表示四位数字的年2019;
第三行, 文字描述,只有两个变量能以文字描述, weekday和month, 分别用A, B表示.weekday %A还是第一重要的.

前三行是常规的表示.

第四行, obscure扩展, 微秒的表示应该是从剩余可选字母中随机确定的, %f(fly飞逝),和数日子day 366 %j , %e空格padding. weekday与weekNumber在u, v, w这三个字母上打转, 小写是weekday大写是weekNumber.

总结: 按照表格前三行可以在一秒钟内永久性记忆, 日常的书写也采用该格式. 日如ctime %a %b %d %H:%M:%S %Y

Timezone的表示

1
2
3
4
In [7]: !date +"%z"   #UTC offset                                                                                                 
+0800
In [8]: !date +"%Z"
CST #China Standard Time

快捷方式的format

1
2
3
4
5
6
In [10]: datetime.now().strftime("%c")      #Locale’s appropriate date and time representation.                                                                              
Out[10]: 'Thu May 9 11:48:33 2019 #这个格式将weekday放在了前面, 也就是 %a %b的形式.
In [11]: datetime.now().strftime("%x") #Locale’s appropriate date representation
Out[11]: '05/09/19'
In [12]: datetime.now().strftime("%X")
Out[12]: '11:49:06'

总结10个时间变量,将时区放置在最后.

%f:%S:%M:%H %d-%m %w %W %Y %Z
日常的书写,使用符号替代minute, hour等

时间格式的的标准:

  1. ISO 8601 - Wikipedia
  2. W3C DTF
  3. RFC 822(as updated by RFC 1123)
  4. RFC 2822 - Internet Message Format
    ISO 8601

Django的built-in template 用的是php的format
Built-in template tags and filters | Django documentation | Django
PHP: date - Manual

datetime.strptime()参数顺序的问题

Posted on 2019-05-08 | Edited on 2019-05-15 | In linux - system | Comments:

提出问题

经常会错写datetime.strptime(string, format),颠倒两个参数的顺序而写成datetime.strptime(format, string) 与re.find(pattern, string)相混淆.

分析问题

datetime.strptime()

1
2
3
4
5
6
strptime(string, format) method of builtins.type instance
string, format -> new datetime parsed from a string (like time.strptime()).

#Case
In [6]: datetime.strptime("8 May, 2019", "%d %B, %Y")
Out[6]: datetime.datetime(2019, 5, 8, 0, 0)

strptime的函数命名不太好, 词义模糊, 不如直接叫str2time. string是source, time是result.

本函数的工作是parse a string to produce a time object. strptime 的字面含义读起来却像是毫无意义的string to parse time或者是读成相反的含义parse time to produce a string.妥协的处理方法理解为”string parsed” to time.将strp当做一个组合名词strp2time

官方的strptime命名比较str2time的优点是存在动词parse,点出函数的内部逻辑需要做的核心工作是解析,将普通的字符串解析成为有实际价值和意义的时间对象.(更像是开发者提醒自己非写给API的用户)

1
2
3
datetime.strptime(string, format)
#扩展为
def strptime(src_string, parsed_format) -> "dst_time_object":

这样看来strptime还是符合 source to destination 的模式.

容易混淆string与format顺序的一个直接原因是存在re.match(pattern, str), 按照module re的这个思路, 要事第一,对strptime(string, format)的处理应该将format拿到前面.

对此的理解:

一, source to destination是惯例, strptime(string, format)没有打破惯例
二, regex突破了惯例, 可能因为consturct regex需要花费较多脑力,而其他如time-format并不需要.
(regex的所有的methods都是将构建regex-pattern作为第一个参数)

三, 处理strptime从字面含义去引导直觉. strptime(string, parsed-format) to a time-object

datetime.strftime()

容易混淆的另外一个原因是strptime的逆函数strftime

1
2
3
4
5
6
strftime(format)
format -> strftime() style string.
In [8]: dt
Out[8]: datetime.datetime(2019, 5, 8, 0, 0)
In [9]: dt.strftime("%d %B, %Y")
Out[9]: '08 May, 2019'

strftime是time2str

受strftime (string format time)这个命名的影响, 很容易写作

1
datetime.strftime("%d %B, %Y", time_obj)

可能想一下会意识到没有充分利用time_obj已经是datetime object这个既成事实, 应该打开其内建的工具箱.
strftime 中的str是多余的, 既然是format, return的结果一定是string.去掉str只留下 ftime更为简洁.
strftime对比str2time的优点,也是有一个显性的动词format.
与strptime(string,parsed_format)对应

1
2
#strftime可以写为
def strftime(self, format) -> string:

观察time_object.strftime(format) - > string 的结构,遵循 src to dst 的原则.作为src的time_object写在前面.输出的结果为string.

总结, 

strptime def strptime(src_string, parsed-format) ->dst_time 与`src_time_object.strftime(string_format)都遵循`src to dst 的原则,引起歧义的根源是两个函数的命名.
解决方案 strptime 直觉扩展为strp string parsed + to + timet
strftime,将多余的str去掉,ftime format time , str当做冗余的形容词修饰format. stringly format.
P.S. format time to string不是一个好的解决方案,因为颠倒了src和dst.
两个动词是核心,parse or format.如果是parse的工作,输出结果time_object.做format的工作,就return string.

应用时刻的思维链条:
parse -> parse src_string to dst_time -> string parsed to time-> datetime.strptime(src_string, format)

format -> format src_time to dst_string-> stringly format time to string ->time_object.strftime(format)

1)辨析parse or format 2)都遵循 src to dst 3) str[pf]time顺序不变.

除了re.search(pattern, src)之外,还有一个不守规矩的特例.

1
2
3
4
5
6
In [12]: "source to destination".split()                                                                                      
Out[12]: ['source', 'to', 'destination'] #遵循source to destination, convert src_str to dst_list
#逆操作却将要输出的结果放在了前面.
In [13]: " ".join(['source', 'to', 'destination'])
Out[13]: 'source to destination'
#显然['source', 'to', 'destination'].join(" ")更为合理 convert src_list to dst_string

可能的解释, Python将所有涉及string的操作集中在了一处.

1
2
3
4
In [16]: len([m for m in dir(str) if not m.startswith("__")])                                                                 
Out[16]: 45
In [17]: len([m for m in dir(list) if not m.startswith("__")])
Out[17]: 11

methods of string 是list的四倍.

辨析特例与常规.

regex和”,”.join是特例, strptime, strftime, str.split是常规.

date and clock

Maintain system time是操作系统提供的最基础的service API.

1
2
3
4
5
6
7
8
9
10
$ date -u
$ sudo hwclock -u
2019-05-08 20:19:14.764965+08:00
#str2time,
$ date -d "08 May 2019" +"%c"
Wed 08 May 2019 14:00:00 AM CST
#time2str, strftime
$ date +"%d %B, %Y"
08 May, 2019
#思路与strptime, strftime一致.

参考资料

strftime() and strptime() Behavior
Python strptime() - string to datetime object

datetime — Basic date and time types — Python 3.7.3 documentation

How To Format Date For Display or Use In a Shell Script - nixCraft

Convert string to date in bash - Stack Overflow

GNU Coreutils: Examples of date

date command in Linux with examples - GeeksforGeeks

1234

Gabriel

32 posts
16 categories
30 tags
GitHub
© 2019 Gabriel
Powered by Hexo v3.8.0
|
Theme – NexT.Mist v7.1.1