From: Eshel Yaron Date: Mon, 23 Jan 2023 18:20:02 +0000 (+0200) Subject: yank holes back as plain variables X-Git-Tag: V9.0.4~2 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=f11dafe6113bbbfa27bc2d3cefc7d60cf8053bd8;p=sweep.git yank holes back as plain variables * sweeprolog.el (sweeprolog-mode): add sweeprolog-hole to yank-excluded-properties buffer-locally. * sweeprolog-tests.el: test it. * README.org (Holes): mention it. --- diff --git a/README.org b/README.org index b5f1070..6fe2fe6 100644 --- a/README.org +++ b/README.org @@ -1008,13 +1008,21 @@ can be automated by adding ~sweeprolog-forward-hole-on-tab-mode~ to (add-hook 'sweeprolog-mode-hook #'sweeprolog-forward-hole-on-tab-mode) #+end_src +#+CINDEX filling holes +#+CINDEX holes, filling To "fill" a hole marked by one of the aforementioned commands, either use ~C-c C-m~ as described above or type ~C-w~ (~M-x kill-region~) to kill the region and remove the placeholder variable, and then insert Prolog -code as usual. As an alternative to manually killing the region with -~C-w~, with ~delete-selection-mode~ enabled the placeholder is -automatically deleted when you insert a character while the region is -active (see also [[info:emacs#Using Region][Using Region in the Emacs manual]]). +code as usual. Yanking a hole with ~C-y~ (~yank~) after you kill it +removes the special hole property and inserts it as a plain variable. +This is particularly useful if you want to keep the variable name that +Sweep chose for the hole--to do that simply press ~C-w C-y~ with the +hole marked. + +As an alternative to manually killing the region with ~C-w~, with +~delete-selection-mode~ enabled the placeholder is automatically deleted +when you insert a character while the region is active (see also [[info:emacs#Using Region][Using +Region]] in the Emacs manual). ** Definitions and References :PROPERTIES: diff --git a/sweeprolog-tests.el b/sweeprolog-tests.el index 3076cb9..e44ccca 100644 --- a/sweeprolog-tests.el +++ b/sweeprolog-tests.el @@ -253,6 +253,20 @@ foo(Foo) :- bar. '(sweeprolog-undefined-default-face sweeprolog-body-default-face))))) +(ert-deftest yank-hole () + "Test killing and yanking a hole as a plain variable." + (let ((temp (make-temp-file "sweeprolog-test" + nil + "pl" + ""))) + (find-file-literally temp) + (sweeprolog-mode) + (sweeprolog-insert-term-with-holes ":-" 2) + (should (get-text-property (point-min) 'sweeprolog-hole)) + (call-interactively #'kill-region) + (call-interactively #'yank) + (should (not (get-text-property (point-min) 'sweeprolog-hole))))) + (ert-deftest insert-term-with-holes () "Test `sweeprolog-insert-term-with-holes'." (let ((temp (make-temp-file "sweeprolog-test" diff --git a/sweeprolog.el b/sweeprolog.el index 61c9865..893a77b 100644 --- a/sweeprolog.el +++ b/sweeprolog.el @@ -4277,7 +4277,10 @@ certain contexts to maintain conventional Prolog layout." (cursor-sensor-mode 1)) (when (boundp 'context-menu-functions) (add-hook 'context-menu-functions - #'sweeprolog-context-menu-function))) + #'sweeprolog-context-menu-function)) + (unless (member 'sweeprolog-hole yank-excluded-properties) + (setq-local yank-excluded-properties + (cons 'sweeprolog-hole yank-excluded-properties)))) ;;;; Skeletons and auto-insert