]> code.delx.au - gnu-emacs/blobdiff - lisp/electric.el
Detect remote uid and gid in tramp-gvfs.el
[gnu-emacs] / lisp / electric.el
index 88b28352ac020061cd6b872628f6849c1496af55..e2896010405e1665d50084ab369ef7cd4068111b 100644 (file)
@@ -1,6 +1,6 @@
 ;;; electric.el --- window maker and Command loop for `electric' modes
 
-;; Copyright (C) 1985-1986, 1995, 2001-2015 Free Software Foundation,
+;; Copyright (C) 1985-1986, 1995, 2001-2016 Free Software Foundation,
 ;; Inc.
 
 ;; Author: K. Shane Hartman
@@ -417,32 +417,42 @@ The variable `electric-layout-rules' says when and how to insert newlines."
 
 (defcustom electric-quote-comment t
   "Non-nil means to use electric quoting in program comments."
+  :version "25.1"
   :type 'boolean :safe 'booleanp :group 'electricity)
 
 (defcustom electric-quote-string nil
   "Non-nil means to use electric quoting in program strings."
+  :version "25.1"
   :type 'boolean :safe 'booleanp :group 'electricity)
 
 (defcustom electric-quote-paragraph t
   "Non-nil means to use electric quoting in text paragraphs."
+  :version "25.1"
   :type 'boolean :safe 'booleanp :group 'electricity)
 
 (defun electric--insertable-p (string)
-  (not (unencodable-char-position nil nil buffer-file-coding-system
-                                  nil string)))
+  (or (not buffer-file-coding-system)
+      (eq (coding-system-base buffer-file-coding-system) 'undecided)
+      (not (unencodable-char-position nil nil buffer-file-coding-system
+                                      nil string))))
 
 (defun electric-quote-post-self-insert-function ()
-  "Function that ‘electric-quote-mode’ adds to ‘post-self-insert-hook’.
+  "Function that `electric-quote-mode' adds to `post-self-insert-hook'.
 This requotes when a quoting key is typed."
   (when (and electric-quote-mode
              (memq last-command-event '(?\' ?\`)))
     (let ((start
-           (if comment-start
+           (if (and comment-start comment-use-syntax)
                (when (or electric-quote-comment electric-quote-string)
-                 (let ((syntax (syntax-ppss)))
-                   (and (or (and electric-quote-comment (nth 4 syntax))
+                 (let* ((syntax (syntax-ppss))
+                        (beg (nth 8 syntax)))
+                   (and beg
+                        (or (and electric-quote-comment (nth 4 syntax))
                             (and electric-quote-string (nth 3 syntax)))
-                        (nth 8 syntax))))
+                        ;; Do not requote a quote that starts or ends
+                        ;; a comment or string.
+                        (eq beg (nth 8 (save-excursion
+                                         (syntax-ppss (1- (point)))))))))
              (and electric-quote-paragraph
                   (derived-mode-p 'text-mode)
                   (or (eq last-command-event ?\`)
@@ -451,7 +461,7 @@ This requotes when a quoting key is typed."
         (save-excursion
           (if (eq last-command-event ?\`)
               (cond ((and (electric--insertable-p "“")
-                          (re-search-backward "[`‘]`" (- (point) 2) t))
+                          (search-backward "‘`" (- (point) 2) t))
                      (replace-match "“")
                      (when (and electric-pair-mode
                                 (eq (cdr-safe
@@ -463,19 +473,14 @@ This requotes when a quoting key is typed."
                           (search-backward "`" (1- (point)) t))
                      (replace-match "‘")
                      (setq last-command-event ?‘)))
-            (let ((pos (point)))
-              (if (memq (char-before (1- (point))) '(?\' ?’))
-                  (when (and (search-backward "“" start t)
-                             (eq pos (re-search-forward
-                                      "“\\(\\([^‘”]\\|‘[^‘’”]*’\\)*\\)['’]'"
-                                      pos t)))
-                    (replace-match "“\\1”")
-                    (setq last-command-event ?”))
-                (when (and (search-backward "‘" start t)
-                           (eq pos (re-search-forward
-                                    "‘\\([^’]*\\)'" pos t)))
-                  (replace-match "‘\\1’")
-                  (setq last-command-event ?’))))))))))
+            (cond ((and (electric--insertable-p "”")
+                        (search-backward "’'" (- (point) 2) t))
+                   (replace-match "”")
+                   (setq last-command-event ?”))
+                  ((and (electric--insertable-p "’")
+                        (search-backward "'" (1- (point)) t))
+                   (replace-match "’")
+                   (setq last-command-event ?’)))))))))
 
 (put 'electric-quote-post-self-insert-function 'priority 10)
 
@@ -486,14 +491,14 @@ With a prefix argument ARG, enable Electric Quote mode if
 ARG is positive, and disable it otherwise.  If called from Lisp,
 enable the mode if ARG is omitted or nil.
 
-When enabled, this replaces \\=`foo bar' with ‘foo bar’ and replaces
-\\=`\\=`foo bar'' with “foo bar” as you type.  This occurs only in
-comments, strings, and text paragraphs, and these are selectively
-controlled with ‘electric-quote-comment’,
-‘electric-quote-string’, and ‘electric-quote-paragraph’.
+When enabled, as you type this replaces \\=` with \\=‘, \\=' with \\=’,
+\\=`\\=` with “, and \\='\\=' with ”.  This occurs only in comments, strings,
+and text paragraphs, and these are selectively controlled with
+`electric-quote-comment', `electric-quote-string', and
+`electric-quote-paragraph'.
 
 This is a global minor mode.  To toggle the mode in a single buffer,
-use ‘electric-quote-local-mode’."
+use `electric-quote-local-mode'."
   :global t :group 'electricity
   :initialize 'custom-initialize-delay
   :init-value nil
@@ -510,7 +515,7 @@ use ‘electric-quote-local-mode’."
 
 ;;;###autoload
 (define-minor-mode electric-quote-local-mode
-  "Toggle ‘electric-quote-mode’ only in this buffer."
+  "Toggle `electric-quote-mode' only in this buffer."
   :variable (buffer-local-value 'electric-quote-mode (current-buffer))
   (cond
    ((eq electric-quote-mode (default-value 'electric-quote-mode))