branch: elpa/go-mode
commit 58b0c3dfc87f5ae4137ea498dc0e03adc9eeb751
Author: Dominik Honnef <domi...@honnef.co>
Commit: Dominik Honnef <domi...@honnef.co>

    Add a basic mode for Go assembly
    
    Updates: gh-445
---
 go-mode.el | 27 +++++++++++++++++++++++++++
 1 file changed, 27 insertions(+)

diff --git a/go-mode.el b/go-mode.el
index e539398e54..a488562993 100644
--- a/go-mode.el
+++ b/go-mode.el
@@ -3089,6 +3089,33 @@ This handles multi-line comments with a * prefix on each 
line."
     (call-interactively #'lsp-rename))
    (error "buffer is not managed by a known LSP client")))
 
+;;;###autoload
+(define-derived-mode go-asm-mode asm-mode "Go assembly"
+  "Major mode for Go assembly (.s) files."
+  (set (make-local-variable 'comment-start) "// ")
+  (set (make-local-variable 'comment-end)   "")
+  (set (make-local-variable 'comment-use-syntax) t)
+  (set (make-local-variable 'comment-start-skip) "\\(//+\\)\\s *")
+  (setq indent-tabs-mode t))
+
+;;;###autoload
+(add-to-list 'magic-mode-alist (cons #'go--is-go-asm #'go-asm-mode))
+
+;;;###autoload
+(defun go--is-go-asm ()
+  "Determine whether a file is (probably) a Go assembly file."
+  (when (string-suffix-p ".s" (buffer-file-name))
+       (let ((directory (file-name-directory (buffer-file-name))))
+         (when directory
+               (cl-some (lambda (s) (or (string-suffix-p ".go" s) 
(string-suffix-p ".mod" s)))
+                                (condition-case nil
+                                        ;; We only look at 8192 files, to 
avoid heavy I/O in
+                                        ;; case the user opens a .s file in a 
giant directory.
+                                        ;; If it weren't for that, we could 
set the count to 1
+                                        ;; and use the 'match' argument of 
directory-files to
+                                        ;; look for the first '.go' file.
+                                        (directory-files directory nil nil t 
8192)
+                                  (error nil)))))))
 
 (provide 'go-mode)
 

Reply via email to