summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBastien Guerry <bzg@altern.org>2011-07-25 15:45:01 +0200
committerBastien Guerry <bzg@altern.org>2011-07-25 15:45:01 +0200
commit07a2f48209a8a5c162027ce30cae5ab95147532f (patch)
tree49a3c499420775ff71838540b23a2881e03e2c8a
parentbbb2ef510ae8fbf28296c8968b99a24408c7c3ce (diff)
parentee3ea164c945268213d3e78ce2548943877790fe (diff)
downloadorg-mode-07a2f48209a8a5c162027ce30cae5ab95147532f.tar.gz
Merge branch 'master' of orgmode.org:org-mode
-rw-r--r--lisp/org-footnote.el37
-rw-r--r--lisp/org.el33
2 files changed, 51 insertions, 19 deletions
diff --git a/lisp/org-footnote.el b/lisp/org-footnote.el
index 5d1736c..7c49eae 100644
--- a/lisp/org-footnote.el
+++ b/lisp/org-footnote.el
@@ -479,21 +479,30 @@ or new, let the user edit the definition of the footnote."
(org-footnote-goto-local-insertion-point)
(org-show-context 'link-search))
(t
- (let ((re (concat "^" org-footnote-tag-for-non-org-mode-files "[ \t]*$")))
- (unless (re-search-forward re nil t)
- (let ((max (if (and (derived-mode-p 'message-mode)
- (re-search-forward message-signature-separator nil t))
- (progn (beginning-of-line) (point))
- (goto-char (point-max)))))
- (skip-chars-backward " \t\r\n")
- (delete-region (point) max)
- (insert "\n\n")
- (insert org-footnote-tag-for-non-org-mode-files "\n"))))
- ;; Skip existing footnotes
- (while (re-search-forward "^[[:space:]]*\\[[^]]+\\] " nil t)
- (forward-line))))
+ ;; In a non-Org file. Search for footnote tag, or create it if
+ ;; necessary (at the end of buffer, or before a signature if in
+ ;; Message mode). Set point after any definition already there.
+ (let ((tag (concat "^" org-footnote-tag-for-non-org-mode-files "[ \t]*$"))
+ (max (save-excursion
+ (if (and (derived-mode-p 'message-mode)
+ (re-search-forward
+ message-signature-separator nil t))
+ (copy-marker (point-at-bol) t)
+ (copy-marker (point-max) t)))))
+ (goto-char max)
+ (unless (re-search-backward tag nil t)
+ (skip-chars-backward " \t\r\n")
+ (delete-region (point) max)
+ (insert "\n\n" org-footnote-tag-for-non-org-mode-files "\n"))
+ ;; Skip existing footnotes.
+ (while (re-search-forward org-footnote-definition-re max t))
+ (let ((def (org-footnote-at-definition-p)))
+ (when def (goto-char (nth 2 def))))
+ (set-marker max nil))))
+ ;; Insert footnote label, position point and notify user.
+ (unless (bolp) (insert "\n"))
(insert "\n[" label "] \n")
- (goto-char (1- (point)))
+ (backward-char)
(message "Edit definition and go back with `C-c &' or, if unique, with `C-c C-c'.")))
;;;###autoload
diff --git a/lisp/org.el b/lisp/org.el
index 36bcaba..81a993f 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -15592,7 +15592,7 @@ With prefix ARG, change that many days."
The date will be changed by N times WHAT. WHAT can be `day', `month',
`year', `minute', `second'. If WHAT is not given, the cursor position
in the timestamp determines what will be changed."
- (let ((pos (point))
+ (let ((origin (point)) origin-cat
with-hm inactive
(dm (max (nth 1 org-time-stamp-rounding-minutes) 1))
org-ts-what
@@ -15602,6 +15602,10 @@ in the timestamp determines what will be changed."
(error "Not at a timestamp"))
(if (and (not what) (eq org-ts-what 'bracket))
(org-toggle-timestamp-type)
+ ;; Point isn't on brackets. Remember the part of the time-stamp
+ ;; the point was in. Indeed, size of time-stamps may change,
+ ;; but point must be kept in the same category nonetheless.
+ (setq origin-cat org-ts-what)
(if (and (not what) (not (eq org-ts-what 'day))
org-display-custom-times
(get-text-property (point) 'display)
@@ -15652,11 +15656,30 @@ in the timestamp determines what will be changed."
(setcar (nthcdr 1 time0) (or (nth 1 time0) 0))
(setcar (nthcdr 2 time0) (or (nth 2 time0) 0))
(setq time (apply 'encode-time time0))))
- (setq org-last-changed-timestamp
- (org-insert-time-stamp time with-hm inactive nil nil extra))
+ ;; Insert the new time-stamp, and ensure point stays in the same
+ ;; category as before (i.e. not after the last position in that
+ ;; category).
+ (let ((pos (point)))
+ ;; Stay before inserted string. `save-excursion' is of no use.
+ (setq org-last-changed-timestamp
+ (org-insert-time-stamp time with-hm inactive nil nil extra))
+ (goto-char pos))
+ (save-match-data
+ (looking-at org-ts-regexp3)
+ (goto-char (cond
+ ;; `day' category ends before `hour' if any, or at
+ ;; the end of the day name.
+ ((eq origin-cat 'day)
+ (min (or (match-beginning 7) (1- (match-end 5))) origin))
+ ((eq origin-cat 'hour) (min (match-end 7) origin))
+ ((eq origin-cat 'minute) (min (1- (match-end 8)) origin))
+ ((integerp origin-cat) (min (1- (match-end 0)) origin))
+ ;; `year' and `month' have both fixed size: point
+ ;; couldn't have moved into another part.
+ (t origin))))
+ ;; Update clock if on a CLOCK line.
(org-clock-update-time-maybe)
- (goto-char pos)
- ;; Try to recenter the calendar window, if any
+ ;; Try to recenter the calendar window, if any.
(if (and org-calendar-follow-timestamp-change
(get-buffer-window "*Calendar*" t)
(memq org-ts-what '(day month year)))