Skip to content

Commit

Permalink
refactor(dart-mode.el): Clean up a little
Browse files Browse the repository at this point in the history
  • Loading branch information
jcs090218 committed Sep 25, 2023
1 parent 9b069e4 commit 2c7bebe
Showing 1 changed file with 63 additions and 58 deletions.
121 changes: 63 additions & 58 deletions dart-mode.el
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,22 @@
;; option.

;;; Commentary:

;;
;; Major mode for editing Dart files.

;;
;; Provides basic syntax highlighting and indentation.
;;

This comment has been minimized.

Copy link
@tarsius

tarsius Sep 29, 2023

Member

IMO this isn't cleaning up but making it messy, but it is a matter of opinion.

Here is my take. The last added ;; is definitely making it worse, that's like putting a closing paren on its own line, after it was at the end of the previous line as it is supposed to. The middle ;; is okay in this case, but it it were in between two normal sized paragraphs (instead of two paragraphs consisting of one very short sentence each), then it would also be a definite step backward. A better approach may be to combine these to "paragraphs" into one. The first ;; is also weird; we don't do that after ;; Code:, so why here?

The changes below are appropriate cleanups in my book too.

This comment has been minimized.

Copy link
@jcs090218

jcs090218 Sep 29, 2023

Author Collaborator

Ah, IMO, this is cleaner than having them separately. 🤔 But I don't have a strong opinion on this. I've reverted in aa4c7e6.

This comment has been minimized.

Copy link
@tarsius

tarsius Sep 29, 2023

Member

I agree that removing the middle ;; looks a bit weird in this case. I am used to commentaries that consist of either one paragraph that is four or more lines long, or multiple paragraphs, most of which are also longer than a line or two. Which is why I suggested merging them into one paragraph, in this case. Maybe even just one sentence would make sense:

;;; Commentary:

;; This package implements a major-mode for the Dart language,
;; providing basic syntax highlighting and indentation support.

;;; Code:

This comment has been minimized.

Copy link
@jcs090218

jcs090218 Sep 29, 2023

Author Collaborator

Sorry, I made the changes too fast in the first commit. I've applied it in 722e7a2. Now we only have one paragraph. :D


;;; Code:

;;; Configuration

(defvar dart-mode-map (make-sparse-keymap)
(defvar dart-mode-map
(let ((map (make-sparse-keymap)))
(define-key map (kbd "<backtab>") #'dart-dedent-simple)
(define-key map (kbd "C-c C-i") #'indent-according-to-mode)
map)
"Keymap used in dart-mode buffers.")
(define-key dart-mode-map (kbd "<backtab>") 'dart-dedent-simple)
(define-key dart-mode-map (kbd "C-c C-i") 'indent-according-to-mode)


;;; Indentation

Expand Down Expand Up @@ -194,36 +196,40 @@ indentation levels from right to left."
"null"
"true"))

(defvar dart--async-keywords-re (rx word-start
(or "async" "await" "sync" "yield")
word-end
(zero-or-one ?*)))
(defvar dart--async-keywords-re
(rx word-start
(or "async" "await" "sync" "yield")
word-end
(zero-or-one ?*)))

;; https://dart.dev/guides/language/specifications/DartLangSpec-v2.10.pdf
;; 17.5 Numbers
(defvar dart--numeric-literal-re (rx-let
((numeric-literal (| number hex-number))
(number (: (| (: (1+ digit) (? (: ?. (1+ digit))))
(: ?. (1+ digit)))
(? exponent)))
(exponent (: (| ?e ?E)
(? (| ?+ ?-))
(1+ digit)))
(hex-number (: ?0 (| ?x ?X) (1+ hex-digit))))
(rx bow numeric-literal eow)))

(defvar dart--operator-declaration-re (rx "operator"
(one-or-more space)
(group
(one-or-more (not (any ?\())))))

(eval-and-compile (defun dart--identifier (&optional case)
`(and (or word-start symbol-start)
(zero-or-more (any ?$ ?_))
,(if case
case
'alpha)
(zero-or-more (or ?$ ?_ alnum)))))
(defvar dart--numeric-literal-re
(rx-let
((numeric-literal (| number hex-number))
(number (: (| (: (1+ digit) (? (: ?. (1+ digit))))
(: ?. (1+ digit)))
(? exponent)))
(exponent (: (| ?e ?E)
(? (| ?+ ?-))
(1+ digit)))
(hex-number (: ?0 (| ?x ?X) (1+ hex-digit))))
(rx bow numeric-literal eow)))

(defvar dart--operator-declaration-re
(rx "operator"
(one-or-more space)
(group
(one-or-more (not (any ?\())))))

(eval-and-compile
(defun dart--identifier (&optional case)
`(and (or word-start symbol-start)
(zero-or-more (any ?$ ?_))
,(if case
case
'alpha)
(zero-or-more (or ?$ ?_ alnum)))))

(defvar dart--metadata-re (rx ?@ (eval (dart--identifier))))

Expand Down Expand Up @@ -351,30 +357,30 @@ For example, \"compareTo\" in \" int compareTo(num other);\" would be
matched."
(catch 'result
(let (beg end)
(while (re-search-forward
(rx (and (not (any ?\.)) (group (eval (dart--identifier 'lower)))) ?\() limit t)
(setq beg (match-beginning 1))
(setq end (match-end 1))
(condition-case nil
(progn
(up-list)
(when (and (< (point) (point-max))
(= (char-after (point)) ?\;))
(goto-char beg)
(back-to-indentation)
(when (and (= (current-column) 2)
(not (looking-at "return"))
(string-match-p
" " (buffer-substring-no-properties
(point) beg))
(not (string-match-p
"=" (buffer-substring-no-properties
(point) beg))))
(goto-char end)
(set-match-data (list beg end))
(throw 'result t))))
(scan-error nil))
(goto-char end)))
(while (re-search-forward
(rx (and (not (any ?\.)) (group (eval (dart--identifier 'lower)))) ?\() limit t)
(setq beg (match-beginning 1))
(setq end (match-end 1))
(condition-case nil
(progn
(up-list)
(when (and (< (point) (point-max))
(= (char-after (point)) ?\;))
(goto-char beg)
(back-to-indentation)
(when (and (= (current-column) 2)
(not (looking-at "return"))
(string-match-p
" " (buffer-substring-no-properties
(point) beg))
(not (string-match-p
"=" (buffer-substring-no-properties
(point) beg))))
(goto-char end)
(set-match-data (list beg end))
(throw 'result t))))
(scan-error nil))
(goto-char end)))
(throw 'result nil)))

(defun dart--declared-identifier-func (limit)
Expand Down Expand Up @@ -693,5 +699,4 @@ Key bindings:
(setq-local syntax-propertize-function 'dart-syntax-propertize-function))

(provide 'dart-mode)

;;; dart-mode.el ends here

0 comments on commit 2c7bebe

Please sign in to comment.