+2013-09-05 Stefan Monnier <monnier@iro.umontreal.ca>
+
+ * subr.el (pop): Use `car-safe'.
+ * emacs-lisp/byte-opt.el (byte-optimize-form-code-walker): Remove hack
+ to detect unused `pop' return value.
+
+ * progmodes/python.el (python-nav-beginning-of-block): Remove unused
+ var `block-regexp'.
+ (python-nav--forward-sexp): Remove unused var `re-search-fn'.
+ (python-fill-string): Remove unused var `marker'.
+ (python-skeleton-add-menu-items): Remove unused var `items'.
+
+ * international/mule-cmds.el: Require CL.
+ (find-coding-systems-for-charsets): Avoid add-to-list.
+ (sanitize-coding-system-list): New function, extracted from
+ select-safe-coding-system-interactively.
+ (select-safe-coding-system-interactively): Use it.
+ (read-input-method-name): Accept symbols for `default'.
+
+ * emacs-lisp/advice.el (defadvice): Add indent rule.
+
2013-09-05 Daniel Hackney <dan@haxney.org>
* dired-x.el:
usage: (defadvice FUNCTION (CLASS NAME [POSITION] [ARGLIST] FLAG...)
[DOCSTRING] [INTERACTIVE-FORM]
BODY...)"
- (declare (doc-string 3)
+ (declare (doc-string 3) (indent 2)
(debug (&define name ;; thing being advised.
(name ;; class is [&or "before" "around" "after"
;; "activation" "deactivation"]
((and for-effect (setq tmp (get fn 'side-effect-free))
(or byte-compile-delete-errors
(eq tmp 'error-free)
- ;; Detect the expansion of (pop foo).
- ;; There is no need to compile the call to `car' there.
- (and (eq fn 'car)
- (eq (car-safe (cadr form)) 'prog1)
- (let ((var (cadr (cadr form)))
- (last (nth 2 (cadr form))))
- (and (symbolp var)
- (null (nthcdr 3 (cadr form)))
- (eq (car-safe last) 'setq)
- (eq (cadr last) var)
- (eq (car-safe (nth 2 last)) 'cdr)
- (eq (cadr (nth 2 last)) var))))
(progn
(byte-compile-warn "value returned from %s is unused"
(prin1-to-string form))
;;; Code:
+(eval-when-compile (require 'cl-lib))
+
(defvar dos-codepage)
(autoload 'widget-value "wid-edit")
(coding-system-charset-list cs)))
(charsets charsets))
(if (coding-system-get cs :ascii-compatible-p)
- (add-to-list 'cs-charsets 'ascii))
+ (cl-pushnew 'ascii cs-charsets))
(if (catch 'ok
(when cs-charsets
(while charsets
function `select-safe-coding-system' (which see). This variable
overrides that argument.")
+(defun sanitize-coding-system-list (codings)
+ "Return a list of coding systems presumably more user-friendly than CODINGS."
+ ;; Change each safe coding system to the corresponding
+ ;; mime-charset name if it is also a coding system. Such a name
+ ;; is more friendly to users.
+ (setq codings
+ (mapcar (lambda (cs)
+ (let ((mime-charset (coding-system-get cs 'mime-charset)))
+ (if (and mime-charset (coding-system-p mime-charset)
+ (coding-system-equal cs mime-charset))
+ mime-charset cs)))
+ codings))
+
+ ;; Don't offer variations with locking shift, which you
+ ;; basically never want.
+ (let (l)
+ (dolist (elt codings (setq codings (nreverse l)))
+ (unless (or (eq 'coding-category-iso-7-else
+ (coding-system-category elt))
+ (eq 'coding-category-iso-8-else
+ (coding-system-category elt)))
+ (push elt l))))
+
+ ;; Remove raw-text, emacs-mule and no-conversion unless nothing
+ ;; else is available.
+ (or (delq 'raw-text
+ (delq 'emacs-mule
+ (delq 'no-conversion (copy-sequence codings))))
+ codings))
+
(defun select-safe-coding-system-interactively (from to codings unsafe
&optional rejected default)
"Select interactively a coding system for the region FROM ... TO.
from to coding 11)))))
unsafe)))
- ;; Change each safe coding system to the corresponding
- ;; mime-charset name if it is also a coding system. Such a name
- ;; is more friendly to users.
- (let ((l codings)
- mime-charset)
- (while l
- (setq mime-charset (coding-system-get (car l) :mime-charset))
- (if (and mime-charset (coding-system-p mime-charset)
- (coding-system-equal (car l) mime-charset))
- (setcar l mime-charset))
- (setq l (cdr l))))
-
- ;; Don't offer variations with locking shift, which you
- ;; basically never want.
- (let (l)
- (dolist (elt codings (setq codings (nreverse l)))
- (unless (or (eq 'coding-category-iso-7-else
- (coding-system-category elt))
- (eq 'coding-category-iso-8-else
- (coding-system-category elt)))
- (push elt l))))
-
- ;; Remove raw-text, emacs-mule and no-conversion unless nothing
- ;; else is available.
- (setq codings
- (or (delq 'raw-text
- (delq 'emacs-mule
- (delq 'no-conversion codings)))
- '(raw-text emacs-mule no-conversion)))
+ (setq codings (sanitize-coding-system-list codings))
(let ((window-configuration (current-window-configuration))
(bufname (buffer-name))
;; buffer local.
(input-method (completing-read prompt input-method-alist
nil t nil 'input-method-history
- default)))
+ (if (and default (symbolp default))
+ (symbol-name default)
+ default))))
(if (and input-method (symbolp input-method))
(setq input-method (symbol-name input-method)))
(if (> (length input-method) 0)
(defun python-nav-beginning-of-block ()
"Move to start of current block."
(interactive "^")
- (let ((starting-pos (point))
- (block-regexp (python-rx
- line-start (* whitespace) block-start)))
+ (let ((starting-pos (point)))
(if (progn
(python-nav-beginning-of-statement)
(looking-at (python-rx block-start)))
(let* ((forward-p (if (> dir 0)
(and (setq dir 1) t)
(and (setq dir -1) nil)))
- (re-search-fn (if forward-p
- 're-search-forward
- 're-search-backward))
(context-type (python-syntax-context-type)))
(cond
((memq context-type '(string comment))
(defun python-fill-string (&optional justify)
"String fill function for `python-fill-paragraph'.
JUSTIFY should be used (if applicable) as in `fill-paragraph'."
- (let* ((marker (point-marker))
- (str-start-pos
+ (let* ((str-start-pos
(set-marker
(make-marker)
(or (python-syntax-context 'string)
;; Again indent only if a newline is added.
(indent-according-to-mode))))) t)
-(defun python-fill-decorator (&optional justify)
+(defun python-fill-decorator (&optional _justify)
"Decorator fill function for `python-fill-paragraph'.
JUSTIFY should be used (if applicable) as in `fill-paragraph'."
t)
(defun python-skeleton-add-menu-items ()
"Add menu items to Python->Skeletons menu."
- (let ((skeletons (sort python-skeleton-available 'string<))
- (items))
+ (let ((skeletons (sort python-skeleton-available 'string<)))
(dolist (skeleton skeletons)
(easy-menu-add-item
nil '("Python" "Skeletons")
(let ((process-environment (python-shell-calculate-process-environment))
(exec-path (python-shell-calculate-exec-path)))
(compilation-start command nil
- (lambda (mode-name)
+ (lambda (_modename)
(format python-check-buffer-name command)))))
\f
"Return imenu label for parent node using TYPE and NAME."
(format "%s..." (python-imenu-format-item-label type name)))
-(defun python-imenu-format-parent-item-jump-label (type name)
+(defun python-imenu-format-parent-item-jump-label (type _name)
"Return imenu label for parent node jump using TYPE and NAME."
(if (string= type "class")
"*class definition*"
(cons name (cdar pos))
(python-imenu-create-flat-index (cddr item) name))))))
(or alist
- (let* ((fn (lambda (type name) name))
+ (let* ((fn (lambda (_type name) name))
(python-imenu-format-item-label-function fn)
(python-imenu-format-parent-item-label-function fn)
(python-imenu-format-parent-item-jump-label-function fn))
(add-to-list 'hs-special-modes-alist
`(python-mode "^\\s-*\\(?:def\\|class\\)\\>" nil "#"
- ,(lambda (arg)
+ ,(lambda (_arg)
(python-nav-end-of-defun)) nil))
(set (make-local-variable 'mode-require-final-newline) t)
If the value is nil, `pop' returns nil but does not actually
change the list."
(declare (debug (gv-place)))
- (list 'car
- (if (symbolp place)
- ;; So we can use `pop' in the bootstrap before `gv' can be used.
- (list 'prog1 place (list 'setq place (list 'cdr place)))
- (gv-letplace (getter setter) place
- `(prog1 ,getter ,(funcall setter `(cdr ,getter)))))))
+ ;; We use `car-safe' here instead of `car' because the behavior is the same
+ ;; (if it's not a cons cell, the `cdr' would have signaled an error already),
+ ;; but `car-safe' is total, so the byte-compiler can safely remove it if the
+ ;; result is not used.
+ `(car-safe
+ ,(if (symbolp place)
+ ;; So we can use `pop' in the bootstrap before `gv' can be used.
+ (list 'prog1 place (list 'setq place (list 'cdr place)))
+ (gv-letplace (getter setter) place
+ `(prog1 ,getter ,(funcall setter `(cdr ,getter)))))))
(defmacro when (cond &rest body)
"If COND yields non-nil, do BODY, else return nil.