@@ -360,7 +360,6 @@ Median Non-consecutive errors: %d")
360360(defvar speed-type-mode-map
361361 (let ((keymap (make-sparse-keymap )))
362362 (define-key keymap (kbd " C-c C-k" ) #'speed-type-complete )
363- (define-key keymap (kbd " M-q" ) #'speed-type-fill-paragraph )
364363 keymap)
365364 " Keymap for `speed-type-mode' ." )
366365
@@ -1114,11 +1113,6 @@ Expects CURRENT-BUFFER to be buffer of speed-type session."
11141113 " Store the region between START and END which is going to be modified."
11151114 (setq speed-type--last-changed-text (buffer-substring start end)))
11161115
1117- (defun speed-type-fill-paragraph ()
1118- " Override keybinding of FILL-PARAGRAPH with this to not destory session."
1119- (interactive )
1120- (message " Fill paragraph not available " ))
1121-
11221116(defun speed-type-format-stats (entries errors non-consecutive-errors corrections seconds )
11231117 " Format statistic data using given arguments:
11241118ENTRIES ERRORS NON-CONSECUTIVE-ERRORS CORRECTIONS SECONDS."
@@ -1173,31 +1167,35 @@ END is a point where the check stops to scan for diff."
11731167 (remove-overlays start end 'face 'speed-type-error-face )
11741168 (remove-overlays start end 'face 'speed-type-consecutive-error-face )
11751169 (dotimes (i (- end start))
1176- (let* ((correct nil )
1170+ (let* ((is-same nil )
11771171 (pos0 (+ start0 i))
11781172 (pos (+ start i))
11791173 (non-consecutive-error-p (or (and (<= pos0 0 ) (= speed-type--non-consecutive-errors 0 )) ; ; first char is always a non-consecutive error if counter is 0
11801174 (or (and (eq speed-type-point-motion-on-error 'point-stay ) (not (eq (get-text-property (1+ pos0) 'speed-type-char-status ) 'error ))) ; ; staying, no movement, check current
11811175 (and (> pos0 0 ) (eq speed-type-point-motion-on-error 'point-move ) (not (eq (get-text-property pos0 'speed-type-char-status ) 'error ))))))) ; ; moving, check previous
1176+
11821177 (if (speed-type--check-same i orig new)
1183- (progn (setq correct t )
1184- (when (eq (get-text-property (1+ pos0) 'speed-type-char-status ) 'error ) (cl-incf speed-type--corrections))
1185- (add-text-properties pos (1+ pos) '(speed-type-char-status correct)))
1186- (progn (cl-incf speed-type--errors)
1187- (unless any-error (setq any-error t ))
1178+ (progn (setq is-same t )
1179+ (let ((char-status (get-text-property (1+ pos0) 'speed-type-char-status )))
1180+ (cond ((eq char-status 'ignore ) t )
1181+ (t (progn
1182+ (when (eq char-status 'error ) (cl-incf speed-type--corrections))
1183+ (add-text-properties pos (1+ pos) '(speed-type-char-status correct)))))))
1184+ (progn (unless any-error (setq any-error t ))
1185+ (cl-incf speed-type--errors)
11881186 (when non-consecutive-error-p (cl-incf speed-type--non-consecutive-errors))
11891187 (add-text-properties pos (1+ pos) '(speed-type-char-status error ))
11901188 (speed-type-add-extra-words (+ (or speed-type-add-extra-words-on-error 0 )
11911189 (or (and non-consecutive-error-p speed-type-add-extra-words-on-non-consecutive-errors) 0 )))))
11921190 (cl-incf speed-type--entries)
11931191 (let ((overlay (make-overlay pos (1+ pos))))
11941192 (overlay-put overlay 'priority 1 )
1195- (overlay-put overlay 'face (if correct 'speed-type-correct-face (if non-consecutive-error-p 'speed-type-error-face 'speed-type-consecutive-error-face ))))))
1193+ (overlay-put overlay 'face (if is-same 'speed-type-correct-face (if non-consecutive-error-p 'speed-type-error-face 'speed-type-consecutive-error-face ))))))
11961194 (if (or (eq speed-type-point-motion-on-error 'point-move )
1197- (equal new " " )
1195+ (string= new " " )
11981196 (not any-error))
1199- (goto-char end)
1200- (goto-char (- end 1 ))
1197+ (goto-char ( - end ( if overwrite-mode 1 0 )) )
1198+ (goto-char (- end ( if overwrite-mode 2 1 ) ))
12011199 (beep )
12021200 (message " Wrong key " ))
12031201 (not any-error)))
@@ -1207,50 +1205,51 @@ END is a point where the check stops to scan for diff."
12071205LENGTH is ignored. Used for hook AFTER-CHANGE-FUNCTIONS.
12081206Make sure that the contents don't actually change, but rather the contents
12091207are color coded and stats are gathered about the typing performance."
1210- (unless speed-type--idle-pause-timer (speed-type--resume))
1211- (let ((new-text (buffer-substring start end))
1212- (old-text speed-type--last-changed-text))
1213- (speed-type--handle-del start end)
1214- (insert old-text)
1215- (if (< start (point-max ))
1216- (let* ((end (if (> end (point-max )) (point-max ) end))
1217- (orig (buffer-substring start end)))
1218- (when speed-type--preview-buffer
1219- (let ((new-last-pos start))
1220- (with-current-buffer speed-type--preview-buffer
1221- (unwind-protect
1222- (save-excursion
1223- (goto-char (point-max ))
1224- (when-let* ((win (get-buffer-window (current-buffer ))))
1225- (set-window-point win (point )))
1226- (read-only-mode -1 )
1227- (when (and (not (= speed-type--last-position 0 ))
1228- (> (abs (- new-last-pos speed-type--last-position)) 2 ))
1229- (let ((point-movement-str (concat " [ " (symbol-name last-command) " (" (number-to-string speed-type--last-position) " ) → (" (number-to-string (1- new-last-pos)) " ) ]" )))
1230- (insert point-movement-str)
1231- (let ((overlay (make-overlay (- (point ) (length point-movement-str)) (point ))))
1232- (overlay-put overlay 'priority 1 )
1233- (overlay-put overlay 'face 'speed-type-info-face ))))
1234- (insert (cond ((eq this-command (key-binding (kbd " <deletechar>" ))) " ⌦" )
1235- ((eq this-command (key-binding (kbd " DEL" ))) " ⌫" )
1236- (t (string-replace " \t " " ⇥" (string-replace " " " ·" (string-replace " \n " " ⏎" new-text))))))
1237- (setq-local speed-type--last-position new-last-pos))
1238- (read-only-mode )))))
1239- (when speed-type-ignore-whitespace-for-complete ; ; add the ignore status again to deleted blank-chars
1240- (save-excursion
1241- (goto-char start)
1242- (while (search-forward-regexp " [[:blank:]\n ]+" (+ end length ) t 1 )
1243- (add-text-properties (match-beginning 0 ) (match-end 0 ) '(speed-type-char-status ignore)))))
1244- (when-let* ((overlay (and (equal new-text " " )
1245- (car (overlays-at end)))))
1246- (move-overlay overlay (1- (overlay-end overlay)) (overlay-end overlay)) (current-buffer ))
1247- (speed-type--diff orig new-text start end)
1248- (when (and (not (save-excursion (text-property-search-forward 'speed-type-char-status 'nil t )))
1249- (not (save-excursion (text-property-search-backward 'speed-type-char-status 'nil t )))
1250- (not (text-property-any (point-min ) (point-max ) 'speed-type-char-status 'nil )))
1251- (speed-type-complete)))
1252- (beep )
1253- (message " End of buffer " ))))
1208+ (unless (eq this-command 'fill-paragraph )
1209+ (unless speed-type--idle-pause-timer (speed-type--resume))
1210+ (let ((new-text (buffer-substring start end))
1211+ (old-text speed-type--last-changed-text))
1212+ (speed-type--handle-del start end)
1213+ (insert old-text)
1214+ (if (< start (point-max ))
1215+ (let* ((end (if (> end (point-max )) (point-max ) end))
1216+ (orig (buffer-substring start end)))
1217+ (when speed-type--preview-buffer
1218+ (let ((new-last-pos start))
1219+ (with-current-buffer speed-type--preview-buffer
1220+ (unwind-protect
1221+ (save-excursion
1222+ (goto-char (point-max ))
1223+ (when-let* ((win (get-buffer-window (current-buffer ))))
1224+ (set-window-point win (point )))
1225+ (read-only-mode -1 )
1226+ (when (and (not (= speed-type--last-position 0 ))
1227+ (> (abs (- new-last-pos speed-type--last-position)) 2 ))
1228+ (let ((point-movement-str (concat " [ " (symbol-name last-command) " (" (number-to-string speed-type--last-position) " ) → (" (number-to-string (1- new-last-pos)) " ) ]" )))
1229+ (insert point-movement-str)
1230+ (let ((overlay (make-overlay (- (point ) (length point-movement-str)) (point ))))
1231+ (overlay-put overlay 'priority 1 )
1232+ (overlay-put overlay 'face 'speed-type-info-face ))))
1233+ (insert (cond ((eq this-command (key-binding (kbd " <deletechar>" ))) " ⌦" )
1234+ ((eq this-command (key-binding (kbd " DEL" ))) " ⌫" )
1235+ (t (string-replace " \t " " ⇥" (string-replace " " " ·" (string-replace " \n " " ⏎" new-text))))))
1236+ (setq-local speed-type--last-position new-last-pos))
1237+ (read-only-mode )))))
1238+ (when speed-type-ignore-whitespace-for-complete ; ; add the ignore status again to deleted blank-chars
1239+ (save-excursion
1240+ (goto-char start)
1241+ (while (search-forward-regexp " [[:blank:]\n ]+" (+ end length ) t 1 )
1242+ (add-text-properties (match-beginning 0 ) (match-end 0 ) '(speed-type-char-status ignore)))))
1243+ (when-let* ((overlay (and (equal new-text " " )
1244+ (car (overlays-at end)))))
1245+ (move-overlay overlay (1- (overlay-end overlay)) (overlay-end overlay)) (current-buffer ))
1246+ (speed-type--diff orig new-text start end)
1247+ (when (and (not (save-excursion (text-property-search-forward 'speed-type-char-status 'nil t )))
1248+ (not (save-excursion (text-property-search-backward 'speed-type-char-status 'nil t )))
1249+ (not (text-property-any (point-min ) (point-max ) 'speed-type-char-status 'nil )))
1250+ (speed-type-complete)))
1251+ (beep )
1252+ (message " End of buffer " )))))
12541253
12551254(defun speed-type--trim (str )
12561255 " Trim leading and tailing whitespace from STR."
@@ -1395,10 +1394,10 @@ CALLBACK is called when the setup process has been completed."
13951394 (add-hook 'after-change-functions #'speed-type--change nil t )
13961395 (add-hook 'kill-buffer-hook #'speed-type--kill-buffer-hook nil t )
13971396 (setq-local post-self-insert-hook nil )
1397+ (local-set-key (kbd " TAB" ) #'speed-type--code-tab )
1398+ (local-set-key (kbd " RET" ) #'speed-type--code-ret )
13981399 (when (speed-type--code-buffer-p content-buffer)
13991400 (electric-pair-mode -1 )
1400- (local-set-key (kbd " TAB" ) #'speed-type--code-tab )
1401- (local-set-key (kbd " RET" ) #'speed-type--code-ret )
14021401 (when syntax-table (set-syntax-table syntax-table))
14031402 (when fldf
14041403 (let ((font-lock-defaults fldf))
@@ -1725,12 +1724,23 @@ LIMIT is supplied to the random-function."
17251724 (let ((start (point ))
17261725 (end (re-search-forward " [^\t ]" (line-end-position ) t )))
17271726 (goto-char start)
1728- (when end (insert (buffer-substring-no-properties start (1- end))))))
1727+ (when end
1728+ (let ((fill-content (buffer-substring-no-properties start (1- end))))
1729+ (if (string-empty-p fill-content)
1730+ (insert " \t " )
1731+ (insert fill-content))))))
17291732
17301733(defun speed-type--code-ret ()
17311734 " A command to be mapped to RET when speed typing code."
17321735 (interactive )
1733- (when (eolp ) (newline ) (move-beginning-of-line nil ) (speed-type--code-tab)))
1736+ (if (eolp )
1737+ (progn (newline )
1738+ (move-beginning-of-line nil )
1739+ (let ((start (point ))
1740+ (end (re-search-forward " [^\t ]" (line-end-position ) t )))
1741+ (goto-char start)
1742+ (when end (insert (buffer-substring-no-properties start (1- end))))))
1743+ (insert " \n " )))
17341744
17351745;;;### autoload
17361746(defun speed-type-text-top-x (x )
0 commit comments