octave-expansions.el (3020B)
1 ;;; octave-expansions.el --- octave-mode expansions for expand-region -*- lexical-binding: t; -*- 2 3 ;; Copyright (C) 2012-2023 Free Software Foundation, Inc 4 5 ;; Author: Mark Hepburn 6 ;; Keywords: marking region 7 8 ;; This program is free software; you can redistribute it and/or modify 9 ;; it under the terms of the GNU General Public License as published by 10 ;; the Free Software Foundation, either version 3 of the License, or 11 ;; (at your option) any later version. 12 13 ;; This program is distributed in the hope that it will be useful, 14 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of 15 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 ;; GNU General Public License for more details. 17 18 ;; You should have received a copy of the GNU General Public License 19 ;; along with this program. If not, see <http://www.gnu.org/licenses/>. 20 21 ;;; Commentary: 22 23 ;; Feel free to contribute any other expansions for Octave at 24 ;; 25 ;; https://github.com/magnars/expand-region.el 26 27 ;;; Code: 28 29 (require 'expand-region-core) 30 (declare-function octave-mark-block "octave-mod") 31 32 ;;; Octave-mod received a major rewrite between versions 23 and 24 of 33 ;;; Emacs, for example using the new smie package instead of 34 ;;; hand-coding a lot of motion commands. Unfortunately for our 35 ;;; purposes here, in the process the behaviour of `octave-mark-block' 36 ;;; changed slightly. So, in order to behave identically across both 37 ;;; versions we need to check which is which in a few places and 38 ;;; adjust accordingly: 39 (defconst er/old-octave-mod-p (fboundp 'octave-up-block)) 40 41 (defalias 'er/up-block 42 (if er/old-octave-mod-p 'octave-up-block 'up-list)) 43 44 (defun er/octave-mark-up-block () 45 "Mark the containing block, assuming the current block has 46 already been marked." 47 (interactive) 48 (when (use-region-p) 49 (when (< (point) (mark)) 50 (exchange-point-and-mark)) 51 (er/up-block -1) ; -1 means backwards, ie to the front 52 (octave-mark-block))) 53 54 (defun er/octave-mark-block () 55 "Not for general use; this is a work-around for the different 56 behaviour of `octave-mark-block' between emacs versions 23 and 57 24." 58 (interactive) 59 (forward-word) 60 (octave-mark-block)) 61 62 (defun er/add-octave-expansions () 63 "Adds octave/matlab-specific expansions for buffers in octave-mode" 64 (let ((try-expand-list-additions (if er/old-octave-mod-p 65 '(octave-mark-block 66 er/octave-mark-up-block 67 octave-mark-defun) 68 '(octave-mark-block 69 er/octave-mark-block 70 er/octave-mark-up-block 71 mark-defun)))) 72 (set (make-local-variable 'er/try-expand-list) 73 (append er/try-expand-list try-expand-list-additions)))) 74 75 (er/enable-mode-expansions 'octave-mode #'er/add-octave-expansions) 76 77 (provide 'octave-expansions) 78 ;;; octave-expansions.el ends here