You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Add __DIR__ path completion capf and php-dot-context primitive
Redefine php-complete.el as a small collection of dependency-light,
offline completion-at-point functions usable both as `M-x` commands and
as building blocks for `cape-capf-super'.
* lisp/php.el (php-dot-context): New dependency-free primitive that
classifies the context before point (`string-or-comment',
`next-to-string', `code') for context-sensitive `.' insertion, without
cc-engine. Meant to drive smartchr/key-combo setups.
* lisp/php-complete.el: State the file's mission in the Commentary.
(php-complete-complete-function): Redefine as the offline built-in
function-name source (behavior unchanged).
(php-complete-path-dir-constants): New option; directory-valued subset
of `php-magical-constants'.
(php-complete-complete-path): New capf completing a filesystem path in
the `__DIR__ . '/...'' idiom, one component at a time, rooted at the
directory of the current file. Robust to the unterminated string that
is normal while typing.
* tests/php-mode-test.el: Cover `php-dot-context' and
`php-complete-complete-path'.
* README.md, README.ja.md: Document the completion capfs, `cape-capf-super'
composition, and a `php-dot-context'-based smartchr recipe for `.'.
Copy file name to clipboardExpand all lines: README.md
+47Lines changed: 47 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -88,6 +88,51 @@ The `symfony2` style has been removed, since PER supersedes the coding style use
88
88
89
89
Because the indentation engine no longer uses CC Mode, `c-basic-offset` is obsolete in `php-mode`; customize `php-indent-offset` instead. For backward compatibility, when a project sets `c-basic-offset` buffer-locally (for example via `.dir-locals.el` or file-local variables), `php-mode` copies that value into `php-indent-offset` and displays a warning.
90
90
91
+
## Completion
92
+
93
+
`php-complete.el` provides a few small, dependency-light `completion-at-point` functions (capfs) for use without a language server. Each is usable both as an `M-x` command and as a building block for [`cape`][cape]'s `cape-capf-super`:
94
+
95
+
-`php-complete-complete-function` — built-in function names.
96
+
-`php-complete-complete-path` — a filesystem path inside the `__DIR__ . '/...'` idiom, completed one component at a time and rooted at the directory of the current file (what `__DIR__` resolves to at runtime).
97
+
98
+
```elisp
99
+
(add-hook 'php-mode-hook
100
+
(lambda ()
101
+
(add-hook 'completion-at-point-functions
102
+
#'php-complete-complete-path nil t)))
103
+
104
+
;; …or compose several offline sources into one super-capf with cape:
105
+
(add-hook 'php-mode-hook
106
+
(lambda ()
107
+
(add-hook 'completion-at-point-functions
108
+
(cape-capf-super #'php-complete-complete-function
109
+
#'php-complete-complete-path)
110
+
nil t)))
111
+
```
112
+
113
+
### A context-sensitive `.` key
114
+
115
+
Inserting the `. '/'` that bridges `__DIR__` into path completion is deliberately *not* the capf's job; it is left to your editing setup. `php-dot-context` is the primitive for that: it reports whether point is inside a string or comment (`string-or-comment`), directly after a string literal or a magic constant such as `__DIR__` (`next-to-string`), or in plain code (`code`). Because the capf and this primitive share the same notion of "string" and "magic constant", key-driven insertion and completion stay consistent.
116
+
117
+
For example, with [smartchr][smartchr] the `.` key can cycle `->` / `.` / `. ` in code, insert a literal `.` inside strings, and prefer `. ` right after `__DIR__` (which then flows straight into `php-complete-complete-path`):
`php-mode` is designed for pure PHP scripts. Files that embed PHP inside HTML, such as templates, are better edited in a major mode that understands both languages. Indentation in particular is unreliable when the HTML part of a file is edited in plain `php-mode`.
@@ -169,8 +214,10 @@ This project was maintained by [Eric James Michael Ritz][@ejmr] until 2017. Curr
0 commit comments