all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Philip Kaludercic <philipk@posteo.net>
To: John Task <q01@disroot.org>
Cc: emacs-devel@gnu.org
Subject: Re: [NonGNU Elpa] New package: ETT
Date: Wed, 03 May 2023 16:41:21 +0000	[thread overview]
Message-ID: <87a5ylcqq6.fsf@posteo.net> (raw)
In-Reply-To: <86ild9bgel.fsf@disroot.org> (John Task's message of "Wed, 03 May 2023 12:02:57 -0300")

John Task <q01@disroot.org> writes:

>>  (defun ett-do-division (num1 num2)
>> -  "Divide NUM1 between NUM2."
>> +  "Divide NUM1 between NUM2."		;can you explain why this is needed?
>>    (if (/= (% num1 num2) 0)
>>        (/ (float num1) num2)
>>      (/ num1 num2)))
>
> I need the extra precision for various functions.  (/ 12 7) gives me
> 1, while (ett-do-division 12 7) gives me 1.7142857142857142.

If that is so, I would explain that in the documentation string, but
what I wonder is why if condition is needed.  All you basically do is
avoid converting num1 to a float, and the result remains a integer, in
some cases.

>>  (defun ett-prettify-time (time)
>>    "Return a prettified string for TIME."
>>    (let ((hr 0))
>> -    (while (>= time 60)
>> +    (while (>= time 60)			;the loop here shouldn't be necessary, you can calculate the same thing using remainder and floor
>>        (setq hr (1+ hr)
>>              time (- time 60)))
>
> I'll look into that.  Is there any reason why I would need to avoid
> that loop?  The code just works for now.

While this will calculate the values in constant time,

  (list (floor time 60) (% time 60))

a loop will always take more iterations depending on the value of the input:

  (let ((hr 0))
    (while (>= time 60)
      (setq hr (1+ hr)
             time (- time 60)))
    (list hr time))

>>      (save-excursion
>>        ;; Sort items
>>        ;; We need to do it in two steps because it's somehow complicated
>> -      (sort-regexp-fields t "^.*$" "\\(:[0-9]+\\)" (point-min) (point-max))
>> +      (sort-regexp-fields t "^.*$" "\\(:[0-9]+\\)" (point-min) (point-max)) ;have you considered using rx?
>>        (sort-regexp-fields t "^.*$" "\\([0-9]+:\\)" (point-min) (point-max))
>>        ;; We now align
>>        (align-regexp
>
> I have considered it, but while my regexps are weird, they are
> still readable for now.  Maybe I'll reconsider it.

FWIW i even hesitated in bringing this up, because as you say the
regular expressions are currently modest in complexity.

>> +(defvar ett-view-mode-map
>> +  (let ((map (make-sparse-keymap)))
>> +    (define-key map (kbd "C-c C-c") #'ett-add-track)
>> +    (define-key map (kbd "SPC") #'ett-space-dwim)
>> +    map))
>
> I think you mean just ett-mode-map.  In that case, OK.

Right, that was a typo.  All I provide is faulty static analysis ^^

>> (define-derived-mode ett-mode text-mode "ETT"
>>    "Major mode for editing ETT based texts."
>>    (setq font-lock-defaults '(ett-font-lock-keywords t))
>> -  (setq-local outline-regexp "[0-9]+-[0-9]+-[0-9]+")
>> +  (setq-local outline-regexp "[0-9]+-[0-9]+-[0-9]+") ;does this need to start with a ^
>>    ;; show-paren-mode can be somehow annoying here
>>    (show-paren-local-mode -1))
>
> Documentation of the variable says it isn't necessary, and it worked
> as is on my tests, but I'm not an expert.

OK, I didn't know about that, then this is fine.



  reply	other threads:[~2023-05-03 16:41 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-05-03 15:02 [NonGNU Elpa] New package: ETT John Task
2023-05-03 16:41 ` Philip Kaludercic [this message]
  -- strict thread matches above, loose matches on Subject: below --
2023-05-03 18:06 John Task
2023-05-03 17:14 John Task
2023-05-03 18:05 ` Eli Zaretskii
2023-05-03 15:29 John Task
2023-05-03 16:57 ` Sam Steingold
2023-05-03 14:07 John Task
2023-05-03 15:55 ` Eli Zaretskii
2023-05-02 21:21 John Task
2023-05-03  6:08 ` Philip Kaludercic
2023-05-03  6:11   ` Philip Kaludercic
2023-05-03  7:12   ` Yuri Khan
2023-05-03 11:12 ` Eli Zaretskii
2023-03-01 18:17 John Task
2023-03-01 17:46 John Task
2023-03-02  4:33 ` Richard Stallman
2023-03-02 10:08   ` Holger Schurig
2023-03-02 14:50 ` q01
2023-03-02 15:55 ` John Task

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87a5ylcqq6.fsf@posteo.net \
    --to=philipk@posteo.net \
    --cc=emacs-devel@gnu.org \
    --cc=q01@disroot.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.