aboutsummaryrefslogtreecommitdiffstats
path: root/lisp/progmodes
diff options
context:
space:
mode:
authorKenichi Handa2012-11-13 23:24:26 +0900
committerKenichi Handa2012-11-13 23:24:26 +0900
commit0cdbf84521791935fdfeabf2e84f585cc64db325 (patch)
tree68a169af3af4a8859685682ab07c05e8f9ff93b3 /lisp/progmodes
parente1bf05c1fbf63087801c242208212df133921ed1 (diff)
parent5745cae6984ed60299a89485aaea8f2f3fb67382 (diff)
downloademacs-0cdbf84521791935fdfeabf2e84f585cc64db325.tar.gz
emacs-0cdbf84521791935fdfeabf2e84f585cc64db325.zip
merge trunk
Diffstat (limited to 'lisp/progmodes')
-rw-r--r--lisp/progmodes/flymake.el30
-rw-r--r--lisp/progmodes/js.el35
-rw-r--r--lisp/progmodes/perl-mode.el121
-rw-r--r--lisp/progmodes/python.el137
-rw-r--r--lisp/progmodes/ruby-mode.el57
-rw-r--r--lisp/progmodes/sql.el47
6 files changed, 238 insertions, 189 deletions
diff --git a/lisp/progmodes/flymake.el b/lisp/progmodes/flymake.el
index 2614af9ffa4..5ba84f8991e 100644
--- a/lisp/progmodes/flymake.el
+++ b/lisp/progmodes/flymake.el
@@ -764,25 +764,39 @@ line number outside the file being compiled."
764 (and (overlayp ov) (overlay-get ov 'flymake-overlay))) 764 (and (overlayp ov) (overlay-get ov 'flymake-overlay)))
765 765
766(defcustom flymake-error-bitmap '(exclamation-mark error) 766(defcustom flymake-error-bitmap '(exclamation-mark error)
767 "Bitmap used in the fringe for indicating errors. 767 "Bitmap (a symbol) used in the fringe for indicating errors.
768The value may also be a list of two elements where the second 768The value may also be a list of two elements where the second
769element specifies the face for the bitmap." 769element specifies the face for the bitmap. For possible bitmap
770symbols, see `fringe-bitmaps'. See also `flymake-warning-bitmap'.
771
772The option `flymake-fringe-indicator-position' controls how and where
773this is used."
770 :group 'flymake 774 :group 'flymake
771 :version "24.3" 775 :version "24.3"
772 :type 'symbol) 776 :type '(choice (symbol :tag "Bitmap")
777 (list :tag "Bitmap and face"
778 (symbol :tag "Bitmap")
779 (face :tag "Face"))))
773 780
774(defcustom flymake-warning-bitmap 'question-mark 781(defcustom flymake-warning-bitmap 'question-mark
775 "Bitmap used in the fringe for indicating warnings. 782 "Bitmap (a symbol) used in the fringe for indicating warnings.
776The value may also be a list of two elements where the second 783The value may also be a list of two elements where the second
777element specifies the face for the bitmap." 784element specifies the face for the bitmap. For possible bitmap
785symbols, see `fringe-bitmaps'. See also `flymake-error-bitmap'.
786
787The option `flymake-fringe-indicator-position' controls how and where
788this is used."
778 :group 'flymake 789 :group 'flymake
779 :version "24.3" 790 :version "24.3"
780 :type 'symbol) 791 :type '(choice (symbol :tag "Bitmap")
792 (list :tag "Bitmap and face"
793 (symbol :tag "Bitmap")
794 (face :tag "Face"))))
781 795
782(defcustom flymake-fringe-indicator-position 'left-fringe 796(defcustom flymake-fringe-indicator-position 'left-fringe
783 "The position to put flymake fringe indicator. 797 "The position to put flymake fringe indicator.
784The value can be nil, left-fringe or right-fringe. 798The value can be nil (do not use indicators), `left-fringe' or `right-fringe'.
785Fringe indicators are disabled if nil." 799See `flymake-error-bitmap' and `flymake-warning-bitmap'."
786 :group 'flymake 800 :group 'flymake
787 :version "24.3" 801 :version "24.3"
788 :type '(choice (const left-fringe) 802 :type '(choice (const left-fringe)
diff --git a/lisp/progmodes/js.el b/lisp/progmodes/js.el
index d954cd53e0a..33ef7607671 100644
--- a/lisp/progmodes/js.el
+++ b/lisp/progmodes/js.el
@@ -1823,22 +1823,31 @@ nil."
1823 1823
1824;;; Filling 1824;;; Filling
1825 1825
1826(defvar js--filling-paragraph nil)
1827
1828;; FIXME: Such redefinitions are bad style. We should try and use some other
1829;; way to get the same result.
1830(defadvice c-forward-sws (around js-fill-paragraph activate)
1831 (if js--filling-paragraph
1832 (setq ad-return-value (js--forward-syntactic-ws (ad-get-arg 0)))
1833 ad-do-it))
1834
1835(defadvice c-backward-sws (around js-fill-paragraph activate)
1836 (if js--filling-paragraph
1837 (setq ad-return-value (js--backward-syntactic-ws (ad-get-arg 0)))
1838 ad-do-it))
1839
1840(defadvice c-beginning-of-macro (around js-fill-paragraph activate)
1841 (if js--filling-paragraph
1842 (setq ad-return-value (js--beginning-of-macro (ad-get-arg 0)))
1843 ad-do-it))
1844
1826(defun js-c-fill-paragraph (&optional justify) 1845(defun js-c-fill-paragraph (&optional justify)
1827 "Fill the paragraph with `c-fill-paragraph'." 1846 "Fill the paragraph with `c-fill-paragraph'."
1828 (interactive "*P") 1847 (interactive "*P")
1829 ;; FIXME: Such redefinitions are bad style. We should try and use some other 1848 (let ((js--filling-paragraph t)
1830 ;; way to get the same result. 1849 (fill-paragraph-function 'c-fill-paragraph))
1831 (cl-letf (((symbol-function 'c-forward-sws) 1850 (c-fill-paragraph justify)))
1832 (lambda (&optional limit)
1833 (js--forward-syntactic-ws limit)))
1834 ((symbol-function 'c-backward-sws)
1835 (lambda (&optional limit)
1836 (js--backward-syntactic-ws limit)))
1837 ((symbol-function 'c-beginning-of-macro)
1838 (lambda (&optional limit)
1839 (js--beginning-of-macro limit))))
1840 (let ((fill-paragraph-function 'c-fill-paragraph))
1841 (c-fill-paragraph justify))))
1842 1851
1843;;; Type database and Imenu 1852;;; Type database and Imenu
1844 1853
diff --git a/lisp/progmodes/perl-mode.el b/lisp/progmodes/perl-mode.el
index 3dd9a48bb33..d2f7fc7a059 100644
--- a/lisp/progmodes/perl-mode.el
+++ b/lisp/progmodes/perl-mode.el
@@ -1,4 +1,4 @@
1;;; perl-mode.el --- Perl code editing commands for GNU Emacs 1;;; perl-mode.el --- Perl code editing commands for GNU Emacs -*- coding: utf-8 -*-
2 2
3;; Copyright (C) 1990, 1994, 2001-2012 Free Software Foundation, Inc. 3;; Copyright (C) 1990, 1994, 2001-2012 Free Software Foundation, Inc.
4 4
@@ -102,11 +102,6 @@
102 102
103;;; Code: 103;;; Code:
104 104
105
106(defvar font-lock-comment-face)
107(defvar font-lock-doc-face)
108(defvar font-lock-string-face)
109
110(defgroup perl nil 105(defgroup perl nil
111 "Major mode for editing Perl code." 106 "Major mode for editing Perl code."
112 :link '(custom-group-link :tag "Font Lock Faces group" font-lock-faces) 107 :link '(custom-group-link :tag "Font Lock Faces group" font-lock-faces)
@@ -119,16 +114,11 @@
119 114
120(defvar perl-mode-map 115(defvar perl-mode-map
121 (let ((map (make-sparse-keymap))) 116 (let ((map (make-sparse-keymap)))
122 (define-key map "{" 'perl-electric-terminator)
123 (define-key map "}" 'perl-electric-terminator)
124 (define-key map ";" 'perl-electric-terminator)
125 (define-key map ":" 'perl-electric-terminator)
126 (define-key map "\e\C-a" 'perl-beginning-of-function) 117 (define-key map "\e\C-a" 'perl-beginning-of-function)
127 (define-key map "\e\C-e" 'perl-end-of-function) 118 (define-key map "\e\C-e" 'perl-end-of-function)
128 (define-key map "\e\C-h" 'perl-mark-function) 119 (define-key map "\e\C-h" 'perl-mark-function)
129 (define-key map "\e\C-q" 'perl-indent-exp) 120 (define-key map "\e\C-q" 'perl-indent-exp)
130 (define-key map "\177" 'backward-delete-char-untabify) 121 (define-key map "\177" 'backward-delete-char-untabify)
131 (define-key map "\t" 'perl-indent-command)
132 map) 122 map)
133 "Keymap used in Perl mode.") 123 "Keymap used in Perl mode.")
134 124
@@ -158,16 +148,54 @@
158 148
159(defvar perl-imenu-generic-expression 149(defvar perl-imenu-generic-expression
160 '(;; Functions 150 '(;; Functions
161 (nil "^sub\\s-+\\([-A-Za-z0-9+_:]+\\)" 1) 151 (nil "^[ \t]*sub\\s-+\\([-A-Za-z0-9+_:]+\\)" 1)
162 ;;Variables 152 ;;Variables
163 ("Variables" "^\\(?:my\\|our\\)\\s-+\\([$@%][-A-Za-z0-9+_:]+\\)\\s-*=" 1) 153 ("Variables" "^\\(?:my\\|our\\)\\s-+\\([$@%][-A-Za-z0-9+_:]+\\)\\s-*=" 1)
164 ("Packages" "^package\\s-+\\([-A-Za-z0-9+_:]+\\);" 1) 154 ("Packages" "^[ \t]*package\\s-+\\([-A-Za-z0-9+_:]+\\);" 1)
165 ("Doc sections" "^=head[0-9][ \t]+\\(.*\\)" 1)) 155 ("Doc sections" "^=head[0-9][ \t]+\\(.*\\)" 1))
166 "Imenu generic expression for Perl mode. See `imenu-generic-expression'.") 156 "Imenu generic expression for Perl mode. See `imenu-generic-expression'.")
167 157
168;; Regexps updated with help from Tom Tromey <tromey@cambric.colorado.edu> and 158;; Regexps updated with help from Tom Tromey <tromey@cambric.colorado.edu> and
169;; Jim Campbell <jec@murzim.ca.boeing.com>. 159;; Jim Campbell <jec@murzim.ca.boeing.com>.
170 160
161(defcustom perl-prettify-symbols t
162 "If non-nil, some symbols will be displayed using Unicode chars."
163 :type 'boolean)
164
165(defconst perl--prettify-symbols-alist
166 '(;;("andalso" . ?∧) ("orelse" . ?∨) ("as" . ?≡)("not" . ?¬)
167 ;;("div" . ?÷) ("*" . ?×) ("o" . ?○)
168 ("->" . ?→)
169 ("=>" . ?⇒)
170 ;;("<-" . ?←) ("<>" . ?≠) (">=" . ?≥) ("<=" . ?≤) ("..." . ?⋯)
171 ("::" . ?∷)
172 ))
173
174(defun perl--font-lock-compose-symbol ()
175 "Compose a sequence of ascii chars into a symbol.
176Regexp match data 0 points to the chars."
177 ;; Check that the chars should really be composed into a symbol.
178 (let* ((start (match-beginning 0))
179 (end (match-end 0))
180 (syntaxes (if (eq (char-syntax (char-after start)) ?w)
181 '(?w) '(?. ?\\))))
182 (if (or (memq (char-syntax (or (char-before start) ?\ )) syntaxes)
183 (memq (char-syntax (or (char-after end) ?\ )) syntaxes)
184 (nth 8 (syntax-ppss)))
185 ;; No composition for you. Let's actually remove any composition
186 ;; we may have added earlier and which is now incorrect.
187 (remove-text-properties start end '(composition))
188 ;; That's a symbol alright, so add the composition.
189 (compose-region start end (cdr (assoc (match-string 0)
190 perl--prettify-symbols-alist)))))
191 ;; Return nil because we're not adding any face property.
192 nil)
193
194(defun perl--font-lock-symbols-keywords ()
195 (when perl-prettify-symbols
196 `((,(regexp-opt (mapcar 'car perl--prettify-symbols-alist) t)
197 (0 (perl--font-lock-compose-symbol))))))
198
171(defconst perl-font-lock-keywords-1 199(defconst perl-font-lock-keywords-1
172 '(;; What is this for? 200 '(;; What is this for?
173 ;;("\\(--- .* ---\\|=== .* ===\\)" . font-lock-string-face) 201 ;;("\\(--- .* ---\\|=== .* ===\\)" . font-lock-string-face)
@@ -190,32 +218,32 @@
190 "Subdued level highlighting for Perl mode.") 218 "Subdued level highlighting for Perl mode.")
191 219
192(defconst perl-font-lock-keywords-2 220(defconst perl-font-lock-keywords-2
193 (append perl-font-lock-keywords-1 221 (append
194 (list 222 perl-font-lock-keywords-1
195 ;; 223 `( ;; Fontify keywords, except those fontified otherwise.
196 ;; Fontify keywords, except those fontified otherwise. 224 ,(concat "\\<"
197 (concat "\\<" 225 (regexp-opt '("if" "until" "while" "elsif" "else" "unless"
198 (regexp-opt '("if" "until" "while" "elsif" "else" "unless" 226 "do" "dump" "for" "foreach" "exit" "die"
199 "do" "dump" "for" "foreach" "exit" "die" 227 "BEGIN" "END" "return" "exec" "eval") t)
200 "BEGIN" "END" "return" "exec" "eval") t) 228 "\\>")
201 "\\>") 229 ;;
202 ;; 230 ;; Fontify local and my keywords as types.
203 ;; Fontify local and my keywords as types. 231 ("\\<\\(local\\|my\\)\\>" . font-lock-type-face)
204 '("\\<\\(local\\|my\\)\\>" . font-lock-type-face) 232 ;;
205 ;; 233 ;; Fontify function, variable and file name references.
206 ;; Fontify function, variable and file name references. 234 ("&\\(\\sw+\\(::\\sw+\\)*\\)" 1 font-lock-function-name-face)
207 '("&\\(\\sw+\\(::\\sw+\\)*\\)" 1 font-lock-function-name-face) 235 ;; Additionally underline non-scalar variables. Maybe this is a bad idea.
208 ;; Additionally underline non-scalar variables. Maybe this is a bad idea. 236 ;;'("[$@%*][#{]?\\(\\sw+\\)" 1 font-lock-variable-name-face)
209 ;;'("[$@%*][#{]?\\(\\sw+\\)" 1 font-lock-variable-name-face) 237 ("[$*]{?\\(\\sw+\\(::\\sw+\\)*\\)" 1 font-lock-variable-name-face)
210 '("[$*]{?\\(\\sw+\\(::\\sw+\\)*\\)" 1 font-lock-variable-name-face) 238 ("\\([@%]\\|\\$#\\)\\(\\sw+\\(::\\sw+\\)*\\)"
211 '("\\([@%]\\|\\$#\\)\\(\\sw+\\(::\\sw+\\)*\\)"
212 (2 (cons font-lock-variable-name-face '(underline)))) 239 (2 (cons font-lock-variable-name-face '(underline))))
213 '("<\\(\\sw+\\)>" 1 font-lock-constant-face) 240 ("<\\(\\sw+\\)>" 1 font-lock-constant-face)
214 ;; 241 ;;
215 ;; Fontify keywords with/and labels as we do in `c++-font-lock-keywords'. 242 ;; Fontify keywords with/and labels as we do in `c++-font-lock-keywords'.
216 '("\\<\\(continue\\|goto\\|last\\|next\\|redo\\)\\>[ \t]*\\(\\sw+\\)?" 243 ("\\<\\(continue\\|goto\\|last\\|next\\|redo\\)\\>[ \t]*\\(\\sw+\\)?"
217 (1 font-lock-keyword-face) (2 font-lock-constant-face nil t)) 244 (1 font-lock-keyword-face) (2 font-lock-constant-face nil t))
218 '("^[ \t]*\\(\\sw+\\)[ \t]*:[^:]" 1 font-lock-constant-face))) 245 ("^[ \t]*\\(\\sw+\\)[ \t]*:[^:]" 1 font-lock-constant-face)
246 ,@(perl--font-lock-symbols-keywords)))
219 "Gaudy level highlighting for Perl mode.") 247 "Gaudy level highlighting for Perl mode.")
220 248
221(defvar perl-font-lock-keywords perl-font-lock-keywords-1 249(defvar perl-font-lock-keywords perl-font-lock-keywords-1
@@ -543,8 +571,10 @@ create a new comment."
543 571
544(defun perl-outline-level () 572(defun perl-outline-level ()
545 (cond 573 (cond
546 ((looking-at "package\\s-") 0) 574 ((looking-at "[ \t]*\\(package\\)\\s-")
547 ((looking-at "sub\\s-") 1) 575 (- (match-beginning 1) (match-beginning 0)))
576 ((looking-at "[ \t]*s\\(ub\\)\\s-")
577 (- (match-beginning 1) (match-beginning 0)))
548 ((looking-at "=head[0-9]") (- (char-before (match-end 0)) ?0)) 578 ((looking-at "=head[0-9]") (- (char-before (match-end 0)) ?0))
549 ((looking-at "=cut") 1) 579 ((looking-at "=cut") 1)
550 (t 3))) 580 (t 3)))
@@ -621,6 +651,11 @@ Turning on Perl mode runs the normal hook `perl-mode-hook'."
621 #'perl-syntax-propertize-function) 651 #'perl-syntax-propertize-function)
622 (add-hook 'syntax-propertize-extend-region-functions 652 (add-hook 'syntax-propertize-extend-region-functions
623 #'syntax-propertize-multiline 'append 'local) 653 #'syntax-propertize-multiline 'append 'local)
654 ;; Electricity.
655 ;; FIXME: setup electric-layout-rules.
656 (set (make-local-variable 'electric-indent-chars)
657 (append '(?\{ ?\} ?\; ?\:) electric-indent-chars))
658 (add-hook 'electric-indent-functions #'perl-electric-noindent-p nil t)
624 ;; Tell imenu how to handle Perl. 659 ;; Tell imenu how to handle Perl.
625 (set (make-local-variable 'imenu-generic-expression) 660 (set (make-local-variable 'imenu-generic-expression)
626 perl-imenu-generic-expression) 661 perl-imenu-generic-expression)
@@ -637,7 +672,11 @@ Turning on Perl mode runs the normal hook `perl-mode-hook'."
637 0 ;Existing comment at bol stays there. 672 0 ;Existing comment at bol stays there.
638 comment-column)) 673 comment-column))
639 674
640(defalias 'electric-perl-terminator 'perl-electric-terminator) 675(define-obsolete-function-alias 'electric-perl-terminator
676 'perl-electric-terminator "22.1")
677(defun perl-electric-noindent-p (char)
678 (unless (eolp) 'no-indent))
679
641(defun perl-electric-terminator (arg) 680(defun perl-electric-terminator (arg)
642 "Insert character and maybe adjust indentation. 681 "Insert character and maybe adjust indentation.
643If at end-of-line, and not in a comment or a quote, correct the indentation." 682If at end-of-line, and not in a comment or a quote, correct the indentation."
@@ -661,6 +700,7 @@ If at end-of-line, and not in a comment or a quote, correct the indentation."
661 (perl-indent-line) 700 (perl-indent-line)
662 (delete-char -1)))) 701 (delete-char -1))))
663 (self-insert-command (prefix-numeric-value arg))) 702 (self-insert-command (prefix-numeric-value arg)))
703(make-obsolete 'perl-electric-terminator 'electric-indent-mode "24.4")
664 704
665;; not used anymore, but may be useful someday: 705;; not used anymore, but may be useful someday:
666;;(defun perl-inside-parens-p () 706;;(defun perl-inside-parens-p ()
@@ -744,6 +784,7 @@ following list:
744 (t 784 (t
745 (message "Use backslash to quote # characters.") 785 (message "Use backslash to quote # characters.")
746 (ding t))))))))) 786 (ding t)))))))))
787(make-obsolete 'perl-indent-command 'indent-according-to-mode "24.4")
747 788
748(defun perl-indent-line (&optional nochange parse-start) 789(defun perl-indent-line (&optional nochange parse-start)
749 "Indent current line as Perl code. 790 "Indent current line as Perl code.
diff --git a/lisp/progmodes/python.el b/lisp/progmodes/python.el
index ee98feaef5e..949b0252bf1 100644
--- a/lisp/progmodes/python.el
+++ b/lisp/progmodes/python.el
@@ -1074,12 +1074,9 @@ automatically if needed."
1074The name of the defun should be grouped so it can be retrieved 1074The name of the defun should be grouped so it can be retrieved
1075via `match-string'.") 1075via `match-string'.")
1076 1076
1077(defun python-nav-beginning-of-defun (&optional arg) 1077(defun python-nav--beginning-of-defun (&optional arg)
1078 "Move point to `beginning-of-defun'. 1078 "Internal implementation of `python-nav-beginning-of-defun'.
1079With positive ARG move search backwards. With negative do the 1079With positive ARG search backwards, else search forwards."
1080same but forward. When ARG is nil or 0 defaults to 1. This is
1081the main part of `python-beginning-of-defun-function'. Return
1082non-nil if point is moved to `beginning-of-defun'."
1083 (when (or (null arg) (= arg 0)) (setq arg 1)) 1080 (when (or (null arg) (= arg 0)) (setq arg 1))
1084 (let* ((re-search-fn (if (> arg 0) 1081 (let* ((re-search-fn (if (> arg 0)
1085 #'re-search-backward 1082 #'re-search-backward
@@ -1087,6 +1084,15 @@ non-nil if point is moved to `beginning-of-defun'."
1087 (line-beg-pos (line-beginning-position)) 1084 (line-beg-pos (line-beginning-position))
1088 (line-content-start (+ line-beg-pos (current-indentation))) 1085 (line-content-start (+ line-beg-pos (current-indentation)))
1089 (pos (point-marker)) 1086 (pos (point-marker))
1087 (beg-indentation
1088 (and (> arg 0)
1089 (save-excursion
1090 (and (python-info-current-line-empty-p)
1091 (python-util-forward-comment -1))
1092 (python-nav-beginning-of-statement)
1093 (if (python-info-looking-at-beginning-of-defun)
1094 (+ (current-indentation) python-indent-offset)
1095 (current-indentation)))))
1090 (found 1096 (found
1091 (progn 1097 (progn
1092 (when (and (< arg 0) 1098 (when (and (< arg 0)
@@ -1094,7 +1100,12 @@ non-nil if point is moved to `beginning-of-defun'."
1094 (end-of-line 1)) 1100 (end-of-line 1))
1095 (while (and (funcall re-search-fn 1101 (while (and (funcall re-search-fn
1096 python-nav-beginning-of-defun-regexp nil t) 1102 python-nav-beginning-of-defun-regexp nil t)
1097 (python-syntax-context-type))) 1103 (or (python-syntax-context-type)
1104 ;; Handle nested defuns when moving
1105 ;; backwards by checking indentation.
1106 (and (> arg 0)
1107 (not (= (current-indentation) 0))
1108 (>= (current-indentation) beg-indentation)))))
1098 (and (python-info-looking-at-beginning-of-defun) 1109 (and (python-info-looking-at-beginning-of-defun)
1099 (or (not (= (line-number-at-pos pos) 1110 (or (not (= (line-number-at-pos pos)
1100 (line-number-at-pos))) 1111 (line-number-at-pos)))
@@ -1105,55 +1116,43 @@ non-nil if point is moved to `beginning-of-defun'."
1105 (or (beginning-of-line 1) t) 1116 (or (beginning-of-line 1) t)
1106 (and (goto-char pos) nil)))) 1117 (and (goto-char pos) nil))))
1107 1118
1108(defun python-beginning-of-defun-function (&optional arg) 1119(defun python-nav-beginning-of-defun (&optional arg)
1109 "Move point to the beginning of def or class. 1120 "Move point to `beginning-of-defun'.
1110With positive ARG move that number of functions backwards. With 1121With positive ARG search backwards else search forward. When ARG
1111negative do the same but forward. When ARG is nil or 0 defaults 1122is nil or 0 defaults to 1. When searching backwards nested
1112to 1. Return non-nil if point is moved to `beginning-of-defun'." 1123defuns are handled with care depending on current point
1124position. Return non-nil if point is moved to
1125`beginning-of-defun'."
1113 (when (or (null arg) (= arg 0)) (setq arg 1)) 1126 (when (or (null arg) (= arg 0)) (setq arg 1))
1114 (let ((found)) 1127 (let ((found))
1115 (cond ((and (eq this-command 'mark-defun) 1128 (cond ((and (eq this-command 'mark-defun)
1116 (python-info-looking-at-beginning-of-defun))) 1129 (python-info-looking-at-beginning-of-defun)))
1117 (t 1130 (t
1118 (dotimes (i (if (> arg 0) arg (- arg))) 1131 (dotimes (i (if (> arg 0) arg (- arg)))
1119 (when (and (python-nav-beginning-of-defun arg) 1132 (when (and (python-nav--beginning-of-defun arg)
1120 (not found)) 1133 (not found))
1121 (setq found t))))) 1134 (setq found t)))))
1122 found)) 1135 found))
1123 1136
1124(defun python-end-of-defun-function () 1137(defun python-nav-end-of-defun ()
1125 "Move point to the end of def or class. 1138 "Move point to the end of def or class.
1126Returns nil if point is not in a def or class." 1139Returns nil if point is not in a def or class."
1127 (interactive) 1140 (interactive)
1128 (let ((beg-defun-indent)) 1141 (let ((beg-defun-indent)
1142 (beg-pos (point)))
1129 (when (or (python-info-looking-at-beginning-of-defun) 1143 (when (or (python-info-looking-at-beginning-of-defun)
1130 (python-beginning-of-defun-function 1) 1144 (python-nav-beginning-of-defun 1)
1131 (python-beginning-of-defun-function -1)) 1145 (python-nav-beginning-of-defun -1))
1132 (setq beg-defun-indent (current-indentation)) 1146 (setq beg-defun-indent (current-indentation))
1147 (while (progn
1148 (python-nav-end-of-statement)
1149 (python-util-forward-comment 1)
1150 (and (> (current-indentation) beg-defun-indent)
1151 (not (eobp)))))
1152 (python-util-forward-comment -1)
1133 (forward-line 1) 1153 (forward-line 1)
1134 ;; Go as forward as possible 1154 ;; Ensure point moves forward.
1135 (while (and (or 1155 (and (> beg-pos (point)) (goto-char beg-pos)))))
1136 (python-nav-beginning-of-defun -1)
1137 (and (goto-char (point-max)) nil))
1138 (> (current-indentation) beg-defun-indent)))
1139 (beginning-of-line 1)
1140 ;; Go as backwards as possible
1141 (while (and (forward-line -1)
1142 (not (bobp))
1143 (or (not (current-word))
1144 (equal (char-after (+ (point) (current-indentation))) ?#)
1145 (<= (current-indentation) beg-defun-indent)
1146 (looking-at (python-rx decorator))
1147 (python-syntax-context-type))))
1148 (forward-line 1)
1149 ;; If point falls inside a paren or string context the point is
1150 ;; forwarded at the end of it (or end of buffer if its not closed)
1151 (let ((context-type (python-syntax-context-type)))
1152 (when (memq context-type '(paren string))
1153 ;; Slow but safe.
1154 (while (and (not (eobp))
1155 (python-syntax-context-type))
1156 (forward-line 1)))))))
1157 1156
1158(defun python-nav-beginning-of-statement () 1157(defun python-nav-beginning-of-statement ()
1159 "Move to start of current statement." 1158 "Move to start of current statement."
@@ -2022,7 +2021,7 @@ When argument ARG is non-nil do not include decorators."
2022 (python-shell-send-region 2021 (python-shell-send-region
2023 (progn 2022 (progn
2024 (end-of-line 1) 2023 (end-of-line 1)
2025 (while (and (or (python-beginning-of-defun-function) 2024 (while (and (or (python-nav-beginning-of-defun)
2026 (beginning-of-line 1)) 2025 (beginning-of-line 1))
2027 (> (current-indentation) 0))) 2026 (> (current-indentation) 0)))
2028 (when (not arg) 2027 (when (not arg)
@@ -2031,7 +2030,7 @@ When argument ARG is non-nil do not include decorators."
2031 (forward-line 1)) 2030 (forward-line 1))
2032 (point-marker)) 2031 (point-marker))
2033 (progn 2032 (progn
2034 (or (python-end-of-defun-function) 2033 (or (python-nav-end-of-defun)
2035 (end-of-line 1)) 2034 (end-of-line 1))
2036 (point-marker))))) 2035 (point-marker)))))
2037 2036
@@ -2879,38 +2878,40 @@ Optional argument INCLUDE-TYPE indicates to include the type of the defun.
2879This function is compatible to be used as 2878This function is compatible to be used as
2880`add-log-current-defun-function' since it returns nil if point is 2879`add-log-current-defun-function' since it returns nil if point is
2881not inside a defun." 2880not inside a defun."
2882 (let ((names '())
2883 (starting-indentation)
2884 (starting-point)
2885 (first-run t))
2886 (save-restriction 2881 (save-restriction
2887 (widen) 2882 (widen)
2888 (save-excursion 2883 (save-excursion
2889 (setq starting-point (point-marker))
2890 (setq starting-indentation (save-excursion
2891 (python-nav-beginning-of-statement)
2892 (current-indentation)))
2893 (end-of-line 1) 2884 (end-of-line 1)
2894 (while (python-beginning-of-defun-function 1) 2885 (let ((names)
2895 (when (or (< (current-indentation) starting-indentation) 2886 (starting-indentation
2896 (and first-run 2887 (save-excursion
2897 (< 2888 (and
2898 starting-point 2889 (python-nav-beginning-of-defun 1)
2899 (save-excursion 2890 ;; This extra number is just for checking code
2900 (python-end-of-defun-function) 2891 ;; against indentation to work well on first run.
2901 (point-marker))))) 2892 (+ (current-indentation) 4))))
2902 (setq first-run nil) 2893 (starting-point (point)))
2903 (setq starting-indentation (current-indentation)) 2894 ;; Check point is inside a defun.
2904 (looking-at python-nav-beginning-of-defun-regexp) 2895 (when (and starting-indentation
2905 (setq names (cons 2896 (< starting-point
2897 (save-excursion
2898 (python-nav-end-of-defun)
2899 (point))))
2900 (catch 'exit
2901 (while (python-nav-beginning-of-defun 1)
2902 (when (< (current-indentation) starting-indentation)
2903 (setq starting-indentation (current-indentation))
2904 (setq names
2905 (cons
2906 (if (not include-type) 2906 (if (not include-type)
2907 (match-string-no-properties 1) 2907 (match-string-no-properties 1)
2908 (mapconcat 'identity 2908 (mapconcat 'identity
2909 (split-string 2909 (split-string
2910 (match-string-no-properties 0)) " ")) 2910 (match-string-no-properties 0)) " "))
2911 names)))))) 2911 names)))
2912 (when names 2912 (and (= (current-indentation) 0) (throw 'exit t)))))
2913 (mapconcat (lambda (string) string) names ".")))) 2913 (and names
2914 (mapconcat (lambda (string) string) names "."))))))
2914 2915
2915(defun python-info-current-symbol (&optional replace-self) 2916(defun python-info-current-symbol (&optional replace-self)
2916 "Return current symbol using dotty syntax. 2917 "Return current symbol using dotty syntax.
@@ -3200,9 +3201,9 @@ if that value is non-nil."
3200 'python-fill-paragraph) 3201 'python-fill-paragraph)
3201 3202
3202 (set (make-local-variable 'beginning-of-defun-function) 3203 (set (make-local-variable 'beginning-of-defun-function)
3203 #'python-beginning-of-defun-function) 3204 #'python-nav-beginning-of-defun)
3204 (set (make-local-variable 'end-of-defun-function) 3205 (set (make-local-variable 'end-of-defun-function)
3205 #'python-end-of-defun-function) 3206 #'python-nav-end-of-defun)
3206 3207
3207 (add-hook 'completion-at-point-functions 3208 (add-hook 'completion-at-point-functions
3208 'python-completion-complete-at-point nil 'local) 3209 'python-completion-complete-at-point nil 'local)
@@ -3230,7 +3231,7 @@ if that value is non-nil."
3230 (add-to-list 'hs-special-modes-alist 3231 (add-to-list 'hs-special-modes-alist
3231 `(python-mode "^\\s-*\\(?:def\\|class\\)\\>" nil "#" 3232 `(python-mode "^\\s-*\\(?:def\\|class\\)\\>" nil "#"
3232 ,(lambda (arg) 3233 ,(lambda (arg)
3233 (python-end-of-defun-function)) nil)) 3234 (python-nav-end-of-defun)) nil))
3234 3235
3235 (set (make-local-variable 'mode-require-final-newline) t) 3236 (set (make-local-variable 'mode-require-final-newline) t)
3236 3237
diff --git a/lisp/progmodes/ruby-mode.el b/lisp/progmodes/ruby-mode.el
index 84cf7308d75..7c72b73a879 100644
--- a/lisp/progmodes/ruby-mode.el
+++ b/lisp/progmodes/ruby-mode.el
@@ -898,17 +898,7 @@ or blocks containing the current block."
898 (back-to-indentation) 898 (back-to-indentation)
899 (if (looking-at (concat "\\<\\(" ruby-block-mid-re "\\)\\>")) 899 (if (looking-at (concat "\\<\\(" ruby-block-mid-re "\\)\\>"))
900 (setq done nil))))) 900 (setq done nil)))))
901 (back-to-indentation) 901 (back-to-indentation)))
902 (when (< n 0)
903 (let ((eol (point-at-eol)) state next)
904 (if (< orig eol) (setq eol orig))
905 (setq orig (point))
906 (while (and (setq next (apply 'ruby-parse-partial eol state))
907 (< (point) eol))
908 (setq state next))
909 (when (cdaadr state)
910 (goto-char (cdaadr state)))
911 (backward-word)))))
912 902
913(defun ruby-beginning-of-block (&optional arg) 903(defun ruby-beginning-of-block (&optional arg)
914 "Move backward to the beginning of the current block. 904 "Move backward to the beginning of the current block.
@@ -1043,21 +1033,19 @@ For example:
1043 #exit 1033 #exit
1044 String#gsub 1034 String#gsub
1045 Net::HTTP#active? 1035 Net::HTTP#active?
1046 File::open. 1036 File.open
1047 1037
1048See `add-log-current-defun-function'." 1038See `add-log-current-defun-function'."
1049 ;; TODO: Document body
1050 ;; Why does this append a period to class methods?
1051 (condition-case nil 1039 (condition-case nil
1052 (save-excursion 1040 (save-excursion
1053 (let (mname mlist (indent 0)) 1041 (let (mname mlist (indent 0))
1054 ;; get current method (or class/module) 1042 ;; Get the current method definition (or class/module).
1055 (if (re-search-backward 1043 (if (re-search-backward
1056 (concat "^[ \t]*" ruby-defun-beg-re "[ \t]+" 1044 (concat "^[ \t]*" ruby-defun-beg-re "[ \t]+"
1057 "\\(" 1045 "\\("
1058 ;; \\. and :: for class method 1046 ;; \\. and :: for class methods
1059 "\\([A-Za-z_]" ruby-symbol-re "*\\|\\.\\|::" "\\)" 1047 "\\([A-Za-z_]" ruby-symbol-re "*\\|\\.\\|::" "\\)"
1060 "+\\)") 1048 "+\\)")
1061 nil t) 1049 nil t)
1062 (progn 1050 (progn
1063 (setq mname (match-string 2)) 1051 (setq mname (match-string 2))
@@ -1066,7 +1054,7 @@ See `add-log-current-defun-function'."
1066 (goto-char (match-beginning 1)) 1054 (goto-char (match-beginning 1))
1067 (setq indent (current-column)) 1055 (setq indent (current-column))
1068 (beginning-of-line))) 1056 (beginning-of-line)))
1069 ;; nest class/module 1057 ;; Walk up the class/module nesting.
1070 (while (and (> indent 0) 1058 (while (and (> indent 0)
1071 (re-search-backward 1059 (re-search-backward
1072 (concat 1060 (concat
@@ -1079,28 +1067,26 @@ See `add-log-current-defun-function'."
1079 (setq mlist (cons (match-string 2) mlist)) 1067 (setq mlist (cons (match-string 2) mlist))
1080 (setq indent (current-column)) 1068 (setq indent (current-column))
1081 (beginning-of-line)))) 1069 (beginning-of-line))))
1070 ;; Process the method name.
1082 (when mname 1071 (when mname
1083 (let ((mn (split-string mname "\\.\\|::"))) 1072 (let ((mn (split-string mname "\\.\\|::")))
1084 (if (cdr mn) 1073 (if (cdr mn)
1085 (progn 1074 (progn
1086 (cond 1075 (unless (string-equal "self" (car mn)) ; def self.foo
1087 ((string-equal "" (car mn)) 1076 ;; def C.foo
1088 (setq mn (cdr mn) mlist nil)) 1077 (let ((ml (nreverse mlist)))
1089 ((string-equal "self" (car mn)) 1078 ;; If the method name references one of the
1090 (setq mn (cdr mn))) 1079 ;; containing modules, drop the more nested ones.
1091 ((let ((ml (nreverse mlist)))
1092 (while ml 1080 (while ml
1093 (if (string-equal (car ml) (car mn)) 1081 (if (string-equal (car ml) (car mn))
1094 (setq mlist (nreverse (cdr ml)) ml nil)) 1082 (setq mlist (nreverse (cdr ml)) ml nil))
1095 (or (setq ml (cdr ml)) (nreverse mlist)))))) 1083 (or (setq ml (cdr ml)) (nreverse mlist))))
1096 (if mlist 1084 (if mlist
1097 (setcdr (last mlist) mn) 1085 (setcdr (last mlist) (butlast mn))
1098 (setq mlist mn)) 1086 (setq mlist (butlast mn))))
1099 (setq mn (last mn 2)) 1087 (setq mname (concat "." (car (last mn)))))
1100 (setq mname (concat "." (cadr mn)))
1101 (setcdr mn nil))
1102 (setq mname (concat "#" mname))))) 1088 (setq mname (concat "#" mname)))))
1103 ;; generate string 1089 ;; Generate the string.
1104 (if (consp mlist) 1090 (if (consp mlist)
1105 (setq mlist (mapconcat (function identity) mlist "::"))) 1091 (setq mlist (mapconcat (function identity) mlist "::")))
1106 (if mname 1092 (if mname
@@ -1561,7 +1547,8 @@ See `font-lock-syntax-table'.")
1561 ruby-keyword-end-re) 1547 ruby-keyword-end-re)
1562 2) 1548 2)
1563 ;; here-doc beginnings 1549 ;; here-doc beginnings
1564 (list ruby-here-doc-beg-re 0 'font-lock-string-face) 1550 `(,ruby-here-doc-beg-re 0 (unless (ruby-singleton-class-p (match-beginning 0))
1551 'font-lock-string-face))
1565 ;; variables 1552 ;; variables
1566 '("\\(^\\|[^_:.@$]\\|\\.\\.\\)\\b\\(nil\\|self\\|true\\|false\\)\\>" 1553 '("\\(^\\|[^_:.@$]\\|\\.\\.\\)\\b\\(nil\\|self\\|true\\|false\\)\\>"
1567 2 font-lock-variable-name-face) 1554 2 font-lock-variable-name-face)
@@ -1638,6 +1625,8 @@ The variable `ruby-indent-level' controls the amount of indentation.
1638 1625
1639;;;###autoload 1626;;;###autoload
1640(add-to-list 'auto-mode-alist (cons (purecopy "\\.rb\\'") 'ruby-mode)) 1627(add-to-list 'auto-mode-alist (cons (purecopy "\\.rb\\'") 'ruby-mode))
1628;;;###autoload
1629(add-to-list 'auto-mode-alist '("Rakefile\\'" . ruby-mode))
1641 1630
1642;;;###autoload 1631;;;###autoload
1643(dolist (name (list "ruby" "rbx" "jruby" "ruby1.9" "ruby1.8")) 1632(dolist (name (list "ruby" "rbx" "jruby" "ruby1.9" "ruby1.8"))
diff --git a/lisp/progmodes/sql.el b/lisp/progmodes/sql.el
index 3d5abc4df62..64b87d9e436 100644
--- a/lisp/progmodes/sql.el
+++ b/lisp/progmodes/sql.el
@@ -2802,8 +2802,12 @@ each line with INDENT."
2802 doc)) 2802 doc))
2803 2803
2804;;;###autoload 2804;;;###autoload
2805(defun sql-help () 2805(eval
2806 "Show short help for the SQL modes. 2806 ;; FIXME: This dynamic-docstring-function trick doesn't work for byte-compiled
2807 ;; functions, because of the lazy-loading of docstrings, which strips away
2808 ;; text properties.
2809 '(defun sql-help ()
2810 #("Show short help for the SQL modes.
2807 2811
2808Use an entry function to open an interactive SQL buffer. This buffer is 2812Use an entry function to open an interactive SQL buffer. This buffer is
2809usually named `*SQL*'. The name of the major mode is SQLi. 2813usually named `*SQL*'. The name of the major mode is SQLi.
@@ -2834,32 +2838,23 @@ anything. The name of the major mode is SQL.
2834In this SQL buffer (SQL mode), you can send the region or the entire 2838In this SQL buffer (SQL mode), you can send the region or the entire
2835buffer to the interactive SQL buffer (SQLi mode). The results are 2839buffer to the interactive SQL buffer (SQLi mode). The results are
2836appended to the SQLi buffer without disturbing your SQL buffer." 2840appended to the SQLi buffer without disturbing your SQL buffer."
2841 0 1 (dynamic-docstring-function sql--make-help-docstring))
2837 (interactive) 2842 (interactive)
2843 (describe-function 'sql-help)))
2838 2844
2839 ;; Insert references to loaded products into the help buffer string 2845(defun sql--make-help-docstring (doc _fun)
2840 (let ((doc (documentation 'sql-help t)) 2846 "Insert references to loaded products into the help buffer string."
2841 changedp) 2847
2842 (setq changedp nil) 2848 ;; Insert FREE software list
2843 2849 (when (string-match "^\\(\\s-*\\)[\\\\][\\\\]FREE\\s-*\n" doc 0)
2844 ;; Insert FREE software list 2850 (setq doc (replace-match (sql-help-list-products (match-string 1 doc) t)
2845 (when (string-match "^\\(\\s-*\\)[\\\\][\\\\]FREE\\s-*\n" doc 0) 2851 t t doc 0)))
2846 (setq doc (replace-match (sql-help-list-products (match-string 1 doc) t) 2852
2847 t t doc 0) 2853 ;; Insert non-FREE software list
2848 changedp t)) 2854 (when (string-match "^\\(\\s-*\\)[\\\\][\\\\]NONFREE\\s-*\n" doc 0)
2849 2855 (setq doc (replace-match (sql-help-list-products (match-string 1 doc) nil)
2850 ;; Insert non-FREE software list 2856 t t doc 0)))
2851 (when (string-match "^\\(\\s-*\\)[\\\\][\\\\]NONFREE\\s-*\n" doc 0) 2857 doc)
2852 (setq doc (replace-match (sql-help-list-products (match-string 1 doc) nil)
2853 t t doc 0)
2854 changedp t))
2855
2856 ;; If we changed the help text, save the change so that the help
2857 ;; sub-system will see it
2858 (when changedp
2859 (put 'sql-help 'function-documentation doc)))
2860
2861 ;; Call help on this function
2862 (describe-function 'sql-help))
2863 2858
2864(defun sql-read-passwd (prompt &optional default) 2859(defun sql-read-passwd (prompt &optional default)
2865 "Read a password using PROMPT. Optional DEFAULT is password to start with." 2860 "Read a password using PROMPT. Optional DEFAULT is password to start with."