aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStefan Monnier2013-03-29 10:23:24 -0400
committerStefan Monnier2013-03-29 10:23:24 -0400
commitefc0bb734970ef30dfe6fbda151b797bcac4ae1f (patch)
tree9e0695479336aed27e5ba91129f47ef6ab3586f4
parentd406cffa8e82893802232f4eea8f6f1a478d263a (diff)
downloademacs-efc0bb734970ef30dfe6fbda151b797bcac4ae1f.tar.gz
emacs-efc0bb734970ef30dfe6fbda151b797bcac4ae1f.zip
* lisp/mpc.el: Use defvar-local and setq-local.
(mpc--proc-connect): Connection failures are not bugs. (mpc-mode-map): `follow-link' only applies to the buffer's content. (mpc-volume-map): Bind to the up-events.
-rw-r--r--lisp/ChangeLog7
-rw-r--r--lisp/mpc.el162
2 files changed, 91 insertions, 78 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index 1865491d382..36b69c1ac28 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,3 +1,10 @@
12013-03-29 Stefan Monnier <monnier@iro.umontreal.ca>
2
3 * mpc.el: Use defvar-local and setq-local.
4 (mpc--proc-connect): Connection failures are not bugs.
5 (mpc-mode-map): `follow-link' only applies to the buffer's content.
6 (mpc-volume-map): Bind to the up-events.
7
12013-03-29 Teodor Zlatanov <tzz@lifelogs.com> 82013-03-29 Teodor Zlatanov <tzz@lifelogs.com>
2 9
3 * progmodes/subword.el (superword-mode): Use `forward-sexp' 10 * progmodes/subword.el (superword-mode): Use `forward-sexp'
diff --git a/lisp/mpc.el b/lisp/mpc.el
index a6494575a43..9d9da27f6da 100644
--- a/lisp/mpc.el
+++ b/lisp/mpc.el
@@ -192,7 +192,7 @@ numerically rather than lexicographically."
192;; to the fact that MPD tends to disconnect fairly often, although our 192;; to the fact that MPD tends to disconnect fairly often, although our
193;; constant polling often prevents disconnection. 193;; constant polling often prevents disconnection.
194(defvar mpc--find-memoize (make-hash-table :test 'equal)) ;; :weakness t 194(defvar mpc--find-memoize (make-hash-table :test 'equal)) ;; :weakness t
195(defvar mpc-tag nil) (make-variable-buffer-local 'mpc-tag) 195(defvar-local mpc-tag nil)
196 196
197;;; Support for the actual connection and MPD command execution ;;;;;;;;;;;; 197;;; Support for the actual connection and MPD command execution ;;;;;;;;;;;;
198 198
@@ -279,7 +279,9 @@ defaults to 6600 and HOST defaults to localhost."
279 (erase-buffer) 279 (erase-buffer)
280 (let* ((coding-system-for-read 'utf-8-unix) 280 (let* ((coding-system-for-read 'utf-8-unix)
281 (coding-system-for-write 'utf-8-unix) 281 (coding-system-for-write 'utf-8-unix)
282 (proc (open-network-stream "MPC" (current-buffer) host port))) 282 (proc (condition-case err
283 (open-network-stream "MPC" (current-buffer) host port)
284 (error (user-error (error-message-string err))))))
283 (when (processp mpc-proc) 285 (when (processp mpc-proc)
284 ;; Inherit the properties of the previous connection. 286 ;; Inherit the properties of the previous connection.
285 (let ((plist (process-plist mpc-proc))) 287 (let ((plist (process-plist mpc-proc)))
@@ -1079,7 +1081,11 @@ If PLAYLIST is t or nil or missing, use the main playlist."
1079 (define-key map [C-mouse-2] 'mpc-select-toggle) 1081 (define-key map [C-mouse-2] 'mpc-select-toggle)
1080 (define-key map [drag-mouse-2] 'mpc-drag-n-drop) 1082 (define-key map [drag-mouse-2] 'mpc-drag-n-drop)
1081 ;; We use `always' because a binding to t is like a binding to nil. 1083 ;; We use `always' because a binding to t is like a binding to nil.
1082 (define-key map [follow-link] 'always) 1084 (define-key map [follow-link] :always)
1085 ;; But follow-link doesn't apply blindly to header-line and
1086 ;; mode-line clicks.
1087 (define-key map [header-line follow-link] 'ignore)
1088 (define-key map [mode-line follow-link] 'ignore)
1083 ;; Doesn't work because the first click changes the buffer, so the second 1089 ;; Doesn't work because the first click changes the buffer, so the second
1084 ;; is applied elsewhere :-( 1090 ;; is applied elsewhere :-(
1085 ;; (define-key map [(double mouse-2)] 'mpc-play-at-point) 1091 ;; (define-key map [(double mouse-2)] 'mpc-play-at-point)
@@ -1136,17 +1142,18 @@ If PLAYLIST is t or nil or missing, use the main playlist."
1136 "Major mode for the features common to all buffers of MPC." 1142 "Major mode for the features common to all buffers of MPC."
1137 (buffer-disable-undo) 1143 (buffer-disable-undo)
1138 (setq buffer-read-only t) 1144 (setq buffer-read-only t)
1139 (set (make-local-variable 'tool-bar-map) mpc-tool-bar-map) 1145 (setq-local tool-bar-map mpc-tool-bar-map)
1140 (set (make-local-variable 'truncate-lines) t)) 1146 (setq-local truncate-lines t))
1141 1147
1142;;; The mpc-status-mode buffer ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 1148;;; The mpc-status-mode buffer ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1143 1149
1144(define-derived-mode mpc-status-mode mpc-mode "MPC-Status" 1150(define-derived-mode mpc-status-mode mpc-mode "MPC-Status"
1145 "Major mode to display MPC status info." 1151 "Major mode to display MPC status info."
1146 (set (make-local-variable 'mode-line-format) 1152 (setq-local mode-line-format
1147 '("%e" mode-line-frame-identification mode-line-buffer-identification)) 1153 '("%e" mode-line-frame-identification
1148 (set (make-local-variable 'window-area-factor) 3) 1154 mode-line-buffer-identification))
1149 (set (make-local-variable 'header-line-format) '("MPC " mpc-volume))) 1155 (setq-local window-area-factor 3)
1156 (setq-local header-line-format '("MPC " mpc-volume)))
1150 1157
1151(defvar mpc-status-buffer-format 1158(defvar mpc-status-buffer-format
1152 '("%-5{Time} / %{Duration} %2{Disc--}%4{Track}" "%{Title}" "%{Album}" "%{Artist}" "%128{Cover}")) 1159 '("%-5{Time} / %{Duration} %2{Disc--}%4{Track}" "%{Title}" "%{Album}" "%{Artist}" "%128{Cover}"))
@@ -1188,8 +1195,7 @@ If PLAYLIST is t or nil or missing, use the main playlist."
1188 1195
1189(defvar mpc-separator-ol nil) 1196(defvar mpc-separator-ol nil)
1190 1197
1191(defvar mpc-select nil) 1198(defvar-local mpc-select nil)
1192(make-variable-buffer-local 'mpc-select)
1193 1199
1194(defmacro mpc-select-save (&rest body) 1200(defmacro mpc-select-save (&rest body)
1195 "Execute BODY and restore the selection afterwards." 1201 "Execute BODY and restore the selection afterwards."
@@ -1420,20 +1426,18 @@ when constructing the set of constraints."
1420;;; The TagBrowser mode ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 1426;;; The TagBrowser mode ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1421 1427
1422(defconst mpc-tagbrowser-all-name (propertize "*ALL*" 'face 'italic)) 1428(defconst mpc-tagbrowser-all-name (propertize "*ALL*" 'face 'italic))
1423(defvar mpc-tagbrowser-all-ol nil) 1429(defvar-local mpc-tagbrowser-all-ol nil)
1424(make-variable-buffer-local 'mpc-tagbrowser-all-ol) 1430(defvar-local mpc-tag-name nil)
1425(defvar mpc-tag-name nil) (make-variable-buffer-local 'mpc-tag-name)
1426(defun mpc-tagbrowser-all-p () 1431(defun mpc-tagbrowser-all-p ()
1427 (and (eq (point-min) (line-beginning-position)) 1432 (and (eq (point-min) (line-beginning-position))
1428 (equal mpc-tagbrowser-all-name 1433 (equal mpc-tagbrowser-all-name
1429 (buffer-substring (point-min) (line-end-position))))) 1434 (buffer-substring (point-min) (line-end-position)))))
1430 1435
1431(define-derived-mode mpc-tagbrowser-mode mpc-mode '("MPC-" mpc-tag-name) 1436(define-derived-mode mpc-tagbrowser-mode mpc-mode '("MPC-" mpc-tag-name)
1432 (set (make-local-variable 'mode-line-process) '("" mpc-tag-name)) 1437 (setq-local mode-line-process '("" mpc-tag-name))
1433 (set (make-local-variable 'mode-line-format) nil) 1438 (setq-local mode-line-format nil)
1434 (set (make-local-variable 'header-line-format) '("" mpc-tag-name ;; "s" 1439 (setq-local header-line-format '("" mpc-tag-name)) ;; "s"
1435 )) 1440 (setq-local buffer-undo-list t)
1436 (set (make-local-variable 'buffer-undo-list) t)
1437 ) 1441 )
1438 1442
1439(defun mpc-tagbrowser-refresh () 1443(defun mpc-tagbrowser-refresh ()
@@ -1539,14 +1543,14 @@ when constructing the set of constraints."
1539 (let ((ol (make-overlay (point) (line-beginning-position 2)))) 1543 (let ((ol (make-overlay (point) (line-beginning-position 2))))
1540 (overlay-put ol 'face 'region) 1544 (overlay-put ol 'face 'region)
1541 (overlay-put ol 'evaporate t) 1545 (overlay-put ol 'evaporate t)
1542 (set (make-local-variable 'mpc-tagbrowser-all-ol) ol)))))) 1546 (setq-local mpc-tagbrowser-all-ol ol))))))
1543 1547
1544;; (defvar mpc-constraints nil) 1548;; (defvar mpc-constraints nil)
1545(defun mpc-separator (active) 1549(defun mpc-separator (active)
1546 ;; Place a separator mark. 1550 ;; Place a separator mark.
1547 (unless mpc-separator-ol 1551 (unless mpc-separator-ol
1548 (set (make-local-variable 'mpc-separator-ol) 1552 (setq-local mpc-separator-ol
1549 (make-overlay (point) (point))) 1553 (make-overlay (point) (point)))
1550 (overlay-put mpc-separator-ol 'after-string 1554 (overlay-put mpc-separator-ol 'after-string
1551 (propertize "\n" 1555 (propertize "\n"
1552 'face '(:height 0.05 :inverse-video t)))) 1556 'face '(:height 0.05 :inverse-video t))))
@@ -1605,7 +1609,7 @@ Return non-nil if a selection was deactivated."
1605 (let ((constraints (mpc-constraints-get-current (current-buffer))) 1609 (let ((constraints (mpc-constraints-get-current (current-buffer)))
1606 (active 'all)) 1610 (active 'all))
1607 ;; (unless (equal constraints mpc-constraints) 1611 ;; (unless (equal constraints mpc-constraints)
1608 ;; (set (make-local-variable 'mpc-constraints) constraints) 1612 ;; (setq-local mpc-constraints constraints)
1609 (dolist (cst constraints) 1613 (dolist (cst constraints)
1610 (let ((vals (apply 'mpc-union 1614 (let ((vals (apply 'mpc-union
1611 (mapcar (lambda (val) 1615 (mapcar (lambda (val)
@@ -1672,7 +1676,7 @@ Return non-nil if a selection was deactivated."
1672;; '(mpc-tagbrowser-dir-hide-prefix)) 1676;; '(mpc-tagbrowser-dir-hide-prefix))
1673 1677
1674(define-derived-mode mpc-tagbrowser-dir-mode mpc-tagbrowser-mode '("MPC-" mpc-tag-name) 1678(define-derived-mode mpc-tagbrowser-dir-mode mpc-tagbrowser-mode '("MPC-" mpc-tag-name)
1675 ;; (set (make-local-variable 'font-lock-defaults) 1679 ;; (setq-local font-lock-defaults
1676 ;; '(mpc-tagbrowser-dir-keywords t)) 1680 ;; '(mpc-tagbrowser-dir-keywords t))
1677 ) 1681 )
1678 1682
@@ -1705,10 +1709,9 @@ Return non-nil if a selection was deactivated."
1705 1709
1706;;; Playlist management ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 1710;;; Playlist management ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1707 1711
1708(defvar mpc-songs-playlist nil 1712(defvar-local mpc-songs-playlist nil
1709 "Name of the currently selected playlist, if any. 1713 "Name of the currently selected playlist, if any.
1710A value of t means the main playlist.") 1714A value of t means the main playlist.")
1711(make-variable-buffer-local 'mpc-songs-playlist)
1712 1715
1713(defun mpc-playlist-create (name) 1716(defun mpc-playlist-create (name)
1714 "Save current playlist under name NAME." 1717 "Save current playlist under name NAME."
@@ -1775,12 +1778,14 @@ A value of t means the main playlist.")
1775 1778
1776(defvar mpc-volume-map 1779(defvar mpc-volume-map
1777 (let ((map (make-sparse-keymap))) 1780 (let ((map (make-sparse-keymap)))
1778 (define-key map [down-mouse-1] 'mpc-volume-mouse-set) 1781 ;; Bind the up-events rather than the down-event, so the
1779 (define-key map [mouse-1] 'ignore) 1782 ;; `message' isn't canceled by the subsequent up-event binding.
1780 (define-key map [header-line down-mouse-1] 'mpc-volume-mouse-set) 1783 (define-key map [down-mouse-1] 'ignore)
1781 (define-key map [header-line mouse-1] 'ignore) 1784 (define-key map [mouse-1] 'mpc-volume-mouse-set)
1782 (define-key map [mode-line down-mouse-1] 'mpc-volume-mouse-set) 1785 (define-key map [header-line mouse-1] 'mpc-volume-mouse-set)
1783 (define-key map [mode-line mouse-1] 'ignore) 1786 (define-key map [header-line down-mouse-1] 'ignore)
1787 (define-key map [mode-line mouse-1] 'mpc-volume-mouse-set)
1788 (define-key map [mode-line down-mouse-1] 'ignore)
1784 map)) 1789 map))
1785 1790
1786(defvar mpc-volume nil) (put 'mpc-volume 'risky-local-variable t) 1791(defvar mpc-volume nil) (put 'mpc-volume 'risky-local-variable t)
@@ -1945,9 +1950,9 @@ This is used so that they can be compared with `eq', which is needed for
1945 (search-backward (cdr curline) nil t)) 1950 (search-backward (cdr curline) nil t))
1946 (beginning-of-line) 1951 (beginning-of-line)
1947 (goto-char (point-min))) 1952 (goto-char (point-min)))
1948 (set (make-local-variable 'mpc-songs-totaltime) 1953 (setq-local mpc-songs-totaltime
1949 (unless (zerop totaltime) 1954 (unless (zerop totaltime)
1950 (list " " (mpc-secs-to-time totaltime)))) 1955 (list " " (mpc-secs-to-time totaltime))))
1951 )))) 1956 ))))
1952 (let ((mpc-songpointer-set-visible t)) 1957 (let ((mpc-songpointer-set-visible t))
1953 (mpc-songpointer-refresh))) 1958 (mpc-songpointer-refresh)))
@@ -2056,46 +2061,47 @@ This is used so that they can be compared with `eq', which is needed for
2056(define-derived-mode mpc-songs-mode mpc-mode "MPC-song" 2061(define-derived-mode mpc-songs-mode mpc-mode "MPC-song"
2057 (setq mpc-songs-format-description 2062 (setq mpc-songs-format-description
2058 (with-temp-buffer (mpc-format mpc-songs-format 'self) (buffer-string))) 2063 (with-temp-buffer (mpc-format mpc-songs-format 'self) (buffer-string)))
2059 (set (make-local-variable 'header-line-format) 2064 (setq-local header-line-format
2060 ;; '("MPC " mpc-volume " " mpc-current-song) 2065 ;; '("MPC " mpc-volume " " mpc-current-song)
2061 (list (propertize " " 'display '(space :align-to 0)) 2066 (list (propertize " " 'display '(space :align-to 0))
2062 ;; 'mpc-songs-format-description 2067 ;; 'mpc-songs-format-description
2063 '(:eval 2068 '(:eval
2064 (let ((hscroll (window-hscroll))) 2069 (let ((hscroll (window-hscroll)))
2065 (with-temp-buffer 2070 (with-temp-buffer
2066 (mpc-format mpc-songs-format 'self hscroll) 2071 (mpc-format mpc-songs-format 'self hscroll)
2067 ;; That would be simpler than the hscroll handling in 2072 ;; That would be simpler than the hscroll handling in
2068 ;; mpc-format, but currently move-to-column does not 2073 ;; mpc-format, but currently move-to-column does not
2069 ;; recognize :space display properties. 2074 ;; recognize :space display properties.
2070 ;; (move-to-column hscroll) 2075 ;; (move-to-column hscroll)
2071 ;; (delete-region (point-min) (point)) 2076 ;; (delete-region (point-min) (point))
2072 (buffer-string)))))) 2077 (buffer-string))))))
2073 (set (make-local-variable 'mode-line-format) 2078 (setq-local
2074 '("%e" mode-line-frame-identification mode-line-buffer-identification 2079 mode-line-format
2075 #(" " 0 3 2080 '("%e" mode-line-frame-identification mode-line-buffer-identification
2076 (help-echo "mouse-1: Select (drag to resize)\nmouse-2: Make current window occupy the whole frame\nmouse-3: Remove current window from display")) 2081 #(" " 0 3
2077 mode-line-position 2082 (help-echo "mouse-1: Select (drag to resize)\nmouse-2: Make current window occupy the whole frame\nmouse-3: Remove current window from display"))
2078 #(" " 0 2 2083 mode-line-position
2079 (help-echo "mouse-1: Select (drag to resize)\nmouse-2: Make current window occupy the whole frame\nmouse-3: Remove current window from display")) 2084 #(" " 0 2
2080 mpc-songs-totaltime 2085 (help-echo "mouse-1: Select (drag to resize)\nmouse-2: Make current window occupy the whole frame\nmouse-3: Remove current window from display"))
2081 mpc-current-updating 2086 mpc-songs-totaltime
2082 #(" " 0 2 2087 mpc-current-updating
2083 (help-echo "mouse-1: Select (drag to resize)\nmouse-2: Make current window occupy the whole frame\nmouse-3: Remove current window from display")) 2088 #(" " 0 2
2084 (mpc--song-search 2089 (help-echo "mouse-1: Select (drag to resize)\nmouse-2: Make current window occupy the whole frame\nmouse-3: Remove current window from display"))
2085 (:propertize 2090 (mpc--song-search
2086 ("Search=\"" mpc--song-search "\"") 2091 (:propertize
2087 help-echo "mouse-2: kill this search" 2092 ("Search=\"" mpc--song-search "\"")
2088 follow-link t 2093 help-echo "mouse-2: kill this search"
2089 mouse-face mode-line-highlight 2094 follow-link t
2090 keymap (keymap (mode-line keymap 2095 mouse-face mode-line-highlight
2091 (mouse-2 . mpc-songs-kill-search)))) 2096 keymap (keymap (mode-line keymap
2092 (:propertize "NoSearch" 2097 (mouse-2 . mpc-songs-kill-search))))
2093 help-echo "mouse-2: set a search restriction" 2098 (:propertize "NoSearch"
2094 follow-link t 2099 help-echo "mouse-2: set a search restriction"
2095 mouse-face mode-line-highlight 2100 follow-link t
2096 keymap (keymap (mode-line keymap (mouse-2 . mpc-songs-search))))))) 2101 mouse-face mode-line-highlight
2097 2102 keymap (keymap (mode-line keymap (mouse-2 . mpc-songs-search)))))))
2098 ;; (set (make-local-variable 'mode-line-process) 2103
2104 ;; (setq-local mode-line-process
2099 ;; '("" ;; mpc-volume " " 2105 ;; '("" ;; mpc-volume " "
2100 ;; mpc-songs-totaltime 2106 ;; mpc-songs-totaltime
2101 ;; mpc-current-updating)) 2107 ;; mpc-current-updating))
@@ -2111,7 +2117,7 @@ This is used so that they can be compared with `eq', which is needed for
2111 (<= (window-start win) overlay-arrow-position) 2117 (<= (window-start win) overlay-arrow-position)
2112 (< overlay-arrow-position (window-end win))))))) 2118 (< overlay-arrow-position (window-end win)))))))
2113 (unless (local-variable-p 'overlay-arrow-position) 2119 (unless (local-variable-p 'overlay-arrow-position)
2114 (set (make-local-variable 'overlay-arrow-position) (make-marker))) 2120 (setq-local overlay-arrow-position (make-marker)))
2115 (move-marker overlay-arrow-position pos) 2121 (move-marker overlay-arrow-position pos)
2116 ;; If the arrow was visible, try to keep it that way. 2122 ;; If the arrow was visible, try to keep it that way.
2117 (if (and visible pos 2123 (if (and visible pos
@@ -2613,8 +2619,8 @@ This is used so that they can be compared with `eq', which is needed for
2613 (window-minibuffer-p)) 2619 (window-minibuffer-p))
2614 (ignore-errors (select-frame (make-frame mpc-frame-alist))) 2620 (ignore-errors (select-frame (make-frame mpc-frame-alist)))
2615 (with-current-buffer song-buf 2621 (with-current-buffer song-buf
2616 (set (make-local-variable 'mpc-previous-window-config) 2622 (setq-local mpc-previous-window-config
2617 (current-window-configuration)))) 2623 (current-window-configuration))))
2618 (let* ((win1 (selected-window)) 2624 (let* ((win1 (selected-window))
2619 (win2 (split-window)) 2625 (win2 (split-window))
2620 (tags mpc-browser-tags)) 2626 (tags mpc-browser-tags))