summaryrefslogtreecommitdiff
path: root/lisp/ledger-context.el
diff options
context:
space:
mode:
Diffstat (limited to 'lisp/ledger-context.el')
-rw-r--r--lisp/ledger-context.el79
1 files changed, 40 insertions, 39 deletions
diff --git a/lisp/ledger-context.el b/lisp/ledger-context.el
index b1bcd870..064ac380 100644
--- a/lisp/ledger-context.el
+++ b/lisp/ledger-context.el
@@ -1,6 +1,6 @@
;;; ledger-context.el --- Helper code for use with the "ledger" command-line tool
-;; Copyright (C) 2003-2013 John Wiegley (johnw AT gnu DOT org)
+;; Copyright (C) 2003-2014 John Wiegley (johnw AT gnu DOT org)
;; This file is not part of GNU Emacs.
@@ -16,8 +16,8 @@
;;
;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs; see the file COPYING. If not, write to the
-;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
-;; MA 02111-1307, USA.
+;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+;; MA 02110-1301 USA.
;;; Commentary:
@@ -28,56 +28,57 @@
(eval-when-compile
(require 'cl))
-;; *-string constants are assembled in the single-line-config macro to
-;; form the regex and list of elements
-(defconst indent-string "\\(^[ \t]+\\)")
-(defconst status-string "\\([*! ]?\\)")
-(defconst account-string "[\\[(]?\\(.*?\\)[])]?")
-(defconst amount-string "[ \t]?\\(-?[0-9]+\\.[0-9]*\\)")
-(defconst comment-string "[ \t]*;[ \t]*\\(.*?\\)")
-(defconst nil-string "\\([ \t]+\\)")
-(defconst commodity-string "\\(.+?\\)")
-(defconst date-string "^\\([0-9]\\{4\\}[/-][01]?[0-9][/-][0123]?[0-9]\\)")
-(defconst code-string "\\((.*)\\)?")
-(defconst payee-string "\\(.*\\)")
-
-(defmacro line-regex (&rest elements)
+;; ledger-*-string constants are assembled in the
+;; `ledger-single-line-config' macro to form the regex and list of
+;; elements
+(defconst ledger-indent-string "\\(^[ \t]+\\)")
+(defconst ledger-status-string "\\([*! ]?\\)")
+(defconst ledger-account-string "[\\[(]?\\(.*?\\)[])]?")
+(defconst ledger-amount-string "[ \t]?\\(-?[0-9]+\\.[0-9]*\\)")
+(defconst ledger-comment-string "[ \t]*;[ \t]*\\(.*?\\)")
+(defconst ledger-nil-string "\\([ \t]+\\)")
+(defconst ledger-commodity-string "\\(.+?\\)")
+(defconst ledger-date-string "^\\([0-9]\\{4\\}[/-][01]?[0-9][/-][0123]?[0-9]\\)")
+(defconst ledger-code-string "\\((.*)\\)?")
+(defconst ledger-payee-string "\\(.*\\)")
+
+(defmacro ledger-line-regex (&rest elements)
(let (regex-string)
(concat (dolist (e elements regex-string)
(setq regex-string
(concat regex-string
(eval
(intern
- (concat (symbol-name e) "-string")))))) "[ \t]*$")))
+ (concat "ledger-" (symbol-name e) "-string")))))) "[ \t]*$")))
-(defmacro single-line-config2 (&rest elements)
-"Take list of ELEMENTS and return regex and element list for use in context-at-point"
+(defmacro ledger-single-line-config2 (&rest elements)
+ "Take list of ELEMENTS and return regex and element list for use in context-at-point"
(let (regex-string)
`'(,(concat (dolist (e elements regex-string)
- (setq regex-string
- (concat regex-string
- (eval
- (intern
- (concat (symbol-name e) "-string")))))) "[ \t]*$")
+ (setq regex-string
+ (concat regex-string
+ (eval
+ (intern
+ (concat "ledger-" (symbol-name e) "-string")))))) "[ \t]*$")
,elements)))
-(defmacro single-line-config (&rest elements)
+(defmacro ledger-single-line-config (&rest elements)
"Take list of ELEMENTS and return regex and element list for use in context-at-point"
- `'(,(eval `(line-regex ,@elements))
+ `'(,(eval `(ledger-line-regex ,@elements))
,elements))
(defconst ledger-line-config
- (list (list 'xact (list (single-line-config date nil status nil code nil payee nil comment)
- (single-line-config date nil status nil code nil payee)
- (single-line-config date nil status nil payee)))
- (list 'acct-transaction (list (single-line-config indent comment)
- (single-line-config2 indent status account nil commodity amount nil comment)
- (single-line-config2 indent status account nil commodity amount)
- (single-line-config2 indent status account nil amount nil commodity comment)
- (single-line-config2 indent status account nil amount nil commodity)
- (single-line-config2 indent status account nil amount)
- (single-line-config2 indent status account nil comment)
- (single-line-config2 indent status account)))))
+ (list (list 'xact (list (ledger-single-line-config date nil status nil code nil payee nil comment)
+ (ledger-single-line-config date nil status nil code nil payee)
+ (ledger-single-line-config date nil status nil payee)))
+ (list 'acct-transaction (list (ledger-single-line-config indent comment)
+ (ledger-single-line-config2 indent status account nil commodity amount nil comment)
+ (ledger-single-line-config2 indent status account nil commodity amount)
+ (ledger-single-line-config2 indent status account nil amount nil commodity comment)
+ (ledger-single-line-config2 indent status account nil amount nil commodity)
+ (ledger-single-line-config2 indent status account nil amount)
+ (ledger-single-line-config2 indent status account nil comment)
+ (ledger-single-line-config2 indent status account)))))
(defun ledger-extract-context-info (line-type pos)
"Get context info for current line with LINE-TYPE.
@@ -113,7 +114,7 @@ Leave point at the beginning of the thing under point"
(cond ((looking-at "^[0-9/.=-]+\\(\\s-+\\*\\)?\\(\\s-+(.+?)\\)?\\s-+")
(goto-char (match-end 0))
'transaction)
- ((looking-at "^\\s-+\\([*!]\\s-+\\)?[[(]?\\(.\\)")
+ ((looking-at "^\\s-+\\([*!]\\s-+\\)?[[(]?\\([^\\s-]\\)")
(goto-char (match-beginning 2))
'posting)
((looking-at "^\\(sun\\|mon\\|tue\\|wed\\|thu\\|fri\\|sat\\)\\s-+")