Convert load calls to require

This commit is contained in:
contrapunctus 2020-06-12 19:33:00 +05:30
parent 843d250189
commit 30436e3e53
3 changed files with 128 additions and 124 deletions

View File

@ -11,121 +11,121 @@
("M-N" . cp-lower-level) ("M-N" . cp-lower-level)
("C-c C-w" . cp-ly-wrap-para)) ("C-c C-w" . cp-ly-wrap-para))
:commands LilyPond-mode :commands LilyPond-mode
:load-path "../user/"
:mode (("\\.ly$" . LilyPond-mode)
("\\.ily$" . LilyPond-mode))
:config :config
(--map (add-hook 'LilyPond-mode-hook it) (--map (add-hook 'LilyPond-mode-hook it)
'(subword-mode '(subword-mode
(lambda () (turn-on-font-lock)))) (lambda () (turn-on-font-lock))))
(defalias 'string-to-int #'string-to-number) (defalias 'string-to-int #'string-to-number)
:load-path "../user/"
:mode (("\\.ly$" . LilyPond-mode)
("\\.ily$" . LilyPond-mode)))
(defvar cp/ly-definition-rx (defvar cp/ly-definition-rx
'(and bol '(and bol
(1+ (any "a-z" "A-Z" "\\\\")) (1+ (any "a-z" "A-Z" "\\\\"))
(1+ (any "a-z" "A-Z" "\\\\" " ")) (1+ (any "a-z" "A-Z" "\\\\" " "))
(any "{" "=" "#"))) (any "{" "=" "#")))
(defun cp-backward-def () (defun cp-backward-def ()
(interactive) (interactive)
(unless (region-active-p)
(push-mark))
(re-search-backward (rx-to-string cp/ly-definition-rx)
nil t)
(beginning-of-line)
(recenter))
(defun cp-forward-def ()
(interactive)
(let* ((regex (rx-to-string cp/ly-definition-rx))
(count (if (looking-at-p regex) 2 1)))
(unless (region-active-p) (unless (region-active-p)
(push-mark)) (push-mark))
;; (forward-char) (re-search-backward (rx-to-string cp/ly-definition-rx)
(if (not (re-search-forward regex nil t count)) nil t)
(re-search-forward "^}" nil t))
;; (re-search-forward "^[\\a-zA-Z]" nil t)
(beginning-of-line) (beginning-of-line)
(recenter))) (recenter))
;; (defun cp-backward-def () (defun cp-forward-def ()
;; (interactive) (interactive)
;; (re-search-backward "\(^\\\\?[a-zA-Z]\|^ *\\[a-zA-Z]\)") (let* ((regex (rx-to-string cp/ly-definition-rx))
;; (beginning-of-line)) (count (if (looking-at-p regex) 2 1)))
(unless (region-active-p)
(push-mark))
;; (forward-char)
(if (not (re-search-forward regex nil t count))
(re-search-forward "^}" nil t))
;; (re-search-forward "^[\\a-zA-Z]" nil t)
(beginning-of-line)
(recenter)))
;; (defun cp-forward-def () ;; (defun cp-backward-def ()
;; (interactive) ;; (interactive)
;; (forward-char) ;; (re-search-backward "\(^\\\\?[a-zA-Z]\|^ *\\[a-zA-Z]\)")
;; (re-search-forward "\(^\\\\?[a-zA-Z]\|^ *\\[a-zA-Z]\)") ;; (beginning-of-line))
;; (beginning-of-line))
(defun cp-upper-level () ;; (defun cp-forward-def ()
(interactive) ;; (interactive)
(re-search-backward "{")) ;; (forward-char)
;; (re-search-forward "\(^\\\\?[a-zA-Z]\|^ *\\[a-zA-Z]\)")
;; (beginning-of-line))
(defun cp-lower-level () (defun cp-upper-level ()
(interactive) (interactive)
(if (equal (string (char-after)) "{") (re-search-backward "{"))
(forward-char))
(if (not (re-search-forward "{"))
(message "At deepest level."))
(backward-char))
;; (defun cp-lilypond-enclose-<< () (defun cp-lower-level ()
;; (interactive) (interactive)
;; (if (equal (string (char-after)) "\\") (if (equal (string (char-after)) "{")
;; (progn (insert "<< ") (forward-char))
;; (search-forward "{") (if (not (re-search-forward "{"))
;; (backward-char) (message "At deepest level."))
;; (forward-sexp)))) (backward-char))
;; if at a \new ... block - enclose expression ;; (defun cp-lilypond-enclose-<< ()
;; otherwise, enclose current position and after the first bar check ;; (interactive)
;; found ;; (if (equal (string (char-after)) "\\")
;; if region is active, enclose beginning and end ;; (progn (insert "<< ")
;; (search-forward "{")
;; (backward-char)
;; (forward-sexp))))
;; (defun cp-lilypond-enclose-<< () ;; if at a \new ... block - enclose expression
;; (interactive) ;; otherwise, enclose current position and after the first bar check
;; (if (equal (thing-at-point 'sexp) ;; found
;; "\\new") ;; if region is active, enclose beginning and end
;; (progn ;; (insert "<< ")
;; (newline-and-indent)
;; (search-forward "{")
;; (backward-char)
;; (forward-list)
;; ;; (forward-sexp))
;; )
;; ;; (let ((point1 (point)))
;; ;; (next-line)
;; ;; (goto-char point1))
;; ))
;; (define-key LilyPond-mode-map (kbd "<<")
;; 'cp-lilypond-enclose-<<)
;; If I change files, it's still main.ly that gets compiled; this is ;; (defun cp-lilypond-enclose-<< ()
;; good most of the time, but many times I want to compile a part-* ;; (interactive)
;; file instead. If we compile both main.ly and the respective part-* ;; (if (equal (thing-at-point 'sexp)
;; file every time, it's wasteful. Having to select means giving up ;; "\\new")
;; the 'effortless-compilation' behaviour. ;; (progn ;; (insert "<< ")
;; (newline-and-indent)
;; (search-forward "{")
;; (backward-char)
;; (forward-list)
;; ;; (forward-sexp))
;; )
;; ;; (let ((point1 (point)))
;; ;; (next-line)
;; ;; (goto-char point1))
;; ))
;; (define-key LilyPond-mode-map (kbd "<<")
;; 'cp-lilypond-enclose-<<)
;; 2017-03-14T00:52:07+0530 - commented out, see cp/after-save ;; If I change files, it's still main.ly that gets compiled; this is
;; (defadvice LilyPond-save-buffer ;; good most of the time, but many times I want to compile a part-*
;; (after lysb activate) ;; file instead. If we compile both main.ly and the respective part-*
;; ;; (compile "make") ;; file every time, it's wasteful. Having to select means giving up
;; (cd (locate-dominating-file (buffer-file-name) ;; the 'effortless-compilation' behaviour.
;; "main.ly"))
;; (compile (car compile-history)))
;;
;; (defadvice compile
;; (before compile activate)
;; (if (equal major-mode 'LilyPond-mode)
;; (cd (locate-dominating-file (buffer-file-name)
;; "main.ly"))))
;; TODO - refactor into one COND, with one case per operation. ;; 2017-03-14T00:52:07+0530 - commented out, see cp/after-save
;; TODO - operate on region as well. ;; (defadvice LilyPond-save-buffer
(defun cp-ly-wrap-para (arg) ;; (after lysb activate)
"Wrap current paragraph with - ;; ;; (compile "make")
;; (cd (locate-dominating-file (buffer-file-name)
;; "main.ly"))
;; (compile (car compile-history)))
;;
;; (defadvice compile
;; (before compile activate)
;; (if (equal major-mode 'LilyPond-mode)
;; (cd (locate-dominating-file (buffer-file-name)
;; "main.ly"))))
;; TODO - refactor into one COND, with one case per operation.
;; TODO - operate on region as well.
(defun cp-ly-wrap-para (arg)
"Wrap current paragraph with -
\\relative c { ... } with no args, \\relative c { ... } with no args,
\\repeat { ... } with universal argument, \\repeat { ... } with universal argument,
and only braces - { ... } - with null argument. and only braces - { ... } - with null argument.
@ -133,34 +133,36 @@ and only braces - { ... } - with null argument.
Numeric arg wraps that many paragraphs. Numeric arg wraps that many paragraphs.
TODO - wrap region if region active" TODO - wrap region if region active"
(interactive "P") (interactive "P")
(let ((point-a (point))) (let ((point-a (point)))
(beginning-of-line) (beginning-of-line)
(unless (looking-at "[[:blank:]]*$") (unless (looking-at "[[:blank:]]*$")
;; go to start of paragraph or block, or previous blank line ;; go to start of paragraph or block, or previous blank line
(re-search-backward (rx (or (and bol (0+ blank) eol) (re-search-backward (rx (or (and bol (0+ blank) eol)
(and "{" eol)))) (and "{" eol))))
(end-of-line)) (end-of-line))
(newline-and-indent) (newline-and-indent)
(insert (pcase arg (insert (pcase arg
(`(,x) "\\repeat {") (`(,x) "\\repeat {")
(0 "{") (0 "{")
;; nil ;; nil
(_ "\\relative c {"))) (_ "\\relative c {")))
(let ((indent-start (point))) (let ((indent-start (point)))
(forward-paragraph (pcase arg (forward-paragraph (pcase arg
(`(,x) 1) (`(,x) 1)
(_ (if (and arg (<= arg 0)) (_ (if (and arg (<= arg 0))
1 arg)))) 1 arg))))
(indent-region indent-start (point)) (indent-region indent-start (point))
(insert "}") (insert "}")
(indent-for-tab-command) (indent-for-tab-command)
(newline) (newline)
;; FIXME ;; FIXME
(goto-char (pcase arg (goto-char (pcase arg
(0 point-a) (0 point-a)
(_ (- indent-start 2))))))) (_ (- indent-start 2))))))))
;; TODO - cp-ly-new-var, bind to M-RET. ;; TODO - cp-ly-new-var, bind to M-RET.
;; Exits current variable body, if in any, and inserts "| = \relative ;; Exits current variable body, if in any, and inserts "| = \relative
;; c {\n\n \n}", where | is the cursor ;; c {\n\n \n}", where | is the cursor
(provide 'cp-lily)

View File

@ -24,3 +24,5 @@
(define-key sfz-mode-map (kbd "M-p") 'sfz-prev-group) (define-key sfz-mode-map (kbd "M-p") 'sfz-prev-group)
(define-key sfz-mode-map (kbd "M-n") 'sfz-next-group) (define-key sfz-mode-map (kbd "M-n") 'sfz-next-group)
(provide 'cp-sfz)

View File

@ -575,8 +575,8 @@ and eval it."
(require 'cp-editing) (require 'cp-editing)
;; (load "cp-evil") ;; (load "cp-evil")
(load "cp-fm") (load "cp-fm")
(load "cp-lily") (require 'cp-lily)
(load "cp-sfz") (require 'cp-sfz)
(require 'cp-prog) (require 'cp-prog)
(require 'cp-lisp) (require 'cp-lisp)
(require 'cp-nav) (require 'cp-nav)