Skip to content

Commit b2d9cca

Browse files
committed
Fix small bugs
Make compatible with Emacs 24.4. Other bugs.
1 parent fa4f491 commit b2d9cca

File tree

2 files changed

+32
-19
lines changed

2 files changed

+32
-19
lines changed

swift-mode-beginning-of-defun.el

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -512,7 +512,8 @@ If the point is between defuns, narrow depend on
512512
513513
Preceding comments are included if INCLUDE-COMMENTS is non-nil.
514514
Interactively, the behavior depends on ‘narrow-to-defun-include-comments’."
515-
(interactive (list narrow-to-defun-include-comments))
515+
(interactive (list (and (boundp 'narrow-to-defun-include-comments)
516+
narrow-to-defun-include-comments)))
516517
(let ((region (swift-mode:narrow-to-generic-block
517518
include-comments
518519
#'swift-mode:end-of-defun
@@ -795,7 +796,7 @@ Otherwise, try to mark the following one."
795796
(funcall move-backward)
796797
(when (/= start (point))
797798
(throw 'swift-mode:found-block
798-
(list (cons start end)) 'containing))))))
799+
(list (cons start end) 'containing)))))))
799800
(list (cons (point-min) (point-max)) 'containing)))))))
800801

801802
(defun swift-mode:extend-region-with-spaces (region)
@@ -1341,7 +1342,8 @@ If the point is between sentences, narrow depend on
13411342
13421343
Preceding comments are included if INCLUDE-COMMENTS is non-nil.
13431344
Interactively, the behavior depends on ‘narrow-to-defun-include-comments’."
1344-
(interactive (list narrow-to-defun-include-comments))
1345+
(interactive (list (and (boundp 'narrow-to-defun-include-comments)
1346+
narrow-to-defun-include-comments)))
13451347
(let ((region (swift-mode:narrow-to-generic-block
13461348
include-comments
13471349
#'swift-mode:forward-sentence
@@ -1442,7 +1444,7 @@ of ancestors."
14421444

14431445
;; Ignored: "import" "get" "set" "willSet" "didSet"
14441446
(t nil))))
1445-
(if (eq (swift-mode:token:type name-token) identifier)
1447+
(if (eq (swift-mode:token:type name-token) 'identifier)
14461448
name-token
14471449
nil)))
14481450

swift-mode-imenu.el

Lines changed: 26 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,7 @@ names."
103103
"Scan declarations from current point.
104104
105105
Return found declarations in reverse order."
106-
(let (previous-token
107-
next-token
106+
(let (next-token
108107
next-type
109108
next-text
110109
name-token
@@ -320,6 +319,16 @@ TYPE is one of `case', `let', or `var'."
320319
items))
321320

322321
(defun swift-mode:scan-function-name-and-parameter-names ()
322+
"Parse function name and parameter names.
323+
324+
The point is assumed to be before a function name.
325+
326+
Return tokens of function names and parameter names.
327+
328+
For example, given the following code, this return tokens \"foo\", \"a\",
329+
and \"c\".
330+
331+
func foo(a b: Int, c: Int)"
323332
(let* ((name-token
324333
(swift-mode:forward-token-or-list-except-curly-bracket))
325334
next-token
@@ -368,19 +377,21 @@ TYPE is one of `case', `let', or `var'."
368377
"Convert list of DECLARATIONS to alist for `imenu--index-alist'.
369378
370379
Declarations are organized as trees."
371-
(mapcan
372-
(lambda (declaration)
373-
(let* ((name-token (swift-mode:declaration:name-token declaration))
374-
(name (swift-mode:token:text name-token))
375-
(position (swift-mode:token:start name-token))
376-
(children (swift-mode:declaration:children declaration)))
377-
(cons
378-
(cons name position)
379-
(mapcar
380-
(lambda (pair)
381-
(cons (concat name "." (car pair)) (cdr pair)))
382-
(swift-mode:format-for-imenu:flat children)))))
383-
declarations))
380+
(apply
381+
'nconc
382+
(mapcar
383+
(lambda (declaration)
384+
(let* ((name-token (swift-mode:declaration:name-token declaration))
385+
(name (swift-mode:token:text name-token))
386+
(position (swift-mode:token:start name-token))
387+
(children (swift-mode:declaration:children declaration)))
388+
(cons
389+
(cons name position)
390+
(mapcar
391+
(lambda (pair)
392+
(cons (concat name "." (car pair)) (cdr pair)))
393+
(swift-mode:format-for-imenu:flat children)))))
394+
declarations)))
384395

385396
(defun swift-mode:format-for-imenu:nested (declarations)
386397
"Convert list of DECLARATIONS to alist for `imenu--index-alist'.

0 commit comments

Comments
 (0)