-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathcsound-manual-lookup.el
More file actions
122 lines (101 loc) · 4.15 KB
/
Copy pathcsound-manual-lookup.el
File metadata and controls
122 lines (101 loc) · 4.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
;;; csound-manual-lookup.el --- Browse the Csound manual
;; Copyright (C) 2017 - 2023 Hlöðver Sigurðsson
;; Author: Hlöðver Sigurðsson <hlolli@gmail.com>
;; Version: 0.2.9
;; Package-Requires: ((emacs "27.1"))
;; URL: https://github.com/hlolli/csound-mode
;; 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 3 of the License, or
;; (at your option) any later version.
;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with this program. If not, see <http://www.gnu.org/licenses/>.
;;; Commentary:
;; This module implements Csound manual lookup functionality for
;;; csound-mode.
;;; Code:
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; Csound manual lookup
;;;
;;; DESCRIPTION
;;; This extension enables the interactive lookup of Csound functions in the
;;; Csound reference manual located at the Csound homepage.
;;;
;;; TODO:
;;; - Implement a global variable referring to the Csound manual base url.
;;; This might be handy e.g. when the manual is installed locally.
;;;
;;; AUTHOR
;;; Ruben Philipp
;;;
;;; CREATED
;;; 2023-12-26, Lütgendortmund
;;;
;;; $$ Last modified: 16:40:01 Tue Oct 24 2023 CEST
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(require 'csound-opcodes)
(require 'csound-util)
(require 'cl-lib)
(require 'browse-url)
(require 'thingatpt)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; The url to the Csound manual
;;; Customizing this could be useful e.g. when the manual is
;;; installed locally.
;;; RP Wed Sep 20 19:51:22 2023
;;; Updated by Brandon Hale April 25, 2026
(defgroup csound-mode-manual-lookup nil
"Csound manual lookup."
:prefix "csound-manual-"
:group 'csound-mode)
(defcustom csound-manual-url
"https://csound.com/docs/manual/"
"The URL to the root directory of the Csound manual."
:group 'csound-mode-manual-lookup
:type 'string)
(defun csound-manual--file-name-concat (directory filename)
"Return FILENAME under DIRECTORY.
Use `file-name-concat' when available, and fall back to an Emacs 27
compatible implementation otherwise."
(if (fboundp 'file-name-concat)
(file-name-concat directory filename)
(concat (file-name-as-directory directory) filename)))
(defun csound-manual--browse (file)
(browse-url (csound-manual--file-name-concat csound-manual-url file)))
(defun csound-manual-lookup ()
(interactive)
(let* ((lemma (thing-at-point 'word 'no-properties))
(lookup-lemma (if (gethash lemma
csdoc-opcode-database)
(downcase lemma)
(read-string "Lookup function in Csound manual: "))))
(csound-manual--browse (concat lookup-lemma ".html"))))
(defun csound-gen-manual-lookup ()
(interactive)
(let* ((cursor-text (thing-at-point 'number 'no-properties))
(user-input (if (not cursor-text)
(read-string "Lookup GEN in Csound manual: ")
(number-to-string cursor-text)))
(use-input (if (= (length user-input) 1)
(concat "0" user-input)
user-input)))
(csound-manual--browse (concat "GEN" use-input ".html"))))
(defun csound-browse-manual ()
(interactive)
(csound-manual--browse "index.html"))
(defun csound-browse-gen-manual ()
(interactive)
(csound-manual--browse "ScoreGenRef.html"))
;;; key binding
(with-eval-after-load 'csound-mode
(define-key csound-mode-map (kbd "C-c C-d h") 'csound-manual-lookup)
(define-key csound-mode-map (kbd "C-c C-d g") 'csound-gen-manual-lookup)
(define-key csound-mode-map (kbd "C-c g") 'csound-browse-gen-manual)
(define-key csound-mode-map (kbd "C-c m") 'csound-browse-manual))
(provide 'csound-manual-lookup)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; EOF csound-manual-lookup.el