diff options
| author | Sebastian Kuhnert | 2010-06-23 14:50:08 +0000 |
|---|---|---|
| committer | Sebastian Kuhnert | 2010-06-23 14:50:08 +0000 |
| commit | 6985f7b60adefe33fa8444be3fcfc321ee2806ed (patch) | |
| tree | 4f5db5e9d3686a4079154316e213a357c311ab90 /exercisesheets.el | |
| parent | af0a8b411dc95fac37859dd731a8caa626f1db72 (diff) | |
| download | exercisesheets-6985f7b60adefe33fa8444be3fcfc321ee2806ed.tar.gz exercisesheets-6985f7b60adefe33fa8444be3fcfc321ee2806ed.tar.bz2 exercisesheets-6985f7b60adefe33fa8444be3fcfc321ee2806ed.zip | |
improve emacs integration of exercisesheets
Diffstat (limited to 'exercisesheets.el')
| -rw-r--r-- | exercisesheets.el | 59 |
1 files changed, 38 insertions, 21 deletions
diff --git a/exercisesheets.el b/exercisesheets.el index 6c37747..35af451 100644 --- a/exercisesheets.el +++ b/exercisesheets.el @@ -5,37 +5,54 @@ ;; Keywords: tex -(defun LaTeX-exercisesheets-read-kwopt (context spec &optional required) +(defun LaTeX-exercisesheets-read-kwopt (context spec) "Ask the user if/how an option should be included. CONTEXT is used in the prompt. -SPEC is a string of the form `opt' for boolean options (ask if it should be included), +SPEC is a string of the form +`opt' for boolean options (ask if it should be included, default no), +`!opt' for boolean options (ask if it should be included, default yes), `opt=' for free-form arguments for the option (include if non-empty), +`!opt=' for free-form arguments for the option (always included), `opt=arg1,arg2,arg3' for suggestions with completion (empty means skip), -`opt=!arg1,arg2,arg3' for alternatives with completion (empty means skip). - -If REQUIRED is non-nil, +`!opt=arg1,arg2,arg3' for suggestions with completion (always included), +`opt=!arg1,arg2,arg3' for alternatives with completion (empty means skip), +`!opt=!arg1,arg2,arg3' for alternatives with completion (always included). The result is the string to be used as argument. If the option is skipped, the result is nil." - (if (string-match "^\\(.*\\)=\\(!?\\)\\(.*\\)$" spec) - (let* ((optstr (if required "optional " "")) - (require-match (if (match-string 2 spec) t nil)) + (if (string-match "^\\(!?\\)\\(.*\\)=\\(!?\\)\\(.*\\)$" spec) + (let* ((required (if (match-string 1 spec) nil t)) + (optstr (if required "optional " "")) + (require-match (if (match-string 3 spec) t nil)) (answer (save-match-data - (if (string= "" (match-string 3 spec)) - (read-string (concat context ": " optstr "argument " (match-string 1 spec) "=")) - (completing-read (concat context ": " optstr "argument " (match-string 1 spec) "=") - (split-string (match-string 3 spec) ",") + (if (string= "" (match-string 4 spec)) + (read-string (concat context ": " optstr "argument " (match-string 2 spec) "=")) + (completing-read (concat context ": " optstr "argument " (match-string 2 spec) "=") + (split-string (match-string 4 spec) ",") nil require-match))))) (if (or (not (string= "" answer)) required) (if (string-match-p "[,= ]" answer) - (concat (match-string 1 spec) "={" answer "}") - (concat (match-string 1 spec) "=" answer)) - nil)) - (if (y-or-n-p (concat context ": include argument " spec "? ")) - spec - nil))) + (concat (match-string 2 spec) "={" answer "}") + (concat (match-string 2 spec) "=" answer)))) + (if (string-match "^!\\(.*\\)$" spec) + (if (Y-or-n-p (concat context ": include argument " (match-string 1 spec) "? ")) + (match-string 1 spec)) + (if (y-or-N-p (concat context ": include argument " spec "? ")) + spec)))) + +(defun Y-or-n-p (query) + "Variant of `y-or-n-p' where return/enter means yes" + (let ((query-replace-map + (append '(keymap (return . act) (enter . act)) (cdr query-replace-map)))) + (y-or-n-p query))) + +(defun y-or-N-p (query) + "Variant of `y-or-n-p' where return/enter means no" + (let ((query-replace-map + (append '(keymap (return . skip) (enter . skip)) (cdr query-replace-map)))) + (y-or-n-p query))) (defun LaTeX-exercisesheets-read-kwopts(context startdelim enddelim &rest specs) (let* ((anslist (mapcar @@ -70,9 +87,9 @@ consisting of keyword and explanation for the user (used in the prompt)." (LaTeX-add-environments '("sheet" LaTeX-exercisesheets-insert-environment "date=" "note=" "title=") '("exercise" LaTeX-exercisesheets-insert-environment "points=" "oral" "name=" "firstline=") - "solution" ;;; oral - "hint" - "hint*") + '("solution" LaTeX-exercisesheets-insert-environment "oral") + '("hint" LaTeX-exercisesheets-insert-environment "remark") + '("hint*" LaTeX-exercisesheets-insert-environment "remark")) ;; Warning keywords (font-latex-add-keywords '("TODO") 'warning) |
