~ubuntu-branches/ubuntu/wily/ledger/wily

« back to all changes in this revision

Viewing changes to lisp/ledger-init.el

  • Committer: Package Import Robot
  • Author(s): David Bremner
  • Date: 2014-10-08 19:20:38 UTC
  • mfrom: (1.1.3) (9.1.7 sid)
  • Revision ID: package-import@ubuntu.com-20141008192038-py5cxm93rdt3x2uz
Tags: 3.1+dfsg1-1
New upstream release

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
;;
17
17
;; You should have received a copy of the GNU General Public License
18
18
;; along with GNU Emacs; see the file COPYING.  If not, write to the
19
 
;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
20
 
;; MA 02111-1307, USA.
 
19
;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
 
20
;; MA 02110-1301 USA.
21
21
 
22
22
;;; Commentary:
23
23
;; Determine the ledger environment
37
37
    (let (environment-alist)
38
38
      (goto-char (point-min))
39
39
      (while (re-search-forward ledger-init-string-regex nil t )
40
 
                                (let ((matchb (match-beginning 0)) ;; save the match data, string-match stamp on it
41
 
                                                        (matche (match-end 0)))
42
 
                                        (end-of-line)
43
 
                                        (setq environment-alist
44
 
                                                                (append environment-alist
45
 
                                                                                                (list (cons (let ((flag (buffer-substring-no-properties (+ 2 matchb) matche)))
46
 
                                                                                                                                                        (if (string-match "[ \t\n\r]+\\'" flag)
47
 
                                                                                                                                                                        (replace-match "" t t flag)
48
 
                                                                                                                                                                flag))
49
 
                                                                                                                                                (let ((value (buffer-substring-no-properties  matche (point) )))
50
 
                                                                                                                                                        (if (> (length value) 0)
51
 
                                                                                                                                                                        value
52
 
                                                                                                                                                                t))))))))
 
40
        (let ((matchb (match-beginning 0)) ;; save the match data, string-match stamp on it
 
41
              (matche (match-end 0)))
 
42
          (end-of-line)
 
43
          (setq environment-alist
 
44
                (append environment-alist
 
45
                        (list (cons (let ((flag (buffer-substring-no-properties (+ 2 matchb) matche)))
 
46
                                      (if (string-match "[ \t\n\r]+\\'" flag)
 
47
                                          (replace-match "" t t flag)
 
48
                                        flag))
 
49
                                    (let ((value (buffer-substring-no-properties  matche (point) )))
 
50
                                      (if (> (length value) 0)
 
51
                                          value
 
52
                                        t))))))))
53
53
      environment-alist)))
54
54
 
55
55
(defun ledger-init-load-init-file ()
56
56
  (interactive)
57
57
  (let ((init-base-name (file-name-nondirectory ledger-init-file-name)))
58
58
    (if (get-buffer init-base-name) ;; init file already loaded, parse it and leave it
59
 
                                (setq ledger-environment-alist
60
 
              (ledger-init-parse-initialization init-base-name))
61
 
                        (when (and ledger-init-file-name
62
 
                                                                 (file-exists-p ledger-init-file-name)
63
 
                                                                 (file-readable-p ledger-init-file-name))
64
 
                                (find-file-noselect ledger-init-file-name)
65
 
                                (setq ledger-environment-alist
66
 
                                                        (ledger-init-parse-initialization init-base-name))
67
 
                                (kill-buffer init-base-name)))))
 
59
        (setq ledger-environment-alist
 
60
              (ledger-init-parse-initialization init-base-name))
 
61
      (when (and ledger-init-file-name
 
62
                 (file-exists-p ledger-init-file-name)
 
63
                 (file-readable-p ledger-init-file-name))
 
64
        (find-file-noselect ledger-init-file-name)
 
65
        (setq ledger-environment-alist
 
66
              (ledger-init-parse-initialization init-base-name))
 
67
        (kill-buffer init-base-name)))))
68
68
 
69
69
(provide 'ledger-init)
70
70