patch 8.2.3399: Octave files are not recognized

Problem:    Octave files are not recognized.
Solution:   Detect Octave files. (Doug Kearns)
diff --git a/runtime/autoload/dist/ft.vim b/runtime/autoload/dist/ft.vim
index ac80659..48a9657 100644
--- a/runtime/autoload/dist/ft.vim
+++ b/runtime/autoload/dist/ft.vim
@@ -264,6 +264,13 @@
 endfunc
 
 func dist#ft#FTm()
+  if exists("g:filetype_m")
+    exe "setf " . g:filetype_m
+    return
+  endif
+
+  let octave_block_terminators = '\<end\%(_try_catch\|classdef\|enumeration\|events\|for\|function\|if\|methods\|parfor\|properties\|switch\|while\)\>'
+
   let n = 1
   let saw_comment = 0 " Whether we've seen a multiline comment leader.
   while n < 100
@@ -278,6 +285,13 @@
       setf objc
       return
     endif
+    if line =~ '^\s*\%(#\|%!\|[#%]{\=\s*$\)' ||
+	  \ line =~ '^\s*unwind_protect\>' ||
+	  \ line =~ '\%(^\|;\)\s*' .. octave_block_terminators
+      setf octave
+      return
+    endif
+    " TODO: could be Matlab or Octave
     if line =~ '^\s*%'
       setf matlab
       return
@@ -298,11 +312,8 @@
     " or Murphi based on the comment leader. Assume the former as it is more
     " common.
     setf objc
-  elseif exists("g:filetype_m")
-    " Use user specified default filetype for .m
-    exe "setf " . g:filetype_m
   else
-    " Default is matlab
+    " Default is Matlab
     setf matlab
   endif
 endfunc
diff --git a/runtime/doc/filetype.txt b/runtime/doc/filetype.txt
index 8295d67..75e9679 100644
--- a/runtime/doc/filetype.txt
+++ b/runtime/doc/filetype.txt
@@ -146,6 +146,7 @@
 	*.inc		g:filetype_inc
 	*.w		g:filetype_w	|ft-cweb-syntax|
 	*.i		g:filetype_i	|ft-progress-syntax|
+	*.m		g:filetype_m	|ft-mathematica-syntax|
 	*.p		g:filetype_p	|ft-pascal-syntax|
 	*.pp		g:filetype_pp	|ft-pascal-syntax|
 	*.sh		g:bash_is_sh	|ft-sh-syntax|
diff --git a/runtime/filetype.vim b/runtime/filetype.vim
index 06038e9..0975ccd 100644
--- a/runtime/filetype.vim
+++ b/runtime/filetype.vim
@@ -1029,7 +1029,7 @@
 " Mason
 au BufNewFile,BufRead *.mason,*.mhtml,*.comp	setf mason
 
-" Mathematica, Matlab, Murphi or Objective C
+" Mathematica, Matlab, Murphi, Objective C or Octave
 au BufNewFile,BufRead *.m			call dist#ft#FTm()
 
 " Mathematica notebook
@@ -1175,6 +1175,9 @@
 " Occam
 au BufNewFile,BufRead *.occ			setf occam
 
+" Octave
+au BufNewFile,BufRead octave.conf,.octaverc,octaverc	setf octave
+
 " Omnimark
 au BufNewFile,BufRead *.xom,*.xin		setf omnimark