command =M-x sweep-find-predicate= jumping to the definition a
loaded or auto-loadable Prolog predicate.
+** Prolog file specification expansion
+
+=sweep= defines a handler for file name the Emacs function
+=expand-file-file= that recognizes Prolog file specifications, such as
+=library(lists)=, and expands them to the corresponding absolute paths.
+This means that one can use Prolog file specifications with Emacs'
+standard =find-file= (=C-x C-f=) to locate Prolog resources directly.
+
+For example, typing =C-x C-f library(pldoc/doc_man)= will open the
+source of the =pldoc_man= module from the Prolog library.
+
* Installing Prolog packages
:PROPERTIES:
:CUSTOM_ID: prolog-packages
As an example, with the above binding the =sweep= top-level can be
access from anywhere with =C-c p t=.
+#+html: <!--
+
* Indices
:PROPERTIES:
:CUSTOM_ID: indices
:INDEX: cp
:CUSTOM_ID: cindex
:END:
+
+#+html: -->
map)
"Keymap for `sweep' global commands.")
+;;;###autoload
+(defun sweep-file-name-handler (operation &rest args)
+ (cond ((eq operation 'expand-file-name)
+ (let ((fn (car args))
+ (dn (cadr args)))
+ (sweep-open-query "user"
+ "sweep"
+ "sweep_expand_file_name"
+ (cons fn dn))
+ (let ((sol (sweep-next-solution)))
+ (sweep-close-query)
+ (if (sweep-true-p sol)
+ (cdr sol)
+ (let ((inhibit-file-name-handlers
+ (cons 'sweep-file-name-handler
+ (and (eq inhibit-file-name-operation operation)
+ inhibit-file-name-handlers)))
+ (inhibit-file-name-operation operation))
+ (apply operation args))))))
+ (t (let ((inhibit-file-name-handlers
+ (cons 'sweep-file-name-handler
+ (and (eq inhibit-file-name-operation operation)
+ inhibit-file-name-handlers)))
+ (inhibit-file-name-operation operation))
+ (apply operation args)))))
+
+(add-to-list 'file-name-handler-alist
+ (cons (rx (seq bol (one-or-more lower) "("))
+ #'sweep-file-name-handler))
+
+(defun sweep-beginning-of-top-term ()
+ (unless (bobp)
+ (when-let ((safe-start (nth 8 (syntax-ppss))))
+ (goto-char safe-start))
+ (re-search-backward (rx (seq bol graph)) nil t)
+ (let ((safe-start (nth 8 (syntax-ppss))))
+ (while (and safe-start (not (bobp)))
+ (goto-char safe-start)
+ (re-search-backward (rx (seq bol graph)) nil t)
+ (setq safe-start (nth 8 (syntax-ppss)))))))
+
+(defun sweep-end-of-top-term ()
+ (unless (eobp)
+ (while (nth 8 (syntax-ppss))
+ (forward-char))
+ (or (re-search-forward (rx (seq "." (or white "\n"))) nil t)
+ (goto-char (point-max)))))
;;;; Testing:
;; (add-to-list 'load-path (file-name-directory (buffer-file-name)))
:- module(sweep,
[ sweep_colors/2,
sweep_documentation/2,
+ sweep_expand_file_name/2,
sweep_predicate_location/2,
sweep_predicates_collection/2,
sweep_modules_collection/2,
sweep_color_goal(goal_term).
sweep_color_goal(head).
sweep_color_goal(head_term).
+
+
+sweep_expand_file_name([String|Dir], Exp) :-
+ term_string(Spec, String, [syntax_errors(quiet)]),
+ sweep_expand_file_name_(Dir, Spec, Atom),
+ ( exists_file(Atom)
+ -> true
+ ; exists_directory(Atom)
+ ),
+ atom_string(Atom, Exp).
+
+sweep_expand_file_name_([], Spec, Atom) :-
+ absolute_file_name(Spec, Atom, [file_errors(fail),
+ solutions(all),
+ extensions(['', '.pl'])]).
+sweep_expand_file_name_(Dir, Spec, Exp) :-
+ !,
+ absolute_file_name(Spec, Exp, [file_errors(fail),
+ relative_to(Dir),
+ solutions(all),
+ extensions(['', '.pl'])]).