aboutsummaryrefslogtreecommitdiffstats
path: root/lisp/progmodes
diff options
context:
space:
mode:
authorLeo Liu2013-05-21 17:43:14 +0800
committerLeo Liu2013-05-21 17:43:14 +0800
commit9cc3e83f9db0958931b358cda25741459fb733c5 (patch)
tree9a4785e1304968c9a98272d40ff157229b473ee8 /lisp/progmodes
parentf440830d606632693e41c26890ba54f31c57b22a (diff)
downloademacs-9cc3e83f9db0958931b358cda25741459fb733c5.tar.gz
emacs-9cc3e83f9db0958931b358cda25741459fb733c5.zip
Simplify auto fill in Octave mode and some small improvements
Diffstat (limited to 'lisp/progmodes')
-rw-r--r--lisp/progmodes/octave.el113
1 files changed, 29 insertions, 84 deletions
diff --git a/lisp/progmodes/octave.el b/lisp/progmodes/octave.el
index 4f1e6c2cc14..76172d5b59a 100644
--- a/lisp/progmodes/octave.el
+++ b/lisp/progmodes/octave.el
@@ -540,11 +540,11 @@ definitions can also be stored in files and used in batch mode."
540 (setq-local paragraph-separate paragraph-start) 540 (setq-local paragraph-separate paragraph-start)
541 (setq-local paragraph-ignore-fill-prefix t) 541 (setq-local paragraph-ignore-fill-prefix t)
542 (setq-local fill-paragraph-function 'octave-fill-paragraph) 542 (setq-local fill-paragraph-function 'octave-fill-paragraph)
543 ;; FIXME: Why disable it? 543
544 ;; (setq-local adaptive-fill-regexp nil) 544 ;; Use `smie-auto-fill' after fixing bug#14381.
545 ;; Again, this is not a property of the language, don't set it here. 545 (setq-local normal-auto-fill-function 'do-auto-fill)
546 ;; (setq fill-column 72) 546 (setq-local fill-nobreak-predicate #'octave-in-string-p)
547 (setq-local normal-auto-fill-function 'octave-auto-fill) 547 (setq-local comment-line-break-function #'octave-indent-new-comment-line)
548 548
549 (setq font-lock-defaults '(octave-font-lock-keywords)) 549 (setq font-lock-defaults '(octave-font-lock-keywords))
550 550
@@ -946,7 +946,7 @@ directory and makes this the current buffer's default directory."
946 (or done (goto-char (point-min))))))) 946 (or done (goto-char (point-min)))))))
947 (pcase (file-name-extension (buffer-file-name)) 947 (pcase (file-name-extension (buffer-file-name))
948 (`"cc" (funcall search 948 (`"cc" (funcall search
949 "\\_<DEFUN\\s-*(\\s-*\\(\\(?:\\sw\\|\\s_\\)+\\)" 1)) 949 "\\_<DEFUN\\(?:_DLD\\)?\\s-*(\\s-*\\(\\(?:\\sw\\|\\s_\\)+\\)" 1))
950 (t (funcall search octave-function-header-regexp 3))))) 950 (t (funcall search octave-function-header-regexp 3)))))
951 951
952(defun octave-function-file-p () 952(defun octave-function-file-p ()
@@ -1100,21 +1100,25 @@ q: Don't fix\n" func file))
1100 1100
1101;;; Indentation 1101;;; Indentation
1102 1102
1103(defun octave-indent-new-comment-line () 1103(defun octave-indent-new-comment-line (&optional soft)
1104 "Break Octave line at point, continuing comment if within one. 1104 "Break Octave line at point, continuing comment if within one.
1105If within code, insert `octave-continuation-string' before breaking the 1105Insert `octave-continuation-string' before breaking the line
1106line. If within a string, signal an error. 1106unless inside a list. Signal an error if within a single-quoted
1107The new line is properly indented." 1107string."
1108 (interactive) 1108 (interactive)
1109 (delete-horizontal-space)
1110 (cond 1109 (cond
1111 ((octave-in-comment-p) 1110 ((octave-in-comment-p) nil)
1112 (indent-new-comment-line)) 1111 ((eq (octave-in-string-p) ?')
1113 ((octave-in-string-p) 1112 (error "Cannot split a single-quoted string"))
1114 (error "Cannot split a code line inside a string")) 1113 ((eq (octave-in-string-p) ?\")
1114 (insert octave-continuation-string))
1115 (t 1115 (t
1116 (insert (concat " " octave-continuation-string)) 1116 (delete-horizontal-space)
1117 (reindent-then-newline-and-indent)))) 1117 (unless (and (cadr (syntax-ppss))
1118 (eq (char-after (cadr (syntax-ppss))) ?\())
1119 (insert " " octave-continuation-string))))
1120 (indent-new-comment-line soft)
1121 (indent-according-to-mode))
1118 1122
1119(define-obsolete-function-alias 1123(define-obsolete-function-alias
1120 'octave-indent-defun 'prog-indent-sexp "24.4") 1124 'octave-indent-defun 'prog-indent-sexp "24.4")
@@ -1224,71 +1228,9 @@ The block marked is the one that contains point or follows point."
1224 (when (and (> arg 0) (/= orig (point))) 1228 (when (and (> arg 0) (/= orig (point)))
1225 (setq arg (1- arg))) 1229 (setq arg (1- arg)))
1226 (forward-sexp (- arg)) 1230 (forward-sexp (- arg))
1231 (and (< arg 0) (forward-sexp -1))
1227 (/= orig (point)))) 1232 (/= orig (point))))
1228 1233
1229
1230;;; Filling
1231(defun octave-auto-fill ()
1232 "Perform auto-fill in Octave mode.
1233Returns nil if no feasible place to break the line could be found, and t
1234otherwise."
1235 (let (fc give-up)
1236 (if (or (null (setq fc (current-fill-column)))
1237 (save-excursion
1238 (beginning-of-line)
1239 (and auto-fill-inhibit-regexp
1240 (octave-looking-at-kw auto-fill-inhibit-regexp))))
1241 nil ; Can't do anything
1242 (if (and (not (octave-in-comment-p))
1243 (> (current-column) fc))
1244 (setq fc (- fc (+ (length octave-continuation-string) 1))))
1245 (while (and (not give-up) (> (current-column) fc))
1246 (let* ((opoint (point))
1247 (fpoint
1248 (save-excursion
1249 (move-to-column (+ fc 1))
1250 (skip-chars-backward "^ \t\n")
1251 ;; If we're at the beginning of the line, break after
1252 ;; the first word
1253 (if (bolp)
1254 (re-search-forward "[ \t]" opoint t))
1255 ;; If we're in a comment line, don't break after the
1256 ;; comment chars
1257 (if (save-excursion
1258 (skip-syntax-backward " <")
1259 (bolp))
1260 (re-search-forward "[ \t]" (line-end-position)
1261 'move))
1262 ;; If we're not in a comment line and just ahead the
1263 ;; continuation string, don't break here.
1264 (if (and (not (octave-in-comment-p))
1265 (looking-at
1266 (concat "\\s-*"
1267 (regexp-quote
1268 octave-continuation-string)
1269 "\\s-*$")))
1270 (end-of-line))
1271 (skip-chars-backward " \t")
1272 (point))))
1273 (if (save-excursion
1274 (goto-char fpoint)
1275 (not (or (bolp) (eolp))))
1276 (let ((prev-column (current-column)))
1277 (if (save-excursion
1278 (skip-chars-backward " \t")
1279 (= (point) fpoint))
1280 (progn
1281 (octave-maybe-insert-continuation-string)
1282 (indent-new-comment-line t))
1283 (save-excursion
1284 (goto-char fpoint)
1285 (octave-maybe-insert-continuation-string)
1286 (indent-new-comment-line t)))
1287 (if (>= (current-column) prev-column)
1288 (setq give-up t)))
1289 (setq give-up t))))
1290 (not give-up))))
1291
1292(defun octave-fill-paragraph (&optional _arg) 1234(defun octave-fill-paragraph (&optional _arg)
1293 "Fill paragraph of Octave code, handling Octave comments." 1235 "Fill paragraph of Octave code, handling Octave comments."
1294 ;; FIXME: difference with generic fill-paragraph: 1236 ;; FIXME: difference with generic fill-paragraph:
@@ -1354,11 +1296,10 @@ otherwise."
1354 (and (= (current-column) cfc) (eolp))) 1296 (and (= (current-column) cfc) (eolp)))
1355 (forward-line 1) 1297 (forward-line 1)
1356 (if (not (eolp)) (insert " ")) 1298 (if (not (eolp)) (insert " "))
1357 (or (octave-auto-fill) 1299 (or (do-auto-fill)
1358 (forward-line 1)))) 1300 (forward-line 1))))
1359 t))) 1301 t)))
1360 1302
1361
1362;;; Completions 1303;;; Completions
1363 1304
1364(defun octave-completion-at-point () 1305(defun octave-completion-at-point ()
@@ -1658,10 +1599,14 @@ if ismember(exist(\"%s\"), [2 3 5 103]) print_usage(\"%s\") endif\n"
1658 (when (re-search-forward "from the file \\(.*\\)$" 1599 (when (re-search-forward "from the file \\(.*\\)$"
1659 (line-end-position) 1600 (line-end-position)
1660 t) 1601 t)
1661 (let ((file (match-string 1))) 1602 (let* ((file (match-string 1))
1603 (dir (file-name-directory
1604 (directory-file-name (file-name-directory file)))))
1662 (replace-match "" nil nil nil 1) 1605 (replace-match "" nil nil nil 1)
1663 (insert "`") 1606 (insert "`")
1664 (help-insert-xref-button (file-name-nondirectory file) 1607 ;; Include the parent directory which may be regarded as
1608 ;; the category for the FN.
1609 (help-insert-xref-button (file-relative-name file dir)
1665 'octave-help-file fn) 1610 'octave-help-file fn)
1666 (insert "'"))) 1611 (insert "'")))
1667 ;; Make 'See also' clickable 1612 ;; Make 'See also' clickable