Skip to content

Commit

Permalink
Various fixes for Emacs 21.
Browse files Browse the repository at this point in the history
Ignore-this: caae466ff29882fa42f44e081d0a8909

darcs-hash:20091105211507-d4134-9760a383d1bd0d15501d223cbf334798f59ed80d.gz
  • Loading branch information
loveshack committed Nov 5, 2009
1 parent b9769ec commit 748ee94
Show file tree
Hide file tree
Showing 7 changed files with 89 additions and 7 deletions.
5 changes: 5 additions & 0 deletions README
Expand Up @@ -25,6 +25,11 @@ Otherwise:
- Download and unpack the basic mode and modules into a suitable directory,
e.g. ~/lib/emacs/haskell-mode/ where ~ stands for your home directory.

- If you are using Emacs 21, you need an additional library, "syntax", from
a later version of Emacs. The one you can get as
http://cvs.savannah.gnu.org/viewcvs/*checkout*/emacs/emacs/lisp/emacs-lisp/syntax.el?rev=1.16
definitely works.

- Assuming you have placed the basic mode haskell-mode.el and the modules
you want to use in the directory ~/lib/emacs/haskell-mode/, add the
following command to your init file (~/.emacs):
Expand Down
1 change: 1 addition & 0 deletions haskell-cabal.el
Expand Up @@ -124,6 +124,7 @@
(setq root nil))))
nil)))

