下一个/上个月在议程视图和日历中的自定义功能 [英] Custom function for next / previous month in agenda view and the calendar

查看:123
本文介绍了下一个/上个月在议程视图和日历中的自定义功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一种在议程视图和日历中选择 next previous month的方法。我已经写了一个概念/原型函数(下面),但是它不会计算下一个下一个 previous months我也需要每月重写这个功能。

I'm looking for a way to select next or previous month in both agenda view and the calendar. I've written a concept/prototype function (below), but it doesn't calculate the next or previous months and I would also need to rewrite the function every month.

org-agenda-month-view的日期格式 calendar-other-month 的日期格式不同。下面还有一些与我正在努力完成的功能相关的功能 - 例如,日历已经有能力按月前进或后退。

The date format for the org-agenda-month-view is different than the date format for calendar-other-month. Further down below are some functions that are related to what I'm trying to accomplish -- e.g., calendar already has the ability to move forward or backward by month.

我认为可能需要的是识别被查看的月份的功能,然后在点击下一个或<$时添加正负一个月(正确的格式) c $ c>以前的按钮。

I think what may be needed is a function that identifies the month being viewed and then adds plus-or-minus one month (in the proper format) when hitting the next or previous button.

(defun lawlist-org-agenda-view-mode-dispatch ()
  "Select the month in agenda view."
  (interactive)
  (message "View: [7] JUL | [8] AUG | [9] SEP | [o]CT | [n]OV | [d]EC ")
  (let ((a (read-char-exclusive)))
    (case a
      (?7
        (org-agenda nil "a")
        (org-agenda-month-view 201307)
        (calendar)
        (calendar-other-month 7 2013)
        (lawlist-org-agenda-view-mode-dispatch))
      (?8
        (org-agenda nil "a")
        (org-agenda-month-view 201308)
        (calendar)
        (calendar-other-month 8 2013)
        (lawlist-org-agenda-view-mode-dispatch))
      (?9
        (org-agenda nil "a")
        (org-agenda-month-view 201309)
        (calendar)
        (calendar-other-month 9 2013)
        (lawlist-org-agenda-view-mode-dispatch))
      (?o
        (org-agenda nil "a")
        (org-agenda-month-view 201310)
        (calendar)
        (calendar-other-month 10 2013)
        (lawlist-org-agenda-view-mode-dispatch))
      (?n
        (org-agenda nil "a")
        (org-agenda-month-view 201311)
        (calendar)
        (calendar-other-month 11 2013)
        (lawlist-org-agenda-view-mode-dispatch))
      (?d
        (org-agenda nil "a")
        (org-agenda-month-view 201312)
        (calendar)
        (calendar-other-month 12 2013)
        (lawlist-org-agenda-view-mode-dispatch))
      (?q (message "Abort"))
      (otherwise (error "Either press \"q\" to quit, or select another option." )))))






以下是从 cal-move.el 中提取的一些相关功能, calendar.el


Here are some related functions I've extracted from cal-move.el and calendar.el:

