mirror of
				https://github.com/ruby/ruby.git
				synced 2022-11-09 12:17:21 -05:00 
			
		
		
		
	ruby-additional.el: set encoding
* misc/ruby-additional.el (ruby-mode-set-encoding): now encoding needs to be set always explicitly actually. [Feature #6679] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37533 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
		
							parent
							
								
									bd9b31e557
								
							
						
					
					
						commit
						1c5104ac9c
					
				
					 2 changed files with 46 additions and 0 deletions
				
			
		| 
						 | 
				
			
			@ -56,4 +56,45 @@
 | 
			
		|||
      (interactive)
 | 
			
		||||
      (or (ruby-brace-to-do-end)
 | 
			
		||||
	  (ruby-do-end-to-brace)))
 | 
			
		||||
 | 
			
		||||
    (defun ruby-mode-set-encoding ()
 | 
			
		||||
      "Insert a magic comment header with the proper encoding always.
 | 
			
		||||
Now encoding needs to be set always explicitly actually."
 | 
			
		||||
      (save-excursion
 | 
			
		||||
	(let ((coding-system))
 | 
			
		||||
	  (widen)
 | 
			
		||||
	  (goto-char (point-min))
 | 
			
		||||
	  (if (re-search-forward "[^\0-\177]" nil t)
 | 
			
		||||
	      (progn
 | 
			
		||||
		(goto-char (point-min))
 | 
			
		||||
		(set coding-system
 | 
			
		||||
		     (or coding-system-for-write
 | 
			
		||||
			 buffer-file-coding-system))
 | 
			
		||||
		(if coding-system
 | 
			
		||||
		    (setq coding-system
 | 
			
		||||
			  (or (coding-system-get coding-system 'mime-charset)
 | 
			
		||||
			      (coding-system-change-eol-conversion coding-system nil))))
 | 
			
		||||
		(setq coding-system
 | 
			
		||||
		      (if coding-system
 | 
			
		||||
			  (symbol-name
 | 
			
		||||
			   (or (and ruby-use-encoding-map
 | 
			
		||||
				    (cdr (assq coding-system ruby-encoding-map)))
 | 
			
		||||
			       coding-system))
 | 
			
		||||
			"ascii-8bit")))
 | 
			
		||||
	    (setq coding-system "us-ascii"))
 | 
			
		||||
	  (if (looking-at "^#!") (beginning-of-line 2))
 | 
			
		||||
	  (cond ((looking-at "\\s *#.*-\*-\\s *\\(en\\)?coding\\s *:\\s *\\([-a-z0-9_]*\\)\\s *\\(;\\|-\*-\\)")
 | 
			
		||||
		 (unless (string= (match-string 2) coding-system)
 | 
			
		||||
		   (goto-char (match-beginning 2))
 | 
			
		||||
		   (delete-region (point) (match-end 2))
 | 
			
		||||
		   (and (looking-at "-\*-")
 | 
			
		||||
			(let ((n (skip-chars-backward " ")))
 | 
			
		||||
			  (cond ((= n 0) (insert "  ") (backward-char))
 | 
			
		||||
				((= n -1) (insert " "))
 | 
			
		||||
				((forward-char)))))
 | 
			
		||||
		   (insert coding-system)))
 | 
			
		||||
		((looking-at "\\s *#.*coding\\s *[:=]"))
 | 
			
		||||
		(t (when ruby-insert-encoding-magic-comment
 | 
			
		||||
		     (insert "# -*- coding: " coding-system " -*-\n")))))))
 | 
			
		||||
 | 
			
		||||
    ))
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue