Now on revision 111249. ------------------------------------------------------------ revno: 111249 author: Timo Myyr? committer: Chong Yidong branch nick: trunk timestamp: Sun 2012-12-16 11:17:50 +0800 message: * battery.el (battery-bsd-apm): New function. diff: === modified file 'etc/NEWS' --- etc/NEWS 2012-12-15 13:03:17 +0000 +++ etc/NEWS 2012-12-16 03:17:50 +0000 @@ -41,6 +41,10 @@ * Changes in Specialized Modes and Packages in Emacs 24.4 +** Battery + +*** Battery information via the BSD `apm' utility is now supported. + ** cl-lib *** New macro cl-tagbody. === modified file 'lisp/ChangeLog' --- lisp/ChangeLog 2012-12-16 02:52:11 +0000 +++ lisp/ChangeLog 2012-12-16 03:17:50 +0000 @@ -1,3 +1,7 @@ +2012-12-16 Timo Myyrä + + * battery.el (battery-bsd-apm): New function. + 2012-12-16 Jay Belanger * calc/calc.el (calc-standard-date-formats): Adjust one of the === modified file 'lisp/battery.el' --- lisp/battery.el 2012-09-17 11:55:02 +0000 +++ lisp/battery.el 2012-12-16 03:17:50 +0000 @@ -53,6 +53,9 @@ (directory-files "/sys/class/power_supply/" nil battery--linux-sysfs-regexp)) 'battery-linux-sysfs) + ((and (eq system-type 'berkeley-unix) + (file-executable-p "/usr/sbin/apm")) + 'battery-bsd-apm) ((and (eq system-type 'darwin) (condition-case nil (with-temp-buffer @@ -523,6 +526,75 @@ "AC" "BAT") "N/A"))))) + + +;;; `apm' interface for BSD. +(defun battery-bsd-apm () + "Get APM status information from BSD apm binary. +The following %-sequences are provided: +%L AC line status (verbose) +%B Battery status (verbose) +%b Battery status, empty means high, `-' means low, + `!' means critical, and `+' means charging +%P Advanced power saving mode state (verbose) +%p Battery charge percentage +%s Remaining battery charge time in seconds +%m Remaining battery charge time in minutes +%h Remaining battery charge time in hours +%t Remaining battery charge time in the form `h:min'" + (let* ((os-name (car (split-string + (shell-command-to-string "/usr/bin/uname")))) + (apm-flag (if (equal os-name "OpenBSD") "P" "s")) + (apm-cmd (concat "/usr/sbin/apm -ablm" apm-flag)) + (apm-output (split-string (shell-command-to-string apm-cmd))) + ;; Battery status + (battery-status + (let ((stat (string-to-number (nth 0 apm-output)))) + (cond ((eq stat 0) '("high" . "")) + ((eq stat 1) '("low" . "-")) + ((eq stat 2) '("critical" . "!")) + ((eq stat 3) '("charging" . "+")) + ((eq stat 4) '("absent" . nil))))) + ;; Battery percentage + (battery-percentage (nth 1 apm-output)) + ;; Battery life + (battery-life (nth 2 apm-output)) + ;; AC status + (line-status + (let ((ac (string-to-number (nth 3 apm-output)))) + (cond ((eq ac 0) "disconnected") + ((eq ac 1) "connected") + ((eq ac 2) "backup power")))) + ;; Advanced power savings mode + (apm-mode + (let ((apm (string-to-number (nth 4 apm-output)))) + (if (string= os-name "OpenBSD") + (cond ((eq apm 0) "manual") + ((eq apm 1) "automatic") + ((eq apm 2) "cool running")) + (if (eq apm 1) "on" "off")))) + seconds minutes hours remaining-time) + (unless (member battery-life '("unknown" "-1")) + (if (member os-name '("OpenBSD" "NetBSD")) + (setq minutes (string-to-number battery-life) + seconds (* 60 minutes)) + (setq seconds (string-to-number battery-life) + minutes (truncate (/ seconds 60)))) + (setq hours (truncate (/ minutes 60)) + remaining-time (format "%d:%02d" hours + (- minutes (* 60 hours))))) + (list (cons ?L (or line-status "N/A")) + (cons ?B (or (car battery-status) "N/A")) + (cons ?b (or (cdr battery-status) "N/A")) + (cons ?p (if (string= battery-percentage "255") + "N/A" + battery-percentage)) + (cons ?P (or apm-mode "N/A")) + (cons ?s (or (and seconds (number-to-string seconds)) "N/A")) + (cons ?m (or (and minutes (number-to-string minutes)) "N/A")) + (cons ?h (or (and hours (number-to-string hours)) "N/A")) + (cons ?t (or remaining-time "N/A"))))) + ;;; `pmset' interface for Darwin (OS X). ------------------------------------------------------------ revno: 111248 committer: Jay Belanger branch nick: trunk timestamp: Sat 2012-12-15 20:52:11 -0600 message: * calc/calc.el (calc-standard-date-formats): Adjust one of the standard date formats. diff: === modified file 'doc/misc/calc.texi' --- doc/misc/calc.texi 2012-12-16 02:07:30 +0000 +++ doc/misc/calc.texi 2012-12-16 02:52:11 +0000 @@ -13792,7 +13792,7 @@ @item 10 @samp{ZYYY-MM-DD Www< hh:mm>} (Org mode format) @item 11 -@samp{IYYY-Iww-w< Thh:mm:ss>} (ISO-8601 week numbering format) +@samp{IYYY-Iww-w} (ISO-8601 week numbering format) @end table @node Truncating the Stack, Justification, Date Formats, Display Modes === modified file 'lisp/ChangeLog' --- lisp/ChangeLog 2012-12-15 13:03:17 +0000 +++ lisp/ChangeLog 2012-12-16 02:52:11 +0000 @@ -1,3 +1,8 @@ +2012-12-16 Jay Belanger + + * calc/calc.el (calc-standard-date-formats): Adjust one of the + standard date formats. + 2012-12-15 Juri Linkov * isearch.el (isearch-mode-map): Bind `C-x 8 RET' to === modified file 'lisp/calc/calc.el' --- lisp/calc/calc.el 2012-12-11 02:29:21 +0000 +++ lisp/calc/calc.el 2012-12-16 02:52:11 +0000 @@ -789,7 +789,7 @@ "j<, h:mm:SS>" "YYddd< hh:mm:ss>" "ZYYY-MM-DD Www< hh:mm>" - "IYYY-Iww-w< Thh:mm:ss>")) + "IYYY-Iww-w")) (defcalcmodevar calc-autorange-units nil "If non-nil, automatically set unit prefixes to keep units in a reasonable range.") ------------------------------------------------------------ revno: 111247 committer: Jay Belanger branch nick: trunk timestamp: Sat 2012-12-15 20:07:30 -0600 message: * doc/misc/calc.texi (ISO-8601): New section. (Date Formatting Codes): Mention new codes. (Standard Date Formats): Mention new formats. diff: === modified file 'doc/misc/ChangeLog' --- doc/misc/ChangeLog 2012-12-14 15:37:27 +0000 +++ doc/misc/ChangeLog 2012-12-16 02:07:30 +0000 @@ -1,3 +1,9 @@ +2012-12-16 Jay Belanger + + * calc.texi (ISO-8601): New section. + (Date Formatting Codes): Mention new codes. + (Standard Date Formats): Mention new formats. + 2012-12-14 Michael Albinus * tramp.texi (External methods): Move `adb' method here. === modified file 'doc/misc/calc.texi' --- doc/misc/calc.texi 2012-12-06 06:17:10 +0000 +++ doc/misc/calc.texi 2012-12-16 02:07:30 +0000 @@ -13417,12 +13417,91 @@ functions, your date formats should avoid using the @samp{#} character. @menu +* ISO-8601:: * Date Formatting Codes:: * Free-Form Dates:: * Standard Date Formats:: @end menu -@node Date Formatting Codes, Free-Form Dates, Date Formats, Date Formats +@node ISO-8601, Date Formatting Codes, Date Formats, Date Formats +@subsubsection ISO-8601 + +@noindent +@cindex ISO-8601 +The same date can be written down in different formats and Calc tries +to allow you to choose your preferred format. Some common formats are +ambiguous, however; for example, 10/11/2012 means October 11, +2012 in the United States but it means November 10, 2012 in +Europe. To help avoid such ambiguities, the International Organization +for Standardization (ISO) provides the ISO-8601 standard, which +provides three different but easily distinguishable and unambiguous +ways to represent a date. + +The ISO-8601 calendar date representation is + +@example + @var{YYYY}-@var{MM}-@var{DD} +@end example + +@noindent +where @var{YYYY} is the four digit year, @var{MM} is the two-digit month +number (01 for January to 12 for December), and @var{DD} is the +two-digit day of the month (01 to 31). (Note that @var{YYYY} does not +correspond to Calc's date formatting code, which will be introduced +later.) The year, which should be padded with zeros to ensure it has at +least four digits, is the Gregorian year, except that the year before +0001 (1 AD) is the year 0000 (1 BC). The date October 11, 2012 is +written 2012-10-11 in this representation and November 10, 2012 is +written 2012-11-10. + +The ISO-8601 ordinal date representation is + +@example + @var{YYYY}-@var{DDD} +@end example + +@noindent +where @var{YYYY} is the year, as above, and @var{DDD} is the day of the year. +The date December 31, 2011 is written 2011-365 in this representation +and January 1, 2012 is written 2012-001. + +The ISO-8601 week date representation is + +@example + @var{YYYY}-W@var{ww}-@var{D} +@end example + +@noindent +where @var{YYYY} is the ISO week-numbering year, @var{ww} is the two +digit week number (preceded by a literal ``W''), and @var{D} is the day +of the week (1 for Monday through 7 for Sunday). The ISO week-numbering +year is based on the Gregorian year but can differ slightly. The first +week of an ISO week-numbering year is the week with the Gregorian year's +first Thursday in it (equivalently, the week containing January 4); +any day of that week (Monday through Sunday) is part of the same ISO +week-numbering year, any day from the previous week is part of the +previous year. For example, January 4, 2013 is on a Friday, and so +the first week for the ISO week-numbering year 2013 starts on +Monday, December 31, 2012. The day December 31, 2012 is then part of the +Gregorian year 2012 but ISO week-numbering year 2013. In the week +date representation, this week goes from 2013-W01-1 (December 31, +2012) to 2013-W01-7 (January 6, 2013). + +All three ISO-8601 representations arrange the numbers from most +significant to least significant; as well as being unambiguous +representations, they are easy to sort since chronological order in +this formats corresponds to lexicographical order. The hyphens are +sometimes omitted. + +The ISO-8601 standard uses a 24 hour clock; a particular time is +represented by @var{hh}:@var{mm}:@var{ss} where @var{hh} is the +two-digit hour (from 00 to 24), @var{mm} is the two-digit minute (from +00 to 59) and @var{ss} is the two-digit second. The seconds or minutes +and seconds can be omitted, and decimals can be added. If a date with a +time is represented, they should be separated by a literal ``T'', so noon +on December 13, 2012 can be represented as 2012-12-13T12:00 + +@node Date Formatting Codes, Free-Form Dates, ISO-8601, Date Formats @subsubsection Date Formatting Codes @noindent @@ -13463,6 +13542,10 @@ Year: ``1991'' for 1991, ``23'' for 23 AD. @item YYYY Year: ``1991'' for 1991, ``+23'' for 23 AD. +@item ZYYY +Year: ``1991'' for 1991, ``0023'' for 23 AD., ``0000'' for 1 BC. +@item IYYY +Year: ISO-8601 week-numbering year. @item aa Year: ``ad'' or blank. @item AA @@ -13511,6 +13594,8 @@ Day: `` 7'' for 7th day of month. @item W Weekday: ``0'' for Sunday, ``6'' for Saturday. +@item w +Weekday: ``1'' for Monday, ``7'' for Sunday. @item WWW Weekday: ``SUN'' for Sunday. @item Www @@ -13521,12 +13606,16 @@ Weekday: ``SUNDAY'' for Sunday. @item Wwww Weekday: ``Sunday'' for Sunday. +@item Iww +Week number: ISO-8601 week number, ``W01'' for week 1. @item d Day of year: ``34'' for Feb. 3. @item ddd Day of year: ``034'' for Feb. 3. @item bdd Day of year: `` 34'' for Feb. 3. +@item T +Letter: Literal ``T''. @item h Hour: ``5'' for 5 AM; ``17'' for 5 PM. @item hh @@ -13700,6 +13789,10 @@ @samp{j<, h:mm:ss>} (Julian day plus time) @item 9 @samp{YYddd< hh:mm:ss>} (Year-day format) +@item 10 +@samp{ZYYY-MM-DD Www< hh:mm>} (Org mode format) +@item 11 +@samp{IYYY-Iww-w< Thh:mm:ss>} (ISO-8601 week numbering format) @end table @node Truncating the Stack, Justification, Date Formats, Display Modes