(defun calendar-other-month (month year &optional event)
  "Display a three-month calendar centered around MONTH and YEAR.
EVENT is an event like `last-nonmenu-event'."
  (interactive (let ((event (list last-nonmenu-event)))
                 (append (calendar-read-date 'noday) event)))
  (save-selected-window
    (and event
         (setq event (event-start event))
         (select-window (posn-window event)))
    (unless (and (= month displayed-month)
                 (= year displayed-year))
      (let ((old-date (calendar-cursor-to-date))
            (today (calendar-current-date)))
        (calendar-generate-window month year)
        (calendar-cursor-to-visible-date
         (cond
          ((calendar-date-is-visible-p old-date) old-date)
          ((calendar-date-is-visible-p today) today)
          (t (list month 1 year))))))))

;;;###cal-autoload
(defun calendar-forward-month (arg)
  "Move the cursor forward ARG months.
Movement is backward if ARG is negative."
  (interactive "p")
  (calendar-cursor-to-nearest-date)
  (let* ((cursor-date (calendar-cursor-to-date t))
         (month (calendar-extract-month cursor-date))
         (day (calendar-extract-day cursor-date))
         (year (calendar-extract-year cursor-date))
         (last (progn
                 (calendar-increment-month month year arg)
                 (calendar-last-day-of-month month year)))
         (day (min last day))
         ;; Put the new month on the screen, if needed, and go to the new date.
         (new-cursor-date (list month day year)))
    (if (not (calendar-date-is-visible-p new-cursor-date))
        (calendar-other-month month year))
    (calendar-cursor-to-visible-date new-cursor-date))
  (run-hooks 'calendar-move-hook))

;;;###cal-autoload
(defun calendar-backward-month (arg)
  "Move the cursor backward by ARG months.
Movement is forward if ARG is negative."
  (interactive "p")
  (calendar-forward-month (- arg)))

;;;###cal-autoload
(defun calendar-forward-year (arg)
  "Move the cursor forward by ARG years.
Movement is backward if ARG is negative."
  (interactive "p")
  (calendar-forward-month (* 12 arg)))

;;;###cal-autoload
(defun calendar-backward-year (arg)
  "Move the cursor backward ARG years.
Movement is forward is ARG is negative."
  (interactive "p")
  (calendar-forward-month (* -12 arg)))

;;;###cal-autoload
(defun calendar-scroll-left (&optional arg event)
  "Scroll the displayed calendar left by ARG months.
If ARG is negative the calendar is scrolled right.  Maintains the relative
position of the cursor with respect to the calendar as well as possible.
EVENT is an event like `last-nonmenu-event'."
  (interactive (list (prefix-numeric-value current-prefix-arg)
                     last-nonmenu-event))
  (unless arg (setq arg 1))
  (save-selected-window
    ;; Nil if called from menu-bar.
    (if (setq event (event-start event)) (select-window (posn-window event)))
    (calendar-cursor-to-nearest-date)
    (unless (zerop arg)
      (let ((old-date (calendar-cursor-to-date))
            (today (calendar-current-date))
            (month displayed-month)
            (year displayed-year))
        (calendar-increment-month month year arg)
        (calendar-generate-window month year)
        (calendar-cursor-to-visible-date
         (cond
          ((calendar-date-is-visible-p old-date) old-date)
          ((calendar-date-is-visible-p today) today)
          (t (list month 1 year))))))
    (run-hooks 'calendar-move-hook)))

(define-obsolete-function-alias
  'scroll-calendar-left 'calendar-scroll-left "23.1")

;;;###cal-autoload
(defun calendar-scroll-right (&optional arg event)
  "Scroll the displayed calendar window right by ARG months.
If ARG is negative the calendar is scrolled left.  Maintains the relative
position of the cursor with respect to the calendar as well as possible.
EVENT is an event like `last-nonmenu-event'."
  (interactive (list (prefix-numeric-value current-prefix-arg)
                     last-nonmenu-event))
  (calendar-scroll-left (- (or arg 1)) event))

(define-obsolete-function-alias
  'scroll-calendar-right 'calendar-scroll-right "23.1")


推荐答案

/ p>

Here's my take:

(defvar lawlist-month)

(defun lawlist-org-agenda-view-mode-dispatch ()
  "Select the month in agenda view."
  (interactive)
  (message "View: [1-9] [o]CT [n]OV [d]EC, j(next), k(prev).")
  (let* ((a (read-char-exclusive))
         (month (case a
                  (?o 10)
                  (?n 11)
                  (?d 12)
                  (?j (or (and lawlist-month (mod (1+ lawlist-month) 12)) 1))
                  (?k (or (and lawlist-month (mod (1- lawlist-month) 12)) 1))
                  (t (and (> a ?0) (<= a ?9) (- a ?0))))))
    (if (setq lawlist-month month)
        (let ((year (nth 5 (decode-time (current-time)))))
           (org-agenda nil "a")
           (org-agenda-month-view
            (read (format "%d%02d" year month)))
           (calendar)
           (calendar-other-month month year)
           (lawlist-org-agenda-view-mode-dispatch))
      (message "Aborted"))))

它仍然缺少一些功能,如保存窗口配置和
在中止时恢复。

It still misses some functionality like saving the window configuration and recovering on abort.

更新的代码可以在这个 gist
我已经添加了除了当前的其他年份,支持j / k,以及多年的h / l。

The updated code can be found in this gist. I've added other years besides current, with support for j/k, as well as h/l for years.

这篇关于下一个/上个月在议程视图和日历中的自定义功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