 (global-set-key (kbd "C-c C-v p")       'smsn-toggle-properties-view)
 (global-set-key (kbd "C-c C-v r")       'smsn-enter-readonly-view)
 (global-set-key (kbd "C-c C-v s")       'smsn-toggle-emacspeak)
-(global-set-key (kbd "C-c C-v t")       (minibuffer-arg 'smsn-set-value-truncation-length "value truncation length: "))
+(global-set-key (kbd "C-c C-v t")       'smsn-set-value-truncation-length-prompt)
 (global-set-key (kbd "C-c C-v v")       'smsn-toggle-minimize-verbatim-blocks)
-(global-set-key (kbd "C-c C-w C-d")     (char-arg 'smsn-set-default-weight "default weight = ?"))
-(global-set-key (kbd "C-c C-w C-m")     (char-arg 'smsn-set-min-weight "minimun weight = ?"))
-(global-set-key (kbd "C-c a")           (minibuffer-arg 'smsn-acronym-query "acronym search for: "))
+(global-set-key (kbd "C-c C-w C-d")     'smsn-set-default-weight-prompt)
+(global-set-key (kbd "C-c C-w C-m")     'smsn-set-min-weight-prompt)
+(global-set-key (kbd "C-c a")           'smsn-acronym-query-prompt)
 (global-set-key (kbd "C-c b")           'smsn-visit-url-at-point)
 (global-set-key (kbd "C-c d")           'smsn-duplicates)
 (global-set-key (kbd "C-c f")           'smsn-find-roots)
 (global-set-key (kbd "C-c h")           'smsn-history)
 (global-set-key (kbd "C-c i")           'smsn-infer-types)
-(global-set-key (kbd "C-c o")           (minibuffer-arg 'smsn-shortcut-query "shortcut search for: "))
+(global-set-key (kbd "C-c o")           'smsn-shortcut-query-prompt)
 (global-set-key (kbd "C-c P")           'smsn-priorities)
 (global-set-key (kbd "C-c p")           'smsn-push-view)
-(global-set-key (kbd "C-c r")           (minibuffer-arg 'smsn-ripple-query "ripple query: "))
-(global-set-key (kbd "C-c s")           (minibuffer-arg 'smsn-fulltext-query "full-text search for: "))
+(global-set-key (kbd "C-c r")           'smsn-ripple-query-prompt)
+(global-set-key (kbd "C-c s")           'smsn-fulltext-query-prompt)
 (global-set-key (kbd "C-c t")           'smsn-visit-target)
 (global-set-key (kbd "C-c u")           'smsn-update-view)
 (global-set-key (kbd "C-c v")           'smsn-events)



;; KEYBOARD MAPPINGS ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(defun minibuffer-arg (function prompt &optional initial)
    (lexical-let ((f function) (p prompt) (i initial))
        (lambda ()
            (interactive)
            ;; note: use of the INITIAL argument is discouraged, but here it makes sense
            (let ((arg (read-from-minibuffer p i)))
                (if arg (funcall f arg))))))

(defun char-arg (function prompt)
    (lexical-let ((f function) (p prompt))
        (lambda ()
            (interactive)
            (let ((c (read-char p)))
                (if c (funcall f c))))))

;; Note: when updating this list of mappings, also update the PKB
(global-set-key (kbd "C-c C-I f")       'smsn-find-isolated-atoms)
(global-set-key (kbd "C-c C-I r")       'smsn-remove-isolated-atoms)
(global-set-key (kbd "C-c C-a C-p")     (char-arg 'smsn-insert-attr-priority "priority = ?"))
(global-set-key (kbd "C-c C-a C-s")     (char-arg 'smsn-insert-attr-sharability "sharability = ?"))
(global-set-key (kbd "C-c C-a C-w")     (char-arg 'smsn-insert-attr-weight "weight = ?"))
(global-set-key (kbd "C-c C-a d")       'smsn-insert-current-date)
(global-set-key (kbd "C-c C-a s")       'smsn-insert-current-time-with-seconds)
(global-set-key (kbd "C-c C-a t")       'smsn-insert-current-time)
(global-set-key (kbd "C-c C-d")         (char-arg 'smsn-set-view-height "height = ?"))
(global-set-key (kbd "C-c C-e e")       (minibuffer-arg 'smsn-export-edges "export edges to file: " smsn-default-edges-file))
(global-set-key (kbd "C-c C-e g")       (minibuffer-arg 'smsn-export-graphml "export GraphML to file: " smsn-default-graphml-file))
(global-set-key (kbd "C-c C-e l")       (minibuffer-arg 'smsn-export-latex "export LaTeX to file: " smsn-default-latex-file))
(global-set-key (kbd "C-c C-e p")       (minibuffer-arg 'smsn-export-pagerank "export PageRank results to file: " smsn-default-pagerank-file))
(global-set-key (kbd "C-c C-e r")       (minibuffer-arg 'smsn-export-rdf "export private RDF dump to file: " smsn-default-rdf-file))
(global-set-key (kbd "C-c C-e v")       (minibuffer-arg 'smsn-export-vertices "export vertices to file: " smsn-default-vertices-file))
(global-set-key (kbd "C-c C-e w")       (minibuffer-arg 'smsn-export-webrdf "export public Web RDF dump to file: " smsn-default-webrdf-file))
(global-set-key (kbd "C-c C-i g")       (minibuffer-arg 'smsn-import-graphml "import GraphML from file: " smsn-default-graphml-file))
(global-set-key (kbd "C-c C-l")         (minibuffer-arg 'smsn-goto-line "line: "))
(global-set-key (kbd "C-c C-r C-b a")   (smsn-visit-in-amazon 'current-root-value))
(global-set-key (kbd "C-c C-r C-b e")   (smsn-visit-in-ebay 'current-root-value))
(global-set-key (kbd "C-c C-r C-b d")   (smsn-visit-in-delicious 'current-root-value))


(defun set-min-weight (s)
    (if (and (in-setproperties-mode) (>= s 0) (<= s 1))
        (request-view t smsn-mode smsn-root-id smsn-height smsn-style
            smsn-min-sharability smsn-max-sharability smsn-default-sharability
            s smsn-max-weight smsn-default-weight)
        (error-message
            (concat "min weight " (number-to-string s) " is outside of range [0, 1]"))))

