|
89 | 89 | (cond ((symex--current-line-empty-p) ; ^<>$
|
90 | 90 | ;; only join up to the next symex if the context suggests
|
91 | 91 | ;; that a line break is not desired
|
92 |
| - (if (or (save-excursion (next-line) |
| 92 | + (if (or (save-excursion (forward-line) |
93 | 93 | (not (symex--current-line-empty-p)))
|
94 | 94 | (save-excursion (previous-line)
|
95 | 95 | (symex--current-line-empty-p)))
|
|
99 | 99 | ((or (save-excursion (evil-last-non-blank) ; (<>$
|
100 | 100 | (symex-left-p)))
|
101 | 101 | (symex--join-to-next))
|
102 |
| - ((looking-at-p "\n") (symex--go-backward)) ; (abc <> |
| 102 | + ((looking-at-p "\n") ; (abc <> |
| 103 | + (if (save-excursion (forward-line) |
| 104 | + (not (symex--current-line-empty-p))) |
| 105 | + ;; only join up to the next symex if the context suggests |
| 106 | + ;; that a line break is not desired |
| 107 | + (symex--join-to-next) |
| 108 | + (symex--go-backward))) |
103 | 109 | ((save-excursion (back-to-indentation) ; ^<>)
|
104 | 110 | (forward-char)
|
105 | 111 | (symex-right-p))
|
|
109 | 115 | ;; on the same line, then don't attempt to join lines
|
110 | 116 | (let ((original-position (point)))
|
111 | 117 | (when (symex--go-backward)
|
112 |
| - (let ((previous-symex-end-pos (symex--get-end-point 1))) |
113 |
| - (unless (symex--intervening-comment-line-p previous-symex-end-pos |
114 |
| - original-position) |
115 |
| - (goto-char previous-symex-end-pos) |
116 |
| - ;; ensure that there isn't a comment on the |
117 |
| - ;; preceding line before joining lines |
118 |
| - (unless (condition-case nil |
119 |
| - (progn (evil-find-char 1 ?\;) |
120 |
| - t) |
121 |
| - (error nil)) |
122 |
| - (symex--join-to-match symex--re-right) |
123 |
| - (symex--adjust-point))))))) |
| 118 | + (save-excursion |
| 119 | + (let ((previous-symex-end-pos (symex--get-end-point 1))) |
| 120 | + (unless (symex--intervening-comment-line-p previous-symex-end-pos |
| 121 | + original-position) |
| 122 | + (goto-char previous-symex-end-pos) |
| 123 | + ;; ensure that there isn't a comment on the |
| 124 | + ;; preceding line before joining lines |
| 125 | + (unless (condition-case nil |
| 126 | + (progn (evil-find-char 1 ?\;) |
| 127 | + t) |
| 128 | + (error nil)) |
| 129 | + (symex--join-to-match symex--re-right)))))))) |
124 | 130 | ((save-excursion (forward-char) ; ... <>)
|
125 | 131 | (symex-right-p))
|
126 | 132 | (symex--go-backward))
|
@@ -209,17 +215,28 @@ text, on the respective side."
|
209 | 215 | (eolp))
|
210 | 216 | ;; and if the side we want to paste on already
|
211 | 217 | ;; contains an empty line,
|
212 |
| - (save-excursion (if before |
| 218 | + (save-excursion (if (or before |
| 219 | + ;; if we happen to be at the end |
| 220 | + ;; of the buffer for pasting after, |
| 221 | + ;; then check the opposite side instead |
| 222 | + ;; for the clue on what's expected |
| 223 | + (save-excursion (forward-sexp) |
| 224 | + (eobp))) |
213 | 225 | (previous-line)
|
214 |
| - (progn (forward-sexp) (next-line))) |
| 226 | + (progn (forward-sexp) |
| 227 | + (forward-line))) |
215 | 228 | (symex--current-line-empty-p))
|
216 | 229 | ;; and if the text to be pasted contains newlines,
|
217 | 230 | ;; then we typically want an extra newline separator
|
218 | 231 | (seq-contains-p (current-kill 0 t) ?\n))
|
219 | 232 | "\n\n")
|
220 | 233 | ((or (symex--point-at-indentation-p)
|
221 |
| - (save-excursion (forward-sexp) |
222 |
| - (eolp))) |
| 234 | + (let ((original-line (line-number-at-pos))) |
| 235 | + (save-excursion (forward-sexp) |
| 236 | + (or (eolp) |
| 237 | + ;; for multi-line symex, add a newline |
| 238 | + (not (= original-line |
| 239 | + (line-number-at-pos))))))) |
223 | 240 | "\n")
|
224 | 241 | (t " ")))
|
225 | 242 |
|
|
0 commit comments