Skip to content

Commit

Permalink
changes for MELPA compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
zzkt committed Aug 2, 2022
1 parent 36eae66 commit 53d3959
Show file tree
Hide file tree
Showing 17 changed files with 1,472 additions and 1,226 deletions.
15 changes: 9 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ SuperCollider/Emacs interface
There are 3 options for installation:

1. Using SuperCollider Quarks (recommended)
2. From debian package `supercollider-emacs`
3. From source
2. Using an Emacs package manager
3. From debian package `supercollider-emacs`
4. From source

Option #1 is the best cross-platform option, and is recommended. Whatever option
you choose, *make sure not to mix installation methods*. In particular, do not
Expand Down Expand Up @@ -61,17 +62,19 @@ exec-path.
(setq exec-path (append exec-path '("/Applications/SuperCollider.app/Contents/MacOS/")))
```

#### Installing with an emacs package manager
### Install Option 2: Emacs package manager

It's completely possible to install with
The `sclang` package can be installed from [MELPA](https://melpa.org/#/sclang) and configured with [use-package](https://github.com/jwiegley/use-package).

It's possible to install with
[straight.el](https://github.com/raxod502/straight.el),
[use-package](https://github.com/jwiegley/use-package),
[doom](https://github.com/hlissner/doom-emacs), etc. Instructions for doing so
are beyond the scope of this README, but note that `autoloads` are implemented
for entry-point functions so if you like to have a speedy start-up time you can
use the `:defer t` option.

### Install Option 2: Debian package
### Install Option 3: Debian package

There is a debian package which provides emacs integration called
`supercollider-emacs`. Option #1 will likely be more recent, but
Expand All @@ -81,7 +84,7 @@ if you prefer you can install the package with:
sudo apt install supercollider-emacs
```

### Install Option 3: Installing from source
### Install Option 4: Installing from source

If you are building SuperCollider from source, you can optionally compile and
install this library along with it. The cmake `-DSC_EL` flag controls whether
Expand Down
1 change: 1 addition & 0 deletions el/Eldev
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@
;; We use it for package development and running tests

(eldev-use-plugin 'autoloads)
(eldev-use-package-archive 'melpa)
197 changes: 111 additions & 86 deletions el/sclang-browser.el
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
;; copyright 2003 stefan kersten <[email protected]>
;;; sclang-browser.el --- SuperCollider documentation browser -*- coding: utf-8; lexical-binding: t -*-
;;
;; Copyright 2003 stefan kersten <[email protected]>

;;; License:

;; This program is free software; you can redistribute it and/or
;; modify it under the terms of the GNU General Public License as
;; published by the Free Software Foundation; either version 2 of the
Expand All @@ -15,163 +19,184 @@
;; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
;; USA

(require 'sclang-util)
(require 'view nil t)
;;; Commentary:
;; Browser for SuperCollider documentation.

;; TODO: better factoring
;; derive from view mode, make mode-map pluggable
;; define derived mode for completion, definition, help

(defun sclang-browser-fill-keymap (map)
(define-key map "\r" 'sclang-browser-follow-link)
(define-key map [mouse-2] 'sclang-browser-mouse-follow-link)
(define-key map "\t" 'sclang-browser-next-link)
(define-key map [backtab] 'sclang-browser-previous-link)
(define-key map [(shift tab)] 'sclang-browser-previous-link)
(define-key map [?q] 'sclang-browser-quit)
map)

(defvar sclang-browser-mode-map (sclang-browser-fill-keymap (make-sparse-keymap)))
;; - derive from view mode, make mode-map pluggable
;; - define derived mode for completion, definition, help
;; - update 'display-buffer-reuse-frames'
;; - update ‘view-return-to-alist’

(require 'sclang-util)
(require 'view)

;;; Code:

(defun sclang-browser-fill-keymap ()
"Create keymap and bindings."
(let ((map (make-sparse-keymap)))
(set-keymap-parent map view-mode-map)
(define-key map "\r" 'sclang-browser-follow-link)
(define-key map [mouse-2] 'sclang-browser-mouse-follow-link)
(define-key map "\t" 'sclang-browser-next-link)
(define-key map [backtab] 'sclang-browser-previous-link)
(define-key map [(shift tab)] 'sclang-browser-previous-link)
(define-key map [?q] 'sclang-browser-quit)
map))

(defvar sclang-browser-mode-map (sclang-browser-fill-keymap))
(defvar sclang-browser-mode-hook nil)
(defvar sclang-browser-show-hook nil)
(defvar sclang-browser-link-function nil
"buffer local")
(defvar sclang-browser-return-method nil
"buffer local")
(defvar sclang-browser-link-function nil)
(defvar sclang-browser-return-method nil)

(defun sclang-browser-beginning-of-link ()
"Beginning of link."
(interactive)
(when (get-text-property (point) 'sclang-browser-link)
(while (and (not (bobp))
(get-text-property (point) 'sclang-browser-link))
(get-text-property (point) 'sclang-browser-link))
(forward-char -1))
(unless (bobp) (forward-char 1))
(point)))

(defun sclang-browser-next-link (&optional n)
"Next link (or N further)."
(interactive)
(let* ((n (or n 1))
(prop 'sclang-browser-link)
(fwd (>= n 0))
(orig (point))
(beg (if fwd (point-min) (point-max)))
(end (if fwd (point-max) (point-min)))
(inc (if fwd 1 -1))
pos)
(prop 'sclang-browser-link)
(fwd (>= n 0))
(orig (point))
(beg (if fwd (point-min) (point-max)))
(end (if fwd (point-max) (point-min)))
(inc (if fwd 1 -1))
pos)
(when (get-text-property (point) prop)
(while (and (/= (point) beg)
(get-text-property (point) prop))
(forward-char inc))
(get-text-property (point) prop))
(forward-char inc))
(if (= (point) beg) (goto-char end)))
(while (not (eq pos orig))
(cond ((get-text-property (point) prop)
(sclang-browser-beginning-of-link)
(setq pos orig))
(t
(if (= (point) end) (goto-char beg))
(forward-char inc)
(setq pos (point)))))))
(sclang-browser-beginning-of-link)
(setq pos orig))
(t
(if (= (point) end) (goto-char beg))
(forward-char inc)
(setq pos (point)))))))

(defun sclang-browser-previous-link ()
"Previous link."
(interactive)
(sclang-browser-next-link -1))

(defun sclang-browser-follow-link (&optional pos)
"Follow link (optionally POS)."
(interactive)
(let* ((pos (or pos (point)))
(data (get-text-property pos 'sclang-browser-link)))
(data (get-text-property pos 'sclang-browser-link)))
(when (consp data)
(let ((fun (or (car data) sclang-browser-link-function))
(arg (cdr data)))
(when (functionp fun)
(condition-case nil
(funcall fun arg)
(error (sclang-message "Error in link function") nil)))))))
(arg (cdr data)))
(when (functionp fun)
(condition-case nil
(funcall fun arg)
(error (sclang-message "Error in link function") nil)))))))

(defun sclang-browser-mouse-follow-link (event)
"Link. click. EVENT."
(interactive "e")
(let* ((start (event-start event))
(window (car start))
(pos (cadr start)))
(window (car start))
(pos (cadr start)))
(with-current-buffer (window-buffer window)
(sclang-browser-follow-link pos))))

(defun sclang-browser-mode ()
"Major mode for viewing hypertext and navigating references in it.
Entry to this mode runs the normal hook `sclang-browser-mode-hook'.
"Major mode for viewing hypertext and navigating references.
Entry to this mode runs the normal hook `sclang-browser-mode-hook'
Commands:
\\{sclang-browser-mode-map}"
(interactive)
(view-mode)
(kill-all-local-variables)
(use-local-map sclang-browser-mode-map)
(set-keymap-parent sclang-browser-mode-map view-mode-map)
(setq mode-name "Browser")
(setq major-mode 'sclang-browser-mode)
(set (make-local-variable 'sclang-browser-link-function) nil)
(set (make-local-variable 'sclang-browser-return-method) nil)
(set (make-local-variable 'font-lock-defaults) nil)
(view-mode)
(set (make-local-variable 'minor-mode-overriding-map-alist)
(list (cons 'view-mode sclang-browser-mode-map)))
(set (make-local-variable 'view-no-disable-on-exit) t)
(set (make-local-variable 'view-no-disable-on-exit) t)
(run-hooks 'sclang-browser-mode-hook))

(defun sclang-browser-mode-setup ()
"Setup sclang-browser-mode."
(sclang-browser-mode)
(setq buffer-read-only nil))

(defun sclang-browser-mode-finish ()
(toggle-read-only 1)
(setq view-return-to-alist
(list (cons (selected-window) sclang-browser-return-method)))
"Finish sclang-browser-mode."
(read-only-mode)
;; ‘view-return-to-alist’ is an obsolete variable (as of 24.1)
;;(setq view-return-to-alist
;; (list (cons (selected-window) sclang-browser-return-method)))
(view-mode -1)
(run-hooks 'sclang-browser-show-hook))

(defun sclang-browser-quit ()
"Quit the sclang help browser."
(interactive)
(when (eq major-mode 'sclang-browser-mode)
(kill-buffer (current-buffer))))

(defun sclang-browser-make-link (link-text &optional link-data link-function)
(let ((map (make-sparse-keymap)))
(propertize link-text
'mouse-face 'highlight
;;'help-echo "mouse-2: follow link"
;;'keymap map
'sclang-browser-link (cons link-function link-data)
;;'sclang-browser-link-data link-data
;;'sclang-browser-link-function link-function)))
)))
"Make a link using LINK-TEXT (optional LINK-DATA and LINK-FUNCTION)."
(propertize link-text
'mouse-face 'highlight
'sclang-browser-link (cons link-function link-data)))

(defun sclang-display-browser (buffer-name output-function)
"header: what to insert in the buffer
link-list: list of (link-text link-function link-data)
link-function: function with args (link-text link-data)"
"Display browser using BUFFER-NAME and OUTPUT-FUNCTION.
header: what to insert in the buffer.
link-list: list of (link-text link-function link-data)
link-function: function with args (link-text link-data)"
(let ((temp-buffer-setup-hook '(sclang-browser-mode-setup))
(temp-buffer-show-hook '(sclang-browser-mode-finish)))
(temp-buffer-show-hook '(sclang-browser-mode-finish)))
(with-output-to-temp-buffer buffer-name
(with-current-buffer standard-output
;; record return method
(setq sclang-browser-return-method
(cond ((special-display-p (buffer-name standard-output))
;; If the help output buffer is a special display buffer,
;; don't say anything about how to get rid of it.
;; First of all, the user will do that with the window
;; manager, not with Emacs.
;; Secondly, the buffer has not been displayed yet,
;; so we don't know whether its frame will be selected.
(cons (selected-window) t))
(display-buffer-reuse-frames
(cons (selected-window) 'quit-window))
((not (one-window-p t))
(cons (selected-window) 'quit-window))
(pop-up-windows
(cons (selected-window) t))
(t
(list (selected-window) (window-buffer)
(window-start) (window-point)))))
(funcall output-function)))))
;; record return method
(setq sclang-browser-return-method
(cond ((special-display-p (buffer-name standard-output))
;; If the help output buffer is a special display buffer,
;; don't say anything about how to get rid of it.
;; First of all, the user will do that with the window
;; manager, not with Emacs.
;; Secondly, the buffer has not been displayed yet,
;; so we don't know whether its frame will be selected.
(cons (selected-window) t))
;; display-buffer-reuse-frames is obsolete since 24.3
;; replace with something like
;;+ (add-to-list 'display-buffer-alist
;;+ '("." nil (reusable-frames . t)))
;;- (display-buffer-reuse-frames
;;- (cons (selected-window) 'quit-window))
((not (one-window-p t))
(cons (selected-window) 'quit-window))
;; This variable is provided mainly for backward compatibility
;; and should not be used in new code.
;; (pop-up-windows
;; (cons (selected-window) t))
(t
(list (selected-window) (window-buffer)
(window-start) (window-point)))))
(funcall output-function)))))

(defmacro with-sclang-browser (buffer-name &rest body)
"Display browser in BUFFER-NAME and run BODY."
`(sclang-display-browser ,buffer-name (lambda () ,@body)))

;; =====================================================================
Expand All @@ -180,4 +205,4 @@ Commands:

(provide 'sclang-browser)

;; EOF
;;; sclang-browser.el ends here
35 changes: 17 additions & 18 deletions el/sclang-dev.el
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
;;; sclang-dev.el --- IDE for working with SuperCollider -*- coding: utf-8;
;;
;; Copyright 2003 stefan kersten <[email protected]>

;;; License:

;; This program is free software; you can redistribute it and/or
;; modify it under the terms of the GNU General Public License as
;; published by the Free Software Foundation; either version 2 of the
Expand All @@ -13,32 +19,25 @@
;; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
;; USA


;;; Commentary:
;; Edit SuperCollider help files.

(require 'sclang-util)
(require 'sclang-interp)

;;; Code:

(sclang-set-command-handler
'openDevSource
(lambda (file)
)
)
'openDevSource
(lambda (file)))

(defun sclang-edit-dev-source ()
"Edit the help file at the development location."
; (sclang-document-name . (prSetTitle (buffer-name)))
(interactive)
(sclang-perform-command 'openDevSource (buffer-file-name))
)
;; (sclang-document-name . (prSetTitle (buffer-name)))
(sclang-perform-command 'openDevSource (buffer-file-name)))

(provide 'sclang-dev)

;(defun sclang-open-dev-source (file)
; "Open the help file at the development location."
; (if (sclang-html-file-p file)
; (html-mode)
; ;; (find-file file)
; )
; (if ( sclang-sc-file-p file )
; (sclang-mode)
; )
; )

;;; sclang-dev.el ends here
Loading

0 comments on commit 53d3959

Please sign in to comment.