diff options
author | Austin Clements <amdragon@MIT.EDU> | 2014-02-20 14:16:35 -0500 |
---|---|---|
committer | David Bremner <david@tethera.net> | 2014-02-22 19:51:03 -0400 |
commit | 4b734374fb2e26ef54414c8f0b933271fdf58c3b (patch) | |
tree | cee6f3a0a795e3aa94eada286c1a86a6e50b4bd8 | |
parent | 1326ec09ee369b152a6c9bed5fe42c2d80180d01 (diff) |
emacs: Fix exception when fetching empty or unconfigured settings
When "notmuch config" is called with the name of an empty or
unconfigured setting, it prints nothing (not even a new line).
Previously, `notmuch-config-get' assumed it would always print a
newline. As a result, when `notmuch-config-get' was called with the
name of an empty of unconfigured setting, it would attempt to
(substring "" 0 -1) to strip the newline, which would fail with a
(args-out-of-range "" 0 -1) exception.
Fix this by only stripping the newline if there actually is one.
-rw-r--r-- | emacs/notmuch-lib.el | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/emacs/notmuch-lib.el b/emacs/notmuch-lib.el index fa35fa9f..09110b53 100644 --- a/emacs/notmuch-lib.el +++ b/emacs/notmuch-lib.el @@ -198,8 +198,13 @@ on the command line, and then retry your notmuch command"))) (defun notmuch-config-get (item) "Return a value from the notmuch configuration." - ;; Trim off the trailing newline - (substring (notmuch-command-to-string "config" "get" item) 0 -1)) + (let* ((val (notmuch-command-to-string "config" "get" item)) + (len (length val))) + ;; Trim off the trailing newline (if the value is empty or not + ;; configured, there will be no newline) + (if (and (> len 0) (= (aref val (- len 1)) ?\n)) + (substring val 0 -1) + val))) (defun notmuch-database-path () "Return the database.path value from the notmuch configuration." |