[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/sweeprolog e70b4aef2f 057/166: ADDED: sweep-file-name-hand
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/sweeprolog e70b4aef2f 057/166: ADDED: sweep-file-name-handler |
Date: |
Fri, 30 Sep 2022 04:59:26 -0400 (EDT) |
branch: elpa/sweeprolog
commit e70b4aef2f8a9b7d7c990d1f9d70f8dbc84aeee5
Author: Eshel Yaron <me@eshelyaron.com>
Commit: Eshel Yaron <me@eshelyaron.com>
ADDED: sweep-file-name-handler
---
README.org | 15 +++++++++++++++
sweep.el | 47 +++++++++++++++++++++++++++++++++++++++++++++++
sweep.pl | 22 ++++++++++++++++++++++
3 files changed, 84 insertions(+)
diff --git a/README.org b/README.org
index 87f0ee34ee..44c7f51a28 100644
--- a/README.org
+++ b/README.org
@@ -325,6 +325,17 @@ Along with =M-x sweep-find-module=, =sweep= provides the
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
@@ -354,6 +365,8 @@ to a prefix key, e.g. =C-c p=, use:
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
@@ -376,3 +389,5 @@ access from anywhere with =C-c p t=.
:INDEX: cp
:CUSTOM_ID: cindex
:END:
+
+#+html: -->
diff --git a/sweep.el b/sweep.el
index bd1d33e34a..42c00a0f75 100644
--- a/sweep.el
+++ b/sweep.el
@@ -672,6 +672,53 @@ Interactively, a prefix arg means to prompt for BUFFER."
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)))
diff --git a/sweep.pl b/sweep.pl
index d0461cf3d2..9f9987b797 100644
--- a/sweep.pl
+++ b/sweep.pl
@@ -33,6 +33,7 @@
:- 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,
@@ -346,3 +347,24 @@ sweep_color_goal(goal).
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'])]).
- [nongnu] elpa/sweeprolog ccaa53a19c 147/166: DOC: update installation instruction to reflect inclusion in swipl, (continued)
- [nongnu] elpa/sweeprolog ccaa53a19c 147/166: DOC: update installation instruction to reflect inclusion in swipl, ELPA Syncer, 2022/09/30
- [nongnu] elpa/sweeprolog c8192b8c31 145/166: DOC: document imenu support in sweep-mode buffers, ELPA Syncer, 2022/09/30
- [nongnu] elpa/sweeprolog 6b9e2a7833 139/166: Tweak README to prevent a hosting platform from failing to render it, ELPA Syncer, 2022/09/30
- [nongnu] elpa/sweeprolog 79bf5b78b8 042/166: Run `make check` with libswipl preloaded, ELPA Syncer, 2022/09/30
- [nongnu] elpa/sweeprolog 97440dda21 043/166: DOC: update the manual to reflect the latest GMP deconflication, ELPA Syncer, 2022/09/30
- [nongnu] elpa/sweeprolog 9466ce0d59 046/166: ADDED: completion-at-point function in sweep-top-level-mode, ELPA Syncer, 2022/09/30
- [nongnu] elpa/sweeprolog 6e9ac379e6 047/166: DOC: Expand top-level documentation section, ELPA Syncer, 2022/09/30
- [nongnu] elpa/sweeprolog 4ecc8ec55f 050/166: Add BSD license, ELPA Syncer, 2022/09/30
- [nongnu] elpa/sweeprolog a26ca14c81 053/166: ENHANCED: show more relevant candidates in top-level completion, ELPA Syncer, 2022/09/30
- [nongnu] elpa/sweeprolog 7fa11fdcdd 055/166: FIXED: hide predicates starting with '$' in sweep-find-predicate, ELPA Syncer, 2022/09/30
- [nongnu] elpa/sweeprolog e70b4aef2f 057/166: ADDED: sweep-file-name-handler,
ELPA Syncer <=
- [nongnu] elpa/sweeprolog 10516034be 061/166: ADDED: sweep-indent-line, an indent-line-function for sweep-mode, ELPA Syncer, 2022/09/30
- [nongnu] elpa/sweeprolog face064afa 062/166: ADDED: custom font-lock-fontify-region-function for sweep-mode, ELPA Syncer, 2022/09/30
- [nongnu] elpa/sweeprolog 6363ddef3a 073/166: ADDED: implemented all xref backend callback functions, ELPA Syncer, 2022/09/30
- [nongnu] elpa/sweeprolog 8dc9359dca 082/166: ADDED: sweep-set-prolog-flag for setting Prolog flags, ELPA Syncer, 2022/09/30
- [nongnu] elpa/sweeprolog 0f86b23be9 080/166: ENHANCED: emit Prolog messages with color coding, ELPA Syncer, 2022/09/30
- [nongnu] elpa/sweeprolog 1f4b1a6dcc 079/166: MODIFIED: use executable-find to locate the swipl executable..., ELPA Syncer, 2022/09/30
- [nongnu] elpa/sweeprolog f772a136e4 081/166: DOC: fix typos, ELPA Syncer, 2022/09/30
- [nongnu] elpa/sweeprolog 75ec7290be 096/166: ADDED: sweep-load-buffer, ELPA Syncer, 2022/09/30
- [nongnu] elpa/sweeprolog 3717572348 091/166: FIXED: handle more missing color terms, ELPA Syncer, 2022/09/30
- [nongnu] elpa/sweeprolog 1744b29cc2 092/166: FIXED: off by one in sweep-colourise-some-terms, ELPA Syncer, 2022/09/30