hlolli / csound-mode

Emacs major mode for coding in Csound
41 stars 14 forks source link

csound-score-align-block #26

Open ghost opened 1 year ago

ghost commented 1 year ago

hi! i am having problems with it when using characters like ^ or > e.g.

i1 0 2.5
i1 + .
i1 ^ .

will output;

i1 0 2.5
i1 + .
i1 .

Emacs 27.1 csound-mode 0.2.9

hlolli commented 1 year ago

Weird, I can say off the bat that this isn't happening for me. But is it happening as you are typing or when you are saving?

hlolli commented 1 year ago

ahh you are calling the function align-block, gotcha! Let me try agian!

hlolli commented 1 year ago

yes I can reproduce, thanks, I'll fix it now

luqtas commented 9 months ago

so, i'm using this till the fix (sorry i don't understand much about Emacs to fix myself your code);

(defun aling (BEG END)
   (interactive "r")
   (align-regexp BEG END "\\(\\s-*\\)\\s-+" 1 1 t))
(defun csound-score-aling ()
   (interactive)
   (just-one-space) ; (tab-to-tab-stop)
   (point-to-register 0)
   (mark-paragraph)
   (call-interactively 'aling)
   (jump-to-register 0))

(define-key csound-mode-map (kbd "SPC") 'csound-score-aling)
(define-key csound-mode-map (kbd "S-SPC") 'just-one-space)

beware that it aligns everything at cursor's paragraph... ((undo)) can do its job in case you screw! and Shift + SPC for the normal behaviour

luqtas commented 9 months ago

by the way, can the score-align tool quantify the + or ^ sings? e.g.

i1 0 3
i. + .

after the score-align

i1 0 3
i. 3 .
sohet commented 2 weeks ago

A bit more sophisticated version of Iuqtas's aling. Original csound-score--align-cols in csound-score.el can be replaced with it.

(defun csound-score--align-cols (start end)
  (save-excursion
    (save-restriction
      (narrow-to-region (point-min) end)
      (while (progn (goto-char start)
                    (re-search-forward "^\\s-*\\([^;\n]*?[^;\n\0]\\)\\(\\s-+\\|$\\)" nil t))
        (replace-match "\\1\0"))
      (align-regexp start (point-max) "\\(\\)\0" 1 1 t)
      (while (re-search-forward "\0\\| +\0$" nil t)
        (replace-match ""))
      (align-regexp start (point-max) "^[^;]*\\( +\\);" 1 1 t))))