(autoload 'derived-mode-p "derived") ; Emacs 21

(defun haskell-cabal-buffers-clean (&optional buffer)
(let ((bufs ()))
Expand Down
23 changes: 22 additions & 1 deletion haskell-decl-scan.el
Expand Up @@ -128,6 +128,7 @@
;;; Code:

(require 'haskell-mode)
(require 'syntax nil t) ; Emacs 21 add-on

;;###autoload
;; As `cl' defines macros that `imenu' uses, we must require them at
Expand All @@ -136,7 +137,27 @@
(require 'cl)
(condition-case nil
(require 'imenu)
(error nil)))
(error nil))
;; It makes a big difference if we don't copy the syntax table here,
;; as Emacs 21 does, but Emacs 22 doesn't.
(unless (eq (syntax-table)
(with-syntax-table (syntax-table) (syntax-table)))
(defmacro with-syntax-table (table &rest body)
"Evaluate BODY with syntax table of current buffer set to a copy of TABLE.
The syntax table of the current buffer is saved, BODY is evaluated, and the
saved table is restored, even in case of an abnormal exit.
Value is what BODY returns."
(let ((old-table (make-symbol "table"))
(old-buffer (make-symbol "buffer")))
`(let ((,old-table (syntax-table))
(,old-buffer (current-buffer)))
(unwind-protect
(progn
(set-syntax-table ,table)
,@body)
(save-current-buffer
(set-buffer ,old-buffer)
(set-syntax-table ,old-table))))))))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; General declaration scanning functions.
Expand Down
37 changes: 35 additions & 2 deletions haskell-doc.el
Expand Up @@ -535,6 +535,37 @@ Each element is of the form (ID . DOC) where both ID and DOC are strings.
DOC should be a concise single-line string describing the construct in which
the keyword is used.")

(eval-and-compile
(defalias 'haskell-doc-split-string
(if (condition-case ()
(split-string "" nil t)
(wrong-number-of-arguments nil))
'split-string
;; copied from Emacs 22
(lambda (string &optional separators omit-nulls)
(let ((keep-nulls (not (if separators omit-nulls t)))
(rexp (or separators "[ \f\t\n\r\v]+"))
(start 0)
notfirst
(list nil))
(while (and (string-match rexp string
(if (and notfirst
(= start (match-beginning 0))
(< start (length string)))
(1+ start) start))
(< start (length string)))
(setq notfirst t)
(if (or keep-nulls (< start (match-beginning 0)))
(setq list
(cons (substring string start (match-beginning 0))
list)))
(setq start (match-end 0)))
(if (or keep-nulls (< start (length string)))
(setq list
(cons (substring string start)
list)))
(nreverse list))))))

;;@cindex haskell-doc-prelude-types

(defun haskell-doc-extract-types (url)
Expand Down Expand Up @@ -648,7 +679,7 @@ the keyword is used.")
;; module vars)
nil)
(setq curclass nil))
(dolist (var (split-string vars comma-re t))
(dolist (var (haskell-doc-split-string vars comma-re t))
(if (string-match "(.*)" var) (setq var (substring var 1 -1)))
(push (cons var type) elems))))
;; A datatype decl.
Expand All @@ -669,7 +700,7 @@ the keyword is used.")
(if (string-match ",\\'" type)
(setq type (substring type 0 -1)))
(setq type (concat name " -> " type))
(dolist (var (split-string vars comma-re t))
(dolist (var (haskell-doc-split-string vars comma-re t))
(if (string-match "(.*)" var)
(setq var (substring var 1 -1)))
(push (cons var type) elems))))))))
Expand Down Expand Up @@ -1516,6 +1547,8 @@ function. Only the user interface is different."

;;@cindex haskell-doc-show-type

(require 'syntax-ppss nil t) ; possible add-on in Emacs 21

(defun haskell-doc-in-code-p ()
(not (or (and (eq haskell-literate 'bird)
;; Copied from haskell-indent-bolp.
Expand Down
9 changes: 8 additions & 1 deletion haskell-font-lock.el
Expand Up @@ -230,13 +230,20 @@ Regexp match data 0 points to the chars."
;; Return nil because we're not adding any face property.
nil)

(unless (fboundp 'char-displayable-p)
(require 'latin1-disp nil t))

(defun haskell-font-lock-symbols-keywords ()
(when (fboundp 'compose-region)
(let ((alist nil))
(dolist (x haskell-font-lock-symbols-alist)
(when (and (if (fboundp 'char-displayable-p)
(char-displayable-p (if (consp (cdr x)) (cadr x) (cdr x)))
t)
(if (fboundp 'latin1-char-displayable-p)
(latin1-char-displayable-p (if (consp (cdr x))
(cadr x)
(cdr x)))
t))
(not (assoc (car x) alist))) ;Not yet in alist.
(push x alist)))
(when alist
Expand Down
4 changes: 3 additions & 1 deletion haskell-indentation.el
Expand Up @@ -35,6 +35,8 @@

;;; Code:

(require 'syntax nil t) ; Emacs 21 add-on

(defgroup haskell-indentation nil
"Haskell indentation."
:group 'haskell
Expand Down Expand Up @@ -265,7 +267,7 @@ Preserves indentation and removes extra whitespace"
(haskell-indentation-next-indentation
-1
(haskell-indentation-find-indentations))))
((not (eql (point) haskell-indent-last-position))
((not (equal (point) haskell-indent-last-position))
(message "Press TAB again to go to the leftmost indentation")
(setq haskell-indent-last-position (point)))
(t
Expand Down
17 changes: 15 additions & 2 deletions haskell-mode.el
Expand Up @@ -158,6 +158,13 @@
;;; Code:

(eval-when-compile (require 'cl))
(eval-when-compile
;; Emacs 21 defines `values' as a (run-time) alias for list.
;; Don't maerge this with the pervious clause.
(if (string-match "values"
(pp (byte-compile (lambda () (values t)))))
(defsubst values (&rest values)
values)))

;; All functions/variables start with `(literate-)haskell-'.

Expand Down Expand Up @@ -385,8 +392,14 @@ May return a qualified name."
"Hook run after entering Haskell mode.
Do not select more than one of the three indentation modes."
:type 'hook
:options '(turn-on-haskell-indent turn-on-haskell-indentation turn-on-font-lock turn-on-eldoc-mode
turn-on-simple-indent turn-on-haskell-doc-mode imenu-add-menubar-index))
:group 'haskell
:options `(turn-on-haskell-indent turn-on-haskell-indentation
turn-on-font-lock
,(if (boundp 'eldoc-documentation-function)
'turn-on-eldoc-mode
'turn-on-haskell-doc-mode) ; Emacs 21
turn-on-simple-indent turn-on-haskell-doc-mode
imenu-add-menubar-index))

(defvar eldoc-print-current-symbol-info-function)

Expand Down

0 comments on commit 748ee94

Please sign in to comment.