Conversation
|
(following Discord:) I pull the branch, start Lem, start the mode with |
|
Hm. |
|
I tried it, and make was successful. |
Screencast.from.2025-08-14.01-39-12.webm |
cxxxr
left a comment
There was a problem hiding this comment.
I am happy to contribute to lem.
I have made a few comments.
| (defun editor-insert-pair (open close) | ||
| (let ((p (current-point))) | ||
| (cond ((in-string-or-comment-p p) | ||
| (insert-character p open)) | ||
| ((syntax-escape-point-p p 0) | ||
| (insert-character p open)) | ||
| (t | ||
| (unless (non-space-following-context-p p) | ||
| (insert-character p #\Space)) | ||
| (insert-character p open) | ||
| (insert-character p close) | ||
| (unless (or (eolp p) (find (character-at p) *non-space-preceding-chars*)) | ||
| (insert-character p #\Space) | ||
| (character-offset p -1)) | ||
| (character-offset p -1))))) | ||
|
|
||
| ;;; smart parens specific code | ||
|
|
||
| (define-command smart-parens-insert-paren () () | ||
| (editor-insert-pair #\( #\))) | ||
|
|
||
| (define-command smart-parens-insert-bracket () () | ||
| (editor-insert-pair #\[ #\])) | ||
|
|
||
| (define-command smart-parens-insert-brace () () | ||
| (editor-insert-pair #\{ #\})) | ||
|
|
||
| (define-command smart-parens-insert-double-quote () () | ||
| (editor-insert-pair #\" #\")) | ||
|
|
||
| (define-command smart-parens-insert-single-quote () () | ||
| (editor-insert-pair #\' #\')) | ||
|
|
||
| (define-key *smart-parens-keymap* "\"" 'smart-parens-insert-double-quote) | ||
| (define-key *smart-parens-keymap* "'" 'smart-parens-insert-single-quote) | ||
| (define-key *smart-parens-keymap* "(" 'smart-parens-insert-paren) | ||
| (define-key *smart-parens-keymap* "[" 'smart-parens-insert-bracket) | ||
| (define-key *smart-parens-keymap* "{" 'smart-parens-insert-brace) |
There was a problem hiding this comment.
One problem with this implementation is that it implicitly relies on C-like syntax.
It would be better to refer to the syntax-table for each mode.
for example
CL-USER> (lem:syntax-open-paren-char-p #\()
(#\( . #\))
CL-USER> (lem:syntax-open-paren-char-p #\[)
(#\[ . #\])
CL-USER> (lem:syntax-open-paren-char-p #\{)
(#\{ . #\})
There was a problem hiding this comment.
Hm, do you mean that instead of using define-key I should use some function which gets the currently inserted character like this:
(defun close-paren (given-char)
(when (lem:syntax-open-paren-char-p given-char)
(apply #'editor-insert-pair (lem:syntax-open-paren-char-p given-char))))That seems like it would only work for the parens and not the " and ' quote characters.
I don't know lem well enough. What function or macro would I pass this close-paren function to?
There was a problem hiding this comment.
lem/extensions/c-mode/c-mode.lisp
Line 13 in 4072439
syntax-table is defined here in C, for example.
There was a problem hiding this comment.
for example, like this
(defmethod execute ((mode smart-parens-mode) (command self-insert) argument)
(let ((c (get-self-insert-char)))
(alexandria:when-let (pair (syntax-open-paren-char-p c))
(editor-insert-pair (car pair) (cdr pair))
(return-from execute))
(when (syntax-string-quote-char-p c)
(editor-insert-pair c c)
(return-from execute))
(call-next-method)))
|
Ok, I realize I doubt I'll ever get to change this code. This is a stylistic issue for an optional mode, where the code works. It's based on code of existing modes. While I understand it's better to have your desired style in the code base, considering this is not even part of the main code base and it's an additional mode, following the style of other modes, I think it's reasonable to ask to accept the PR. |
not currently working, this is just a draft